From 154bc1b51c067f2c6baa1755d5de28bea7c8e45f Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Sun, 22 Sep 2024 16:38:34 -0700 Subject: [PATCH 1/3] finish wiring up external textures for macOs embedder. --- .../FlutterDarwinExternalTextureMetal.h | 14 + .../FlutterDarwinExternalTextureMetal.mm | 74 +++-- .../FlutterEmbedderExternalTextureTest.mm | 270 ++++++++++++++++++ .../embedder/embedder_external_texture_gl.cc | 2 + .../embedder/embedder_external_texture_gl.h | 1 + .../embedder_external_texture_metal.h | 2 + .../embedder_external_texture_metal.mm | 38 ++- 7 files changed, 370 insertions(+), 31 deletions(-) diff --git a/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h b/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h index 683d515dfc087..9caa23f8178e5 100644 --- a/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h +++ b/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h @@ -8,7 +8,9 @@ #import #import +#include "display_list/image/dl_image.h" #include "flutter/common/graphics/texture.h" +#include "flutter/impeller/aiks/aiks_context.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkImage.h" @@ -29,6 +31,18 @@ @end +@interface FlutterDarwinExternalTextureImpellerImageWrapper : NSObject + ++ (sk_sp)wrapYUVATexture:(nonnull id)yTex + UVTex:(nonnull id)uvTex + YUVColorSpace:(impeller::YUVColorSpace)colorSpace + aiksContext:(nonnull impeller::AiksContext*)aiksContext; + ++ (sk_sp)wrapRGBATexture:(nonnull id)rgbaTex + aiksContext:(nonnull impeller::AiksContext*)aiks_context; + +@end + @interface FlutterDarwinExternalTextureMetal : NSObject - (nullable instancetype)initWithTextureCache:(nonnull CVMetalTextureCacheRef)textureCache diff --git a/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm b/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm index c03ac41cefd01..b1225ff604b61 100644 --- a/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm +++ b/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm @@ -4,6 +4,7 @@ #import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h" #include "flutter/display_list/image/dl_image.h" +#include "impeller/aiks/aiks_context.h" #include "impeller/base/validation.h" #include "impeller/display_list/dl_image_impeller.h" #include "impeller/renderer/backend/metal/texture_mtl.h" @@ -196,29 +197,14 @@ - (void)onTextureUnregistered { CVBufferRelease(uvMetalTexture); if (_enableImpeller) { - impeller::TextureDescriptor yDesc; - yDesc.storage_mode = impeller::StorageMode::kHostVisible; - yDesc.format = impeller::PixelFormat::kR8UNormInt; - yDesc.size = {textureSize.width(), textureSize.height()}; - yDesc.mip_count = 1; - auto yTexture = impeller::TextureMTL::Wrapper(yDesc, yTex); - yTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); - - impeller::TextureDescriptor uvDesc; - uvDesc.storage_mode = impeller::StorageMode::kHostVisible; - uvDesc.format = impeller::PixelFormat::kR8G8UNormInt; - uvDesc.size = {textureSize.width() / 2, textureSize.height() / 2}; - uvDesc.mip_count = 1; - auto uvTexture = impeller::TextureMTL::Wrapper(uvDesc, uvTex); - uvTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); - impeller::YUVColorSpace yuvColorSpace = _pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange ? impeller::YUVColorSpace::kBT601LimitedRange : impeller::YUVColorSpace::kBT601FullRange; - - return impeller::DlImageImpeller::MakeFromYUVTextures(context.aiks_context, yTexture, uvTexture, - yuvColorSpace); + return [FlutterDarwinExternalTextureImpellerImageWrapper wrapYUVATexture:yTex + UVTex:uvTex + YUVColorSpace:yuvColorSpace + aiksContext:context.aiks_context]; } SkYUVColorSpace colorSpace = _pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange @@ -263,14 +249,8 @@ - (void)onTextureUnregistered { CVBufferRelease(metalTexture); if (_enableImpeller) { - impeller::TextureDescriptor desc; - desc.storage_mode = impeller::StorageMode::kHostVisible; - desc.format = impeller::PixelFormat::kB8G8R8A8UNormInt; - desc.size = {textureSize.width(), textureSize.height()}; - desc.mip_count = 1; - auto texture = impeller::TextureMTL::Wrapper(desc, rgbaTex); - texture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); - return impeller::DlImageImpeller::Make(texture); + return [FlutterDarwinExternalTextureImpellerImageWrapper wrapRGBATexture:rgbaTex + aiksContext:context.aiks_context]; } auto skImage = [FlutterDarwinExternalTextureSkImageWrapper wrapRGBATexture:rgbaTex @@ -342,3 +322,43 @@ GrYUVABackendTextures yuvaBackendTextures(yuvaInfo, skiaBackendTextures, #endif // SLIMPELLER } @end + +@implementation FlutterDarwinExternalTextureImpellerImageWrapper + ++ (sk_sp)wrapYUVATexture:(id)yTex + UVTex:(id)uvTex + YUVColorSpace:(impeller::YUVColorSpace)colorSpace + aiksContext:(nonnull impeller::AiksContext*)aiks_context { + impeller::TextureDescriptor yDesc; + yDesc.storage_mode = impeller::StorageMode::kDevicePrivate; + yDesc.format = impeller::PixelFormat::kR8UNormInt; + yDesc.size = impeller::ISize(yTex.width, yTex.height); + yDesc.mip_count = 1; + auto yTexture = impeller::TextureMTL::Wrapper(yDesc, yTex); + yTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); + + impeller::TextureDescriptor uvDesc; + uvDesc.storage_mode = impeller::StorageMode::kDevicePrivate; + uvDesc.format = impeller::PixelFormat::kR8G8UNormInt; + uvDesc.size = impeller::ISize(uvTex.width, uvTex.height); + uvDesc.mip_count = 1; + auto uvTexture = impeller::TextureMTL::Wrapper(uvDesc, uvTex); + uvTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); + ; + + return impeller::DlImageImpeller::MakeFromYUVTextures(aiks_context, yTexture, uvTexture, + colorSpace); +} + ++ (sk_sp)wrapRGBATexture:(id)rgbaTex + aiksContext:(nonnull impeller::AiksContext*)aiks_context { + impeller::TextureDescriptor desc; + desc.storage_mode = impeller::StorageMode::kDevicePrivate; + desc.format = impeller::PixelFormat::kB8G8R8A8UNormInt; + desc.size = impeller::ISize(rgbaTex.width, rgbaTex.height); + desc.mip_count = 1; + auto texture = impeller::TextureMTL::Wrapper(desc, rgbaTex); + texture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); + return impeller::DlImageImpeller::Make(texture); +} +@end diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm index 1d0a6563c1b6f..485a9d42aaf21 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm @@ -4,6 +4,10 @@ #import #import +#include "display_list/display_list.h" +#include "display_list/dl_builder.h" +#include "fml/synchronization/sync_switch.h" +#include "shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h" #include #include @@ -16,12 +20,30 @@ #include "flutter/shell/platform/embedder/embedder_external_texture_metal.h" #include "flutter/testing/autoreleasepool_test.h" #include "flutter/testing/testing.h" +#include "impeller/aiks/aiks_context.h" +#include "impeller/entity/mtl/entity_shaders.h" +#include "impeller/entity/mtl/framebuffer_blend_shaders.h" +#include "impeller/entity/mtl/modern_shaders.h" +#include "impeller/renderer/backend/metal/context_mtl.h" #include "third_party/googletest/googletest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkSamplingOptions.h" #include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" +static std::shared_ptr CreateImpellerContext() { + std::vector> shader_mappings = { + std::make_shared(impeller_entity_shaders_data, + impeller_entity_shaders_length), + std::make_shared(impeller_modern_shaders_data, + impeller_modern_shaders_length), + std::make_shared(impeller_framebuffer_blend_shaders_data, + impeller_framebuffer_blend_shaders_length), + }; + auto sync_switch = std::make_shared(false); + return impeller::ContextMTL::Create(shader_mappings, sync_switch, "Impeller Library"); +} + @interface TestExternalTexture : NSObject - (nonnull instancetype)initWidth:(size_t)width @@ -334,4 +356,252 @@ - (CVPixelBufferRef)pixelBuffer { texture->Paint(context, bounds, /*freeze=*/false, sampling); } +TEST_F(FlutterEmbedderExternalTextureTest, TestTextureResolutionImpeller) { + // Constants. + const size_t width = 100; + const size_t height = 100; + const int64_t texture_id = 1; + + // Set up the surface. + auto device = ::MTLCreateSystemDefaultDevice(); + impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr); + + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + + // Create a texture. + MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init]; + textureDescriptor.pixelFormat = MTLPixelFormatBGRA8Unorm; + textureDescriptor.width = width; + textureDescriptor.height = height; + textureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead; + id mtlTexture = [device newTextureWithDescriptor:textureDescriptor]; + std::vector textures = { + (__bridge FlutterMetalTextureHandle)mtlTexture, + }; + + // Callback to resolve the texture. + EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w, + size_t h) { + EXPECT_TRUE(w == width); + EXPECT_TRUE(h == height); + + auto texture = std::make_unique(); + texture->struct_size = sizeof(FlutterMetalExternalTexture); + texture->num_textures = 1; + texture->height = h; + texture->width = w; + texture->pixel_format = FlutterMetalExternalTexturePixelFormat::kRGBA; + texture->textures = textures.data(); + return texture; + }; + + // Render the texture. + std::unique_ptr texture = + std::make_unique(texture_id, callback); + SkRect bounds = SkRect::MakeWH(info.width(), info.height()); + DlImageSampling sampling = DlImageSampling::kNearestNeighbor; + + DisplayListBuilder builder; + flutter::Texture::PaintContext context{ + .canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context}; + texture->Paint(context, bounds, /*freeze=*/false, sampling); + + ASSERT_TRUE(mtlTexture != nil); +} + +TEST_F(FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureImpeller) { + // Constants. + const size_t width = 100; + const size_t height = 100; + const int64_t texture_id = 1; + + // Set up the surface. + FlutterDarwinContextMetalSkia* darwinContextMetal = + [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice]; + impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr); + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + + // Create a texture. + TestExternalTexture* testExternalTexture = + [[TestExternalTexture alloc] initWidth:width + height:height + pixelFormatType:kCVPixelFormatType_32BGRA]; + FlutterExternalTexture* textureHolder = + [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture + darwinMetalContext:darwinContextMetal]; + + // Callback to resolve the texture. + EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w, + size_t h) { + EXPECT_TRUE(w == width); + EXPECT_TRUE(h == height); + + auto texture = std::make_unique(); + [textureHolder populateTexture:texture.get()]; + + EXPECT_TRUE(texture->num_textures == 1); + EXPECT_TRUE(texture->textures != nullptr); + EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kRGBA); + return texture; + }; + + // Render the texture. + std::unique_ptr texture = + std::make_unique(texture_id, callback); + SkRect bounds = SkRect::MakeWH(info.width(), info.height()); + DlImageSampling sampling = DlImageSampling::kNearestNeighbor; + + DisplayListBuilder builder; + flutter::Texture::PaintContext context{ + .canvas = &builder, + .gr_context = nullptr, + .aiks_context = &aiks_context, + }; + texture->Paint(context, bounds, /*freeze=*/false, sampling); +} + +TEST_F(FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureYUVAImpeller) { + // Constants. + const size_t width = 100; + const size_t height = 100; + const int64_t texture_id = 1; + + // Set up the surface. + FlutterDarwinContextMetalSkia* darwinContextMetal = + [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice]; + impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr); + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + + // Create a texture. + TestExternalTexture* testExternalTexture = + [[TestExternalTexture alloc] initWidth:width + height:height + pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange]; + FlutterExternalTexture* textureHolder = + [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture + darwinMetalContext:darwinContextMetal]; + + // Callback to resolve the texture. + EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w, + size_t h) { + EXPECT_TRUE(w == width); + EXPECT_TRUE(h == height); + + auto texture = std::make_unique(); + [textureHolder populateTexture:texture.get()]; + + EXPECT_TRUE(texture->num_textures == 2); + EXPECT_TRUE(texture->textures != nullptr); + EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA); + EXPECT_TRUE(texture->yuv_color_space == + FlutterMetalExternalTextureYUVColorSpace::kBT601LimitedRange); + return texture; + }; + + // Render the texture. + std::unique_ptr texture = + std::make_unique(texture_id, callback); + SkRect bounds = SkRect::MakeWH(info.width(), info.height()); + DlImageSampling sampling = DlImageSampling::kNearestNeighbor; + + DisplayListBuilder builder; + flutter::Texture::PaintContext context{ + .canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context}; + texture->Paint(context, bounds, /*freeze=*/false, sampling); +} + +TEST_F(FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureYUVA2Impeller) { + // Constants. + const size_t width = 100; + const size_t height = 100; + const int64_t texture_id = 1; + + // Set up the surface. + FlutterDarwinContextMetalSkia* darwinContextMetal = + [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice]; + impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr); + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + + // Create a texture. + TestExternalTexture* testExternalTexture = + [[TestExternalTexture alloc] initWidth:width + height:height + pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange]; + FlutterExternalTexture* textureHolder = + [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture + darwinMetalContext:darwinContextMetal]; + + // Callback to resolve the texture. + EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w, + size_t h) { + EXPECT_TRUE(w == width); + EXPECT_TRUE(h == height); + + auto texture = std::make_unique(); + [textureHolder populateTexture:texture.get()]; + + EXPECT_TRUE(texture->num_textures == 2); + EXPECT_TRUE(texture->textures != nullptr); + EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA); + EXPECT_TRUE(texture->yuv_color_space == + FlutterMetalExternalTextureYUVColorSpace::kBT601FullRange); + return texture; + }; + + // Render the texture. + std::unique_ptr texture = + std::make_unique(texture_id, callback); + SkRect bounds = SkRect::MakeWH(info.width(), info.height()); + DlImageSampling sampling = DlImageSampling::kNearestNeighbor; + + DisplayListBuilder builder; + flutter::Texture::PaintContext context{ + .canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context}; + texture->Paint(context, bounds, /*freeze=*/false, sampling); +} + +TEST_F(FlutterEmbedderExternalTextureTest, TestPopulateUnsupportedExternalTextureImpeller) { + // Constants. + const size_t width = 100; + const size_t height = 100; + const int64_t texture_id = 1; + + // Set up the surface. + FlutterDarwinContextMetalSkia* darwinContextMetal = + [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice]; + impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr); + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + + // Create a texture. + TestExternalTexture* testExternalTexture = + [[TestExternalTexture alloc] initWidth:width + height:height + pixelFormatType:kCVPixelFormatType_420YpCbCr8PlanarFullRange]; + FlutterExternalTexture* textureHolder = + [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture + darwinMetalContext:darwinContextMetal]; + + // Callback to resolve the texture. + EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w, + size_t h) { + EXPECT_TRUE(w == width); + EXPECT_TRUE(h == height); + + auto texture = std::make_unique(); + EXPECT_FALSE([textureHolder populateTexture:texture.get()]); + return nullptr; + }; + + // Render the texture. + std::unique_ptr texture = + std::make_unique(texture_id, callback); + SkRect bounds = SkRect::MakeWH(info.width(), info.height()); + DlImageSampling sampling = DlImageSampling::kNearestNeighbor; + + DisplayListBuilder builder; + flutter::Texture::PaintContext context{ + .canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context}; + texture->Paint(context, bounds, /*freeze=*/false, sampling); +} + } // namespace flutter::testing diff --git a/shell/platform/embedder/embedder_external_texture_gl.cc b/shell/platform/embedder/embedder_external_texture_gl.cc index d4e23769912b1..48ae129b438b5 100644 --- a/shell/platform/embedder/embedder_external_texture_gl.cc +++ b/shell/platform/embedder/embedder_external_texture_gl.cc @@ -38,6 +38,7 @@ void EmbedderExternalTextureGL::Paint(PaintContext& context, last_image_ = ResolveTexture(Id(), // context.gr_context, // + context.aiks_context, // SkISize::Make(bounds.width(), bounds.height()) // ); } @@ -58,6 +59,7 @@ void EmbedderExternalTextureGL::Paint(PaintContext& context, sk_sp EmbedderExternalTextureGL::ResolveTexture( int64_t texture_id, GrDirectContext* context, + impeller::AiksContext* aiks_context, const SkISize& size) { context->flushAndSubmit(); context->resetContext(kAll_GrBackendState); diff --git a/shell/platform/embedder/embedder_external_texture_gl.h b/shell/platform/embedder/embedder_external_texture_gl.h index b01991d0cf1df..a661a783414bb 100644 --- a/shell/platform/embedder/embedder_external_texture_gl.h +++ b/shell/platform/embedder/embedder_external_texture_gl.h @@ -28,6 +28,7 @@ class EmbedderExternalTextureGL : public flutter::Texture { sk_sp ResolveTexture(int64_t texture_id, GrDirectContext* context, + impeller::AiksContext* aiks_context, const SkISize& size); // |flutter::Texture| diff --git a/shell/platform/embedder/embedder_external_texture_metal.h b/shell/platform/embedder/embedder_external_texture_metal.h index ac72fb28b9ccc..80f9ee3283e7b 100644 --- a/shell/platform/embedder/embedder_external_texture_metal.h +++ b/shell/platform/embedder/embedder_external_texture_metal.h @@ -8,6 +8,7 @@ #include "flutter/common/graphics/texture.h" #include "flutter/fml/macros.h" #include "flutter/shell/platform/embedder/embedder.h" +#include "impeller/aiks/aiks_context.h" #include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkSize.h" @@ -29,6 +30,7 @@ class EmbedderExternalTextureMetal : public flutter::Texture { sk_sp ResolveTexture(int64_t texture_id, GrDirectContext* context, + impeller::AiksContext* aiks_context, const SkISize& size); // |flutter::Texture| diff --git a/shell/platform/embedder/embedder_external_texture_metal.mm b/shell/platform/embedder/embedder_external_texture_metal.mm index 0f98aff401bc6..d41cb2660401e 100644 --- a/shell/platform/embedder/embedder_external_texture_metal.mm +++ b/shell/platform/embedder/embedder_external_texture_metal.mm @@ -37,8 +37,8 @@ static bool ValidNumTextures(int expected, int actual) { bool freeze, const DlImageSampling sampling) { if (last_image_ == nullptr) { - last_image_ = - ResolveTexture(Id(), context.gr_context, SkISize::Make(bounds.width(), bounds.height())); + last_image_ = ResolveTexture(Id(), context.gr_context, context.aiks_context, + SkISize::Make(bounds.width(), bounds.height())); } DlCanvas* canvas = context.canvas; @@ -56,6 +56,7 @@ static bool ValidNumTextures(int expected, int actual) { sk_sp EmbedderExternalTextureMetal::ResolveTexture(int64_t texture_id, GrDirectContext* context, + impeller::AiksContext* aiks_context, const SkISize& size) { std::unique_ptr texture = external_texture_callback_(texture_id, size.width(), size.height()); @@ -63,6 +64,35 @@ static bool ValidNumTextures(int expected, int actual) { if (!texture) { return nullptr; } + if (aiks_context) { + switch (texture->pixel_format) { + case FlutterMetalExternalTexturePixelFormat::kRGBA: { + if (ValidNumTextures(1, texture->num_textures)) { + id rgbaTex = (__bridge id)texture->textures[0]; + return [FlutterDarwinExternalTextureImpellerImageWrapper wrapRGBATexture:rgbaTex + aiksContext:aiks_context]; + } + break; + } + case FlutterMetalExternalTexturePixelFormat::kYUVA: { + if (ValidNumTextures(2, texture->num_textures)) { + id yTex = (__bridge id)texture->textures[0]; + id uvTex = (__bridge id)texture->textures[1]; + impeller::YUVColorSpace colorSpace = + texture->yuv_color_space == + FlutterMetalExternalTextureYUVColorSpace::kBT601LimitedRange + ? impeller::YUVColorSpace::kBT601LimitedRange + : impeller::YUVColorSpace::kBT601FullRange; + return [FlutterDarwinExternalTextureImpellerImageWrapper wrapYUVATexture:yTex + UVTex:uvTex + YUVColorSpace:colorSpace + aiksContext:aiks_context]; + } + break; + } + } + return nullptr; + } sk_sp image; @@ -72,8 +102,8 @@ static bool ValidNumTextures(int expected, int actual) { id rgbaTex = (__bridge id)texture->textures[0]; image = [FlutterDarwinExternalTextureSkImageWrapper wrapRGBATexture:rgbaTex grContext:context - width:size.width() - height:size.height()]; + width:rgbaTex.width + height:rgbaTex.height]; } break; } From 55e120f82468fd9de3be32cb64cd970ce81698a6 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 23 Sep 2024 09:28:22 -0700 Subject: [PATCH 2/3] ++ --- .../FlutterEmbedderExternalTextureTest.mm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm index 485a9d42aaf21..013a35a9c4e88 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm @@ -4,15 +4,15 @@ #import #import -#include "display_list/display_list.h" -#include "display_list/dl_builder.h" -#include "fml/synchronization/sync_switch.h" -#include "shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h" #include #include +#include "flutter/display_list/display_list.h" +#include "flutter/display_list/dl_builder.h" #import "flutter/display_list/skia/dl_sk_canvas.h" +#include "flutter/fml/synchronization/sync_switch.h" +#include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h" #import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h" #import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h" #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h" @@ -20,11 +20,11 @@ #include "flutter/shell/platform/embedder/embedder_external_texture_metal.h" #include "flutter/testing/autoreleasepool_test.h" #include "flutter/testing/testing.h" -#include "impeller/aiks/aiks_context.h" -#include "impeller/entity/mtl/entity_shaders.h" -#include "impeller/entity/mtl/framebuffer_blend_shaders.h" -#include "impeller/entity/mtl/modern_shaders.h" -#include "impeller/renderer/backend/metal/context_mtl.h" +#include "impeller/aiks/aiks_context.h" // nogncheck +#include "impeller/entity/mtl/entity_shaders.h" // nogncheck +#include "impeller/entity/mtl/framebuffer_blend_shaders.h" // nogncheck +#include "impeller/entity/mtl/modern_shaders.h" // nogncheck +#include "impeller/renderer/backend/metal/context_mtl.h" // nogncheck #include "third_party/googletest/googletest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkSamplingOptions.h" From ce2716ce748740fbf9c7f77fa0d0f52c393f080f Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 23 Sep 2024 09:30:00 -0700 Subject: [PATCH 3/3] ++ --- .../darwin/graphics/FlutterDarwinExternalTextureMetal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h b/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h index 9caa23f8178e5..fb19049f0d4fe 100644 --- a/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h +++ b/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h @@ -8,8 +8,8 @@ #import #import -#include "display_list/image/dl_image.h" #include "flutter/common/graphics/texture.h" +#include "flutter/display_list/image/dl_image.h" #include "flutter/impeller/aiks/aiks_context.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h" #include "third_party/skia/include/core/SkCanvas.h"