Skip to content

Commit 3a58179

Browse files
authored
Update ios to use new YUVA texture SkImage factory (flutter#23153)
1 parent d193a60 commit 3a58179

File tree

2 files changed

+32
-40
lines changed

2 files changed

+32
-40
lines changed

shell/platform/darwin/ios/ios_external_texture_gl.mm

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
#import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
1212
#include "third_party/skia/include/core/SkSurface.h"
13-
#include "third_party/skia/include/core/SkYUVAIndex.h"
13+
#include "third_party/skia/include/core/SkYUVAInfo.h"
1414
#include "third_party/skia/include/gpu/GrBackendSurface.h"
1515
#include "third_party/skia/include/gpu/GrDirectContext.h"
16-
#include "third_party/skia/src/gpu/gl/GrGLDefines.h"
16+
#include "third_party/skia/include/gpu/GrYUVABackendTextures.h"
1717

1818
namespace flutter {
1919

@@ -108,27 +108,20 @@
108108

109109
sk_sp<SkImage> IOSExternalTextureGL::CreateImageFromYUVTextures(GrDirectContext* context,
110110
const SkRect& bounds) {
111+
GrBackendTexture textures[2];
111112
GrGLTextureInfo yTextureInfo = {CVOpenGLESTextureGetTarget(y_texture_ref_),
112-
CVOpenGLESTextureGetName(y_texture_ref_), GR_GL_LUMINANCE8};
113-
GrBackendTexture yBackendTexture(bounds.width(), bounds.height(), GrMipMapped::kNo, yTextureInfo);
113+
CVOpenGLESTextureGetName(y_texture_ref_), GL_LUMINANCE8_EXT};
114+
textures[0] = GrBackendTexture(bounds.width(), bounds.height(), GrMipMapped::kNo, yTextureInfo);
114115
GrGLTextureInfo uvTextureInfo = {CVOpenGLESTextureGetTarget(uv_texture_ref_),
115-
CVOpenGLESTextureGetName(uv_texture_ref_), GR_GL_RGBA8};
116-
GrBackendTexture uvBackendTexture(bounds.width(), bounds.height(), GrMipMapped::kNo,
117-
uvTextureInfo);
118-
GrBackendTexture nv12TextureHandles[] = {yBackendTexture, uvBackendTexture};
119-
SkYUVAIndex yuvaIndices[4] = {
120-
SkYUVAIndex{0, SkColorChannel::kR}, // Read Y data from the red channel of the first texture
121-
SkYUVAIndex{1, SkColorChannel::kR}, // Read U data from the red channel of the second texture
122-
SkYUVAIndex{
123-
1, SkColorChannel::kA}, // Read V data from the alpha channel of the second texture,
124-
// normal NV12 data V should be taken from the green channel, but
125-
// currently only the uv texture created by GL_LUMINANCE_ALPHA
126-
// can be used, so the V value is taken from the alpha channel
127-
SkYUVAIndex{-1, SkColorChannel::kA}}; //-1 means to omit the alpha data of YUVA
128-
SkISize size{yBackendTexture.width(), yBackendTexture.height()};
129-
sk_sp<SkImage> image = SkImage::MakeFromYUVATextures(
130-
context, kRec601_SkYUVColorSpace, nv12TextureHandles, yuvaIndices, size,
131-
kTopLeft_GrSurfaceOrigin, /*imageColorSpace=*/nullptr);
116+
CVOpenGLESTextureGetName(uv_texture_ref_),
117+
GL_LUMINANCE8_ALPHA8_EXT};
118+
textures[1] = GrBackendTexture(bounds.width(), bounds.height(), GrMipMapped::kNo, uvTextureInfo);
119+
120+
SkYUVAInfo yuvaInfo(textures[0].dimensions(), SkYUVAInfo::PlaneConfig::kY_UV,
121+
SkYUVAInfo::Subsampling::k444, kRec601_SkYUVColorSpace);
122+
GrYUVABackendTextures yuvaBackendTextures(yuvaInfo, textures, kTopLeft_GrSurfaceOrigin);
123+
sk_sp<SkImage> image = SkImage::MakeFromYUVATextures(context, yuvaBackendTextures,
124+
/*imageColorSpace=*/nullptr);
132125
return image;
133126
}
134127

shell/platform/darwin/ios/ios_external_texture_metal.mm

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
#import "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h"
66

