Rework of context window device setting. Requires corresponding change

in gui.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@25981 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2008-01-19 13:12:03 +00:00
parent 0f9d79fc58
commit 0f0191c547
8 changed files with 89 additions and 95 deletions

View file

@ -64,24 +64,13 @@ static int byte_order(void)
[FTFontInfo initializeBackend]; [FTFontInfo initializeBackend];
} }
- (id) initWithContextInfo: (NSDictionary *)info + (Class) GStateClass
{ {
NSString *contextType; return [ARTGState class];
contextType = [info objectForKey: }
NSGraphicsContextRepresentationFormatAttributeName];
self = [super initWithContextInfo: info];
if (contextType)
{
/* Most likely this is a PS or PDF context, so just return what
super gave us
*/
return self;
}
/* Create a default gstate */
gstate = [[ARTGState allocWithZone: [self zone]] initWithDrawContext: self];
- (void) setupDrawInfo
{
#ifdef RDS #ifdef RDS
{ {
RDSServer *s = (RDSServer *)server; RDSServer *s = (RDSServer *)server;
@ -110,21 +99,21 @@ static int byte_order(void)
visualInfo = XGetVisualInfo(d, VisualClassMask, &template, &numMatches); visualInfo = XGetVisualInfo(d, VisualClassMask, &template, &numMatches);
if (!visualInfo) if (!visualInfo)
{ {
template.class = TrueColor; template.class = TrueColor;
visualInfo = XGetVisualInfo(d, VisualClassMask, &template, &numMatches); visualInfo = XGetVisualInfo(d, VisualClassMask, &template, &numMatches);
} }
if (visualInfo) if (visualInfo)
{ {
visual = visualInfo->visual; visual = visualInfo->visual;
bpp = visualInfo->depth; bpp = visualInfo->depth;
XFree(visualInfo); XFree(visualInfo);
} }
else else
{ {
visual = DefaultVisual(d, DefaultScreen(d)); visual = DefaultVisual(d, DefaultScreen(d));
bpp = DefaultDepth(d, DefaultScreen(d)); bpp = DefaultDepth(d, DefaultScreen(d));
} }
i = XCreateImage(d, visual, bpp, ZPixmap, 0, NULL, 8, 8, 8, 0); i = XCreateImage(d, visual, bpp, ZPixmap, 0, NULL, 8, 8, 8, 0);
bpp = i->bits_per_pixel; bpp = i->bits_per_pixel;
XDestroyImage(i); XDestroyImage(i);
@ -136,11 +125,11 @@ static int byte_order(void)
int us = byte_order(); /* True iff we're big-endian. */ int us = byte_order(); /* True iff we're big-endian. */
int them = ImageByteOrder(d); /* True iff the server is big-endian. */ int them = ImageByteOrder(d); /* True iff the server is big-endian. */
if (us != them) if (us != them)
{ {
visual->red_mask = flip_bytes(visual->red_mask); visual->red_mask = flip_bytes(visual->red_mask);
visual->green_mask = flip_bytes(visual->green_mask); visual->green_mask = flip_bytes(visual->green_mask);
visual->blue_mask = flip_bytes(visual->blue_mask); visual->blue_mask = flip_bytes(visual->blue_mask);
} }
} }
/* Only returns if the visual was usable. */ /* Only returns if the visual was usable. */
@ -148,8 +137,6 @@ static int byte_order(void)
visual->blue_mask, bpp); visual->blue_mask, bpp);
} }
#endif #endif
return self;
} }
- (void) flushGraphics - (void) flushGraphics
@ -183,6 +170,7 @@ static int byte_order(void)
@implementation ARTContext (ops) @implementation ARTContext (ops)
- (void) GSSetDevice: (void*)device : (int)x : (int)y - (void) GSSetDevice: (void*)device : (int)x : (int)y
{ {
[self setupDrawInfo];
[(ARTGState *)gstate GSSetDevice: device : x : y]; [(ARTGState *)gstate GSSetDevice: device : x : y];
} }

View file

@ -58,19 +58,14 @@
[GSFontInfo setDefaultClass: [CairoFontInfo class]]; [GSFontInfo setDefaultClass: [CairoFontInfo class]];
} }
- (id) initWithContextInfo: (NSDictionary *)info + (Class) GStateClass
{ {
// Don't allow super to handle PS case. return [CairoGState class];
self = [super initWithContextInfo: nil]; }
if (!self)
return self;
// Now save the info + (BOOL) handlesPS
ASSIGN(context_info, info); {
return YES;
gstate = [[CairoGState allocWithZone: [self zone]] initWithDrawContext: self];
return self;
} }
- (void) flushGraphics - (void) flushGraphics

