[cairo-commit] 5 commits - ROADMAP src/cairo-image-surface.c src/cairoint.h src/cairo-pattern.c src/cairo-xlib-surface.c

Carl Worth cworth at kemper.freedesktop.org
Tue Aug 21 17:15:53 PDT 2007


 ROADMAP                   |    4 
 src/cairo-image-surface.c |  279 ++++++++++++++++++++++++++++++++++------------
 src/cairo-pattern.c       |    2 
 src/cairo-xlib-surface.c  |  117 +------------------
 src/cairoint.h            |   63 +++-------
 5 files changed, 243 insertions(+), 222 deletions(-)

New commits:
diff-tree 333b96f0e0a7d775b96014b91c6887cdcda3e93a (from f00fb10f87d1341b91f025bb068d935355c68c70)
Author: Carl Worth <cworth at cworth.org>
Date:   Fri Aug 17 10:41:03 2007 -0700

    Add support for image fallbacks for X servers with 555 visuals
    
    This fixes bugzilla #9993:
    
    	Cairo fails with 555 X server visual
    	https://bugs.freedesktop.org/show_bug.cgi?id=9993

diff --git a/ROADMAP b/ROADMAP
index ba52d6c..9431f1e 100644
--- a/ROADMAP
+++ b/ROADMAP
@@ -37,7 +37,7 @@ cairo 1.4.x (not scheduled, may become p
 	 7735 cairo doesn't support 8-bit truecolor visuals
 	 4945 Cairo doesn't support 8-bit pseudocolor visuals
 	 9719 Cairo doesn't support 655 xlib format
-	 9993 Cairo fails with 555 X server visual
+      ✓	 9993 Cairo fails with 555 X server visual
       ✓	10461 Cairo doesn't support 565 xlib visual
 
  ✓ Discard trapezoids that lie outside the clip region (cworth)
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 969ac63..3b7768a 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -217,6 +217,13 @@ _pixman_format_from_masks (cairo_format_
 	{
 	    return PIXMAN_r5g6b5;
 	}
+	if (masks->alpha_mask == 0x0000 &&
+	    masks->red_mask   == 0x7c00 &&
+	    masks->green_mask == 0x03e0 &&
+	    masks->blue_mask  == 0x001f)
+	{
+	    return PIXMAN_x1r5g5b5;
+	}
 	break;
     case 8:
 	if (masks->alpha_mask == 0xff)
@@ -278,6 +285,13 @@ _pixman_format_to_masks (pixman_format_c
 	*blue  = 0x001f;
 	break;
 
+    case PIXMAN_x1r5g5b5:
+	*bpp   = 16;
+	*red   = 0x7c00;
+	*green = 0x03e0;
+	*blue  = 0x001f;
+	break;
+
     case PIXMAN_a8:
 	*bpp = 8;
 	break;
diff-tree f00fb10f87d1341b91f025bb068d935355c68c70 (from ddb78df4c92fc8e51ca18202b59bcef7d1e1d66d)
Author: Carl Worth <cworth at cworth.org>
Date:   Fri Aug 17 10:36:14 2007 -0700

    Add support for image fallbacks for X servers with 565 visuals
    
    This fixes bugzilla #10461:
    
    	Cairo doesn't support 565 xlib visual
    	https://bugs.freedesktop.org/show_bug.cgi?id=1046

diff --git a/ROADMAP b/ROADMAP
index 864f11c..ba52d6c 100644
--- a/ROADMAP
+++ b/ROADMAP
@@ -38,7 +38,7 @@ cairo 1.4.x (not scheduled, may become p
 	 4945 Cairo doesn't support 8-bit pseudocolor visuals
 	 9719 Cairo doesn't support 655 xlib format
 	 9993 Cairo fails with 555 X server visual
-	10461 Cairo doesn't support 565 xlib visual
+      ✓	10461 Cairo doesn't support 565 xlib visual
 
  ✓ Discard trapezoids that lie outside the clip region (cworth)
 
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index b9c6609..969ac63 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -209,6 +209,15 @@ _pixman_format_from_masks (cairo_format_
 	    return PIXMAN_x8r8g8b8;
 	}
 	break;
+    case 16:
+	if (masks->alpha_mask == 0x0000 &&
+	    masks->red_mask   == 0xf800 &&
+	    masks->green_mask == 0x07e0 &&
+	    masks->blue_mask  == 0x001f)
+	{
+	    return PIXMAN_r5g6b5;
+	}
+	break;
     case 8:
 	if (masks->alpha_mask == 0xff)
 	{
@@ -262,6 +271,13 @@ _pixman_format_to_masks (pixman_format_c
 	*blue  = 0x000000ff;
 	break;
 
+    case PIXMAN_r5g6b5:
+	*bpp   = 16;
+	*red   = 0xf800;
+	*green = 0x07e0;
+	*blue  = 0x001f;
+	break;
+
     case PIXMAN_a8:
 	*bpp = 8;
 	break;
diff-tree ddb78df4c92fc8e51ca18202b59bcef7d1e1d66d (from 72fab3675c46a773dac315fffff72cd7f887f79f)
Author: Carl Worth <cworth at cworth.org>
Date:   Fri Aug 17 10:33:25 2007 -0700

    Restore the error message for unsupported X server visuals
    
    Apparently, our much-beloved error message, (just look at how many people
    love to quote it in bugzilla entries), was removed during the switch to
    the new pixman. It was replaced with an obscure failure of a nil surface
    being returned, (leading to obscure failures or false "out of memory"
    errors).
    
    So we're putting this back now, (even though we _really_ want to ensure
    that this message never gets printed in practice).

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index f112bcd..b9c6609 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -223,6 +223,18 @@ _pixman_format_from_masks (cairo_format_
 	break;
     }
 
+    fprintf (stderr,
+	     "Error: Cairo " PACKAGE_VERSION " does not yet support the requested image format:\n"
+	     "\tDepth: %d\n"
+	     "\tAlpha mask: 0x%08lx\n"
+	     "\tRed   mask: 0x%08lx\n"
+	     "\tGreen mask: 0x%08lx\n"
+	     "\tBlue  mask: 0x%08lx\n"
+	     "Please file an enhancement request (quoting the above) at:\n"
+	     PACKAGE_BUGREPORT "\n",
+	     masks->bpp, masks->alpha_mask,
+	     masks->red_mask, masks->green_mask, masks->blue_mask);
+
     ASSERT_NOT_REACHED;
     return 0;
 }
diff-tree 72fab3675c46a773dac315fffff72cd7f887f79f (from a9662d0aaed8685292ffe13c458182046a644fa7)
Author: Carl Worth <cworth at cworth.org>
Date:   Fri Aug 17 10:29:37 2007 -0700

    Use a pixman_format_code to describe the image surface used for xlib fallbacks
    
    Previously, the code was just using cairo_format_t which is much more limited
    than the formats supported by pixman, (so many "odd" X server visuals would
    just fall over).

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 55a8be1..f112bcd 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -71,6 +71,7 @@ static const cairo_image_surface_t _cair
 	  CAIRO_HINT_METRICS_DEFAULT
 	}				/* font_options */
     },					/* base */
+    PIXMAN_a8r8g8b8,			/* pixman_format */
     CAIRO_FORMAT_ARGB32,		/* format */
     NULL,				/* data */
     FALSE,				/* owns_data */
@@ -173,6 +174,7 @@ _cairo_image_surface_create_for_pixman_i
 
     surface->pixman_image = pixman_image;
 
+    surface->pixman_format = pixman_format;
     surface->format = _cairo_format_from_pixman_format (pixman_format);
     surface->data = (unsigned char *) pixman_image_get_data (pixman_image);
     surface->owns_data = FALSE;
@@ -186,49 +188,79 @@ _cairo_image_surface_create_for_pixman_i
     return &surface->base;
 }
 
-static cairo_bool_t
-_CAIRO_MASK_FORMAT (cairo_format_masks_t *masks, cairo_format_t *format)
+/* XXX: This function should really live inside pixman. */
+pixman_format_code_t
+_pixman_format_from_masks (cairo_format_masks_t *masks)
 {
-    /* XXX: many formats are simply not supported by pixman, so this function
-     * converts the masks into something we know will be supported.
-     */
     switch (masks->bpp) {
     case 32:
 	if (masks->alpha_mask == 0xff000000 &&
-	    masks->red_mask == 0x00ff0000 &&
+	    masks->red_mask   == 0x00ff0000 &&
 	    masks->green_mask == 0x0000ff00 &&
-	    masks->blue_mask == 0x000000ff)
+	    masks->blue_mask  == 0x000000ff)
 	{
-	    *format = CAIRO_FORMAT_ARGB32;
-	    return TRUE;
+	    return PIXMAN_a8r8g8b8;
 	}
 	if (masks->alpha_mask == 0x00000000 &&
-	    masks->red_mask == 0x00ff0000 &&
+	    masks->red_mask   == 0x00ff0000 &&
 	    masks->green_mask == 0x0000ff00 &&
-	    masks->blue_mask == 0x000000ff)
+	    masks->blue_mask  == 0x000000ff)
 	{
-	    *format = CAIRO_FORMAT_RGB24;
-	    return TRUE;
+	    return PIXMAN_x8r8g8b8;
 	}
 	break;
     case 8:
 	if (masks->alpha_mask == 0xff)
 	{
-	    *format = CAIRO_FORMAT_A8;
-	    return TRUE;
+	    return PIXMAN_a8;
 	}
 	break;
     case 1:
 	if (masks->alpha_mask == 0x1)
 	{
-	    *format = CAIRO_FORMAT_A1;
-	    return TRUE;
+	    return PIXMAN_a1;
 	}
 	break;
     }
