src/video/uikit/SDL_uikitmetalview.m
changeset 12320 758d4e1222a7
parent 12002 9116d02d3feb
child 12503 806492103856
equal deleted inserted replaced
12319:06e89f1159f9 12320:758d4e1222a7
    47 - (instancetype)initWithFrame:(CGRect)frame
    47 - (instancetype)initWithFrame:(CGRect)frame
    48                         scale:(CGFloat)scale
    48                         scale:(CGFloat)scale
    49 {
    49 {
    50     if ((self = [super initWithFrame:frame])) {
    50     if ((self = [super initWithFrame:frame])) {
    51         self.tag = METALVIEW_TAG;
    51         self.tag = METALVIEW_TAG;
    52         /* Set the desired scale. */
       
    53         ((CAMetalLayer *) self.layer).drawableSize = self.bounds.size;
       
    54         self.layer.contentsScale = scale;
    52         self.layer.contentsScale = scale;
       
    53         [self updateDrawableSize];
    55     }
    54     }
    56 
    55 
    57     return self;
    56     return self;
    58 }
    57 }
    59 
    58 
    60 /* Set the size of the metal drawables when the view is resized. */
    59 /* Set the size of the metal drawables when the view is resized. */
    61 - (void)layoutSubviews
    60 - (void)layoutSubviews
    62 {
    61 {
    63     CGSize bounds;
    62     [super layoutSubviews];
       
    63     [self updateDrawableSize];
       
    64 }
    64 
    65 
    65     [super layoutSubviews];
    66 - (void)updateDrawableSize
    66 
    67 {
    67     bounds = [self bounds].size;
    68     CGSize size = self.bounds.size;
    68     bounds.width *= self.layer.contentsScale;
    69     size.width *= self.layer.contentsScale;
    69     bounds.height *= self.layer.contentsScale;
    70     size.height *= self.layer.contentsScale;
    70     ((CAMetalLayer *) self.layer).drawableSize = bounds;
    71     ((CAMetalLayer *)self.layer).drawableSize = size;
    71 }
    72 }
    72 
    73 
    73 @end
    74 @end
    74 
    75 
    75 SDL_uikitmetalview*
    76 SDL_uikitmetalview*