View file

@ -155,6 +155,16 @@ static NSMapTable *gtable;
NSMapRemove(gtable, (void *)(uintptr_t)index); NSMapRemove(gtable, (void *)(uintptr_t)index);
} }
+ (Class) GStateClass
{
return [GSGState class];
}
+ (BOOL) handlesPS
{
return NO;
}
- (id) initWithContextInfo: (NSDictionary *)info - (id) initWithContextInfo: (NSDictionary *)info
{ {
NSString *contextType; NSString *contextType;
@ -162,24 +172,39 @@ static NSMapTable *gtable;
contextType = [info objectForKey: contextType = [info objectForKey:
NSGraphicsContextRepresentationFormatAttributeName]; NSGraphicsContextRepresentationFormatAttributeName];
if ([self isMemberOfClass: [GSStreamContext class]] == NO if (([isa handlesPS] == NO) && contextType
&& contextType && [contextType isEqual: NSGraphicsContextPSFormat]) && [contextType isEqual: NSGraphicsContextPSFormat])
{ {
/* Don't call self, since we aren't initialized */ /* Don't call self, since we aren't initialized */
[super dealloc]; [super dealloc];
return [[GSStreamContext allocWithZone: z] initWithContextInfo: info]; return [[GSStreamContext allocWithZone: z] initWithContextInfo: info];
} }
/* A context is only associated with one server. Do not retain self = [super initWithContextInfo: info];
the server, however */ if (self != nil)
server = GSCurrentServer(); {
id dest;
/* Initialize lists and stacks */ /* Initialize lists and stacks */
opstack = NSZoneMalloc(z, sizeof(GSIArray_t)); opstack = NSZoneMalloc(z, sizeof(GSIArray_t));
GSIArrayInitWithZoneAndCapacity((GSIArray)opstack, z, 2); GSIArrayInitWithZoneAndCapacity((GSIArray)opstack, z, 2);
gstack = NSZoneMalloc(z, sizeof(GSIArray_t)); gstack = NSZoneMalloc(z, sizeof(GSIArray_t));
GSIArrayInitWithZoneAndCapacity((GSIArray)gstack, z, 2); GSIArrayInitWithZoneAndCapacity((GSIArray)gstack, z, 2);
[super initWithContextInfo: info]; /* Create a default gstate */
gstate = [[[isa GStateClass] allocWithZone: z]
initWithDrawContext: self];
// Special handling for window drawing
dest = [info objectForKey: NSGraphicsContextDestinationAttributeName];
if ((dest != nil) && [dest isKindOfClass: [NSWindow class]])
{
/* A context is only associated with one server. Do not retain
the server, however */
server = GSCurrentServer();
[server setWindowdevice: [(NSWindow*)dest windowNumber]
forContext: self];
}
}
return self; return self;
} }

View file

