From dc25ace13618432ae589bb1f95c154e8c7744727 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Mon, 21 Dec 2020 15:55:05 -0500 Subject: [PATCH] Update ios to use new YUVA texture SkImage factory (flutter/engine#23153) --- .../darwin/ios/ios_external_texture_gl.mm | 35 +++++++----------- .../darwin/ios/ios_external_texture_metal.mm | 37 +++++++++---------- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_external_texture_gl.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_external_texture_gl.mm index 1429add5f2..685c3cbdf4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_external_texture_gl.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_external_texture_gl.mm @@ -10,10 +10,10 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h" #include "third_party/skia/include/core/SkSurface.h" -#include "third_party/skia/include/core/SkYUVAIndex.h" +#include "third_party/skia/include/core/SkYUVAInfo.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" -#include "third_party/skia/src/gpu/gl/GrGLDefines.h" +#include "third_party/skia/include/gpu/GrYUVABackendTextures.h" namespace flutter { @@ -108,27 +108,20 @@ sk_sp IOSExternalTextureGL::CreateImageFromRGBATexture(GrDirectContext* sk_sp IOSExternalTextureGL::CreateImageFromYUVTextures(GrDirectContext* context, const SkRect& bounds) { + GrBackendTexture textures[2]; GrGLTextureInfo yTextureInfo = {CVOpenGLESTextureGetTarget(y_texture_ref_), - CVOpenGLESTextureGetName(y_texture_ref_), GR_GL_LUMINANCE8}; - GrBackendTexture yBackendTexture(bounds.width(), bounds.height(), GrMipMapped::kNo, yTextureInfo); + CVOpenGLESTextureGetName(y_texture_ref_), GL_LUMINANCE8_EXT}; + textures[0] = GrBackendTexture(bounds.width(), bounds.height(), GrMipMapped::kNo, yTextureInfo); GrGLTextureInfo uvTextureInfo = {CVOpenGLESTextureGetTarget(uv_texture_ref_), - CVOpenGLESTextureGetName(uv_texture_ref_), GR_GL_RGBA8}; - GrBackendTexture uvBackendTexture(bounds.width(), bounds.height(), GrMipMapped::kNo, - uvTextureInfo); - GrBackendTexture nv12TextureHandles[] = {yBackendTexture, uvBackendTexture}; - SkYUVAIndex yuvaIndices[4] = { - SkYUVAIndex{0, SkColorChannel::kR}, // Read Y data from the red channel of the first texture - SkYUVAIndex{1, SkColorChannel::kR}, // Read U data from the red channel of the second texture - SkYUVAIndex{ - 1, SkColorChannel::kA}, // Read V data from the alpha channel of the second texture, - // normal NV12 data V should be taken from the green channel, but - // currently only the uv texture created by GL_LUMINANCE_ALPHA - // can be used, so the V value is taken from the alpha channel - SkYUVAIndex{-1, SkColorChannel::kA}}; //-1 means to omit the alpha data of YUVA - SkISize size{yBackendTexture.width(), yBackendTexture.height()}; - sk_sp image = SkImage::MakeFromYUVATextures( - context, kRec601_SkYUVColorSpace, nv12TextureHandles, yuvaIndices, size, - kTopLeft_GrSurfaceOrigin, /*imageColorSpace=*/nullptr); + CVOpenGLESTextureGetName(uv_texture_ref_), + GL_LUMINANCE8_ALPHA8_EXT}; + textures[1] = GrBackendTexture(bounds.width(), bounds.height(), GrMipMapped::kNo, uvTextureInfo); + + SkYUVAInfo yuvaInfo(textures[0].dimensions(), SkYUVAInfo::PlaneConfig::kY_UV, + SkYUVAInfo::Subsampling::k444, kRec601_SkYUVColorSpace); + GrYUVABackendTextures yuvaBackendTextures(yuvaInfo, textures, kTopLeft_GrSurfaceOrigin); + sk_sp image = SkImage::MakeFromYUVATextures(context, yuvaBackendTextures, + /*imageColorSpace=*/nullptr); return image; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_external_texture_metal.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_external_texture_metal.mm index 859022bc0e..48ccc27f25 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_external_texture_metal.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_external_texture_metal.mm @@ -5,9 +5,10 @@ #import "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h" #include "flutter/fml/logging.h" -#include "third_party/skia/include/core/SkYUVAIndex.h" +#include "third_party/skia/include/core/SkYUVAInfo.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" +#include "third_party/skia/include/gpu/GrYUVABackendTextures.h" #include "third_party/skia/include/gpu/mtl/GrMtlTypes.h" namespace flutter { @@ -132,10 +133,11 @@ sk_sp IOSExternalTextureMetal::WrapNV12ExternalPixelBuffer( y_skia_texture_info.fTexture = sk_cf_obj{ [reinterpret_cast(CVMetalTextureGetTexture(y_metal_texture)) retain]}; - GrBackendTexture y_skia_backend_texture(/*width=*/texture_size.width(), - /*height=*/texture_size.height(), - /*mipMapped=*/GrMipMapped ::kNo, - /*textureInfo=*/y_skia_texture_info); + GrBackendTexture skia_backend_textures[2]; + skia_backend_textures[0] = GrBackendTexture(/*width=*/texture_size.width(), + /*height=*/texture_size.height(), + /*mipMapped=*/GrMipMapped ::kNo, + /*textureInfo=*/y_skia_texture_info); fml::CFRef uv_metal_texture(uv_metal_texture_raw); @@ -143,17 +145,14 @@ sk_sp IOSExternalTextureMetal::WrapNV12ExternalPixelBuffer( uv_skia_texture_info.fTexture = sk_cf_obj{ [reinterpret_cast(CVMetalTextureGetTexture(uv_metal_texture)) retain]}; - GrBackendTexture uv_skia_backend_texture(/*width=*/texture_size.width(), - /*height=*/texture_size.height(), - /*mipMapped=*/GrMipMapped ::kNo, - /*textureInfo=*/uv_skia_texture_info); - GrBackendTexture nv12TextureHandles[] = {y_skia_backend_texture, uv_skia_backend_texture}; - SkYUVAIndex yuvaIndices[4] = { - SkYUVAIndex{0, SkColorChannel::kR}, // Read Y data from the red channel of the first texture - SkYUVAIndex{1, SkColorChannel::kR}, // Read U data from the red channel of the second texture - SkYUVAIndex{1, - SkColorChannel::kG}, // Read V data from the green channel of the second texture - SkYUVAIndex{-1, SkColorChannel::kA}}; //-1 means to omit the alpha data of YUVA + skia_backend_textures[1] = GrBackendTexture(/*width=*/texture_size.width(), + /*height=*/texture_size.height(), + /*mipMapped=*/GrMipMapped ::kNo, + /*textureInfo=*/uv_skia_texture_info); + SkYUVAInfo yuva_info(skia_backend_textures[0].dimensions(), SkYUVAInfo::PlaneConfig::kY_UV, + SkYUVAInfo::Subsampling::k444, kRec601_SkYUVColorSpace); + GrYUVABackendTextures yuva_backend_textures(yuva_info, skia_backend_textures, + kTopLeft_GrSurfaceOrigin); struct ImageCaptures { fml::CFRef buffer; @@ -170,9 +169,9 @@ sk_sp IOSExternalTextureMetal::WrapNV12ExternalPixelBuffer( auto captures = reinterpret_cast(release_context); delete captures; }; - sk_sp image = SkImage::MakeFromYUVATextures( - context, kRec601_SkYUVColorSpace, nv12TextureHandles, yuvaIndices, texture_size, - kTopLeft_GrSurfaceOrigin, /*imageColorSpace=*/nullptr, release_proc, captures.release()); + sk_sp image = + SkImage::MakeFromYUVATextures(context, yuva_backend_textures, /*imageColorSpace=*/nullptr, + release_proc, captures.release()); return image; }