diff --git a/Headers/opal/OpalSurface.h b/Headers/opal/OpalSurface.h index 1e6e104..4e57425 100644 --- a/Headers/opal/OpalSurface.h +++ b/Headers/opal/OpalSurface.h @@ -35,7 +35,7 @@ CGContextRef _x11CGContext; } -- (id) initWithDevice: (void *)device; +- (id) initWithDevice: (void *)device context: (CGContextRef)ctx; - (void *)device; - (CGContextRef) CGContext; - (NSSize) size; diff --git a/Source/opal/OpalContext.m b/Source/opal/OpalContext.m index e77a03c..74983e2 100644 --- a/Source/opal/OpalContext.m +++ b/Source/opal/OpalContext.m @@ -167,8 +167,20 @@ : (int)y { OpalSurface *surface; - - surface = [[OpalSurface alloc] initWithDevice: device]; + + /* + * The "graphics port" associated to an OpalContext is necessarily a + * CGContextRef supplied by the client to back the OpalContext, instead + * of having us create the CGContextRef ourselves. + * + * Since -graphicsPort is overriden from NSGraphicsContext to compute the + * CGContextRef for an OpalSurface (which is not initialized yet), we + * get the _graphicsPort ivar directly to obtain the supplied CGContextRef + * on initialization, and use that to init our surface. + */ + CGContextRef suppliedContext = self->_graphicsPort; + surface = [[OpalSurface alloc] initWithDevice: device + context: suppliedContext]; [OGSTATE GSSetSurface: surface : x diff --git a/Source/opal/OpalSurface.m b/Source/opal/OpalSurface.m index c49d8d1..13df6df 100644 --- a/Source/opal/OpalSurface.m +++ b/Source/opal/OpalSurface.m @@ -70,7 +70,7 @@ static CGContextRef createCGBitmapContext(int pixelsWide, @implementation OpalSurface -- (void) createCGContexts +- (void) createCGContextsWithSuppliedBackingContext: (CGContextRef)ctx { // FIXME: this method and class presumes we are being passed // a window device. @@ -83,7 +83,7 @@ static CGContextRef createCGBitmapContext(int pixelsWide, Display * display = _gsWindowDevice->display; Window window = _gsWindowDevice->ident; - _x11CGContext = OPX11ContextCreate(display, window); + _x11CGContext = ctx ?: OPX11ContextCreate(display, window); #if 0 if (_gsWindowDevice->type == NSBackingStoreNonretained) @@ -114,7 +114,9 @@ static CGContextRef createCGBitmapContext(int pixelsWide, } -- (id) initWithDevice: (void *)device +// FIXME: *VERY* bad things will happen if a non-bitmap +// context is passed here. +- (id) initWithDevice: (void *)device context: (CGContextRef)ctx { self = [super init]; if (!self) @@ -124,7 +126,7 @@ static CGContextRef createCGBitmapContext(int pixelsWide, // a window device. _gsWindowDevice = (gswindow_device_t *) device; - [self createCGContexts]; + [self createCGContextsWithSuppliedBackingContext: ctx]; return self; }