Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions flow/surface_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class SurfaceFrame {
// Time at which this frame is scheduled to be presented. This is a hint
// that can be passed to the platform to drop queued frames.
std::optional<fml::TimePoint> presentation_time;

// Whether this surface frame represents the last in a group frames that
// were submitted as part of a platform compositor interop step, such as
// during iOS platform view compositing.
//
// Defaults to true, which is generally a safe value.
bool frame_boundary = true;
};

bool Submit();
Expand Down
6 changes: 4 additions & 2 deletions shell/gpu/gpu_surface_gl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
impeller_dispatcher,
SkIRect::MakeWH(cull_rect.width, cull_rect.height));
auto picture = impeller_dispatcher.EndRecordingAsPicture();
const bool reset_host_buffer =
surface_frame.submit_info().frame_boundary;

return renderer->Render(
std::move(surface),
fml::MakeCopyable(
[aiks_context, picture = std::move(picture)](
[aiks_context, picture = std::move(picture), reset_host_buffer](
impeller::RenderTarget& render_target) -> bool {
return aiks_context->Render(picture, render_target,
/*reset_host_buffer=*/true);
reset_host_buffer);
}));
});

Expand Down
14 changes: 8 additions & 6 deletions shell/gpu/gpu_surface_metal_impeller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,13 @@
impeller::DlDispatcher impeller_dispatcher(cull_rect);
display_list->Dispatch(impeller_dispatcher, sk_cull_rect);
auto picture = impeller_dispatcher.EndRecordingAsPicture();
const bool reset_host_buffer = surface_frame.submit_info().frame_boundary;

return renderer->Render(
std::move(surface),
fml::MakeCopyable([aiks_context, picture = std::move(picture)](
impeller::RenderTarget& render_target) -> bool {
return aiks_context->Render(picture, render_target, /*reset_host_buffer=*/true);
fml::MakeCopyable([aiks_context, picture = std::move(picture),
reset_host_buffer](impeller::RenderTarget& render_target) -> bool {
return aiks_context->Render(picture, render_target, reset_host_buffer);
}));
#endif
});
Expand Down Expand Up @@ -307,11 +308,12 @@
display_list->Dispatch(impeller_dispatcher, sk_cull_rect);
auto picture = impeller_dispatcher.EndRecordingAsPicture();

const bool reset_host_buffer = surface_frame.submit_info().frame_boundary;
bool render_result = renderer->Render(
std::move(surface),
fml::MakeCopyable([aiks_context, picture = std::move(picture)](
impeller::RenderTarget& render_target) -> bool {
return aiks_context->Render(picture, render_target, /*reset_host_buffer=*/true);
fml::MakeCopyable([aiks_context, picture = std::move(picture),
reset_host_buffer](impeller::RenderTarget& render_target) -> bool {
return aiks_context->Render(picture, render_target, reset_host_buffer);
}));
#endif
if (!render_result) {
Expand Down
27 changes: 27 additions & 0 deletions shell/gpu/gpu_surface_metal_impeller_unittests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,32 @@ GPUCAMetalLayerHandle GetCAMetalLayer(const SkISize& frame_info) const override
ASSERT_TRUE(frame->Submit());
}

TEST(GPUSurfaceMetalImpeller, ResetHostBufferBasedOnFrameBoundary) {
auto delegate = std::make_shared<TestGPUSurfaceMetalDelegate>();
delegate->SetDevice();

auto context = CreateImpellerContext();
std::unique_ptr<Surface> surface =
std::make_unique<GPUSurfaceMetalImpeller>(delegate.get(), CreateImpellerContext());

ASSERT_TRUE(surface->IsValid());

auto& host_buffer = surface->GetAiksContext()->GetContentContext().GetTransientsBuffer();

EXPECT_EQ(host_buffer.GetStateForTest().current_frame, 0u);

auto frame = surface->AcquireFrame(SkISize::Make(100, 100));
frame->set_submit_info({.frame_boundary = false});

ASSERT_TRUE(frame->Submit());
EXPECT_EQ(host_buffer.GetStateForTest().current_frame, 0u);

frame = surface->AcquireFrame(SkISize::Make(100, 100));
frame->set_submit_info({.frame_boundary = true});

ASSERT_TRUE(frame->Submit());
EXPECT_EQ(host_buffer.GetStateForTest().current_frame, 1u);
}

} // namespace testing
} // namespace flutter
5 changes: 3 additions & 2 deletions shell/gpu/gpu_surface_vulkan_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceVulkanImpeller::AcquireFrame(
impeller_dispatcher,
SkIRect::MakeWH(cull_rect.width, cull_rect.height));
auto picture = impeller_dispatcher.EndRecordingAsPicture();

const bool reset_host_buffer =
surface_frame.submit_info().frame_boundary;
return aiks_context->Render(picture, render_target,
/*reset_host_buffer=*/true);
reset_host_buffer);
#endif
}));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,10 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
slice->render_into(overlay_canvas);
overlay_canvas->RestoreToCount(restore_count);

// This flutter view is never the last in a frame, since we always submit the
// underlay view last.
frame->set_submit_info({.frame_boundary = false});

layer->did_submit_last_frame = frame->Submit();
return layer;
}
Expand Down