Code style cleanup in the Cocoa and UIKit vulkan files.
authorAlex Szpakowski <slime73@gmail.com>
Thu, 31 Aug 2017 21:26:13 -0300
changeset 11435181eadbddae2
parent 11434 fffd7c61e077
child 11436 37b2fcd8fc8c
Code style cleanup in the Cocoa and UIKit vulkan files.
src/video/cocoa/SDL_cocoametalview.m
src/video/cocoa/SDL_cocoavulkan.h
src/video/cocoa/SDL_cocoavulkan.m
src/video/uikit/SDL_uikitmetalview.m
     1.1 --- a/src/video/cocoa/SDL_cocoametalview.m	Thu Aug 31 21:13:32 2017 -0300
     1.2 +++ b/src/video/cocoa/SDL_cocoametalview.m	Thu Aug 31 21:26:13 2017 -0300
     1.3 @@ -42,31 +42,37 @@
     1.4  /* Return a Metal-compatible layer. */
     1.5  + (Class)layerClass
     1.6  {
     1.7 -  return NSClassFromString(@"CAMetalLayer");
     1.8 +	return NSClassFromString(@"CAMetalLayer");
     1.9  }
    1.10  
    1.11  /* Indicate the view wants to draw using a backing layer instead of drawRect. */
    1.12 --(BOOL) wantsUpdateLayer { return YES; }
    1.13 +-(BOOL) wantsUpdateLayer
    1.14 +{
    1.15 +    return YES;
    1.16 +}
    1.17  
    1.18  /* When the wantsLayer property is set to YES, this method will be invoked to
    1.19   * return a layer instance.
    1.20   */
    1.21 --(CALayer*) makeBackingLayer { return [self.class.layerClass layer]; }
    1.22 +-(CALayer*) makeBackingLayer
    1.23 +{
    1.24 +    return [self.class.layerClass layer];
    1.25 +}
    1.26  
    1.27  - (instancetype)initWithFrame:(NSRect)frame
    1.28                     useHighDPI:(bool)useHighDPI
    1.29  {
    1.30 -  if ((self = [super initWithFrame:frame])) {
    1.31 +	if ((self = [super initWithFrame:frame])) {
    1.32      
    1.33 -    /* Allow resize. */
    1.34 -    self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
    1.35 -    _tag = METALVIEW_TAG;
    1.36 +        /* Allow resize. */
    1.37 +        self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
    1.38 +        _tag = METALVIEW_TAG;
    1.39        
    1.40 -    _useHighDPI = useHighDPI;
    1.41 -    [self updateDrawableSize];
    1.42 -  }
    1.43 +        _useHighDPI = useHighDPI;
    1.44 +        [self updateDrawableSize];
    1.45 +	}
    1.46    
    1.47 -  return self;
    1.48 +	return self;
    1.49  }
    1.50  
    1.51  /* Set the size of the metal drawables when the view is resized. */
    1.52 @@ -77,12 +83,11 @@
    1.53  
    1.54  - (void)updateDrawableSize
    1.55  {
    1.56 +    NSRect bounds = [self bounds];
    1.57      if (_useHighDPI) {
    1.58 -        NSSize size = [self convertRectToBacking:[self bounds]].size;
    1.59 -         /* Isn't there a better way to convert from NSSize to CGSize? */
    1.60 -        CGSize cgsize = *(CGSize*)&size;
    1.61 -        ((CAMetalLayer *) self.layer).drawableSize = cgsize;
    1.62 +        bounds = [self convertRectToBacking:bounds];
    1.63      }
    1.64 +    ((CAMetalLayer *) self.layer).drawableSize = NSSizeToCGSize(bounds.size);
    1.65  }
    1.66  
    1.67  @end
    1.68 @@ -111,10 +116,12 @@
    1.69      if (metalview) {
    1.70          CAMetalLayer *layer = (CAMetalLayer*)metalview.layer;
    1.71          assert(layer != NULL);
    1.72 -        if (w)
    1.73 +        if (w) {
    1.74              *w = layer.drawableSize.width;
    1.75 -        if (h)
    1.76 +        }
    1.77 +        if (h) {
    1.78              *h = layer.drawableSize.height;
    1.79 +        }
    1.80      }
    1.81  }
    1.82  
     2.1 --- a/src/video/cocoa/SDL_cocoavulkan.h	Thu Aug 31 21:13:32 2017 -0300
     2.2 +++ b/src/video/cocoa/SDL_cocoavulkan.h	Thu Aug 31 21:26:13 2017 -0300
     2.3 @@ -1,6 +1,6 @@
     2.4  /*
     2.5    Simple DirectMedia Layer
     2.6 -  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     2.7 +  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     2.8  
     2.9    This software is provided 'as-is', without any express or implied
    2.10    warranty.  In no event will the authors be held liable for any damages
     3.1 --- a/src/video/cocoa/SDL_cocoavulkan.m	Thu Aug 31 21:13:32 2017 -0300
     3.2 +++ b/src/video/cocoa/SDL_cocoavulkan.m	Thu Aug 31 21:26:13 2017 -0300
     3.3 @@ -1,6 +1,6 @@
     3.4  /*
     3.5    Simple DirectMedia Layer
     3.6 -  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     3.7 +  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     3.8  
     3.9    This software is provided 'as-is', without any express or implied
    3.10    warranty.  In no event will the authors be held liable for any damages
    3.11 @@ -50,17 +50,17 @@
    3.12      SDL_bool hasSurfaceExtension = SDL_FALSE;
    3.13      SDL_bool hasMacOSSurfaceExtension = SDL_FALSE;
    3.14      PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
    3.15 -    if(_this->vulkan_config.loader_handle)
    3.16 -    {
    3.17 +
    3.18 +    if (_this->vulkan_config.loader_handle) {
    3.19          SDL_SetError("MoltenVK/Vulkan already loaded");
    3.20          return -1;
    3.21      }
    3.22  
    3.23      /* Load the Vulkan loader library */
    3.24 -    if(!path)
    3.25 +    if (!path) {
    3.26          path = SDL_getenv("SDL_VULKAN_LIBRARY");
    3.27 -    if(!path)
    3.28 -    {
    3.29 +    }
    3.30 +    if (!path) {
    3.31          /* MoltenVK framework, currently, v0.17.0, has a static library and is
    3.32           * the recommended way to use the package. There is likely no object to
    3.33           * load. */
    3.34 @@ -69,28 +69,25 @@
    3.35                                            "vkGetInstanceProcAddr");
    3.36      }
    3.37      
    3.38 -    if(vkGetInstanceProcAddr)
    3.39 -    {
    3.40 +    if (vkGetInstanceProcAddr) {
    3.41          _this->vulkan_config.loader_handle = DEFAULT_HANDLE;
    3.42 -    }
    3.43 -    else
    3.44 -    {
    3.45 -        if (!path)
    3.46 -        {
    3.47 +    } else {
    3.48 +        if (!path) {
    3.49              /* Look for the .dylib packaged with the application instead. */
    3.50              path = DEFAULT_MOLTENVK;
    3.51          }
    3.52          
    3.53          _this->vulkan_config.loader_handle = SDL_LoadObject(path);
    3.54 -        if(!_this->vulkan_config.loader_handle)
    3.55 +        if (!_this->vulkan_config.loader_handle) {
    3.56              return -1;
    3.57 +        }
    3.58          SDL_strlcpy(_this->vulkan_config.loader_path, path,
    3.59                      SDL_arraysize(_this->vulkan_config.loader_path));
    3.60          vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
    3.61              _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
    3.62      }
    3.63 -    if(!vkGetInstanceProcAddr)
    3.64 -    {
    3.65 +
    3.66 +    if (!vkGetInstanceProcAddr) {
    3.67          SDL_SetError("Failed to find %s in either executable or %s: %s",
    3.68                       "vkGetInstanceProcAddr",
    3.69                       DEFAULT_MOLTENVK,
    3.70 @@ -102,30 +99,29 @@
    3.71      _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
    3.72          (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
    3.73              VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
    3.74 -    if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties)
    3.75 +    if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) {
    3.76          goto fail;
    3.77 +    }
    3.78      extensions = SDL_Vulkan_CreateInstanceExtensionsList(
    3.79          (PFN_vkEnumerateInstanceExtensionProperties)
    3.80              _this->vulkan_config.vkEnumerateInstanceExtensionProperties,
    3.81          &extensionCount);
    3.82 -    if(!extensions)
    3.83 +    if (!extensions) {
    3.84          goto fail;
    3.85 -    for(Uint32 i = 0; i < extensionCount; i++)
    3.86 -    {
    3.87 -        if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
    3.88 +    }
    3.89 +    for (Uint32 i = 0; i < extensionCount; i++) {
    3.90 +        if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
    3.91              hasSurfaceExtension = SDL_TRUE;
    3.92 -        else if(SDL_strcmp(VK_MVK_MACOS_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
    3.93 +        } else if (SDL_strcmp(VK_MVK_MACOS_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
    3.94              hasMacOSSurfaceExtension = SDL_TRUE;
    3.95 +        }
    3.96      }
    3.97      SDL_free(extensions);
    3.98 -    if(!hasSurfaceExtension)
    3.99 -    {
   3.100 +    if (!hasSurfaceExtension) {
   3.101          SDL_SetError("Installed MoltenVK/Vulkan doesn't implement the "
   3.102                       VK_KHR_SURFACE_EXTENSION_NAME " extension");
   3.103          goto fail;
   3.104 -    }
   3.105 -    else if(!hasMacOSSurfaceExtension)
   3.106 -    {
   3.107 +    } else if (!hasMacOSSurfaceExtension) {
   3.108          SDL_SetError("Installed MoltenVK/Vulkan doesn't implement the "
   3.109                       VK_MVK_MACOS_SURFACE_EXTENSION_NAME "extension");
   3.110          goto fail;
   3.111 @@ -140,10 +136,10 @@
   3.112  
   3.113  void Cocoa_Vulkan_UnloadLibrary(_THIS)
   3.114  {
   3.115 -    if(_this->vulkan_config.loader_handle)
   3.116 -    {
   3.117 -        if (_this->vulkan_config.loader_handle != DEFAULT_HANDLE)
   3.118 +    if (_this->vulkan_config.loader_handle) {
   3.119 +        if (_this->vulkan_config.loader_handle != DEFAULT_HANDLE) {
   3.120              SDL_UnloadObject(_this->vulkan_config.loader_handle);
   3.121 +        }
   3.122          _this->vulkan_config.loader_handle = NULL;
   3.123      }
   3.124  }
   3.125 @@ -156,8 +152,7 @@
   3.126      static const char *const extensionsForCocoa[] = {
   3.127          VK_KHR_SURFACE_EXTENSION_NAME, VK_MVK_MACOS_SURFACE_EXTENSION_NAME
   3.128      };
   3.129 -    if(!_this->vulkan_config.loader_handle)
   3.130 -    {
   3.131 +    if (!_this->vulkan_config.loader_handle) {
   3.132          SDL_SetError("Vulkan is not loaded");
   3.133          return SDL_FALSE;
   3.134      }
   3.135 @@ -180,14 +175,12 @@
   3.136      VkMacOSSurfaceCreateInfoMVK createInfo = {};
   3.137      VkResult result;
   3.138  
   3.139 -    if(!_this->vulkan_config.loader_handle)
   3.140 -    {
   3.141 +    if (!_this->vulkan_config.loader_handle) {
   3.142          SDL_SetError("Vulkan is not loaded");
   3.143          return SDL_FALSE;
   3.144      }
   3.145  
   3.146 -    if(!vkCreateMacOSSurfaceMVK)
   3.147 -    {
   3.148 +    if (!vkCreateMacOSSurfaceMVK) {
   3.149          SDL_SetError(VK_MVK_MACOS_SURFACE_EXTENSION_NAME
   3.150                       " extension is not enabled in the Vulkan instance.");
   3.151          return SDL_FALSE;
   3.152 @@ -198,8 +191,7 @@
   3.153      createInfo.pView = Cocoa_Mtl_AddMetalView(window);
   3.154      result = vkCreateMacOSSurfaceMVK(instance, &createInfo,
   3.155                                         NULL, surface);
   3.156 -    if(result != VK_SUCCESS)
   3.157 -    {
   3.158 +    if (result != VK_SUCCESS) {
   3.159          SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s",
   3.160                       SDL_Vulkan_GetResultString(result));
   3.161          return SDL_FALSE;
     4.1 --- a/src/video/uikit/SDL_uikitmetalview.m	Thu Aug 31 21:13:32 2017 -0300
     4.2 +++ b/src/video/uikit/SDL_uikitmetalview.m	Thu Aug 31 21:26:13 2017 -0300
     4.3 @@ -129,18 +129,23 @@
     4.4  void
     4.5  UIKit_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h)
     4.6  {
     4.7 -    SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
     4.8 -    SDL_uikitview *view = (SDL_uikitview*)data.uiwindow.rootViewController.view;
     4.9 -    SDL_uikitmetalview* metalview = [view viewWithTag:METALVIEW_TAG];
    4.10 -    if (metalview) {
    4.11 -        CAMetalLayer *layer = (CAMetalLayer*)metalview.layer;
    4.12 -        assert(layer != NULL);
    4.13 -        if (w)
    4.14 -            *w = layer.drawableSize.width;
    4.15 -        if (h)
    4.16 -            *h = layer.drawableSize.height;
    4.17 -    } else
    4.18 -        SDL_GetWindowSize(window, w, h);
    4.19 +    @autoreleasepool {
    4.20 +        SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
    4.21 +        SDL_uikitview *view = (SDL_uikitview*)data.uiwindow.rootViewController.view;
    4.22 +        SDL_uikitmetalview* metalview = [view viewWithTag:METALVIEW_TAG];
    4.23 +        if (metalview) {
    4.24 +            CAMetalLayer *layer = (CAMetalLayer*)metalview.layer;
    4.25 +            assert(layer != NULL);
    4.26 +            if (w) {
    4.27 +                *w = layer.drawableSize.width;
    4.28 +            }
    4.29 +            if (h) {
    4.30 +                *h = layer.drawableSize.height;
    4.31 +            }
    4.32 +        } else {
    4.33 +            SDL_GetWindowSize(window, w, h);
    4.34 +        }
    4.35 +    }
    4.36  }
    4.37  
    4.38  #endif