Skip to content

Commit

Permalink
macOS: Handle unavailable Metal device
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoole committed Nov 30, 2022
1 parent bbd6ccb commit 6f62954
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Expand Up @@ -1398,7 +1398,10 @@ - (UITextRange*) rangeEnclosingPosition: (JuceUITextPosition*) position

#if JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS
if (@available (iOS 13, *))
metalRenderer = std::make_unique<CoreGraphicsMetalLayerRenderer<UIView>> (view, comp.isOpaque());
{
metalRenderer = CoreGraphicsMetalLayerRenderer<UIView>::create (view, comp.isOpaque());
jassert (metalRenderer != nullptr);
}
#endif

if ((windowStyleFlags & ComponentPeer::windowRequiresSynchronousCoreGraphicsRendering) == 0)
Expand Down
19 changes: 14 additions & 5 deletions modules/juce_gui_basics/native/juce_mac_CGMetalLayerRenderer.h
Expand Up @@ -35,12 +35,11 @@ class CoreGraphicsMetalLayerRenderer
{
public:
//==============================================================================
CoreGraphicsMetalLayerRenderer (ViewType* view, bool isOpaque)
static auto create (ViewType* view, bool isOpaque)
{
device.reset (MTLCreateSystemDefaultDevice());
commandQueue.reset ([device.get() newCommandQueue]);

attach (view, isOpaque);
ObjCObjectHandle<id<MTLDevice>> device { MTLCreateSystemDefaultDevice() };
return rawToUniquePtr (device != nullptr ? new CoreGraphicsMetalLayerRenderer (device, view, isOpaque)
: nullptr);
}

~CoreGraphicsMetalLayerRenderer()
Expand Down Expand Up @@ -223,6 +222,16 @@ class CoreGraphicsMetalLayerRenderer
}

private:
//==============================================================================
CoreGraphicsMetalLayerRenderer (ObjCObjectHandle<id<MTLDevice>> mtlDevice,
ViewType* view,
bool isOpaque)
: device (mtlDevice),
commandQueue ([device.get() newCommandQueue])
{
attach (view, isOpaque);
}

//==============================================================================
static auto alignTo (size_t n, size_t alignment)
{
Expand Down
Expand Up @@ -151,7 +151,7 @@ static constexpr int translateVirtualToAsciiKeyCode (int keyCode) noexcept
#if USE_COREGRAPHICS_RENDERING
#if JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS
if (@available (macOS 10.14, *))
metalRenderer = std::make_unique<CoreGraphicsMetalLayerRenderer<NSView>> (view, getComponent().isOpaque());
metalRenderer = CoreGraphicsMetalLayerRenderer<NSView>::create (view, getComponent().isOpaque());
#endif
if ((windowStyleFlags & ComponentPeer::windowRequiresSynchronousCoreGraphicsRendering) == 0)
{
Expand Down

0 comments on commit 6f62954

Please sign in to comment.