src/video/cocoa/SDL_cocoametalview.m
changeset 11435 181eadbddae2
parent 11407 ff9e8ae4d4fb
child 11507 071deb801690
     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