cocoa: Fix OpenGL rendering on macOS 10.14 ("Mojave"). SDL-ryan-batching-renderer
authorRyan C. Gordon <icculus@icculus.org>
Thu, 18 Oct 2018 12:05:05 -0400
branchSDL-ryan-batching-renderer
changeset 123513c003852825a
parent 12350 b1a820d2f1aa
child 12352 2b1707cc57fc
cocoa: Fix OpenGL rendering on macOS 10.14 ("Mojave").

Fixes Bugzilla #4272.
(transplanted from 86dcfbbcacaf0c4a556501644af11b7f99b4352d)
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Oct 18 11:59:48 2018 -0400
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Thu Oct 18 12:05:05 2018 -0400
     1.3 @@ -632,8 +632,6 @@
     1.4      const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
     1.5      _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
     1.6      SDL_ToggleModState(KMOD_CAPS, newflags != 0);
     1.7 -
     1.8 -    ScheduleContextUpdates(_data);
     1.9  }
    1.10  
    1.11  - (void)windowDidResignKey:(NSNotification *)aNotification
    1.12 @@ -1145,14 +1143,18 @@
    1.13  - (BOOL)mouseDownCanMoveWindow;
    1.14  - (void)drawRect:(NSRect)dirtyRect;
    1.15  - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
    1.16 +- (BOOL)wantsUpdateLayer;
    1.17 +- (void)updateLayer;
    1.18  @end
    1.19  
    1.20  @implementation SDLView
    1.21 +
    1.22  - (void)setSDLWindow:(SDL_Window*)window
    1.23  {
    1.24      _sdlWindow = window;
    1.25  }
    1.26  
    1.27 +/* this is used on older macOS revisions. 10.8 and later use updateLayer. */
    1.28  - (void)drawRect:(NSRect)dirtyRect
    1.29  {
    1.30      /* Force the graphics context to clear to black so we don't get a flash of
    1.31 @@ -1163,6 +1165,21 @@
    1.32      SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
    1.33  }
    1.34  
    1.35 +-(BOOL) wantsUpdateLayer
    1.36 +{
    1.37 +    return YES;
    1.38 +}
    1.39 +
    1.40 +-(void) updateLayer
    1.41 +{
    1.42 +    /* Force the graphics context to clear to black so we don't get a flash of
    1.43 +       white until the app is ready to draw. In practice on modern macOS, this
    1.44 +       only gets called for window creation and other extraordinary events. */
    1.45 +    self.layer.backgroundColor = NSColor.blackColor.CGColor;
    1.46 +    ScheduleContextUpdates((SDL_WindowData *) _sdlWindow->driverdata);
    1.47 +    SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
    1.48 +}
    1.49 +
    1.50  - (void)rightMouseDown:(NSEvent *)theEvent
    1.51  {
    1.52      [[self nextResponder] rightMouseDown:theEvent];
    1.53 @@ -1345,6 +1362,7 @@
    1.54              [contentView setWantsBestResolutionOpenGLSurface:YES];
    1.55          }
    1.56      }
    1.57 +
    1.58  #if SDL_VIDEO_OPENGL_ES2
    1.59  #if SDL_VIDEO_OPENGL_EGL
    1.60      if ((window->flags & SDL_WINDOW_OPENGL) &&