Quartz: Restore 1.2.14 behaviour of letting apps draw from background thread. SDL-1.2
authorRyan C. Gordon
Mon, 02 Jan 2012 21:25:34 -0800
branchSDL-1.2
changeset 61578a1bc41db6bb
parent 6155 894b6e3637c7
child 6158 6f3a2bb301d6
Quartz: Restore 1.2.14 behaviour of letting apps draw from background thread.

Strictly speaking, this isn't encouraged, but it's a regression.
src/video/quartz/SDL_QuartzVideo.h
src/video/quartz/SDL_QuartzVideo.m
     1.1 --- a/src/video/quartz/SDL_QuartzVideo.h	Tue Jan 03 01:41:17 2012 -0500
     1.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Mon Jan 02 21:25:34 2012 -0800
     1.3 @@ -93,6 +93,7 @@
     1.4      const void         *save_mode;         /* original mode of the display */
     1.5      CGDirectPaletteRef palette;            /* palette of an 8-bit display */
     1.6      NSOpenGLContext    *gl_context;        /* OpenGL rendering context */
     1.7 +    NSGraphicsContext  *nsgfx_context;     /* Cocoa graphics context */
     1.8      Uint32             width, height, bpp; /* frequently used data about the display */
     1.9      Uint32             flags;              /* flags for current mode, for teardown purposes */
    1.10      Uint32             video_set;          /* boolean; indicates if video was set correctly */
    1.11 @@ -132,6 +133,7 @@
    1.12  #define allow_screensaver (this->hidden->allow_screensaver)
    1.13  #define palette (this->hidden->palette)
    1.14  #define gl_context (this->hidden->gl_context)
    1.15 +#define nsgfx_context (this->hidden->nsgfx_context)
    1.16  #define device_width (this->hidden->width)
    1.17  #define device_height (this->hidden->height)
    1.18  #define device_bpp (this->hidden->bpp)
     2.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Tue Jan 03 01:41:17 2012 -0500
     2.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Mon Jan 02 21:25:34 2012 -0800
     2.3 @@ -1149,9 +1149,8 @@
     2.4      }
     2.5  
     2.6      if (qz_window != nil) {
     2.7 -        NSGraphicsContext *ctx;
     2.8 -        ctx = [NSGraphicsContext graphicsContextWithWindow:qz_window];
     2.9 -        [NSGraphicsContext setCurrentContext:ctx];
    2.10 +        nsgfx_context = [NSGraphicsContext graphicsContextWithWindow:qz_window];
    2.11 +        [NSGraphicsContext setCurrentContext:nsgfx_context];
    2.12      }
    2.13  
    2.14      /* Setup the new pixel format */
    2.15 @@ -1507,8 +1506,12 @@
    2.16      }
    2.17      
    2.18      else {
    2.19 -        CGContextRef cgc = (CGContextRef)
    2.20 -            [[NSGraphicsContext currentContext] graphicsPort];
    2.21 +        NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
    2.22 +        if (ctx != nsgfx_context) { /* uhoh, you might be rendering from another thread... */
    2.23 +            [NSGraphicsContext setCurrentContext:nsgfx_context];
    2.24 +            ctx = nsgfx_context;
    2.25 +        }
    2.26 +        CGContextRef cgc = (CGContextRef) [ctx graphicsPort];
    2.27          QZ_DrawResizeIcon (this);
    2.28          CGContextFlush (cg_context);
    2.29          CGImageRef image = CGBitmapContextCreateImage (cg_context);