macOS: Fix MoltenVK Metal view resizing, and allow the metal view to be used without vulkan.
authorAlex Szpakowski <slime73@gmail.com>
Sun, 31 Dec 2017 15:21:25 -0400
changeset 117974da70548aa06
parent 11796 8f385b1fd0b6
child 11798 09ce6232a084
macOS: Fix MoltenVK Metal view resizing, and allow the metal view to be used without vulkan.
include/SDL_config_macosx.h
src/video/cocoa/SDL_cocoametalview.h
src/video/cocoa/SDL_cocoametalview.m
     1.1 --- a/include/SDL_config_macosx.h	Sun Dec 31 03:51:17 2017 -0500
     1.2 +++ b/include/SDL_config_macosx.h	Sun Dec 31 15:21:25 2017 -0400
     1.3 @@ -184,7 +184,12 @@
     1.4  #endif
     1.5  
     1.6  #ifndef SDL_VIDEO_RENDER_METAL
     1.7 +/* Metal only supported on 64-bit architectures with 10.11+ */
     1.8 +#if TARGET_CPU_X86_64 && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101100)
     1.9  #define SDL_VIDEO_RENDER_METAL    1
    1.10 +#else
    1.11 +#define SDL_VIDEO_RENDER_METAL    0
    1.12 +#endif
    1.13  #endif
    1.14  
    1.15  /* Enable OpenGL support */
    1.16 @@ -209,7 +214,7 @@
    1.17  #if TARGET_CPU_X86_64 && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101100)
    1.18  #define SDL_VIDEO_VULKAN 1
    1.19  #else
    1.20 -#define  SDL_VIDEO_VULKAN 0
    1.21 +#define SDL_VIDEO_VULKAN 0
    1.22  #endif
    1.23  
    1.24  /* Enable system power support */
     2.1 --- a/src/video/cocoa/SDL_cocoametalview.h	Sun Dec 31 03:51:17 2017 -0500
     2.2 +++ b/src/video/cocoa/SDL_cocoametalview.h	Sun Dec 31 15:21:25 2017 -0400
     2.3 @@ -32,11 +32,11 @@
     2.4  #import "../SDL_sysvideo.h"
     2.5  #import "SDL_cocoawindow.h"
     2.6  
     2.7 -#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA
     2.8 +#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL)
     2.9  
    2.10 -#include <Cocoa/Cocoa.h>
    2.11 -#include <Metal/Metal.h>
    2.12 -#include <QuartzCore/CAMetalLayer.h>
    2.13 +#import <Cocoa/Cocoa.h>
    2.14 +#import <Metal/Metal.h>
    2.15 +#import <QuartzCore/CAMetalLayer.h>
    2.16  
    2.17  #define METALVIEW_TAG 255
    2.18  
    2.19 @@ -57,7 +57,7 @@
    2.20  
    2.21  void Cocoa_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h);
    2.22  
    2.23 -#endif /* SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA */
    2.24 +#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL) */
    2.25  
    2.26  #endif /* SDL_cocoametalview_h_ */
    2.27  
     3.1 --- a/src/video/cocoa/SDL_cocoametalview.m	Sun Dec 31 03:51:17 2017 -0500
     3.2 +++ b/src/video/cocoa/SDL_cocoametalview.m	Sun Dec 31 15:21:25 2017 -0400
     3.3 @@ -28,7 +28,7 @@
     3.4  
     3.5  #import "SDL_cocoametalview.h"
     3.6  
     3.7 -#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA
     3.8 +#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL)
     3.9  
    3.10  #include "SDL_assert.h"
    3.11  
    3.12 @@ -44,7 +44,7 @@
    3.13  }
    3.14  
    3.15  /* Indicate the view wants to draw using a backing layer instead of drawRect. */
    3.16 --(BOOL) wantsUpdateLayer
    3.17 +- (BOOL)wantsUpdateLayer
    3.18  {
    3.19      return YES;
    3.20  }
    3.21 @@ -52,7 +52,7 @@
    3.22  /* When the wantsLayer property is set to YES, this method will be invoked to
    3.23   * return a layer instance.
    3.24   */
    3.25 --(CALayer*) makeBackingLayer
    3.26 +- (CALayer*)makeBackingLayer
    3.27  {
    3.28      return [self.class.layerClass layer];
    3.29  }
    3.30 @@ -74,8 +74,9 @@
    3.31  }
    3.32  
    3.33  /* Set the size of the metal drawables when the view is resized. */
    3.34 -- (void)resizeSubviewsWithOldSize:(NSSize)oldSize {
    3.35 -    [super resizeSubviewsWithOldSize:oldSize];
    3.36 +- (void)resizeWithOldSuperviewSize:(NSSize)oldSize
    3.37 +{
    3.38 +    [super resizeWithOldSuperviewSize:oldSize];
    3.39      [self updateDrawableSize];
    3.40  }
    3.41  
    3.42 @@ -123,6 +124,6 @@
    3.43      }
    3.44  }
    3.45  
    3.46 -#endif /* SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA */
    3.47 +#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL) */
    3.48  
    3.49  /* vi: set ts=4 sw=4 expandtab: */