summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordas <das@noemail.net>2007-10-12 03:13:55 (GMT)
committerdas <das@noemail.net>2007-10-12 03:13:55 (GMT)
commitf6c4bcc717d34031924a43c31c85b6c1c440875b (patch)
tree19db4bde02cd865bf8f7eeedf826c2080de5b5f8
parenta572f75d5b086ec3af662fb715dc436ae8c1f98e (diff)
downloadtk-f6c4bcc717d34031924a43c31c85b6c1c440875b.zip
tk-f6c4bcc717d34031924a43c31c85b6c1c440875b.tar.gz
tk-f6c4bcc717d34031924a43c31c85b6c1c440875b.tar.bz2
* xlib/xgc.c: factor out alloc/free of GC clip_mask;
* macosx/tkMacOSXXStubs.c: manage clip rgn lifetime with new Tkp{Retain,Release}Region(). FossilOrigin-Name: 43cd1a0de3c33c7fa5a517531d805254d0d772a7
-rw-r--r--macosx/tkMacOSXXStubs.c13
-rw-r--r--xlib/xgc.c121
2 files changed, 86 insertions, 48 deletions
diff --git a/macosx/tkMacOSXXStubs.c b/macosx/tkMacOSXXStubs.c
index 31ae7ea..78bd909 100644
--- a/macosx/tkMacOSXXStubs.c
+++ b/macosx/tkMacOSXXStubs.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXXStubs.c,v 1.23 2007/07/04 17:32:39 andreas_kupries Exp $
+ * RCS: @(#) $Id: tkMacOSXXStubs.c,v 1.24 2007/10/12 03:13:55 das Exp $
*/
#include "tkMacOSXPrivate.h"
@@ -706,15 +706,7 @@ XSetClipRectangles(
int n,
int ordering)
{
- TkRegion clipRgn;
-
- if (gc->clip_mask && ((TkpClipMask*)gc->clip_mask)->type
- == TKP_CLIP_REGION) {
- clipRgn = ((TkpClipMask*)gc->clip_mask)->value.region;
- SetEmptyRgn((RgnHandle) clipRgn);
- } else {
- clipRgn = TkCreateRegion(); /* LEAK! */
- }
+ TkRegion clipRgn = TkCreateRegion();
while (n--) {
XRectangle rect = *rectangles;
@@ -725,6 +717,7 @@ XSetClipRectangles(
rectangles++;
}
TkSetRegion(d, gc, clipRgn);
+ TkDestroyRegion(clipRgn);
return 1;
}
#endif
diff --git a/xlib/xgc.c b/xlib/xgc.c
index b2e8446..5efbe3f 100644
--- a/xlib/xgc.c
+++ b/xlib/xgc.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: xgc.c,v 1.13 2007/07/02 13:04:07 das Exp $
+ * RCS: @(#) $Id: xgc.c,v 1.14 2007/10/12 03:13:55 das Exp $
*/
#include <tkInt.h>
@@ -18,11 +18,71 @@
# include <X11/Xlib.h>
#endif
#ifdef MAC_OSX_TK
+# include <tkMacOSXInt.h>
# include <X11/Xlib.h>
# include <X11/X.h>
# define Cursor XCursor
# define Region XRegion
#endif
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * AllocClipMask --
+ *
+ * Static helper proc to allocate new or clear existing TkpClipMask.
+ *
+ * Results:
+ * Returns ptr to the new/cleared TkpClipMask.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static TkpClipMask *AllocClipMask(GC gc) {
+ TkpClipMask *clip_mask = (TkpClipMask*) gc->clip_mask;
+
+ if (clip_mask == None) {
+ clip_mask = (TkpClipMask*) ckalloc(sizeof(TkpClipMask));
+ gc->clip_mask = (Pixmap) clip_mask;
+#ifdef MAC_OSX_TK
+ } else if (clip_mask->type == TKP_CLIP_REGION) {
+ TkpReleaseRegion(clip_mask->value.region);
+#endif
+ }
+ return clip_mask;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * FreeClipMask --
+ *
+ * Static helper proc to free TkpClipMask.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void FreeClipMask(GC gc) {
+ if (gc->clip_mask != None) {
+#ifdef MAC_OSX_TK
+ if (((TkpClipMask*) gc->clip_mask)->type == TKP_CLIP_REGION) {
+ TkpReleaseRegion(((TkpClipMask*) gc->clip_mask)->value.region);
+ }
+#endif
+ ckfree((char*) gc->clip_mask);
+ gc->clip_mask = None;
+ }
+}
/*
*----------------------------------------------------------------------
@@ -92,12 +152,12 @@ XCreateGC(
InitField(dashes, GCDashList, 4);
(&(gp->dashes))[1] = 0;
+ gp->clip_mask = None;
if (mask & GCClipMask) {
- gp->clip_mask = (Pixmap) ckalloc(sizeof(TkpClipMask));
- ((TkpClipMask *) gp->clip_mask)->type = TKP_CLIP_PIXMAP;
- ((TkpClipMask *) gp->clip_mask)->value.pixmap = values->clip_mask;
- } else {
- gp->clip_mask = None;
+ TkpClipMask *clip_mask = AllocClipMask(gp);
+
+ clip_mask->type = TKP_CLIP_PIXMAP;
+ clip_mask->value.pixmap = values->clip_mask;
}
return gp;
@@ -180,9 +240,7 @@ void XFreeGC(
GC gc)
{
if (gc != None) {
- if (gc->clip_mask != None) {
- ckfree((char*) gc->clip_mask);
- }
+ FreeClipMask(gc);
ckfree((char *) gc);
}
}
@@ -344,9 +402,9 @@ XSetClipOrigin(
* Sets the clipping region/pixmap for a GC.
*
* Note that unlike the Xlib equivalent, it is not safe to delete the
- * region after setting it into the GC. The only uses of TkSetRegion
- * are currently in DisplayFrame and in ImgPhotoDisplay, which use the
- * GC immediately.
+ * region after setting it into the GC (except on Mac OS X). The only
+ * uses of TkSetRegion are currently in DisplayFrame and in
+ * ImgPhotoDisplay, which use the GC immediately.
*
* Results:
* None.
@@ -363,22 +421,17 @@ TkSetRegion(
GC gc,
TkRegion r)
{
- TkpClipMask *clip_mask;
-
if (r == None) {
- if (gc->clip_mask) {
- ckfree((char*) gc->clip_mask);
- gc->clip_mask = None;
- }
- return;
- }
+ FreeClipMask(gc);
+ } else {
+ TkpClipMask *clip_mask = AllocClipMask(gc);
- if (gc->clip_mask == None) {
- gc->clip_mask = (Pixmap)ckalloc(sizeof(TkpClipMask));
+ clip_mask->type = TKP_CLIP_REGION;
+ clip_mask->value.region = r;
+#ifdef MAC_OSX_TK
+ TkpRetainRegion(r);
+#endif
}
- clip_mask = (TkpClipMask*) gc->clip_mask;
- clip_mask->type = TKP_CLIP_REGION;
- clip_mask->value.region = r;
}
void
@@ -387,22 +440,14 @@ XSetClipMask(
GC gc,
Pixmap pixmap)
{
- TkpClipMask *clip_mask;
-
if (pixmap == None) {
- if (gc->clip_mask) {
- ckfree((char*) gc->clip_mask);
- gc->clip_mask = None;
- }
- return;
- }
+ FreeClipMask(gc);
+ } else {
+ TkpClipMask *clip_mask = AllocClipMask(gc);
- if (gc->clip_mask == None) {
- gc->clip_mask = (Pixmap)ckalloc(sizeof(TkpClipMask));
+ clip_mask->type = TKP_CLIP_PIXMAP;
+ clip_mask->value.pixmap = pixmap;
}
- clip_mask = (TkpClipMask*) gc->clip_mask;
- clip_mask->type = TKP_CLIP_PIXMAP;
- clip_mask->value.pixmap = pixmap;
}
/*