src/video/cocoa/SDL_cocoametalview.m
changeset 12998 b87ba0fad17e
parent 12797 a7ce9dc7a31f
child 13029 3e281c2da43a
     1.1 --- a/src/video/cocoa/SDL_cocoametalview.m	Sun Aug 04 23:30:55 2019 -0300
     1.2 +++ b/src/video/cocoa/SDL_cocoametalview.m	Mon Aug 05 12:35:32 2019 -0300
     1.3 @@ -27,7 +27,7 @@
     1.4  
     1.5  #import "SDL_cocoametalview.h"
     1.6  
     1.7 -#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL)
     1.8 +#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL)
     1.9  
    1.10  #include "SDL_assert.h"
    1.11  
    1.12 @@ -100,22 +100,38 @@
    1.13  
    1.14  @end
    1.15  
    1.16 -SDL_cocoametalview*
    1.17 -Cocoa_Mtl_AddMetalView(SDL_Window* window)
    1.18 -{
    1.19 +SDL_MetalView
    1.20 +Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
    1.21 +{ @autoreleasepool {
    1.22      SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata;
    1.23      NSView *view = data->nswindow.contentView;
    1.24      BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
    1.25 -    SDL_cocoametalview *metalview;
    1.26 +    SDL_cocoametalview *newview;
    1.27 +    SDL_MetalView metalview;
    1.28  
    1.29 -    metalview = [[SDL_cocoametalview alloc] initWithFrame:view.frame highDPI:highDPI];
    1.30 -    [view addSubview:metalview];
    1.31 +    newview = [[SDL_cocoametalview alloc] initWithFrame:view.frame highDPI:highDPI];
    1.32 +    if (newview == nil) {
    1.33 +        return NULL;
    1.34 +    }
    1.35 +
    1.36 +    [view addSubview:newview];
    1.37 +
    1.38 +    metalview = (SDL_MetalView)CFBridgingRetain(newview);
    1.39 +    [newview release];
    1.40 +
    1.41      return metalview;
    1.42 -}
    1.43 +}}
    1.44  
    1.45  void
    1.46 -Cocoa_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h)
    1.47 -{
    1.48 +Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view)
    1.49 +{ @autoreleasepool {
    1.50 +    SDL_cocoametalview *metalview = CFBridgingRelease(view);
    1.51 +    [metalview removeFromSuperview];
    1.52 +}}
    1.53 +
    1.54 +void
    1.55 +Cocoa_Metal_GetDrawableSize(SDL_Window * window, int * w, int * h)
    1.56 +{ @autoreleasepool {
    1.57      SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
    1.58      NSView *view = data->nswindow.contentView;
    1.59      SDL_cocoametalview* metalview = [view viewWithTag:METALVIEW_TAG];
    1.60 @@ -131,8 +147,8 @@
    1.61      } else {
    1.62          SDL_GetWindowSize(window, w, h);
    1.63      }
    1.64 -}
    1.65 +}}
    1.66  
    1.67 -#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL) */
    1.68 +#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL) */
    1.69  
    1.70  /* vi: set ts=4 sw=4 expandtab: */