opal/context: allow the client to supply a graphics port

In Quartz, the "graphics port" bound to an NSGraphicsContext (subclassed
by OpalContext) is a CGContext. We currently initialize one in
OpalSurface if it does not exist, however we do not allow the client to
initialize a graphics context with a custom graphics port, which should
be allowed. This commit enables this feature.
This commit is contained in:
Daniel Ferreira 2017-07-20 12:20:33 +10:00
parent 3adb72d6e2
commit 720a56dcf3
3 changed files with 21 additions and 7 deletions

View file

@ -35,7 +35,7 @@
CGContextRef _x11CGContext;
}
- (id) initWithDevice: (void *)device;
- (id) initWithDevice: (void *)device context: (CGContextRef)ctx;
- (void *)device;
- (CGContextRef) CGContext;
- (NSSize) size;

View file

@ -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

View file

@ -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;
}