Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Use final cmd buffer to present drawable. #46023

Merged
merged 4 commits into from
Sep 21, 2023
Merged
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
17 changes: 13 additions & 4 deletions impeller/renderer/backend/metal/surface_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,22 @@
}

if (drawable_) {
TRACE_EVENT0("flutter", "waitUntilScheduled");
Copy link
Member

Choose a reason for hiding this comment

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

Should we keep this trace, but move it into waitUntilScheduled's new scope?

id<MTLCommandBuffer> command_buffer =
ContextMTL::Cast(context.get())
->CreateMTLCommandBuffer("Present Waiter Command Buffer");
[command_buffer commit];
[command_buffer waitUntilScheduled];
[drawable_ present];
// If the threads have been merged, or there is a pending frame capture,
// then block on cmd buffer scheduling to ensure that the
// transaction/capture work correctly.
if ([[NSThread currentThread] isMainThread] ||
Copy link
Member

Choose a reason for hiding this comment

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

Would this check work if a custom embedder launched the engine in a thread other than the main thread?

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 think technically this only needs to match wherever we set the layer to presentsWithTransaction. But I suspect that is only for iOS? I'll have to check how macOS desktop is doing.

[[MTLCaptureManager sharedCaptureManager] isCapturing]) {
TRACE_EVENT0("flutter", "waitUntilScheduled");
[command_buffer commit];
[command_buffer waitUntilScheduled];
[drawable_ present];
} else {
[command_buffer presentDrawable:drawable_];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wait, I need to double check if this messes up frame capture. If so we need to check if we're capturing a frame and block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

[command_buffer commit];
}
}

return true;
Expand Down