-    return FALSE;
+
+    ASSERT_NOT_REACHED;
+    return 0;
 }
 
+/* XXX: This function should really live inside pixman. */
+void
+_pixman_format_to_masks (pixman_format_code_t	 pixman_format,
+			 uint32_t		*bpp,
+			 uint32_t		*red,
+			 uint32_t		*green,
+			 uint32_t		*blue)
+{
+    *red = 0x0;
+    *green = 0x0;
+    *blue = 0x0;
+
+    switch (pixman_format)
+    {
+    case PIXMAN_a8r8g8b8:
+    case PIXMAN_x8r8g8b8:
+    default:
+	*bpp   = 32;
+	*red   = 0x00ff0000;
+	*green = 0x0000ff00;
+	*blue  = 0x000000ff;
+	break;
+
+    case PIXMAN_a8:
+	*bpp = 8;
+	break;
+
+    case PIXMAN_a1:
+	*bpp = 1;
+	break;
+    }
+}
+
+
 /* XXX: This function really should be eliminated. We don't really
  * want to advertise a cairo image surface that supports any possible
  * format. A minimal step would be to replace this function with one
@@ -240,18 +272,15 @@ _cairo_image_surface_create_with_masks (
 					int			height,
 					int			stride)
 {
-    cairo_format_t format;
+    pixman_format_code_t pixman_format;
     
-    if (!_CAIRO_MASK_FORMAT (masks, &format)) {
-	_cairo_error (CAIRO_STATUS_INVALID_FORMAT);
-	return (cairo_surface_t*) &_cairo_surface_nil;
-    }
+    pixman_format = _pixman_format_from_masks (masks);
 
-    return cairo_image_surface_create_for_data (data,
-						format,
-						width,
-						height,
-						stride);
+    return _cairo_image_surface_create_with_pixman_format (data,
+							   pixman_format,
+							   width,
+							   height,
+							   stride);
 }
 
 static pixman_format_code_t 
@@ -277,7 +306,7 @@ _cairo_format_to_pixman_format_code (cai
     return ret;
 }
 
-static cairo_surface_t *
+cairo_surface_t *
 _cairo_image_surface_create_with_pixman_format (unsigned char		*data,
 						pixman_format_code_t	 pixman_format,
 						int			 width,
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 7c4fa02..c95ec16 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -344,46 +344,6 @@ _noop_error_handler (Display     *displa
     return False;		/* return value is ignored */
 }
 
