Mac OS X: Try to resize--without destroying--the GL context in SetVideoMode. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Fri, 04 Nov 2011 00:58:24 -0400
branchSDL-1.2
changeset 6050e77741114d13
parent 6049 4b79fd1fd9a3
child 6055 90167a588fd4
Mac OS X: Try to resize--without destroying--the GL context in SetVideoMode.
src/video/quartz/SDL_QuartzVideo.m
     1.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Fri Nov 04 00:56:11 2011 -0400
     1.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Fri Nov 04 00:58:24 2011 -0400
     1.3 @@ -1113,6 +1113,37 @@
     1.4                                       int height, int bpp, Uint32 flags)
     1.5  {
     1.6      const BOOL isLion = IS_LION_OR_LATER(this);
     1.7 +
     1.8 +    /* Don't throw away the GL context if we can just resize the current one. */
     1.9 +    if ( (video_set == SDL_TRUE) && ((flags & (SDL_OPENGL | SDL_FULLSCREEN)) == (current->flags & (SDL_OPENGL | SDL_FULLSCREEN))) && (bpp == current->format->BitsPerPixel) ) {
    1.10 +        const NSRect contentRect = NSMakeRect (0, 0, width, height);
    1.11 +        if (flags & SDL_FULLSCREEN) {
    1.12 +            /* if these fail, we'll try the old way, of tearing everything down. */
    1.13 +            const void *newmode = QZ_BestMode(this, bpp, width, height);
    1.14 +            if ( newmode != NULL ) {
    1.15 +                if ( QZ_SetDisplayMode(this, newmode) != CGDisplayNoErr ) {
    1.16 +                    QZ_ReleaseDisplayMode(this, newmode);
    1.17 +                } else {
    1.18 +                    QZ_ReleaseDisplayMode(this, mode);  /* NULL is okay. */
    1.19 +                    mode = newmode;
    1.20 +                    current->w = width;
    1.21 +                    current->h = height;
    1.22 +                    [ qz_window setContentSize:contentRect.size ];
    1.23 +                    [ window_view setFrameSize:contentRect.size ];
    1.24 +                    [ gl_context update ];
    1.25 +                    return current;
    1.26 +                }
    1.27 +            }
    1.28 +        } else {
    1.29 +            current->w = width;
    1.30 +            current->h = height;
    1.31 +            [ qz_window setContentSize:contentRect.size ];
    1.32 +            [ window_view setFrameSize:contentRect.size ];
    1.33 +            [ gl_context update ];
    1.34 +            return current;
    1.35 +        }
    1.36 +    }
    1.37 +
    1.38      current->flags = 0;
    1.39      current->pixels = NULL;
    1.40