From 4ec8483024d7658b4576af755e854e8ba32db20b Mon Sep 17 00:00:00 2001 From: K Lubick Date: Tue, 2 Apr 2024 11:49:15 -0400 Subject: [PATCH] Use moved GrBackendTexture factories for Skia's Metal backend (flutter/engine#51828) In https://skia-review.googlesource.com/c/skia/+/833302, Skia moved the constructors for Metal versions of GrBackendTexture (and other functions/methods). This updates uses in Flutter to use the new APIs. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat --- .../shell/gpu/gpu_surface_metal_skia.mm | 5 ++++- .../FlutterDarwinExternalTextureMetal.mm | 20 +++++++----------- .../shell/platform/embedder/embedder.cc | 21 ++++++++++--------- .../tests/embedder_metal_unittests.mm | 6 ++++-- .../embedder_test_backingstore_producer.cc | 10 +++++++-- engine/src/flutter/skia/flutter_defines.gni | 9 +------- .../testing/test_metal_surface_impl.mm | 6 ++++-- 7 files changed, 40 insertions(+), 37 deletions(-) diff --git a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm index 652891c9ac..9e666d2a4f 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm +++ b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm @@ -27,6 +27,8 @@ #include "third_party/skia/include/gpu/GpuTypes.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlBackendSurface.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlTypes.h" #include "third_party/skia/include/ports/SkCFObject.h" static_assert(!__has_feature(objc_arc), "ARC must be disabled."); @@ -45,7 +47,8 @@ sk_sp CreateSurfaceFromMetalTexture(GrDirectContext* context, SkSurface::ReleaseContext release_context) { GrMtlTextureInfo info; info.fTexture.reset([texture retain]); - GrBackendTexture backend_texture(texture.width, texture.height, skgpu::Mipmapped::kNo, info); + GrBackendTexture backend_texture = + GrBackendTextures::MakeMtl(texture.width, texture.height, skgpu::Mipmapped::kNo, info); return SkSurfaces::WrapBackendTexture( context, backend_texture, origin, static_cast(sample_cnt), color_type, std::move(color_space), props, release_proc, release_context); diff --git a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm index 79a7eadff3..514b7e67b5 100644 --- a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm +++ b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm @@ -15,6 +15,8 @@ #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/GrYUVABackendTextures.h" #include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlBackendSurface.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlTypes.h" #include "third_party/skia/include/ports/SkCFObject.h" FLUTTER_ASSERT_ARC @@ -294,18 +296,14 @@ FLUTTER_ASSERT_ARC ySkiaTextureInfo.fTexture = sk_cfp{(__bridge_retained const void*)yTex}; GrBackendTexture skiaBackendTextures[2]; - skiaBackendTextures[0] = GrBackendTexture(/*width=*/width, - /*height=*/height, - /*mipMapped=*/skgpu::Mipmapped::kNo, - /*mtlInfo=*/ySkiaTextureInfo); + skiaBackendTextures[0] = + GrBackendTextures::MakeMtl(width, height, skgpu::Mipmapped::kNo, ySkiaTextureInfo); GrMtlTextureInfo uvSkiaTextureInfo; uvSkiaTextureInfo.fTexture = sk_cfp{(__bridge_retained const void*)uvTex}; - skiaBackendTextures[1] = GrBackendTexture(/*width=*/width, - /*height=*/height, - /*mipMapped=*/skgpu::Mipmapped::kNo, - /*mtlInfo=*/uvSkiaTextureInfo); + skiaBackendTextures[1] = + GrBackendTextures::MakeMtl(width, height, skgpu::Mipmapped::kNo, uvSkiaTextureInfo); SkYUVAInfo yuvaInfo(skiaBackendTextures[0].dimensions(), SkYUVAInfo::PlaneConfig::kY_UV, SkYUVAInfo::Subsampling::k444, colorSpace); GrYUVABackendTextures yuvaBackendTextures(yuvaInfo, skiaBackendTextures, @@ -323,10 +321,8 @@ FLUTTER_ASSERT_ARC GrMtlTextureInfo skiaTextureInfo; skiaTextureInfo.fTexture = sk_cfp{(__bridge_retained const void*)rgbaTex}; - GrBackendTexture skiaBackendTexture(/*width=*/width, - /*height=*/height, - /*mipMapped=*/skgpu::Mipmapped ::kNo, - /*mtlInfo=*/skiaTextureInfo); + GrBackendTexture skiaBackendTexture = + GrBackendTextures::MakeMtl(width, height, skgpu::Mipmapped ::kNo, skiaTextureInfo); return SkImages::BorrowTextureFrom(grContext, skiaBackendTexture, kTopLeft_GrSurfaceOrigin, kBGRA_8888_SkColorType, kPremul_SkAlphaType, diff --git a/engine/src/flutter/shell/platform/embedder/embedder.cc b/engine/src/flutter/shell/platform/embedder/embedder.cc index 5b89bcfbc6..5e434d5d9f 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder.cc @@ -85,6 +85,8 @@ extern const intptr_t kPlatformStrongDillSize; #ifdef SHELL_ENABLE_METAL #include "flutter/shell/platform/embedder/embedder_surface_metal.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlBackendSurface.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlTypes.h" #include "third_party/skia/include/ports/SkCFObject.h" #ifdef IMPELLER_SUPPORTS_RENDERING #include "flutter/shell/platform/embedder/embedder_render_target_impeller.h" // nogncheck @@ -747,11 +749,9 @@ static sk_sp MakeSkSurfaceFromBackingStore( texture_info.fID = texture->name; texture_info.fFormat = texture->format; - auto backend_texture = GrBackendTextures::MakeGL(config.size.width, // - config.size.height, // - skgpu::Mipmapped::kNo, // - texture_info // - ); + GrBackendTexture backend_texture = + GrBackendTextures::MakeGL(config.size.width, config.size.height, + skgpu::Mipmapped::kNo, texture_info); SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry); @@ -922,11 +922,12 @@ static sk_sp MakeSkSurfaceFromBackingStore( sk_cfp mtl_texture; mtl_texture.retain(metal->texture.texture); texture_info.fTexture = mtl_texture; - GrBackendTexture backend_texture(config.size.width, // - config.size.height, // - skgpu::Mipmapped::kNo, // - texture_info // - ); + GrBackendTexture backend_texture = + GrBackendTextures::MakeMtl(config.size.width, // + config.size.height, // + skgpu::Mipmapped::kNo, // + texture_info // + ); SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry); diff --git a/engine/src/flutter/shell/platform/embedder/tests/embedder_metal_unittests.mm b/engine/src/flutter/shell/platform/embedder/tests/embedder_metal_unittests.mm index 13a9d49f55..959e2e4fea 100644 --- a/engine/src/flutter/shell/platform/embedder/tests/embedder_metal_unittests.mm +++ b/engine/src/flutter/shell/platform/embedder/tests/embedder_metal_unittests.mm @@ -24,6 +24,8 @@ #include "third_party/skia/include/gpu/GpuTypes.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlBackendSurface.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlTypes.h" // CREATE_NATIVE_ENTRY is leaky by design // NOLINTBEGIN(clang-analyzer-core.StackAddressEscape) @@ -64,8 +66,8 @@ static sk_sp GetSurfaceFromTexture(const sk_sp& skia void* texture) { GrMtlTextureInfo info; info.fTexture.reset([(id)texture retain]); - GrBackendTexture backend_texture(texture_size.width(), texture_size.height(), - skgpu::Mipmapped::kNo, info); + GrBackendTexture backend_texture = GrBackendTextures::MakeMtl( + texture_size.width(), texture_size.height(), skgpu::Mipmapped::kNo, info); return SkSurfaces::WrapBackendTexture(skia_context.get(), backend_texture, kTopLeft_GrSurfaceOrigin, 1, kBGRA_8888_SkColorType, diff --git a/engine/src/flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.cc b/engine/src/flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.cc index 0c67e3dcce..ac6959cacb 100644 --- a/engine/src/flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.cc +++ b/engine/src/flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.cc @@ -26,6 +26,11 @@ #include "third_party/skia/include/gpu/ganesh/vk/GrVkBackendSurface.h" #endif // SHELL_ENABLE_VULKAN +#ifdef SHELL_ENABLE_METAL +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlBackendSurface.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlTypes.h" +#endif + // TODO(zanderso): https://github.com/flutter/flutter/issues/127701 // NOLINTBEGIN(bugprone-unchecked-optional-access) @@ -281,8 +286,9 @@ bool EmbedderTestBackingStoreProducer::CreateMTLTexture( GrMtlTextureInfo skia_texture_info; skia_texture_info.fTexture.reset(SkCFSafeRetain(texture_info.texture)); - GrBackendTexture backend_texture(surface_size.width(), surface_size.height(), - skgpu::Mipmapped::kNo, skia_texture_info); + GrBackendTexture backend_texture = + GrBackendTextures::MakeMtl(surface_size.width(), surface_size.height(), + skgpu::Mipmapped::kNo, skia_texture_info); sk_sp surface = SkSurfaces::WrapBackendTexture( context_.get(), backend_texture, kTopLeft_GrSurfaceOrigin, 1, diff --git a/engine/src/flutter/skia/flutter_defines.gni b/engine/src/flutter/skia/flutter_defines.gni index 650046f712..2c08f76cba 100644 --- a/engine/src/flutter/skia/flutter_defines.gni +++ b/engine/src/flutter/skia/flutter_defines.gni @@ -11,9 +11,8 @@ flutter_defines = [ # Staging "SK_LEGACY_IGNORE_DRAW_VERTICES_BLEND_WITH_NO_SHADER", - "SK_DISABLE_LEGACY_GRDIRECTCONTEXT_BOOLS", - "SK_DISABLE_LEGACY_GRDIRECTCONTEXT_FLUSH", "SK_RESOLVE_FILTERS_BEFORE_RESTORE", + "SK_DISABLE_LEGACY_METAL_BACKEND_SURFACE", # Fast low-precision software rendering isn't a priority for Flutter. "SK_DISABLE_LEGACY_SHADERCONTEXT", @@ -23,12 +22,6 @@ flutter_defines = [ # When running Metal, ensure that command buffers are scheduled before # returning from submit. "SK_METAL_WAIT_UNTIL_SCHEDULED", - - # Staging for b/305780908 - "SK_DEFAULT_TYPEFACE_IS_EMPTY", - "SK_DISABLE_LEGACY_DEFAULT_TYPEFACE", - "SK_DISABLE_LEGACY_FONTMGR_FACTORY", - "SK_DISABLE_LEGACY_FONTMGR_REFDEFAULT", ] if (!is_fuchsia) { diff --git a/engine/src/flutter/testing/test_metal_surface_impl.mm b/engine/src/flutter/testing/test_metal_surface_impl.mm index cf2c6931f8..ade42c33c2 100644 --- a/engine/src/flutter/testing/test_metal_surface_impl.mm +++ b/engine/src/flutter/testing/test_metal_surface_impl.mm @@ -18,6 +18,8 @@ #include "third_party/skia/include/gpu/GpuTypes.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlBackendSurface.h" +#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlTypes.h" namespace flutter { @@ -27,8 +29,8 @@ void TestMetalSurfaceImpl::Init(const TestMetalContext::TextureInfo& texture_inf GrMtlTextureInfo skia_texture_info; skia_texture_info.fTexture.reset([texture retain]); - GrBackendTexture backend_texture(surface_size.width(), surface_size.height(), - skgpu::Mipmapped::kNo, skia_texture_info); + GrBackendTexture backend_texture = GrBackendTextures::MakeMtl( + surface_size.width(), surface_size.height(), skgpu::Mipmapped::kNo, skia_texture_info); sk_sp surface = SkSurfaces::WrapBackendTexture( test_metal_context_.GetSkiaContext().get(), backend_texture, kTopLeft_GrSurfaceOrigin, 1,