mirror of
https://github.com/gnustep/libs-back.git
synced 2025-05-31 09:21:26 +00:00
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:
parent
3adb72d6e2
commit
720a56dcf3
3 changed files with 21 additions and 7 deletions
|
@ -35,7 +35,7 @@
|
||||||
CGContextRef _x11CGContext;
|
CGContextRef _x11CGContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithDevice: (void *)device;
|
- (id) initWithDevice: (void *)device context: (CGContextRef)ctx;
|
||||||
- (void *)device;
|
- (void *)device;
|
||||||
- (CGContextRef) CGContext;
|
- (CGContextRef) CGContext;
|
||||||
- (NSSize) size;
|
- (NSSize) size;
|
||||||
|
|
|
@ -167,8 +167,20 @@
|
||||||
: (int)y
|
: (int)y
|
||||||
{
|
{
|
||||||
OpalSurface *surface;
|
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
|
[OGSTATE GSSetSurface: surface
|
||||||
: x
|
: x
|
||||||
|
|
|
@ -70,7 +70,7 @@ static CGContextRef createCGBitmapContext(int pixelsWide,
|
||||||
|
|
||||||
@implementation OpalSurface
|
@implementation OpalSurface
|
||||||
|
|
||||||
- (void) createCGContexts
|
- (void) createCGContextsWithSuppliedBackingContext: (CGContextRef)ctx
|
||||||
{
|
{
|
||||||
// FIXME: this method and class presumes we are being passed
|
// FIXME: this method and class presumes we are being passed
|
||||||
// a window device.
|
// a window device.
|
||||||
|
@ -83,7 +83,7 @@ static CGContextRef createCGBitmapContext(int pixelsWide,
|
||||||
Display * display = _gsWindowDevice->display;
|
Display * display = _gsWindowDevice->display;
|
||||||
Window window = _gsWindowDevice->ident;
|
Window window = _gsWindowDevice->ident;
|
||||||
|
|
||||||
_x11CGContext = OPX11ContextCreate(display, window);
|
_x11CGContext = ctx ?: OPX11ContextCreate(display, window);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (_gsWindowDevice->type == NSBackingStoreNonretained)
|
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];
|
self = [super init];
|
||||||
if (!self)
|
if (!self)
|
||||||
|
@ -124,7 +126,7 @@ static CGContextRef createCGBitmapContext(int pixelsWide,
|
||||||
// a window device.
|
// a window device.
|
||||||
_gsWindowDevice = (gswindow_device_t *) device;
|
_gsWindowDevice = (gswindow_device_t *) device;
|
||||||
|
|
||||||
[self createCGContexts];
|
[self createCGContextsWithSuppliedBackingContext: ctx];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue