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
4 changes: 4 additions & 0 deletions impeller/renderer/backend/metal/surface_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class SurfaceMTL final : public Surface {
present_with_transaction_ = present_with_transaction;
}

/// @brief Perform the final blit and trigger end of frame workloads.
bool PreparePresent();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps Present can not be renamed to SubmitCommandBuffer? What happens if there is a missing call to prepare present? Does Present do that for you implicitly?

I suppose we can figure this out later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wil add an FML_CHECK that we've done both. its all our code so we should be able to do that...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not too concerned. Simple DCHECKS ought to be fine.


// |Surface|
bool Present() const override;

Expand All @@ -82,6 +85,7 @@ class SurfaceMTL final : public Surface {
std::optional<IRect> clip_rect_;
bool frame_boundary_ = false;
bool present_with_transaction_ = false;
bool prepared_ = false;

static bool ShouldPerformPartialRepaint(std::optional<IRect> damage_rect);

Expand Down
14 changes: 12 additions & 2 deletions impeller/renderer/backend/metal/surface_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ - (void)flutterPrepareForPresent:(nonnull id<MTLCommandBuffer>)commandBuffer;
return IRect::MakeSize(resolve_texture_->GetSize());
}

// |Surface|
bool SurfaceMTL::Present() const {
bool SurfaceMTL::PreparePresent() {
auto context = context_.lock();
if (!context) {
return false;
Expand Down Expand Up @@ -260,6 +259,17 @@ - (void)flutterPrepareForPresent:(nonnull id<MTLCommandBuffer>)commandBuffer;
#ifdef IMPELLER_DEBUG
ContextMTL::Cast(context.get())->GetGPUTracer()->MarkFrameEnd();
#endif // IMPELLER_DEBUG
prepared_ = true;
return true;
}

// |Surface|
bool SurfaceMTL::Present() const {
FML_CHECK(prepared_);
auto context = context_.lock();
if (!context) {
return false;
}

if (drawable_) {
id<MTLCommandBuffer> command_buffer =
Expand Down
27 changes: 23 additions & 4 deletions shell/gpu/gpu_surface_metal_impeller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
surface->PresentWithTransaction(surface_frame.submit_info().present_with_transaction);

if (clip_rect && clip_rect->IsEmpty()) {
if (!surface->PreparePresent()) {
return false;
}
surface_frame.set_user_data(std::move(surface));
return true;
}
Expand All @@ -167,7 +170,6 @@
const impeller::RenderTarget& render_target = surface->GetTargetRenderPassDescriptor();
surface->SetFrameBoundary(surface_frame.submit_info().frame_boundary);

surface_frame.set_user_data(std::move(surface));
#if EXPERIMENTAL_CANVAS
impeller::TextFrameDispatcher collector(aiks_context->GetContentContext(),
impeller::Matrix());
Expand All @@ -181,13 +183,25 @@
impeller_dispatcher.FinishRecording();
aiks_context->GetContentContext().GetTransientsBuffer().Reset();
aiks_context->GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();

if (!surface->PreparePresent()) {
return false;
}
surface_frame.set_user_data(std::move(surface));
return true;
#else
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 aiks_context->Render(picture, render_target, reset_host_buffer);

auto result = aiks_context->Render(picture, render_target, reset_host_buffer);

if (!surface->PreparePresent()) {
return false;
}
surface_frame.set_user_data(std::move(surface));
return result;
#endif
});

Expand Down Expand Up @@ -278,6 +292,9 @@
surface->PresentWithTransaction(surface_frame.submit_info().present_with_transaction);

if (clip_rect && clip_rect->IsEmpty()) {
if (!surface->PreparePresent()) {
return false;
}
return surface->Present();
}

Expand All @@ -296,6 +313,9 @@
impeller_dispatcher.FinishRecording();
aiks_context->GetContentContext().GetTransientsBuffer().Reset();
aiks_context->GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();
if (!surface->PreparePresent()) {
return false;
}
bool render_result = true;
#else
impeller::DlDispatcher impeller_dispatcher(cull_rect);
Expand All @@ -310,8 +330,7 @@
FML_LOG(ERROR) << "Failed to render Impeller frame";
return false;
}

return true;
return surface->PreparePresent();
});

SurfaceFrame::SubmitCallback submit_callback =
Expand Down