[Commits] SDL: metal: Use the existing cocoa code for creating a Metal vie...

libsdl.org revision control commits-owner at libsdl.org
Sun Dec 31 11:30:27 PST 2017


details:   https://hg.libsdl.org/SDL/rev/09ce6232a084
changeset: 11798:09ce6232a084
user:      Alex Szpakowski <slime73 at gmail.com>
date:      Sun Dec 31 15:30:08 2017 -0400
description:
metal: Use the existing cocoa code for creating a Metal view on macOS. Fixes the renderer size when the window is resized.

diffstat:

 src/render/metal/SDL_render_metal.m |  34 +++++++++++++++++-----------------
 1 files changed, 17 insertions(+), 17 deletions(-)

diffs (74 lines):

diff -r 4da70548aa06 -r 09ce6232a084 src/render/metal/SDL_render_metal.m
--- a/src/render/metal/SDL_render_metal.m	Sun Dec 31 15:21:25 2017 -0400
+++ b/src/render/metal/SDL_render_metal.m	Sun Dec 31 15:30:08 2017 -0400
@@ -29,12 +29,12 @@
 #include "../SDL_sysrender.h"
 
 #ifdef __MACOSX__
-#include <Cocoa/Cocoa.h>
+#include "../../video/cocoa/SDL_cocoametalview.h"
 #else
 #include "../../video/uikit/SDL_uikitmetalview.h"
 #endif
-#include <Metal/Metal.h>
-#include <QuartzCore/CAMetalLayer.h>
+#import <Metal/Metal.h>
+#import <QuartzCore/CAMetalLayer.h>
 
 /* Regenerate these with build-metal-shaders.sh */
 #ifdef __MACOSX__
@@ -279,21 +279,15 @@
 
     // !!! FIXME: error checking on all of this.
 
-    NSView *nsview = [syswm.info.cocoa.window contentView];
-
-    // CAMetalLayer is available in QuartzCore starting at OSX 10.11
-    CAMetalLayer *layer = [NSClassFromString( @"CAMetalLayer" ) layer];
+    NSView *view = Cocoa_Mtl_AddMetalView(window);
+    CAMetalLayer *layer = (CAMetalLayer *)[view layer];
 
     layer.device = mtldevice;
-    //layer.pixelFormat = MTLPixelFormatBGRA8Unorm;  // !!! FIXME: MTLPixelFormatBGRA8Unorm_sRGB ?
+
+    // !!! FIXME: We might want this to be NO for RenderReadPixels.
     layer.framebufferOnly = YES;
-    //layer.drawableSize = (CGSize) [nsview convertRectToBacking:[nsview bounds]].size;
     //layer.colorspace = nil;
 
-    [nsview setWantsLayer:YES];
-    [nsview setLayer:layer];
-
-    [layer retain];
 #else
     UIView *view = UIKit_Mtl_AddMetalView(window);
     CAMetalLayer *layer = (CAMetalLayer *)[view layer];
@@ -358,7 +352,7 @@
 
 #if defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)
     if (@available(macOS 10.13, *)) {
-        layer.displaySyncEnabled = (flags & SDL_RENDERER_PRESENTVSYNC) != 0;
+        data.mtllayer.displaySyncEnabled = (flags & SDL_RENDERER_PRESENTVSYNC) != 0;
     } else
 #endif
     {
@@ -401,10 +395,16 @@
 static int
 METAL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
 { @autoreleasepool {
+    METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+    // !!! FIXME: We shouldn't need ActivateRenderer, but drawableSize is 0
+    // in the first frame without it.
     METAL_ActivateRenderer(renderer);
-    METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
-    *w = (int) data.mtlbackbuffer.texture.width;
-    *h = (int) data.mtlbackbuffer.texture.height;
+    if (w) {
+        *w = (int)data.mtllayer.drawableSize.width;
+    }
+    if (h) {
+        *h = (int)data.mtllayer.drawableSize.height;
+    }
     return 0;
 }}
 


More information about the commits mailing list