diff --git a/modules/juce_gui_basics/native/juce_mac_CGMetalLayerRenderer.h b/modules/juce_gui_basics/native/juce_mac_CGMetalLayerRenderer.h index ba0392956c..c451751a6d 100644 --- a/modules/juce_gui_basics/native/juce_mac_CGMetalLayerRenderer.h +++ b/modules/juce_gui_basics/native/juce_mac_CGMetalLayerRenderer.h @@ -45,8 +45,6 @@ public: layer.allowsNextDrawableTimeout = NO; commandQueue.reset ([device.get() newCommandQueue]); - - memoryBlitEvent.reset ([device.get() newSharedEvent]); } ~CoreGraphicsMetalLayerRenderer() @@ -63,14 +61,21 @@ public: Callback&& drawRectWithContext, const RectangleList& dirtyRegions) { - if (resources != nullptr) + if (memoryBlitCommandBuffer != nullptr) { - // If we haven't finished blitting the CPU texture to the GPU then - // report that we have been unable to draw anything. - if (memoryBlitEvent.get().signaledValue != memoryBlitCounter + 1) - return false; - - ++memoryBlitCounter; + switch ([memoryBlitCommandBuffer.get() status]) + { + case MTLCommandBufferStatusNotEnqueued: + case MTLCommandBufferStatusEnqueued: + case MTLCommandBufferStatusCommitted: + case MTLCommandBufferStatusScheduled: + // If we haven't finished blitting the CPU texture to the GPU then + // report that we have been unable to draw anything. + return false; + case MTLCommandBufferStatusCompleted: + case MTLCommandBufferStatusError: + break; + } } layer.contentsScale = scaleFactor; @@ -131,10 +136,6 @@ public: destinationOrigin: MTLOrigin{}]; [blitCommandEncoder endEncoding]; - // Signal that the GPU has finished using the CPU texture - [memoryBlitCommandBuffer.get() encodeSignalEvent: memoryBlitEvent.get() - value: memoryBlitCounter + 1]; - [memoryBlitCommandBuffer.get() addScheduledHandler: ^(id) { // We're on a Metal thread, so we can make a blocking nextDrawable call @@ -351,9 +352,7 @@ private: ObjCObjectHandle> device; ObjCObjectHandle> commandQueue; ObjCObjectHandle> memoryBlitCommandBuffer; - ObjCObjectHandle> memoryBlitEvent; - uint64_t memoryBlitCounter = 0; std::atomic stopGpuCommandSubmission { false }; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CoreGraphicsMetalLayerRenderer)