227 auto context = context_.lock();
232 #ifdef IMPELLER_DEBUG
233 context->GetResourceAllocator()->DebugTraceMemoryStatistics();
234 #endif // IMPELLER_DEBUG
236 if (requires_blit_) {
237 if (!(source_texture_ && destination_texture_)) {
241 auto blit_command_buffer = context->CreateCommandBuffer();
242 if (!blit_command_buffer) {
245 auto blit_pass = blit_command_buffer->CreateBlitPass();
246 if (!clip_rect_.has_value()) {
250 blit_pass->AddCopy(source_texture_, destination_texture_, std::nullopt,
251 clip_rect_->GetOrigin());
252 blit_pass->EncodeCommands(context->GetResourceAllocator());
253 if (!context->GetCommandQueue()->Submit({blit_command_buffer}).ok()) {
257 #ifdef IMPELLER_DEBUG
259 #endif // IMPELLER_DEBUG
262 id<MTLCommandBuffer> command_buffer =
266 id<CAMetalDrawable> metal_drawable =
267 reinterpret_cast<id<CAMetalDrawable>
>(drawable_);
269 [(id<FlutterMetalDrawable>)metal_drawable
270 flutterPrepareForPresent:command_buffer];
277 #if defined(FML_OS_IOS_SIMULATOR) && defined(FML_ARCH_CPU_X86_64)
278 constexpr
bool alwaysWaitForScheduling =
true;
280 constexpr
bool alwaysWaitForScheduling =
false;
281 #endif // defined(FML_OS_IOS_SIMULATOR) && defined(FML_ARCH_CPU_X86_64)
286 if ([[NSThread currentThread] isMainThread] ||
287 [[MTLCaptureManager sharedCaptureManager] isCapturing] ||
288 alwaysWaitForScheduling) {
289 TRACE_EVENT0(
"flutter",
"waitUntilScheduled");
290 [command_buffer commit];
291 #if defined(FML_OS_IOS_SIMULATOR) && defined(FML_ARCH_CPU_X86_64)
292 [command_buffer waitUntilCompleted];
294 [command_buffer waitUntilScheduled];
295 #endif // defined(FML_OS_IOS_SIMULATOR) && defined(FML_ARCH_CPU_X86_64)
300 id<CAMetalDrawable>
drawable = drawable_;
301 [command_buffer addScheduledHandler:^(id<MTLCommandBuffer> buffer) {
304 [command_buffer commit];