diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | macosx/tkMacOSXDraw.c | 92 | ||||
-rw-r--r-- | macosx/tkMacOSXFont.c | 78 |
3 files changed, 104 insertions, 72 deletions
@@ -1,3 +1,9 @@ +2006-03-25 Daniel Steffen <das@users.sourceforge.net> + + * macosx/tkMacOSXDraw.c (TkMacOSXSetUpCGContext): + * macosx/tkMacOSXFont.c (TkMacOSXQuarzStartDraw, TkMacOSXQuarzEndDraw): + performance improvements, sync similar code, formatting & whitespace. + 2006-03-24 Daniel Steffen <das@users.sourceforge.net> * generic/tkTextDisp.c: moved #ifdef MAC_OSX_TK code added by diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index 5aae7d4..2552345 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXDraw.c,v 1.10 2006/03/24 14:58:01 das Exp $ + * RCS: @(#) $Id: tkMacOSXDraw.c,v 1.11 2006/03/25 06:02:43 das Exp $ */ #include "tkMacOSXInt.h" @@ -20,9 +20,9 @@ #ifndef PI # define PI 3.14159265358979323846 #endif -#define RGBFLOATRED(c) (float)((float)(c.red) / 65535.0f) -#define RGBFLOATGREEN(c) (float)((float)(c.green) / 65535.0f) -#define RGBFLOATBLUE(c) (float)((float)(c.blue) / 65535.0f) +#define RGBFLOATRED(c) (float)((float)(c.red) / 65535.0f) +#define RGBFLOATGREEN(c) (float)((float)(c.green) / 65535.0f) +#define RGBFLOATBLUE(c) (float)((float)(c.blue) / 65535.0f) /* * Temporary regions that can be reused. @@ -1716,15 +1716,15 @@ TkMacOSXSetUpGraphicsPort( /* *---------------------------------------------------------------------- * - * TkMacOSXSetUpGraphicsPort -- + * TkMacOSXSetUpCGContext -- * - * Set up the graphics port from the given GC. + * Set up a CGContext for the given graphics port. * * Results: * None. * * Side effects: - * The current port is adjusted. + * None. * *---------------------------------------------------------------------- */ @@ -1734,13 +1734,13 @@ TkMacOSXSetUpCGContext( MacDrawable *macWin, CGrafPtr destPort, GC gc, - CGContextRef *contextPtr) /* GC to apply to current port. */ + CGContextRef *contextPtr) { RGBColor macColor; CGContextRef outContext; OSStatus err; Rect boundsRect; - CGAffineTransform coordsTransform; + CGAffineTransform coordsTransform; static RgnHandle clipRgn = NULL; err = QDBeginCGContext(destPort, contextPtr); @@ -1757,37 +1757,41 @@ TkMacOSXSetUpCGContext( */ if (!clipRgn) { - clipRgn = NewRgn(); + clipRgn = NewRgn(); } GetPortBounds(destPort, &boundsRect); - + RectRgn(clipRgn, &boundsRect); SectRegionWithPortClipRegion(destPort, clipRgn); SectRegionWithPortVisibleRegion(destPort, clipRgn); ClipCGContextToRegion(outContext, &boundsRect, clipRgn); SetEmptyRgn(clipRgn); - + /* * Note: You have to call SyncCGContextOriginWithPort * AFTER all the clip region manipulations. */ - + SyncCGContextOriginWithPort(outContext, destPort); - coordsTransform = CGAffineTransformMake(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, - (float) (boundsRect.bottom - boundsRect.top)); + coordsTransform = CGAffineTransformMake(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, + (float) (boundsRect.bottom - boundsRect.top)); CGContextConcatCTM(outContext, coordsTransform); /* Now offset the CTM to the subwindow offset */ - if (TkSetMacColor(gc->foreground, &macColor) == true) { - CGContextSetRGBFillColor(outContext, RGBFLOATRED(macColor), - RGBFLOATGREEN(macColor), - RGBFLOATBLUE(macColor), 1.0f); - CGContextSetRGBStrokeColor(outContext, RGBFLOATRED(macColor), - RGBFLOATGREEN(macColor), - RGBFLOATBLUE(macColor), 1.0f); + if (TkSetMacColor(gc->foreground, &macColor) == true) { + CGContextSetRGBFillColor(outContext, + RGBFLOATRED(macColor), + RGBFLOATGREEN(macColor), + RGBFLOATBLUE(macColor), + 1.0f); + CGContextSetRGBStrokeColor(outContext, + RGBFLOATRED(macColor), + RGBFLOATGREEN(macColor), + RGBFLOATBLUE(macColor), + 1.0f); } if(gc->function == GXxor) { @@ -1803,22 +1807,22 @@ TkMacOSXSetUpCGContext( } if (gc->line_style != LineSolid) { - int num = 0; - char *p = &(gc->dashes); - float dashOffset = (float) gc->dash_offset; - float lengths[10]; - - while (p[num] != '\0') { - lengths[num] = (float) (p[num]); - num++; - } - CGContextSetLineDash(outContext, dashOffset, lengths, num); + int num = 0; + char *p = &(gc->dashes); + float dashOffset = (float) gc->dash_offset; + float lengths[10]; + + while (p[num] != '\0') { + lengths[num] = (float) (p[num]); + num++; + } + CGContextSetLineDash(outContext, dashOffset, lengths, num); } - if (gc->cap_style == CapButt) { - /* - * What about CapNotLast, CapProjecting? - */ + if (gc->cap_style == CapButt) { + /* + * What about CapNotLast, CapProjecting? + */ CGContextSetLineCap(outContext, kCGLineCapButt); } else if (gc->cap_style == CapRound) { @@ -1835,6 +1839,22 @@ TkMacOSXSetUpCGContext( CGContextSetLineJoin(outContext, kCGLineJoinBevel); } } + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXReleaseCGContext -- + * + * Release the CGContext for the given graphics port. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ static void TkMacOSXReleaseCGContext( diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index f55542d..ce4a0f0 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -35,7 +35,7 @@ * that such fonts can not be used for controls, because controls * definitely require a family id (this assertion needs testing). * - * RCS: @(#) $Id: tkMacOSXFont.c,v 1.12 2006/03/22 00:21:17 das Exp $ + * RCS: @(#) $Id: tkMacOSXFont.c,v 1.13 2006/03/25 06:02:43 das Exp $ */ #include "tkMacOSXInt.h" @@ -1076,6 +1076,9 @@ TkpDrawCharsInContext( } #if TK_MAC_USE_QUARZ +#define RGBFLOATRED(c) (float)((float)(c.red) / 65535.0f) +#define RGBFLOATGREEN(c) (float)((float)(c.green) / 65535.0f) +#define RGBFLOATBLUE(c) (float)((float)(c.blue) / 65535.0f) /* *------------------------------------------------------------------------- * @@ -1111,37 +1114,41 @@ TkMacOSXQuarzStartDraw( * by this function. */ { GDHandle currentDevice; - RgnHandle clipRgn; - RGBColor qdColor; - double red, green, blue; + CGrafPtr destPort; + RGBColor macColor; + CGContextRef outContext; + OSStatus err; + Rect boundsRect; + static RgnHandle clipRgn = NULL; + + GetGWorld(&destPort, ¤tDevice); + + err = QDBeginCGContext(destPort, &outContext); /* - * Create the CGContext. + * Now clip the CG Context to the port. We also have to intersect our clip + * region with the port visible region so we don't overwrite the window + * decoration. */ - GetGWorld(&drawingContextPtr->graphPort, ¤tDevice); - QDBeginCGContext( - drawingContextPtr->graphPort, - &drawingContextPtr->cgContext); - CGContextSaveGState( - drawingContextPtr->cgContext); + if (!clipRgn) { + clipRgn = NewRgn(); + } + + GetPortBounds(destPort, &boundsRect); + + RectRgn(clipRgn, &boundsRect); + SectRegionWithPortClipRegion(destPort, clipRgn); + SectRegionWithPortVisibleRegion(destPort, clipRgn); + ClipCGContextToRegion(outContext, &boundsRect, clipRgn); + SetEmptyRgn(clipRgn); /* - * Sync some parameters, most notably the clipping region. I'm not sure - * if that part of the code is right, as the coordinate systems of the - * graphPort and the cgContext are different. + * Note: You have to call SyncCGContextOriginWithPort + * AFTER all the clip region manipulations. */ - SyncCGContextOriginWithPort( - drawingContextPtr->cgContext, drawingContextPtr->graphPort); - GetPortBounds(drawingContextPtr->graphPort, &drawingContextPtr->portRect); - - clipRgn = NewRgn(); - GetPortClipRegion(drawingContextPtr->graphPort, clipRgn); - ClipCGContextToRegion( - drawingContextPtr->cgContext, - &drawingContextPtr->portRect, clipRgn); - DisposeRgn(clipRgn); + SyncCGContextOriginWithPort(outContext, destPort); /* * Scale the color values, as QD uses UInt16 with the range [0..2^16-1] @@ -1149,18 +1156,19 @@ TkMacOSXQuarzStartDraw( * CGContextSetRGBFillColor() seems to be actually used by ATSU. */ - GetForeColor(&qdColor); - red = (double) qdColor.red / (double) 0xFFFF; - green = (double) qdColor.green / (double) 0xFFFF; - blue = (double) qdColor.blue / (double) 0xFFFF; - CGContextSetRGBFillColor( - drawingContextPtr->cgContext, red, green, blue, 1.0); -/* CGContextSetRGBStrokeColor( */ -/* drawingContextPtr->cgContext, red, green, blue, 1.0); */ + GetForeColor(&macColor); + CGContextSetRGBFillColor(outContext, + RGBFLOATRED(macColor), + RGBFLOATGREEN(macColor), + RGBFLOATBLUE(macColor), + 1.0f); + + drawingContextPtr->graphPort = destPort; + drawingContextPtr->cgContext = outContext; + drawingContextPtr->portRect = boundsRect; + } -#endif /* TK_MAC_USE_QUARZ */ -#if TK_MAC_USE_QUARZ /* *------------------------------------------------------------------------- * @@ -1184,8 +1192,6 @@ void TkMacOSXQuarzEndDraw( DrawingContext * drawingContextPtr) { - CGContextRestoreGState( - drawingContextPtr->cgContext); QDEndCGContext( drawingContextPtr->graphPort, &drawingContextPtr->cgContext); |