From 704dcf7398ec9f97ce2bb8b97a1ee20f604285d5 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 4 Nov 2011 00:58:24 -0400 Subject: [PATCH] Mac OS X: Try to resize--without destroying--the GL context in SetVideoMode. --- src/video/quartz/SDL_QuartzVideo.m | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/video/quartz/SDL_QuartzVideo.m b/src/video/quartz/SDL_QuartzVideo.m index 2f8985741..186302a46 100644 --- a/src/video/quartz/SDL_QuartzVideo.m +++ b/src/video/quartz/SDL_QuartzVideo.m @@ -1113,6 +1113,37 @@ other blitting while waiting on the VBL (and hence results in higher framerates) int height, int bpp, Uint32 flags) { const BOOL isLion = IS_LION_OR_LATER(this); + + /* Don't throw away the GL context if we can just resize the current one. */ + if ( (video_set == SDL_TRUE) && ((flags & (SDL_OPENGL | SDL_FULLSCREEN)) == (current->flags & (SDL_OPENGL | SDL_FULLSCREEN))) && (bpp == current->format->BitsPerPixel) ) { + const NSRect contentRect = NSMakeRect (0, 0, width, height); + if (flags & SDL_FULLSCREEN) { + /* if these fail, we'll try the old way, of tearing everything down. */ + const void *newmode = QZ_BestMode(this, bpp, width, height); + if ( newmode != NULL ) { + if ( QZ_SetDisplayMode(this, newmode) != CGDisplayNoErr ) { + QZ_ReleaseDisplayMode(this, newmode); + } else { + QZ_ReleaseDisplayMode(this, mode); /* NULL is okay. */ + mode = newmode; + current->w = width; + current->h = height; + [ qz_window setContentSize:contentRect.size ]; + [ window_view setFrameSize:contentRect.size ]; + [ gl_context update ]; + return current; + } + } + } else { + current->w = width; + current->h = height; + [ qz_window setContentSize:contentRect.size ]; + [ window_view setFrameSize:contentRect.size ]; + [ gl_context update ]; + return current; + } + } + current->flags = 0; current->pixels = NULL;