Backend part of graphic context rewrite.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@24965 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2007-04-04 14:33:10 +00:00
parent 7f68c2ef43
commit ff21318a0a
6 changed files with 159 additions and 90 deletions

View file

@ -1,3 +1,16 @@
2007-04-04 Fred Kiefer <FredKiefer@gmx.de>
* Headers/gsc/GSContext.h: Remove ivar gtable.
* Source/gsc/GSContext.m: Changed to use a gtable object
shared between all contexts.
* Headers/cairo/CairoGState.h:
Declare new methods for save and restore.
* Source/cairo/CairoContext.m (-DPSgrestore, -DPSgsave): Use these methods.
* Source/cairo/CairoGState.m (-DPSgrestore, -DPSgsave): Implement
these methods.
* Source/cairo/CairoGState.m (-compositeGState:...fraction:):
Another try on conversion of the coordinates.
2007-03-30 Fred Kiefer <FredKiefer@gmx.de> 2007-03-30 Fred Kiefer <FredKiefer@gmx.de>
* header/xlib/XGGeometry.h: Replace calls to the now deprecated * header/xlib/XGGeometry.h: Replace calls to the now deprecated

View file

@ -38,6 +38,8 @@
- (void) GSCurrentDevice: (void **)device: (int *)x : (int *)y; - (void) GSCurrentDevice: (void **)device: (int *)x : (int *)y;
- (void) GSSetDevice: (void *)device : (int)x : (int)y; - (void) GSSetDevice: (void *)device : (int)x : (int)y;
- (void) DPSgsave;
- (void) DPSgrestore;
@end @end

View file

@ -40,7 +40,6 @@
void *opstack; void *opstack;
void *gstack; void *gstack;
GSGState *gstate; GSGState *gstate;
NSMapTable *gtable;
} }
- (GSGState *) currentGState; - (GSGState *) currentGState;

View file

@ -113,4 +113,14 @@
[CGSTATE GSSetDevice: device : x : y]; [CGSTATE GSSetDevice: device : x : y];
} }
- (void) DPSgrestore
{
[CGSTATE DPSgrestore];
}
- (void) DPSgsave
{
[CGSTATE DPSgsave];
}
@end @end

View file

