[cairo] new pattern interface patches and some great news about the OpenGL backend

Carl Worth cworth at east.isi.edu
Thu Apr 1 11:20:23 PST 2004


On Mar 27, David Reveman wrote:
 > I've now put together two new cairo patches. A pattern patch and an
 > OpenGL backend patch. The OpenGL patch requires that the pattern patch
 > is first applied.

David,

Thanks for separating and versioning the patches. This helps a lot.

I've started looking at:

     http://www.cs.umu.se/~c99drn/cairo-pattern-040331.patch

The attached patch cleans up a few minor issues, (a build break if the
gl patch is not applied, a few missing prototypes, etc.). Oh, and
you'll want to be careful to spell "default" correctly in your switch
statements, (though I ended up using explicit enum values instead as
that enables a useful compiler warning when new enum values are added
but the switch statement is not updated).

Take a look at my patch below and make sure that the "fall-through" I
commented is intentional Please explicitly comment all such
fall-throughs as otherwise they just look like bugs.

And take a look at _cairo_image_surface_create_pattern to see if it
shouldn't actually appear in some other module (cairo_pattern.c ?).

Additionally, the indentation on cairo_pattern.c should be made
consistent with the other files.

And you will need to fill out ChangeLog entries for the patch of
course.

And what is the change to cairo_ft_font.c? A bug fix? It seems
unrelated so please commit it separately from the rest.

Finally, after applying this patch I am getting some segfaults in xsvg
with an unpatched libsvg-cairo. I'm looking into that now, and if it's
it the new code I'd like to fix it before we commit.

Thanks for the good work. Keep it up!

-Carl

-------------- next part --------------
diff -ur cairo-c99drn/src/cairo-features.h.in cairo-c99drn-fixed/src/cairo-features.h.in
--- cairo-c99drn/src/cairo-features.h.in	2004-04-01 13:33:53.000000000 -0500
+++ cairo-c99drn-fixed/src/cairo-features.h.in	2004-04-01 13:54:51.000000000 -0500
@@ -36,6 +36,4 @@
 
 #define @XCB_SURFACE_FEATURE@
 
-#define @GL_SURFACE_FEATURE@
-
 #endif
diff -ur cairo-c99drn/src/cairo.h cairo-c99drn-fixed/src/cairo.h
--- cairo-c99drn/src/cairo.h	2004-04-01 13:33:53.000000000 -0500
+++ cairo-c99drn-fixed/src/cairo.h	2004-04-01 13:55:54.000000000 -0500
@@ -363,6 +363,9 @@
 
 /* Clipping */
 void
+cairo_init_clip (cairo_t *cr);
+
+void
 cairo_clip (cairo_t *cr);
 
 /* Font/Text functions */
diff -ur cairo-c99drn/src/cairo_image_surface.c cairo-c99drn-fixed/src/cairo_image_surface.c
--- cairo-c99drn/src/cairo_image_surface.c	2004-04-01 13:33:53.000000000 -0500
+++ cairo-c99drn-fixed/src/cairo_image_surface.c	2004-04-01 14:03:12.000000000 -0500
@@ -562,9 +562,17 @@
   }
 }
 
+static cairo_status_t
+_cairo_image_abstract_surface_create_pattern (void *abstract_surface,
+					      cairo_pattern_t *pattern,
+					      cairo_box_t *box)
+{
+    return _cairo_image_surface_create_pattern (pattern, box);
+}
+
+/* XXX: This is an oddly-named function as it doesn't accept a cairo_image_surface_t */
 cairo_status_t
