[cairo-commit] cairo/src cairo_traps.c, 1.17, 1.18 cairoint.h, 1.70, 1.71 cairo_xlib_surface.c, 1.25, 1.26

Keith Packard commit at pdx.freedesktop.org
Tue Oct 12 14:17:26 PDT 2004


Committed by: keithp

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv9286/src

Modified Files:
	cairo_traps.c cairoint.h cairo_xlib_surface.c 
Log Message:
2004-10-12  Keith Packard  <keithp at keithp.com>

	* src/cairo_traps.c: (_cairo_traps_init), (_cairo_traps_add_trap),
	(_cairo_traps_extents):
	* src/cairoint.h:
	Compute extents of cairo_traps_t on the fly using approximate
	method which is correct given the way cairo generates trapezoids.
	
	* src/cairo_xlib_surface.c: (_cairo_xlib_surface_create_similar):
	Avoid zero-dimensioned pixmaps


Index: cairo_traps.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_traps.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cairo_traps.c	28 May 2004 19:37:15 -0000	1.17
+++ cairo_traps.c	12 Oct 2004 21:17:23 -0000	1.18
@@ -1,23 +1,36 @@
 /*
  * Copyright © 2002 Keith Packard
  *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
  *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * The Initial Developer of the Original Code is Keith Packard
+ *
+ * Contributor(s):
+ *	Keith R. Packard <keithp at keithp.com>
+ *	Carl D. Worth <cworth at isi.edu>
  *
  * 2002-07-15: Converted from XRenderCompositeDoublePoly to cairo_trap. Carl D. Worth
  */
@@ -62,6 +75,8 @@
 
     traps->traps_size = 0;
     traps->traps = NULL;
+    traps->extents.p1.x = traps->extents.p1.y = CAIRO_MAXSHORT << 16;
+    traps->extents.p2.x = traps->extents.p2.y = CAIRO_MINSHORT << 16;
 }
 
 void
@@ -87,7 +102,8 @@
     }
 
     if (traps->num_traps >= traps->traps_size) {
-	status = _cairo_traps_grow_by (traps, CAIRO_TRAPS_GROWTH_INC);
+	int inc = traps->traps_size ? traps->traps_size : 32;
+	status = _cairo_traps_grow_by (traps, inc);
 	if (status)
 	    return status;
     }
@@ -98,6 +114,28 @@
     trap->left = *left;
     trap->right = *right;
 
+    if (top < traps->extents.p1.y)
+	traps->extents.p1.y = top;
+    if (bottom > traps->extents.p2.y)
+	traps->extents.p2.y = bottom;
+    /*
+     * This isn't generally accurate, but it is close enough for
+     * this purpose.  Assuming that the left and right segments always
+     * contain the trapezoid vertical extents, these compares will
+     * yield a containing box.  Assuming that the points all come from
+     * the same figure which will eventually be completely drawn, then
+     * the compares will yield the correct overall extents
+     */
+    if (left->p1.x < traps->extents.p1.x)
+	traps->extents.p1.x = left->p1.x;
+    if (left->p2.x < traps->extents.p1.x)
+	traps->extents.p1.x = left->p2.x;
+    
+    if (right->p1.x > traps->extents.p2.x)
+	traps->extents.p2.x = right->p1.x;
+    if (right->p2.x > traps->extents.p2.x)
+	traps->extents.p2.x = right->p2.x;
+    
     traps->num_traps++;
 
     return CAIRO_STATUS_SUCCESS;
@@ -673,39 +711,8 @@
     return 0;
 }
 
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-
-static void
-_cairo_trap_extents (cairo_trapezoid_t *t, cairo_box_t *extents)
-{
-    cairo_fixed_t x;
-    
-    if (t->top < extents->p1.y)
-	extents->p1.y = t->top;
-    
-    if (t->bottom > extents->p2.y)
-	extents->p2.y = t->bottom;
-    
-    x = MIN (_compute_x (&t->left, t->top),
-	     _compute_x (&t->left, t->bottom));
-    if (x < extents->p1.x)
-	extents->p1.x = x;
-    
-    x = MAX (_compute_x (&t->right, t->top),
-	     _compute_x (&t->right, t->bottom));
-    if (x > extents->p2.x)
-	extents->p2.x = x;
-}
-
 void
 _cairo_traps_extents (cairo_traps_t *traps, cairo_box_t *extents)
 {
-    int i;
-  
-    extents->p1.x = extents->p1.y = CAIRO_MAXSHORT << 16;
-    extents->p2.x = extents->p2.y = CAIRO_MINSHORT << 16;
-    
-    for (i = 0; i < traps->num_traps; i++)
-	_cairo_trap_extents (&traps->traps[i], extents);
+    *extents = traps->extents;
 }

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- cairoint.h	8 Oct 2004 19:09:51 -0000	1.70
+++ cairoint.h	12 Oct 2004 21:17:23 -0000	1.71
@@ -700,6 +700,7 @@
     cairo_trapezoid_t *traps;
     int num_traps;
     int traps_size;
+    cairo_box_t extents;
 } cairo_traps_t;
 
 #define CAIRO_FONT_FAMILY_DEFAULT  "serif"

Index: cairo_xlib_surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_xlib_surface.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- cairo_xlib_surface.c	8 Oct 2004 19:09:51 -0000	1.25
+++ cairo_xlib_surface.c	12 Oct 2004 21:17:23 -0000	1.26
@@ -145,7 +145,7 @@
     scr = DefaultScreen (dpy);
 
     pix = XCreatePixmap (dpy, DefaultRootWindow (dpy),
-			 width, height,
+			 width <= 0 ? 1 : width, height <= 0 ? 1 : height,
 			 _CAIRO_FORMAT_DEPTH (format));
     
     surface = (cairo_xlib_surface_t *)




More information about the cairo-commit mailing list