@ -120,8 +120,8 @@
status = cairo_status(copy->_ct); status = cairo_status(copy->_ct);
if (status != CAIRO_STATUS_SUCCESS) if (status != CAIRO_STATUS_SUCCESS)
{ {
NSLog(@"Cairo status %s in copy", cairo_status_to_string(status)); NSLog(@"Cairo status %s in copy", cairo_status_to_string(status));
} }
} }
RETAIN(_surface); RETAIN(_surface);
@ -138,13 +138,13 @@
if (device) if (device)
{ {
if (_surface) if (_surface)
{ {
*device = _surface->gsDevice; *device = _surface->gsDevice;
} }
else else
{ {
*device = NULL; *device = NULL;
} }
} }
} }
@ -169,6 +169,22 @@
theOffset.y - size.height); theOffset.y - size.height);
} }
- (void) DPSgrestore
{
if (_ct)
{
cairo_restore(_ct);
}
}
- (void) DPSgsave
{
if (_ct)
{
cairo_save(_ct);
}
}
/* /*
* Color operations * Color operations
*/ */
@ -420,9 +436,9 @@
i = size; i = size;
while (i) while (i)
{ {
i--; i--;
dpat[i] = pat[i]; dpat[i] = pat[i];
} }
// FIXME: There may be a difference in concept as some dashes look wrong // FIXME: There may be a difference in concept as some dashes look wrong
cairo_set_dash(_ct, dpat, size, doffset); cairo_set_dash(_ct, dpat, size, doffset);
GS_ENDITEMBUF(); GS_ENDITEMBUF();
@ -494,23 +510,23 @@
type = (NSBezierPathElement)(*elmidx)(path, elmsel, i, points); type = (NSBezierPathElement)(*elmidx)(path, elmsel, i, points);
switch(type) switch(type)
{ {
case NSMoveToBezierPathElement: case NSMoveToBezierPathElement:
cairo_move_to(_ct, points[0].x, points[0].y); cairo_move_to(_ct, points[0].x, points[0].y);
break; break;
case NSLineToBezierPathElement: case NSLineToBezierPathElement:
cairo_line_to(_ct, points[0].x, points[0].y); cairo_line_to(_ct, points[0].x, points[0].y);
break; break;
case NSCurveToBezierPathElement: case NSCurveToBezierPathElement:
cairo_curve_to(_ct, points[0].x, points[0].y, cairo_curve_to(_ct, points[0].x, points[0].y,
points[1].x, points[1].y, points[1].x, points[1].y,
points[2].x, points[2].y); points[2].x, points[2].y);
break; break;
case NSClosePathBezierPathElement: case NSClosePathBezierPathElement:
cairo_close_path(_ct); cairo_close_path(_ct);
break; break;
default: default:
break; break;
} }
} }
} }
@ -772,25 +788,25 @@ _set_op(cairo_t *ct, NSCompositingOperation op)
for (i = 0; i < pixelsHigh; i++) for (i = 0; i < pixelsHigh; i++)
{ {
unsigned char *d = rowData; unsigned char *d = rowData;
for (j = 0; j < pixelsWide; j++) for (j = 0; j < pixelsWide; j++)
{ {
#if GS_WORDS_BIGENDIAN #if GS_WORDS_BIGENDIAN
tmp[index++] = d[3]; tmp[index++] = d[3];
tmp[index++] = d[0]; tmp[index++] = d[0];
tmp[index++] = d[1]; tmp[index++] = d[1];
tmp[index++] = d[2]; tmp[index++] = d[2];
#else #else
tmp[index++] = d[2]; tmp[index++] = d[2];
tmp[index++] = d[1]; tmp[index++] = d[1];
tmp[index++] = d[0]; tmp[index++] = d[0];
tmp[index++] = d[3]; tmp[index++] = d[3];
#endif #endif
d += 4; d += 4;
} }
rowData += bytesPerRow; rowData += bytesPerRow;
} }
format = CAIRO_FORMAT_ARGB32; format = CAIRO_FORMAT_ARGB32;
break; break;
case 24: case 24:
@ -800,25 +816,25 @@ _set_op(cairo_t *ct, NSCompositingOperation op)
for (i = 0; i < pixelsHigh; i++) for (i = 0; i < pixelsHigh; i++)
{ {
unsigned char *d = rowData; unsigned char *d = rowData;
for (j = 0; j < pixelsWide; j++) for (j = 0; j < pixelsWide; j++)
{ {
#if GS_WORDS_BIGENDIAN #if GS_WORDS_BIGENDIAN
tmp[index++] = 0; tmp[index++] = 0;
tmp[index++] = d[0]; tmp[index++] = d[0];
tmp[index++] = d[1]; tmp[index++] = d[1];
tmp[index++] = d[2]; tmp[index++] = d[2];
#else #else
tmp[index++] = d[2]; tmp[index++] = d[2];
tmp[index++] = d[1]; tmp[index++] = d[1];
tmp[index++] = d[0]; tmp[index++] = d[0];
tmp[index++] = 0; tmp[index++] = 0;
#endif #endif
d += 3; d += 3;
} }
rowData += bytesPerRow; rowData += bytesPerRow;
} }
format = CAIRO_FORMAT_RGB24; format = CAIRO_FORMAT_RGB24;
break; break;
default: default:
@ -837,8 +853,8 @@ _set_op(cairo_t *ct, NSCompositingOperation op)
NSLog(@"Image surface could not be created"); NSLog(@"Image surface could not be created");
if (tmp) if (tmp)
{ {
objc_free(tmp); objc_free(tmp);
} }
return; return;
} }
@ -924,10 +940,10 @@ _set_op(cairo_t *ct, NSCompositingOperation op)
} }
- (void) compositeGState: (CairoGState *)source - (void) compositeGState: (CairoGState *)source
fromRect: (NSRect)aRect fromRect: (NSRect)aRect
toPoint: (NSPoint)aPoint toPoint: (NSPoint)aPoint
op: (NSCompositingOperation)op op: (NSCompositingOperation)op
fraction: (float)delta fraction: (float)delta
{ {
cairo_surface_t *src; cairo_surface_t *src;
double minx, miny; double minx, miny;
@ -956,26 +972,32 @@ _set_op(cairo_t *ct, NSCompositingOperation op)
targetRect.size = aRect.size; targetRect.size = aRect.size;
if (!NSIsEmptyRect(NSIntersectionRect(aRect, targetRect))) if (!NSIsEmptyRect(NSIntersectionRect(aRect, targetRect)))
{ {
NSLog(@"Copy onto self"); NSLog(@"Copy onto self");
NSLog(NSStringFromRect(aRect)); NSLog(NSStringFromRect(aRect));
NSLog(NSStringFromPoint(aPoint)); NSLog(NSStringFromPoint(aPoint));
NSLog(@"src %p(%p,%@) des %p(%p,%@)", NSLog(@"src %p(%p,%@) des %p(%p,%@)",
source,cairo_get_target(source->_ct),NSStringFromSize([source->_surface size]), source,cairo_get_target(source->_ct),NSStringFromSize([source->_surface size]),
self,cairo_get_target(_ct),NSStringFromSize([_surface size])); self,cairo_get_target(_ct),NSStringFromSize([_surface size]));
} }
*/ */
} }
/* // Undo flipping in gui
With this bit of code enable scrolling works correctly, but images in cells get displayed wrongly.
if (viewIsFlipped) if (viewIsFlipped)
{ {
aPoint.y += NSHeight(aRect); aPoint.y -= NSHeight(aRect);
} }
*/ {
NSRect newRect;
newRect.origin = aPoint;
newRect.size = aRect.size;
[ctm boundingRectFor: newRect result: &newRect];
aPoint = newRect.origin;
}
//aPoint = [ctm transformPoint: aPoint];
[source->ctm boundingRectFor: aRect result: &aRect]; [source->ctm boundingRectFor: aRect result: &aRect];
aPoint = [ctm transformPoint: aPoint];
x = aPoint.x; x = aPoint.x;
y = aPoint.y; y = aPoint.y;

