forked from firka/flutter
[embedder] Ensure destruction called on present (flutter/engine#38078)
This is a followup to flutter/engine#38038. In that patch, a destruction callback for textures created via the FlutterRendererConfig callbacks (as opposed to by the FlutterCompositor callbacks) was added and passed through to the texture info attached to the SurfaceFrame generated in GPUSurfaceMetalSkia::AcquireFrameFromMTLTexture (called via GPUSurfaceMetalSkia::GetMTLTexture, which invokes the get_next_drawable_callback), however, in order for the destruction callback to make it to the presented Skia texture, it needs to be passed through to the present callback here:960af0a350/shell/gpu/gpu_surface_metal_skia.mm (LL233)which is invoked by the submit callback passed to Skia:960af0a350/shell/gpu/gpu_surface_metal_skia.mm (LL239)The present callback is implemented in EmbedderSurface::PresentTexture, which invokes the present callback registered in FlutterMetalRendererConfig.present_drawable_callback. This patch ensures that the destruction callback is passed through to Skia's present callback so destruction occurs in the right place. Issue: https://github.com/flutter/flutter/issues/116381
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ class EmbedderTestContextMetal : public EmbedderTestContext {
|
||||
using NextDrawableCallback =
|
||||
std::function<FlutterMetalTexture(const FlutterFrameInfo* frame_info)>;
|
||||
|
||||
using PresentCallback = std::function<bool(int64_t texture_id)>;
|
||||
|
||||
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<TestMetalContext> metal_context_;
|
||||
std::unique_ptr<TestMetalSurface> metal_surface_;
|
||||
size_t present_count_ = 0;
|
||||
PresentCallback present_callback_ = nullptr;
|
||||
NextDrawableCallback next_drawable_callback_ = nullptr;
|
||||
|
||||
void SetupSurface(SkISize surface_size) override;
|
||||
|
||||
@@ -235,6 +235,7 @@ TEST_F(EmbedderTest, TextureDestructionCallbackCalledWithoutCustomCompositorMeta
|
||||
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 @@ TEST_F(EmbedderTest, TextureDestructionCallbackCalledWithoutCustomCompositorMeta
|
||||
texture.user_data = collect_context.get();
|
||||
texture.destruction_callback = [](void* user_data) {
|
||||
CollectContext* callback_collect_context = reinterpret_cast<CollectContext*>(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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user