77
#include "flutter/fml/logging.h"
8-
#include "third_party/skia/include/core/SkYUVAIndex.h"
8+
#include "third_party/skia/include/core/SkYUVAInfo.h"
99
#include "third_party/skia/include/gpu/GrBackendSurface.h"
1010
#include "third_party/skia/include/gpu/GrDirectContext.h"
11+
#include "third_party/skia/include/gpu/GrYUVABackendTextures.h"
1112
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"
1213

1314
namespace flutter {
@@ -132,28 +133,26 @@
132133
y_skia_texture_info.fTexture = sk_cf_obj<const void*>{
133134
[reinterpret_cast<NSObject*>(CVMetalTextureGetTexture(y_metal_texture)) retain]};
134135

135-
GrBackendTexture y_skia_backend_texture(/*width=*/texture_size.width(),
136-
/*height=*/texture_size.height(),
137-
/*mipMapped=*/GrMipMapped ::kNo,
138-
/*textureInfo=*/y_skia_texture_info);
136+
GrBackendTexture skia_backend_textures[2];
137+
skia_backend_textures[0] = GrBackendTexture(/*width=*/texture_size.width(),
138+
/*height=*/texture_size.height(),
139+
/*mipMapped=*/GrMipMapped ::kNo,
140+
/*textureInfo=*/y_skia_texture_info);
139141

140142
fml::CFRef<CVMetalTextureRef> uv_metal_texture(uv_metal_texture_raw);
141143

142144
GrMtlTextureInfo uv_skia_texture_info;
143145
uv_skia_texture_info.fTexture = sk_cf_obj<const void*>{
144146
[reinterpret_cast<NSObject*>(CVMetalTextureGetTexture(uv_metal_texture)) retain]};
145147

146-
GrBackendTexture uv_skia_backend_texture(/*width=*/texture_size.width(),
147-
/*height=*/texture_size.height(),
148-
/*mipMapped=*/GrMipMapped ::kNo,
149-
/*textureInfo=*/uv_skia_texture_info);
150-
GrBackendTexture nv12TextureHandles[] = {y_skia_backend_texture, uv_skia_backend_texture};
151-
SkYUVAIndex yuvaIndices[4] = {
152-
SkYUVAIndex{0, SkColorChannel::kR}, // Read Y data from the red channel of the first texture
153-
SkYUVAIndex{1, SkColorChannel::kR}, // Read U data from the red channel of the second texture
154-
SkYUVAIndex{1,
155-
SkColorChannel::kG}, // Read V data from the green channel of the second texture
156-
SkYUVAIndex{-1, SkColorChannel::kA}}; //-1 means to omit the alpha data of YUVA
148+
skia_backend_textures[1] = GrBackendTexture(/*width=*/texture_size.width(),
149+
/*height=*/texture_size.height(),
150+
/*mipMapped=*/GrMipMapped ::kNo,
151+
/*textureInfo=*/uv_skia_texture_info);
152+
SkYUVAInfo yuva_info(skia_backend_textures[0].dimensions(), SkYUVAInfo::PlaneConfig::kY_UV,
153+
SkYUVAInfo::Subsampling::k444, kRec601_SkYUVColorSpace);
154+
GrYUVABackendTextures yuva_backend_textures(yuva_info, skia_backend_textures,
155+
kTopLeft_GrSurfaceOrigin);
157156

158157
struct ImageCaptures {
159158
fml::CFRef<CVPixelBufferRef> buffer;
@@ -170,9 +169,9 @@ GrBackendTexture uv_skia_backend_texture(/*width=*/texture_size.width(),
170169
auto captures = reinterpret_cast<ImageCaptures*>(release_context);
171170
delete captures;
172171
};
173-
sk_sp<SkImage> image = SkImage::MakeFromYUVATextures(
174-
context, kRec601_SkYUVColorSpace, nv12TextureHandles, yuvaIndices, texture_size,
175-
kTopLeft_GrSurfaceOrigin, /*imageColorSpace=*/nullptr, release_proc, captures.release());
172+
sk_sp<SkImage> image =
173+
SkImage::MakeFromYUVATextures(context, yuva_backend_textures, /*imageColorSpace=*/nullptr,
174+
release_proc, captures.release());
176175
return image;
177176
}
178177

0 commit comments

Comments
 (0)