diff --git a/shell/platform/embedder/embedder.cc b/shell/platform/embedder/embedder.cc index e0f3d47e1f05c..64b856971cb10 100644 --- a/shell/platform/embedder/embedder.cc +++ b/shell/platform/embedder/embedder.cc @@ -463,6 +463,8 @@ InferMetalPlatformViewCreationCallback( embedder_texture.struct_size = sizeof(FlutterMetalTexture); embedder_texture.texture = texture.texture; embedder_texture.texture_id = texture.texture_id; + embedder_texture.user_data = texture.destruction_context; + embedder_texture.destruction_callback = texture.destruction_callback; return ptr(user_data, &embedder_texture); }; auto metal_get_texture = diff --git a/shell/platform/embedder/tests/embedder_test_context_metal.cc b/shell/platform/embedder/tests/embedder_test_context_metal.cc index 7554a9278a5af..aa83ca73ddd03 100644 --- a/shell/platform/embedder/tests/embedder_test_context_metal.cc +++ b/shell/platform/embedder/tests/embedder_test_context_metal.cc @@ -47,10 +47,18 @@ TestMetalContext* EmbedderTestContextMetal::GetTestMetalContext() { return metal_context_.get(); } +void EmbedderTestContextMetal::SetPresentCallback( + PresentCallback present_callback) { + present_callback_ = std::move(present_callback); +} + bool EmbedderTestContextMetal::Present(int64_t texture_id) { FireRootSurfacePresentCallbackIfPresent( [&]() { return metal_surface_->GetRasterSurfaceSnapshot(); }); present_count_++; + if (present_callback_ != nullptr) { + return present_callback_(texture_id); + } return metal_context_->Present(texture_id); } diff --git a/shell/platform/embedder/tests/embedder_test_context_metal.h b/shell/platform/embedder/tests/embedder_test_context_metal.h index d4b5914e9ae01..ad1e08b83173c 100644 --- a/shell/platform/embedder/tests/embedder_test_context_metal.h +++ b/shell/platform/embedder/tests/embedder_test_context_metal.h @@ -23,6 +23,8 @@ class EmbedderTestContextMetal : public EmbedderTestContext { using NextDrawableCallback = std::function; + using PresentCallback = std::function; + explicit EmbedderTestContextMetal(std::string assets_path = ""); ~EmbedderTestContextMetal() override; @@ -39,6 +41,9 @@ class EmbedderTestContextMetal : public EmbedderTestContext { void SetExternalTextureCallback( TestExternalTextureCallback external_texture_frame_callback); + // Override the default handling for Present. + void SetPresentCallback(PresentCallback present_callback); + bool Present(int64_t texture_id); bool PopulateExternalTexture(int64_t texture_id, @@ -65,6 +70,7 @@ class EmbedderTestContextMetal : public EmbedderTestContext { std::unique_ptr metal_context_; std::unique_ptr metal_surface_; size_t present_count_ = 0; + PresentCallback present_callback_ = nullptr; NextDrawableCallback next_drawable_callback_ = nullptr; void SetupSurface(SkISize surface_size) override; diff --git a/shell/platform/embedder/tests/embedder_unittests_metal.mm b/shell/platform/embedder/tests/embedder_unittests_metal.mm index 351b9ea428d38..7d07b54d7e894 100644 --- a/shell/platform/embedder/tests/embedder_unittests_metal.mm +++ b/shell/platform/embedder/tests/embedder_unittests_metal.mm @@ -235,6 +235,7 @@ GrBackendTexture backend_texture(texture_size.width(), texture_size.height(), Gr builder.SetDartEntrypoint("texture_destruction_callback_called_without_custom_compositor"); struct CollectContext { + int present_count = 0; int collect_count = 0; fml::AutoResetWaitableEvent latch; }; @@ -249,11 +250,16 @@ GrBackendTexture backend_texture(texture_size.width(), texture_size.height(), Gr texture.user_data = collect_context.get(); texture.destruction_callback = [](void* user_data) { CollectContext* callback_collect_context = reinterpret_cast(user_data); + ASSERT_TRUE(callback_collect_context->present_count > 0); callback_collect_context->collect_count++; callback_collect_context->latch.Signal(); }; return texture; }); + context.SetPresentCallback([&context, &collect_context](int64_t texture_id) { + collect_context->present_count++; + return context.GetTestMetalContext()->Present(texture_id); + }); auto engine = builder.LaunchEngine();