View file

@ -98,6 +98,7 @@
/* Globally unique gstate number */ /* Globally unique gstate number */
static unsigned int unique_index = 0; static unsigned int unique_index = 0;
static NSMapTable *gtable;
@interface GSContext (PrivateOps) @interface GSContext (PrivateOps)
- (void)DPSdefineuserobject; - (void)DPSdefineuserobject;
@ -112,6 +113,7 @@ static unsigned int unique_index = 0;
- (void)DPSpop; - (void)DPSpop;
@end @end
/** /**
<unit> <unit>
<heading>GSContext</heading> <heading>GSContext</heading>
@ -128,6 +130,28 @@ static unsigned int unique_index = 0;
</unit> */ </unit> */
@implementation GSContext @implementation GSContext
+ (void) initialize
{
gtable = NSCreateMapTable(NSIntMapKeyCallBacks,
NSObjectMapValueCallBacks, 20);
}
+ (void) insertObject: (id)obj forKey: (int)index
{
NSMapInsert(gtable, (void *)(uintptr_t)index, obj);
}
+ (id) getObjectForKey: (int)index
{
return NSMapGet(gtable, (void *)(uintptr_t)index);
}
+ (void) removeObjectForKey: (int)index
{
NSMapRemove(gtable, (void *)(uintptr_t)index);
}
- (id) initWithContextInfo: (NSDictionary *)info - (id) initWithContextInfo: (NSDictionary *)info
{ {
NSString *contextType; NSString *contextType;
@ -152,9 +176,6 @@ static unsigned int unique_index = 0;
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);
gtable = NSCreateMapTable(NSIntMapKeyCallBacks,
NSObjectMapValueCallBacks, 20);
[super initWithContextInfo: info]; [super initWithContextInfo: info];
return self; return self;
@ -170,7 +191,6 @@ static unsigned int unique_index = 0;
NSZoneFree([self zone], opstack); NSZoneFree([self zone], opstack);
GSIArrayEmpty((GSIArray)gstack); GSIArrayEmpty((GSIArray)gstack);
NSZoneFree([self zone], gstack); NSZoneFree([self zone], gstack);
NSFreeMapTable(gtable);
DESTROY(gstate); DESTROY(gstate);
[super dealloc]; [super dealloc];
} }
@ -419,8 +439,8 @@ static unsigned int unique_index = 0;
DPS_ERROR(DPSundefined, @"No gstate"); DPS_ERROR(DPSundefined, @"No gstate");
return 0; return 0;
} }
NSMapInsert(gtable, [isa insertObject: AUTORELEASE([gstate copy]) forKey: ++unique_index];
(void *)(uintptr_t)++unique_index, AUTORELEASE([gstate copy]));
return unique_index; return unique_index;
} }
@ -433,7 +453,8 @@ static unsigned int unique_index = 0;
{ {
if (gst <= 0) if (gst <= 0)
return; return;
NSMapInsert(gtable, (void *)(uintptr_t)gst, AUTORELEASE([gstate copy]));
[isa insertObject: AUTORELEASE([gstate copy]) forKey: gst];
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@ -865,27 +886,29 @@ static unsigned int unique_index = 0;
if (n < 0) if (n < 0)
DPS_ERROR(DPSinvalidparam, @"Invalid userobject index"); DPS_ERROR(DPSinvalidparam, @"Invalid userobject index");
else else
NSMapInsert(gtable, (void *)(uintptr_t)n, obj); [isa insertObject: obj forKey: n];
} }
- (void)DPSexecuserobject: (int)index - (void)DPSexecuserobject: (int)index
{ {
if (index < 0 || NSMapGet(gtable, (void *)(uintptr_t)index) == nil) id obj;
if (index < 0 || (obj = [isa getObjectForKey: index]) == nil)
{ {
DPS_ERROR(DPSinvalidparam, @"Invalid userobject index"); DPS_ERROR(DPSinvalidparam, @"Invalid userobject index");
return; return;
} }
ctxt_push((id)NSMapGet(gtable, (void *)(uintptr_t)index), opstack); ctxt_push(obj, opstack);
} }
- (void)DPSundefineuserobject: (int)index - (void)DPSundefineuserobject: (int)index
{ {
if (index < 0 || NSMapGet(gtable, (void *)(uintptr_t)index) == nil) if (index < 0 || [isa getObjectForKey: index] == nil)
{ {
DPS_ERROR(DPSinvalidparam, @"Invalid gstate index"); DPS_ERROR(DPSinvalidparam, @"Invalid gstate index");
return; return;
} }
NSMapRemove(gtable, (void *)(uintptr_t)index); [isa removeObjectForKey: index];
} }
- (void)DPSclear - (void)DPSclear