-static cairo_bool_t
-_CAIRO_MASK_FORMAT (cairo_format_masks_t *masks, cairo_format_t *format)
-{
-    switch (masks->bpp) {
-    case 32:
-	if (masks->alpha_mask == 0xff000000 &&
-	    masks->red_mask == 0x00ff0000 &&
-	    masks->green_mask == 0x0000ff00 &&
-	    masks->blue_mask == 0x000000ff)
-	{
-	    *format = CAIRO_FORMAT_ARGB32;
-	    return True;
-	}
-	if (masks->alpha_mask == 0x00000000 &&
-	    masks->red_mask == 0x00ff0000 &&
-	    masks->green_mask == 0x0000ff00 &&
-	    masks->blue_mask == 0x000000ff)
-	{
-	    *format = CAIRO_FORMAT_RGB24;
-	    return True;
-	}
-	break;
-    case 8:
-	if (masks->alpha_mask == 0xff)
-	{
-	    *format = CAIRO_FORMAT_A8;
-	    return True;
-	}
-	break;
-    case 1:
-	if (masks->alpha_mask == 0x1)
-	{
-	    *format = CAIRO_FORMAT_A1;
-	    return True;
-	}
-	break;
-    }
-    return False;
-}
-
 static void
 _swap_ximage_2bytes (XImage *ximage)
 {
@@ -504,7 +464,7 @@ _get_image_surface (cairo_xlib_surface_t
     XImage *ximage;
     short x1, y1, x2, y2;
     cairo_format_masks_t masks;
-    cairo_format_t format;
+    pixman_format_code_t pixman_format;
 
     x1 = 0;
     y1 = 0;
@@ -638,38 +598,15 @@ _get_image_surface (cairo_xlib_surface_t
 	    masks.alpha_mask = 0xffffffff;
     }
 
-    /*
-     * Prefer to use a standard pixman format instead of the
-     * general masks case.
-     */
-    if (_CAIRO_MASK_FORMAT (&masks, &format))
-    {
-	image = (cairo_image_surface_t*)
-	    cairo_image_surface_create_for_data ((unsigned char *) ximage->data,
-						 format,
-						 ximage->width,
-						 ximage->height,
-						 ximage->bytes_per_line);
-	if (image->base.status)
-	    goto FAIL;
-    }
-    else
-    {
-	/*
-	 * XXX This can't work.  We must convert the data to one of the
-	 * supported pixman formats.  Pixman needs another function
-	 * which takes data in an arbitrary format and converts it
-	 * to something supported by that library.
-	 */
-	image = (cairo_image_surface_t*)
-	    _cairo_image_surface_create_with_masks ((unsigned char *) ximage->data,
-						    &masks,
-						    ximage->width,
-						    ximage->height,
-						    ximage->bytes_per_line);
-	if (image->base.status)
-	    goto FAIL;
-    }
+    pixman_format = _pixman_format_from_masks (&masks);
+    image = (cairo_image_surface_t*)
+	_cairo_image_surface_create_with_pixman_format ((unsigned char *) ximage->data,
+							pixman_format,
+							ximage->width,
+							ximage->height,
+							ximage->bytes_per_line);
+    if (image->base.status)
+	goto FAIL;
 
     /* Let the surface take ownership of the data */
     _cairo_image_surface_assume_ownership_of_data (image);
@@ -770,38 +707,6 @@ _cairo_xlib_surface_ensure_gc (cairo_xli
     return CAIRO_STATUS_SUCCESS;
 }
 
-static void
-cairo_format_get_masks (cairo_format_t  format,
-			uint32_t       *bpp,
-			uint32_t       *red,
-			uint32_t       *green,
-			uint32_t       *blue)
-{
-    *red = 0x0;
-    *green = 0x0;
-    *blue = 0x0;
-    
-    switch (format)
-    {
-    case CAIRO_FORMAT_ARGB32:
-    case CAIRO_FORMAT_RGB24:
-    default:
-	*bpp =   32;
-	*red =   0x00ff0000;
-	*green = 0x0000ff00;
-	*blue =  0x000000ff;
-	break;
-	
-    case CAIRO_FORMAT_A8:
-	*bpp = 8;
-	break;
-	
-    case CAIRO_FORMAT_A1:
-	*bpp = 1;
-	break;
-    }
-}
-
 static cairo_status_t
 _draw_image_surface (cairo_xlib_surface_t   *surface,
 		     cairo_image_surface_t  *image,
@@ -817,7 +722,7 @@ _draw_image_surface (cairo_xlib_surface_
     int native_byte_order = _native_byte_order_lsb () ? LSBFirst : MSBFirst;
     cairo_status_t status;
 
-    cairo_format_get_masks (image->format, &bpp, &red, &green, &blue);
+    _pixman_format_to_masks (image->pixman_format, &bpp, &red, &green, &blue);
     
     ximage.width = image->width;
     ximage.height = image->height;
diff --git a/src/cairoint.h b/src/cairoint.h
index 94f5ae3..8846465 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -915,7 +915,7 @@ typedef struct _cairo_format_masks {
 struct _cairo_image_surface {
     cairo_surface_t base;
 
-    /* libic-specific fields */
+    pixman_format_code_t pixman_format;
     cairo_format_t format;
     unsigned char *data;
     cairo_bool_t owns_data;
@@ -2005,6 +2005,23 @@ cairo_private cairo_surface_t *
 _cairo_image_surface_create_for_pixman_image (pixman_image_t		*pixman_image,
 					      pixman_format_code_t	 pixman_format);
 
+cairo_private pixman_format_code_t
+_pixman_format_from_masks (cairo_format_masks_t *masks);
+
+void
+_pixman_format_to_masks (pixman_format_code_t	 pixman_format,
+			 uint32_t		*bpp,
+			 uint32_t		*red,
+			 uint32_t		*green,
+			 uint32_t		*blue);
+
+cairo_private cairo_surface_t *
+_cairo_image_surface_create_with_pixman_format (unsigned char		*data,
+						pixman_format_code_t	 pixman_format,
+						int			 width,
+						int			 height,
+						int			 stride);
+
 cairo_private cairo_surface_t *
 _cairo_image_surface_create_with_masks (unsigned char	       *data,
 					cairo_format_masks_t   *format,
diff-tree a9662d0aaed8685292ffe13c458182046a644fa7 (from 9f4e6436496fe561aa124bb2b89e1c6711684d98)
Author: Carl Worth <cworth at cworth.org>
Date:   Fri Aug 17 08:15:50 2007 -0700

    Eliminate fragile cairo_internal_format_t
    
    Instead we take advantage of the pixman_format_code_t
    that now exists in the public interface of the new, external
    pixman library.

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 27d6cba..55a8be1 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -82,10 +82,83 @@ static const cairo_image_surface_t _cair
     NULL				/* pixman_image */
 };
 
+static cairo_format_t
+_cairo_format_from_pixman_format (pixman_format_code_t pixman_format)
+{
+    switch (pixman_format) {
+    case PIXMAN_a8r8g8b8:
+	return CAIRO_FORMAT_ARGB32;
+    case PIXMAN_x8r8g8b8:
+	return CAIRO_FORMAT_RGB24;
+    case PIXMAN_a8:
+	return CAIRO_FORMAT_A8;
+    case PIXMAN_a1:
+	return CAIRO_FORMAT_A1;
+    case PIXMAN_a8b8g8r8: case PIXMAN_x8b8g8r8: case PIXMAN_r8g8b8:
+    case PIXMAN_b8g8r8:   case PIXMAN_r5g6b5:   case PIXMAN_b5g6r5:
+    case PIXMAN_a1r5g5b5: case PIXMAN_x1r5g5b5: case PIXMAN_a1b5g5r5:
+    case PIXMAN_x1b5g5r5: case PIXMAN_a4r4g4b4: case PIXMAN_x4r4g4b4:
+    case PIXMAN_a4b4g4r4: case PIXMAN_x4b4g4r4: case PIXMAN_r3g3b2:
+    case PIXMAN_b2g3r3:   case PIXMAN_a2r2g2b2: case PIXMAN_a2b2g2r2:
+    case PIXMAN_c8:       case PIXMAN_g8:       case PIXMAN_x4a4:
+    case PIXMAN_a4:       case PIXMAN_r1g2b1:   case PIXMAN_b1g2r1:
+    case PIXMAN_a1r1g1b1: case PIXMAN_a1b1g1r1: case PIXMAN_c4:
+    case PIXMAN_g4:       case PIXMAN_g1:
+    default:
+	return CAIRO_FORMAT_INVALID;
+    }
+
+    return CAIRO_FORMAT_INVALID;
+}
+
+static cairo_content_t
+_cairo_content_from_pixman_format (pixman_format_code_t pixman_format)
+{
+    switch (pixman_format) {
+    case PIXMAN_a8r8g8b8:
+    case PIXMAN_a8b8g8r8:
+    case PIXMAN_a1r5g5b5:
+    case PIXMAN_a1b5g5r5:
+    case PIXMAN_a4r4g4b4:
+    case PIXMAN_a4b4g4r4:
+    case PIXMAN_a2r2g2b2:
+    case PIXMAN_a2b2g2r2:
+    case PIXMAN_a1r1g1b1:
+    case PIXMAN_a1b1g1r1:
+	return CAIRO_CONTENT_COLOR_ALPHA;
+    case PIXMAN_x8r8g8b8:
+    case PIXMAN_x8b8g8r8:
+    case PIXMAN_r8g8b8:
+    case PIXMAN_b8g8r8:
+    case PIXMAN_r5g6b5:
+    case PIXMAN_b5g6r5:
+    case PIXMAN_x1r5g5b5:
+    case PIXMAN_x1b5g5r5:
+    case PIXMAN_x4r4g4b4:
+    case PIXMAN_x4b4g4r4:
+    case PIXMAN_r3g3b2:
+    case PIXMAN_b2g3r3:
+    case PIXMAN_c8:
+    case PIXMAN_g8:
+    case PIXMAN_r1g2b1:
+    case PIXMAN_b1g2r1:
+    case PIXMAN_c4:
+    case PIXMAN_g4:
+    case PIXMAN_g1:
+	return CAIRO_CONTENT_COLOR;
+    case PIXMAN_a8:
+    case PIXMAN_a1:
+    case PIXMAN_x4a4:
+    case PIXMAN_a4:
+	return CAIRO_CONTENT_ALPHA;
+    }
+
+    return CAIRO_CONTENT_COLOR_ALPHA;
+}
 
 cairo_surface_t *
-_cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image,
-					      cairo_format_t  format)
+_cairo_image_surface_create_for_pixman_image (pixman_image_t		*pixman_image,
+					      pixman_format_code_t	 pixman_format)
 {
     cairo_image_surface_t *surface;
 
@@ -96,11 +169,11 @@ _cairo_image_surface_create_for_pixman_i
     }
 
     _cairo_surface_init (&surface->base, &cairo_image_surface_backend,
-			 _cairo_content_from_format (format));
+			 _cairo_content_from_pixman_format (pixman_format));
 
     surface->pixman_image = pixman_image;
 
-    surface->format = format;
+    surface->format = _cairo_format_from_pixman_format (pixman_format);
     surface->data = (unsigned char *) pixman_image_get_data (pixman_image);
     surface->owns_data = FALSE;
     surface->has_clip = FALSE;
@@ -204,6 +277,33 @@ _cairo_format_to_pixman_format_code (cai
     return ret;
 }
 
+static cairo_surface_t *
+_cairo_image_surface_create_with_pixman_format (unsigned char		*data,
+						pixman_format_code_t	 pixman_format,
+						int			 width,
+						int			 height,
+						int			 stride)
+{
+    cairo_surface_t *surface;
+    pixman_image_t *pixman_image;
+
+    pixman_image = pixman_image_create_bits (pixman_format, width, height,
+					     (uint32_t *) data, stride);
+
+    if (pixman_image == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_surface_t*) &_cairo_surface_nil;
+    }
+
+    surface = _cairo_image_surface_create_for_pixman_image (pixman_image,
+							    pixman_format);
+    if (cairo_surface_status (surface)) {
+	pixman_image_unref (pixman_image);
+    }
+
+    return surface;
+}
+
 /**
  * cairo_image_surface_create:
  * @format: format of pixels in the surface to create
@@ -231,7 +331,6 @@ cairo_image_surface_create (cairo_format
 {
     cairo_surface_t	*surface;
     pixman_format_code_t pixman_format;
-    pixman_image_t	*pixman_image;
 
     if (! CAIRO_FORMAT_VALID (format)) {
 	_cairo_error (CAIRO_STATUS_INVALID_FORMAT);
@@ -239,18 +338,9 @@ cairo_image_surface_create (cairo_format
     }
 
     pixman_format = _cairo_format_to_pixman_format_code (format);
-    
-    pixman_image = pixman_image_create_bits (pixman_format, width, height,
-					     NULL, -1);
-    if (pixman_image == NULL) {
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
-	return (cairo_surface_t*) &_cairo_surface_nil;
-    }
 
-    surface = _cairo_image_surface_create_for_pixman_image (pixman_image, format);
-    if (cairo_surface_status (surface)) {
-	pixman_image_unref (pixman_image);
-    }
+    return _cairo_image_surface_create_with_pixman_format (NULL, pixman_format,
+							   width, height, -1);
 
     return surface;
 }
@@ -305,29 +395,15 @@ cairo_image_surface_create_for_data (uns
 				     int		height,
 				     int		stride)
 {
-    cairo_surface_t	*surface;
     pixman_format_code_t pixman_format;
-    pixman_image_t	*pixman_image;
 
     if (! CAIRO_FORMAT_VALID (format))
 	return (cairo_surface_t*) &_cairo_surface_nil;
 
     pixman_format = _cairo_format_to_pixman_format_code (format);
 
-    pixman_image = pixman_image_create_bits (pixman_format, width, height,
-					     (uint32_t *) data, stride);
-    
-    if (pixman_image == NULL) {
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
-	return (cairo_surface_t*) &_cairo_surface_nil;
-    }
-
-    surface = _cairo_image_surface_create_for_pixman_image (pixman_image, format);
-    if (cairo_surface_status (surface)) {
-	pixman_image_unref (pixman_image);
-    }
-
-    return surface;
+    return _cairo_image_surface_create_with_pixman_format (data, pixman_format,
+							   width, height, stride);
 }
 slim_hidden_def (cairo_image_surface_create_for_data);
 
@@ -486,20 +562,10 @@ _cairo_format_from_content (cairo_conten
 cairo_content_t
 _cairo_content_from_format (cairo_format_t format)
 {
-    /* XXX: Use an int to avoid the warnings from mixed cairo_format_t
-     * and cairo_internal_format_t values. The warnings are extremely
-     * valuable since mixing enums can lead to subtle bugs. It's just
-     * that cairo_internal_format_t is an interim approach to getting
-     * bug #7294 fixed so we can release cairo 1.2.2 . */
-    int f = format;
-
-    switch (f) {
+    switch (format) {
     case CAIRO_FORMAT_ARGB32:
-    case CAIRO_INTERNAL_FORMAT_ABGR32:
 	return CAIRO_CONTENT_COLOR_ALPHA;
     case CAIRO_FORMAT_RGB24:
-    case CAIRO_INTERNAL_FORMAT_RGB16_565:
-    case CAIRO_INTERNAL_FORMAT_BGR24:
 	return CAIRO_CONTENT_COLOR;
     case CAIRO_FORMAT_A8:
     case CAIRO_FORMAT_A1:
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 43c9dc4..abda368 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -1212,7 +1212,7 @@ _cairo_pattern_acquire_surface_for_gradi
     {
 	image = (cairo_image_surface_t *)
 	    _cairo_image_surface_create_for_pixman_image (pixman_image,
-							  CAIRO_FORMAT_ARGB32);
+							  PIXMAN_a8r8g8b8);
 	if (image->base.status)
 	{
 	    pixman_image_unref (pixman_image);
diff --git a/src/cairoint.h b/src/cairoint.h
index fd3a647..94f5ae3 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -339,45 +339,6 @@ typedef enum cairo_internal_surface_type
     CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED
 } cairo_internal_surface_type_t;
 
-/* For xlib fallbacks, we need image surfaces with formats that match
- * the visual of the X server. There are a few common X server visuals
- * for which we do not have corresponding public cairo_format_t
- * values, since we do not plan on always guaranteeing that cairo will
- * be able to draw to these formats.
- *
- * Currently pixman does advertise support for these formats, (with an
- * interface to construct a format from a set of masks---but pixman
- * may not actually have code to support any arbitrary set of
- * maskes). So we lodge a cairo_internal_format_t in the internal
- * cairo image surface to indicate what's going on. The value isn't
- * actually used for much, since it is the set of pixman masks that
- * control the rendering.
- *
- * But even though the value isn't used, it's still useful to maintain
- * this list, as it indicates to use visual formats that have been
- * encountered in practice. We can take advantage of this for future
- * rewrites of pixman that might support a limited set of formats
- * instead of general mask-based rendering, (or at least optimized
- * rendering for a limited set of formats).
- *
- * Another approach that could be taken here is to convert the data at
- * the time of the fallback to a supported format. This is similar to
- * what needs to be done to support PseudoColor visuals, for example.
- *
- * NOTE: The implementation of CAIRO_FORMAT_VALID *must* *not*
- * consider these internal formats as valid.
- *
- * NOTE: When adding a value to this list, be sure to add it to
- * _cairo_format_from_pixman_format, (which is probably the assert
- * failure you're wanting to eliminate), but also don't forget to add
- * it to cairo_content_from_format.
- */
-typedef enum cairo_internal_format {
-    CAIRO_INTERNAL_FORMAT_ABGR32 = 0x1000,
-    CAIRO_INTERNAL_FORMAT_BGR24,
-    CAIRO_INTERNAL_FORMAT_RGB16_565
-} cairo_internal_format_t;
-
 typedef enum cairo_direction {
     CAIRO_DIRECTION_FORWARD,
     CAIRO_DIRECTION_REVERSE
@@ -2025,6 +1986,7 @@ _cairo_surface_has_device_transform (cai
  * to support it (at least cairo_surface_write_to_png and a few spots
  * in cairo-xlib-surface.c--again see -Wswitch-enum).
  */
+#define CAIRO_FORMAT_INVALID ((unsigned int) -1)
 #define CAIRO_FORMAT_VALID(format) ((format) <= CAIRO_FORMAT_A1)
 
 #define CAIRO_CONTENT_VALID(content) ((content) && 			         \
@@ -2040,8 +2002,8 @@ cairo_private cairo_content_t
 _cairo_content_from_format (cairo_format_t format);
 
 cairo_private cairo_surface_t *
-_cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image,
-					      cairo_format_t  format);
+_cairo_image_surface_create_for_pixman_image (pixman_image_t		*pixman_image,
+					      pixman_format_code_t	 pixman_format);
 
 cairo_private cairo_surface_t *
 _cairo_image_surface_create_with_masks (unsigned char	       *data,


More information about the cairo-commit mailing list