@ -72,6 +72,16 @@ fpfloat(FILE *stream, float f)
@implementation GSStreamContext @implementation GSStreamContext
+ (Class) GStateClass
{
return [GSStreamGState class];
}
+ (BOOL) handlesPS
{
return YES;
}
- (void) dealloc - (void) dealloc
{ {
if (gstream) if (gstream)
@ -81,7 +91,10 @@ fpfloat(FILE *stream, float f)
- initWithContextInfo: (NSDictionary *)info - initWithContextInfo: (NSDictionary *)info
{ {
[super initWithContextInfo: info]; self = [super initWithContextInfo: info];
if (!self)
return nil;
if (info && [info objectForKey: @"NSOutputFile"]) if (info && [info objectForKey: @"NSOutputFile"])
{ {
NSString *path = [info objectForKey: @"NSOutputFile"]; NSString *path = [info objectForKey: @"NSOutputFile"];
@ -93,22 +106,19 @@ fpfloat(FILE *stream, float f)
#endif #endif
if (!gstream) if (!gstream)
{ {
NSDebugLLog(@"GSContext", @"%@: Could not open printer file %@", NSDebugLLog(@"GSContext", @"%@: Could not open printer file %@",
DPSinvalidfileaccess, path); DPSinvalidfileaccess, path);
return nil; return nil;
} }
} }
else else
{ {
NSDebugLLog(@"GSContext", @"%@: No stream file specified", NSDebugLLog(@"GSContext", @"%@: No stream file specified",
DPSconfigurationerror); DPSconfigurationerror);
DESTROY(self);
return nil; return nil;
} }
/* Create a default gstate */
gstate = [[GSStreamGState allocWithZone: [self zone]]
initWithDrawContext: self];
return self; return self;
} }

View file

@ -1111,15 +1111,13 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg,
return NO; return NO;
} }
- (void) windowdevice: (int) winNum - (void) setWindowdevice: (int)win forContext: (NSGraphicsContext *)ctxt
{ {
NSGraphicsContext *ctxt;
RECT rect; RECT rect;
float h, l, r, t, b; float h, l, r, t, b;
NSWindow *window; NSWindow *window;
NSDebugLLog(@"WTrace", @"windowdevice: %d", winNum); NSDebugLLog(@"WTrace", @"windowdevice: %d", winNum);
ctxt = GSCurrentContext();
window = GSWindowWithNumber(winNum); window = GSWindowWithNumber(winNum);
GetClientRect((HWND)winNum, &rect); GetClientRect((HWND)winNum, &rect);
h = rect.bottom - rect.top; h = rect.bottom - rect.top;

View file

@ -45,14 +45,9 @@
[GSFontInfo setDefaultClass: [WIN32FontInfo class]]; [GSFontInfo setDefaultClass: [WIN32FontInfo class]];
} }
- (id) initWithContextInfo: (NSDictionary *)info + (Class) GStateClass
{ {
[super initWithContextInfo: info]; return [WIN32GState class];
/* Create a default gstate */
gstate = [[WIN32GState allocWithZone: [self zone]] initWithDrawContext: self];
return self;
} }
- (void)flushGraphics - (void)flushGraphics

View file

@ -2541,13 +2541,12 @@ NSLog(@"styleoffsets ... guessing offsets\n");
/** /**
Make sure we have the most up-to-date window information and then Make sure we have the most up-to-date window information and then
make sure the current context has our new information make sure the context has our new information
*/ */
- (void) windowdevice: (int)win - (void) setWindowdevice: (int)win forContext: (NSGraphicsContext *)ctxt
{ {
unsigned width, height; unsigned width, height;
gswindow_device_t *window; gswindow_device_t *window;
NSGraphicsContext *ctxt;
float t, b, l, r; float t, b, l, r;
NSDebugLLog(@"XGTrace", @"DPSwindowdevice: %d ", win); NSDebugLLog(@"XGTrace", @"DPSwindowdevice: %d ", win);
@ -2572,7 +2571,7 @@ NSLog(@"styleoffsets ... guessing offsets\n");
XFreePixmap(dpy, window->buffer); XFreePixmap(dpy, window->buffer);
window->buffer = 0; window->buffer = 0;
if (window->alpha_buffer) if (window->alpha_buffer)
XFreePixmap (dpy, window->alpha_buffer); XFreePixmap (dpy, window->alpha_buffer);
window->alpha_buffer = 0; window->alpha_buffer = 0;
} }
@ -2584,7 +2583,6 @@ NSLog(@"styleoffsets ... guessing offsets\n");
[self _createBuffer: window]; [self _createBuffer: window];
} }
ctxt = GSCurrentContext();
[self styleoffsets: &l : &r : &t : &b [self styleoffsets: &l : &r : &t : &b
: window->win_attrs.window_style : window->ident]; : window->win_attrs.window_style : window->ident];
GSSetDevice(ctxt, window, l, NSHeight(window->xframe) + b); GSSetDevice(ctxt, window, l, NSHeight(window->xframe) + b);

View file

@ -131,24 +131,9 @@
[GSFontEnumerator setDefaultClass: fontEnumerator]; [GSFontEnumerator setDefaultClass: fontEnumerator];
} }
- (id) initWithContextInfo: (NSDictionary *)info + (Class) GStateClass
{ {
NSString *contextType; return [XGGState class];
contextType = [info objectForKey:
NSGraphicsContextRepresentationFormatAttributeName];
self = [super initWithContextInfo: info];
if (contextType)
{
/* Most likely this is a PS or PDF context, so just return what
super gave us */
return self;
}
/* Create a default gstate */
gstate = [[XGGState allocWithZone: [self zone]] initWithDrawContext: self];
return self;
} }
- (void) flushGraphics - (void) flushGraphics