-_cairo_image_surface_create_pattern (void *abstract_surface,
-                                     cairo_pattern_t *pattern,
+_cairo_image_surface_create_pattern (cairo_pattern_t *pattern,
                                      cairo_box_t *box)
 {
     char *data;
@@ -589,22 +597,18 @@
                                         _cairo_fixed_to_double (box->p1.x),
                                         _cairo_fixed_to_double (box->p1.y));
       
-      switch (pattern->type) {
-      case CAIRO_PATTERN_LINEAR:
+      if (pattern->type == CAIRO_PATTERN_LINEAR)
         _cairo_image_data_set_linear (pattern,
                                       pattern->source_offset.x,
                                       pattern->source_offset.y,
                                       data,
                                       width, height);
-        break;
-      case CAIRO_PATTERN_RADIAL:
+      else
         _cairo_image_data_set_radial (pattern,
                                       pattern->source_offset.x,
                                       pattern->source_offset.y,
                                       data,
                                       width, height);
-        break;
-      }
       
       image = (cairo_image_surface_t *)
         cairo_image_surface_create_for_data (data,
@@ -616,7 +620,8 @@
       pattern->source = (cairo_surface_t *) image;
       status = CAIRO_STATUS_SUCCESS;
       break;
-    defualt:
+    case CAIRO_PATTERN_SOLID:
+    case CAIRO_PATTERN_SURFACE:
       break;
     }
      
@@ -630,7 +635,7 @@
   cairo_int_status_t status;
   cairo_surface_t *surface = NULL;
   
-  status = _cairo_image_surface_create_pattern (NULL, pattern, box);
+  status = _cairo_image_surface_create_pattern (pattern, box);
   if (status == CAIRO_STATUS_SUCCESS) {
     surface = pattern->source;
     pattern->source = NULL;
@@ -642,6 +647,7 @@
     case CAIRO_PATTERN_RADIAL:
       if (pattern->n_stops)
         pattern->color = pattern->stops->color;
+      /* fall-through */
     case CAIRO_PATTERN_SOLID:
       surface =
         cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
@@ -654,7 +660,8 @@
                                               &rect, 1);
         _cairo_image_surface_set_repeat ((void *) surface, 1);
       }
-    defualt:
+      break;
+    case CAIRO_PATTERN_SURFACE:
       break;    
     }
   }
@@ -677,5 +684,5 @@
     _cairo_image_surface_copy_page,
     _cairo_image_surface_show_page,
     _cairo_image_abstract_surface_set_clip_region,
-    _cairo_image_surface_create_pattern
+    _cairo_image_abstract_surface_create_pattern
 };
diff -ur cairo-c99drn/src/cairo_surface.c cairo-c99drn-fixed/src/cairo_surface.c
--- cairo-c99drn/src/cairo_surface.c	2004-04-01 13:33:53.000000000 -0500
+++ cairo-c99drn-fixed/src/cairo_surface.c	2004-04-01 14:03:18.000000000 -0500
@@ -393,7 +393,7 @@
     case CAIRO_PATTERN_LINEAR:
     case CAIRO_PATTERN_RADIAL:
       if (pattern->n_stops > 1) {
-        status = _cairo_image_surface_create_pattern (surface, pattern, box);
+        status = _cairo_image_surface_create_pattern (pattern, box);
         if (status == CAIRO_STATUS_SUCCESS)
           break;
       }
diff -ur cairo-c99drn/src/cairoint.h cairo-c99drn-fixed/src/cairoint.h
--- cairo-c99drn/src/cairoint.h	2004-04-01 13:33:53.000000000 -0500
+++ cairo-c99drn-fixed/src/cairoint.h	2004-04-01 14:02:33.000000000 -0500
@@ -811,6 +811,14 @@
 extern cairo_status_t __internal_linkage
 _cairo_gstate_show_page (cairo_gstate_t *gstate);
 
+cairo_status_t
+_cairo_gstate_stroke_extents (cairo_gstate_t *gstate,
+                              double *x1, double *y1, double *x2, double *y2);
+
+cairo_status_t
+_cairo_gstate_fill_extents (cairo_gstate_t *gstate,
+                            double *x1, double *y1, double *x2, double *y2);
+
 extern cairo_status_t __internal_linkage
 _cairo_gstate_in_stroke (cairo_gstate_t	*gstate,
 			 double		x,
@@ -1166,6 +1174,10 @@
 _cairo_image_surface_set_clip_region (cairo_image_surface_t *surface,
 				      pixman_region16_t *region);
 
+extern cairo_status_t __internal_linkage
+_cairo_image_surface_create_pattern (cairo_pattern_t *pattern,
+                                     cairo_box_t *box);
+
 /* cairo_pen.c */
 extern cairo_status_t __internal_linkage
 _cairo_pen_init (cairo_pen_t *pen, double radius, cairo_gstate_t *gstate);



More information about the cairo mailing list