[Impeller] fix Xcode frame capture. (flutter/engine#42289)

This fixed things for me locally. Confirmed frame captures work and this block otherwise doesn't fire when running regularly
This commit is contained in:
Jonah Williams
2023-05-24 12:32:06 -07:00
committed by GitHub
parent 4c29368376
commit 5fbc30881d

View File

@@ -153,6 +153,20 @@ IRect SurfaceMTL::coverage() const {
return IRect::MakeSize(resolve_texture_->GetSize());
}
static bool ShouldWaitForCommandBuffer() {
#if ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR)
// If a transaction is present, `presentDrawable` will present too early. And
// so we wait on an empty command buffer to get scheduled instead, which
// forces us to also wait for all of the previous command buffers in the queue
// to get scheduled.
return true;
#else
// On Physical iOS devices we still need to wait if we're taking a frame
// capture.
return [[MTLCaptureManager sharedCaptureManager] isCapturing];
#endif // ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR)
}
// |Surface|
bool SurfaceMTL::Present() const {
if (drawable_ == nil) {
@@ -179,17 +193,12 @@ bool SurfaceMTL::Present() const {
}
}
#if ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR)
// If a transaction is present, `presentDrawable` will present too early. And
// so we wait on an empty command buffer to get scheduled instead, which
// forces us to also wait for all of the previous command buffers in the queue
// to get scheduled.
id<MTLCommandBuffer> command_buffer =
ContextMTL::Cast(context.get())->CreateMTLCommandBuffer();
[command_buffer commit];
[command_buffer waitUntilScheduled];
#endif // ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR)
if (ShouldWaitForCommandBuffer()) {
id<MTLCommandBuffer> command_buffer =
ContextMTL::Cast(context.get())->CreateMTLCommandBuffer();
[command_buffer commit];
[command_buffer waitUntilScheduled];
}
[drawable_ present];
return true;