[cairo-commit] 6 commits - doc/public src/cairo-analysis-surface.c src/cairo-directfb-surface.c src/cairo-glitz-surface.c src/cairo.h src/cairo-image-surface.c src/cairoint.h src/cairo-meta-surface.c src/cairo-paginated-surface.c src/cairo-pdf-surface.c src/cairo-pdf-test.h src/cairo-ps-surface.c src/cairo-quartz-surface.c src/cairo-surface.c src/cairo-svg-surface.c src/cairo-win32-surface.c src/cairo-xcb-surface.c src/cairo-xlib-surface.c src/cairo-xlib-test.h src/Makefile.am src/test-fallback-surface.c src/test-meta-surface.c src/test-paginated-surface.c test/cairo-test.c test/device-offset.c test/device-offset-ref.png test/device-offset-rgb24-ref.png test/fallback-resolution.c test/.gitignore test/Makefile.am test/pdf-features.c test/xlib-surface.c

Carl Worth cworth at kemper.freedesktop.org
Wed May 24 17:30:23 PDT 2006


 doc/public/Makefile.am           |    1 
 src/Makefile.am                  |    2 
 src/cairo-analysis-surface.c     |    5 +-
 src/cairo-directfb-surface.c     |    4 +
 src/cairo-glitz-surface.c        |    4 +
 src/cairo-image-surface.c        |    3 -
 src/cairo-meta-surface.c         |    6 +-
 src/cairo-paginated-surface.c    |    3 -
 src/cairo-pdf-surface.c          |   29 ++++++++++-
 src/cairo-pdf-test.h             |   55 ++++++++++++++++++++++
 src/cairo-ps-surface.c           |    3 -
 src/cairo-quartz-surface.c       |    4 +
 src/cairo-surface.c              |   26 +++++++++-
 src/cairo-svg-surface.c          |    3 -
 src/cairo-win32-surface.c        |    6 +-
 src/cairo-xcb-surface.c          |   29 +++++++++++
 src/cairo-xlib-surface.c         |   97 +++++++++++++++++++++------------------
 src/cairo-xlib-test.h            |    2 
 src/cairo.h                      |    3 +
 src/cairoint.h                   |    5 +-
 src/test-fallback-surface.c      |    3 -
 src/test-meta-surface.c          |    3 -
 src/test-paginated-surface.c     |    3 -
 test/.gitignore                  |    3 +
 test/Makefile.am                 |    2 
 test/cairo-test.c                |   18 +++++++
 test/device-offset-ref.png       |binary
 test/device-offset-rgb24-ref.png |binary
 test/device-offset.c             |   93 +++++++++++++++++++++++++++++++++++++
 test/fallback-resolution.c       |   84 +++++++++++++++++++++++++++++++++
 test/pdf-features.c              |    4 -
 test/xlib-surface.c              |    2 
 32 files changed, 434 insertions(+), 71 deletions(-)

New commits:
diff-tree 22232be7592dadc22fef614aefee9c9398a8510c (from d0dd3b822e98358e88f8c9261ef633331548ccfd)
Author: Carl Worth <cworth at cworth.org>
Date:   Wed May 24 17:24:52 2006 -0700

    Note the changed semantics of cairo_surface_set_device_offset
    
    Specifically, device offsets now affect using the offset surface in
    a source pattern as well as drawing to the surface. This behavior
    os also verified with a new test case: test/device-offset.c

diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index a4ec2de..c6f8f9c 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -610,8 +610,8 @@ cairo_surface_mark_dirty_rectangle (cair
  * sufficient to do this, since functions like
  * cairo_device_to_user() will expose the hidden offset.
  *
- * Note that the offset only affects drawing to the surface, not using
- * the surface in a surface pattern.
+ * Note that the offset affects drawing to the surface as well as
+ * using the surface in a source pattern.
  **/
 void
 cairo_surface_set_device_offset (cairo_surface_t *surface,
diff --git a/test/.gitignore b/test/.gitignore
index bf416d2..7ededa1 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -22,6 +22,7 @@ dash-caps-joins
 dash-scale
 dash-offset-negative
 dash-zero-length
+device-offset
 extend-reflect
 fallback-resolution
 fallback-resolution.pdf
diff --git a/test/Makefile.am b/test/Makefile.am
index 3cc6b2f..bc8d524 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -19,6 +19,7 @@ dash-caps-joins			\
 dash-scale			\
 dash-offset-negative		\
 dash-zero-length		\
+device-offset			\
 extend-reflect			\
 fallback-resolution		\
 fill-and-stroke			\
diff --git a/test/device-offset-ref.png b/test/device-offset-ref.png
new file mode 100644
index 0000000..22cbfb4
Binary files /dev/null and b/test/device-offset-ref.png differ
diff --git a/test/device-offset-rgb24-ref.png b/test/device-offset-rgb24-ref.png
new file mode 100644
index 0000000..634388f
Binary files /dev/null and b/test/device-offset-rgb24-ref.png differ
diff --git a/test/device-offset.c b/test/device-offset.c
new file mode 100644
index 0000000..9418c60
--- /dev/null
+++ b/test/device-offset.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2006 Red Hat, Inc.
+ *
+ * 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
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#include "cairo-test.h"
+#include <stddef.h>
+
+#define SIZE 10
+#define PAD 2
+
+cairo_test_t test = {
+    "device-offset",
+    "Simple test using a surface with a device-offset as a source.",
+    SIZE, SIZE
+};
+
+static void
+draw_square (cairo_t *cr)
+{
+    cairo_rectangle (cr,
+		     PAD, PAD,
+		     SIZE - 2 * PAD,
+		     SIZE - 2 * PAD);
+    cairo_fill (cr);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_surface_t *surface, *target;
+    cairo_t *cr2;
+
+    /* First draw a shape in black on the original destination. */
+    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
+    draw_square (cr);
+
+    cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/a.png");
+
+    /* Then, create an offset surface and repeat the drawing in red. */
+    target = cairo_get_target (cr);
+    surface = cairo_surface_create_similar (target,
+					    cairo_surface_get_content (target),
+					    SIZE / 2, SIZE / 2);
+    cairo_surface_set_device_offset (surface, - SIZE / 2, - SIZE / 2);
+    cr2 = cairo_create (surface);
+
+    cairo_set_source_rgb (cr2, 1, 0, 0); /* red */
+    draw_square (cr2);
+
+    cairo_surface_write_to_png (surface, "/tmp/b.png");
+
+    cairo_destroy (cr2);
+
+    /* Finally, copy the offset surface to the original destination.
+    * The final result should be a blue square with the lower-right
+    * quarter red. */
+    cairo_set_source_surface (cr, surface, 0, 0);
+
+    cairo_paint (cr);
+
+    cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/c.png");
+
+    cairo_surface_destroy (surface);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test, draw);
+}
diff-tree d0dd3b822e98358e88f8c9261ef633331548ccfd (from 0796845ae6923f3ccef5df231b7d9a2c145063fd)
Author: Carl Worth <cworth at cworth.org>
Date:   Wed May 24 17:05:51 2006 -0700

    New API: Add new function cairo_surface_get_content
    
    This assumes that the directfb, glitz, and quartz backends
    always create surfaces with content of COLOR_ALPHA which might
    be totally wrong.

diff --git a/src/cairo-analysis-surface.c b/src/cairo-analysis-surface.c
index 0391df4..fdcd17f 100644
--- a/src/cairo-analysis-surface.c
+++ b/src/cairo-analysis-surface.c
@@ -217,7 +217,10 @@ _cairo_analysis_surface_create (cairo_su
     if (surface == NULL)
 	goto FAIL;
 
-    _cairo_surface_init (&surface->base, &cairo_analysis_surface_backend);
+    /* I believe the content type here is truly arbitrary. I'm quite
+     * sure nothing will ever use this value. */
+    _cairo_surface_init (&surface->base, &cairo_analysis_surface_backend,
+			 CAIRO_CONTENT_COLOR_ALPHA);
 
     surface->width = width;
     surface->height = height;
diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index 0a11a5c..0b13de1 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -790,7 +790,9 @@ cairo_directfb_surface_create (IDirectFB
 		cairo_directfb_surface_t *surface = calloc(1,sizeof(cairo_directfb_surface_t));
 		if( surface == NULL ) 
 		return NULL;
-		_cairo_surface_init (&surface->base, &cairo_directfb_surface_backend);
+		/* XXX: The content value here might be totally wrong. */
+		_cairo_surface_init (&surface->base, &cairo_directfb_surface_backend,
+				     CAIRO_CONTENT_COLOR_ALPHA);
 		/*Reference the surface */
 		dfb->AddRef(dfb);	
 		dfbsurface->AddRef(dfbsurface);	
diff --git a/src/cairo-glitz-surface.c b/src/cairo-glitz-surface.c
index e881157..0db3df9 100644
--- a/src/cairo-glitz-surface.c
+++ b/src/cairo-glitz-surface.c
@@ -2163,7 +2163,9 @@ cairo_glitz_surface_create (glitz_surfac
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&crsurface->base, &cairo_glitz_surface_backend);
+    /* XXX: The content value here might be totally wrong. */
+    _cairo_surface_init (&crsurface->base, &cairo_glitz_surface_backend,
+			 CAIRO_CONTENT_COLOR_ALPHA);
 
     glitz_surface_reference (surface);
 
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 655881b..72c593f 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -63,7 +63,8 @@ _cairo_image_surface_create_for_pixman_i
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&surface->base, &cairo_image_surface_backend);
+    _cairo_surface_init (&surface->base, &cairo_image_surface_backend,
+			 _cairo_content_from_format (format));
 
     surface->pixman_image = pixman_image;
 
diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c
index 9a8ce7b..46ea13d 100644
--- a/src/cairo-meta-surface.c
+++ b/src/cairo-meta-surface.c
@@ -72,7 +72,8 @@ _cairo_meta_surface_create (cairo_conten
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&meta->base, &cairo_meta_surface_backend);
+    _cairo_surface_init (&meta->base, &cairo_meta_surface_backend,
+			 content);
 
     meta->content = content;
     meta->width_pixels = width_pixels;
@@ -477,7 +478,8 @@ _cairo_meta_surface_snapshot (void *abst
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&meta->base, &cairo_meta_surface_backend);
+    _cairo_surface_init (&meta->base, &cairo_meta_surface_backend,
+			 other->base.content);
     meta->base.is_snapshot = TRUE;
 
     meta->width_pixels = other->width_pixels;
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index 1e559d6..d4caafe 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -103,7 +103,8 @@ _cairo_paginated_surface_create (cairo_s
     if (surface == NULL)
 	goto FAIL;
 
-    _cairo_surface_init (&surface->base, &cairo_paginated_surface_backend);
+    _cairo_surface_init (&surface->base, &cairo_paginated_surface_backend,
+			 content);
 
     /* Override surface->base.type with target's type so we don't leak
      * evidence of the paginated wrapper out to the user. */
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 8108993..2803e35 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -262,7 +262,8 @@ _cairo_pdf_surface_create_for_stream_int
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&surface->base, &cairo_pdf_surface_backend);
+    _cairo_surface_init (&surface->base, &cairo_pdf_surface_backend,
+			 CAIRO_CONTENT_COLOR_ALPHA);
 
     surface->output = output;
 
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index fb8935b..1a48c91 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -354,7 +354,8 @@ _cairo_ps_surface_create_for_stream_inte
 	goto CLEANUP;
     }
 
-    _cairo_surface_init (&surface->base, &cairo_ps_surface_backend);
+    _cairo_surface_init (&surface->base, &cairo_ps_surface_backend,
+			 CAIRO_CONTENT_COLOR_ALPHA);
 
     surface->final_stream = stream;
 
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index d6fd8ee..698b149 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -240,7 +240,9 @@ cairo_surface_t *cairo_quartz_surface_cr
         return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init(&surface->base, &cairo_quartz_surface_backend);
+    /* XXX: The content value here might be totally wrong. */
+    _cairo_surface_init(&surface->base, &cairo_quartz_surface_backend,
+			CAIRO_CONTENT_COLOR_ALPHA);
 
     surface->context = context;
     surface->clip_region = NULL;
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 422152f..a4ec2de 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -43,6 +43,7 @@
 
 const cairo_surface_t _cairo_surface_nil = {
     &cairo_image_surface_backend,	/* backend */
+    CAIRO_CONTENT_COLOR,
     CAIRO_SURFACE_TYPE_IMAGE,
     -1,					/* ref_count */
     CAIRO_STATUS_NO_MEMORY,		/* status */
@@ -60,6 +61,7 @@ const cairo_surface_t _cairo_surface_nil
 
 const cairo_surface_t _cairo_surface_nil_file_not_found = {
     &cairo_image_surface_backend,	/* backend */
+    CAIRO_CONTENT_COLOR,
     CAIRO_SURFACE_TYPE_IMAGE,
     -1,					/* ref_count */
     CAIRO_STATUS_FILE_NOT_FOUND,	/* status */
@@ -77,6 +79,7 @@ const cairo_surface_t _cairo_surface_nil
 
 const cairo_surface_t _cairo_surface_nil_read_error = {
     &cairo_image_surface_backend,	/* backend */
+    CAIRO_CONTENT_COLOR,
     CAIRO_SURFACE_TYPE_IMAGE,
     -1,					/* ref_count */
     CAIRO_STATUS_READ_ERROR,		/* status */
@@ -146,6 +149,20 @@ cairo_surface_get_type (cairo_surface_t 
 }
 
 /**
+ * cairo_surface_get_content:
+ * @surface: a #cairo_surface_t
+ * 
+ * Return value: The content type of @surface which indicates whether
+ * the surface contains color and/or alpha information. See
+ * #cairo_content_t.
+ **/
+cairo_content_t
+cairo_surface_get_content (cairo_surface_t *surface)
+{
+    return surface->content;
+}
+
+/**
  * cairo_surface_status:
  * @surface: a #cairo_surface_t
  * 
@@ -165,9 +182,12 @@ cairo_surface_status (cairo_surface_t *s
 
 void
 _cairo_surface_init (cairo_surface_t			*surface,
-		     const cairo_surface_backend_t	*backend)
+		     const cairo_surface_backend_t	*backend,
+		     cairo_content_t			 content)
 {
     surface->backend = backend;
+
+    surface->content = content;
     
     surface->type = backend->type;
 
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 94e0abc..f0c1e5c 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -384,7 +384,8 @@ _cairo_svg_surface_create_for_document (
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&surface->base, &cairo_svg_surface_backend);
+    _cairo_surface_init (&surface->base, &cairo_svg_surface_backend,
+			 content);
 
     surface->width = width;
     surface->height = height;
diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index 9ea5522..fd7f9e0 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -300,7 +300,8 @@ _cairo_win32_surface_create_for_dc (HDC 
 
     surface->extents = surface->clip_rect;
 
-    _cairo_surface_init (&surface->base, &cairo_win32_surface_backend);
+    _cairo_surface_init (&surface->base, &cairo_win32_surface_backend,
+			 _cairo_content_from_format (format));
 
     return (cairo_surface_t *)surface;
 
@@ -1166,7 +1167,8 @@ cairo_win32_surface_create (HDC hdc)
 
     surface->extents = surface->clip_rect;
 
-    _cairo_surface_init (&surface->base, &cairo_win32_surface_backend);
+    _cairo_surface_init (&surface->base, &cairo_win32_surface_backend,
+			 _cairo_content_from_format (format));
 
     return (cairo_surface_t *)surface;
 }
diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c
index a281694..bfa3730 100644
--- a/src/cairo-xcb-surface.c
+++ b/src/cairo-xcb-surface.c
@@ -66,6 +66,32 @@ format_from_visual(XCBConnection *c, XCB
     return nil;
 }
 
+static cairo_content_t
+_xcb_render_format_to_content (XCBRenderPICTFORMINFO *xrender_format)
+{
+    cairo_bool_t xrender_format_has_alpha;
+    cairo_bool_t xrender_format_has_color;
+
+    /* This only happens when using a non-Render server. Let's punt
+     * and say there's no alpha here. */
+    if (xrender_format == NULL)
+	return CAIRO_CONTENT_COLOR;
+
+    xrender_format_has_alpha = (xrender_format->direct.alpha_mask != 0);
+    xrender_format_has_color = (xrender_format->direct.red_mask   != 0 ||
+				xrender_format->direct.green_mask != 0 ||
+				xrender_format->direct.blue_mask  != 0);
+
+    if (xrender_format_has_alpha)
+	if (xrender_format_has_color)
+	    return CAIRO_CONTENT_COLOR_ALPHA;
+	else
+	    return CAIRO_CONTENT_ALPHA;
+    else
+	return CAIRO_CONTENT_COLOR;
+
+}
+
 /* XXX: Why is this ridiculously complex compared to the equivalent
  * function in cairo-xlib-surface.c */
 static XCBRenderPICTFORMINFO
@@ -1100,7 +1126,8 @@ _cairo_xcb_surface_create_internal (XCBC
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&surface->base, &cairo_xcb_surface_backend);
+    _cairo_surface_init (&surface->base, &cairo_xcb_surface_backend,
+			 _xcb_render_format_to_content (format));
 
     surface->dpy = dpy;
 
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 042294a..0a11611 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -244,21 +244,29 @@ _cairo_xlib_surface_create_similar_with_
     return &surface->base;
 }
 
-static cairo_bool_t
-_xrender_format_matches_content (XRenderPictFormat *format,
-                                 cairo_content_t   content)
+static cairo_content_t
+_xrender_format_to_content (XRenderPictFormat *xrender_format)
 {
-    cairo_bool_t format_has_alpha = format->direct.alpha != 0;
-    cairo_bool_t format_has_color = (format->direct.red   != 0 ||
-				     format->direct.green != 0 ||
-				     format->direct.blue  != 0);
-    cairo_bool_t content_has_alpha = (content == CAIRO_CONTENT_ALPHA ||
-				      content == CAIRO_CONTENT_COLOR_ALPHA);
-    cairo_bool_t content_has_color = (content == CAIRO_CONTENT_COLOR ||
-				      content == CAIRO_CONTENT_COLOR_ALPHA);
+    cairo_bool_t xrender_format_has_alpha;
+    cairo_bool_t xrender_format_has_color;
 
-    return (format_has_alpha == content_has_alpha &&
-	    format_has_color == content_has_color);
+    /* This only happens when using a non-Render server. Let's punt
+     * and say there's no alpha here. */
+    if (xrender_format == NULL)
+	return CAIRO_CONTENT_COLOR;
+
+    xrender_format_has_alpha = (xrender_format->direct.alpha != 0);
+    xrender_format_has_color = (xrender_format->direct.red   != 0 ||
+				xrender_format->direct.green != 0 ||
+				xrender_format->direct.blue  != 0);
+
+    if (xrender_format_has_alpha)
+	if (xrender_format_has_color)
+	    return CAIRO_CONTENT_COLOR_ALPHA;
+	else
+	    return CAIRO_CONTENT_ALPHA;
+    else
+	return CAIRO_CONTENT_COLOR;
 }
 
 static cairo_surface_t *
@@ -284,7 +292,7 @@ _cairo_xlib_surface_create_similar (void
      * arbitrarily pick a visual/depth for the similar surface.
      */
     if (xrender_format == NULL ||
-	! _xrender_format_matches_content (xrender_format, content))
+	_xrender_format_to_content (xrender_format) != content)
     {
 	return _cairo_xlib_surface_create_similar_with_format (abstract_src,
 							       _cairo_format_from_content (content),
@@ -1783,7 +1791,7 @@ _cairo_xlib_surface_create_internal (Dis
 				     Drawable		        drawable,
 				     Screen		       *screen,
 				     Visual		       *visual,
-				     XRenderPictFormat	       *format,
+				     XRenderPictFormat	       *xrender_format,
 				     int			width,
 				     int			height,
 				     int			depth)
@@ -1803,21 +1811,8 @@ _cairo_xlib_surface_create_internal (Dis
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&surface->base, &cairo_xlib_surface_backend);
-
-    surface->dpy = dpy;
-    surface->screen_info = screen_info;
-
-    surface->gc = NULL;
-    surface->drawable = drawable;
-    surface->screen = screen;
-    surface->owns_pixmap = FALSE;
-    surface->use_pixmap = 0;
-    surface->width = width;
-    surface->height = height;
-    
-    if (format) {
-	depth = format->depth;
+    if (xrender_format) {
+	depth = xrender_format->depth;
     } else if (visual) {
 	int j, k;
 
@@ -1843,6 +1838,31 @@ _cairo_xlib_surface_create_internal (Dis
 	surface->render_minor = -1;
     }
 
+    if (CAIRO_SURFACE_RENDER_HAS_CREATE_PICTURE (surface)) {
+	if (!xrender_format) {
+	    if (visual)
+		xrender_format = XRenderFindVisualFormat (dpy, visual);
+	    else if (depth == 1)
+		xrender_format = XRenderFindStandardFormat (dpy, PictStandardA1);
+	}
+    } else {
+	xrender_format = NULL;
+    }
+
+    _cairo_surface_init (&surface->base, &cairo_xlib_surface_backend,
+			 _xrender_format_to_content (xrender_format));
+
+    surface->dpy = dpy;
+    surface->screen_info = screen_info;
+
+    surface->gc = NULL;
+    surface->drawable = drawable;
+    surface->screen = screen;
+    surface->owns_pixmap = FALSE;
+    surface->use_pixmap = 0;
+    surface->width = width;
+    surface->height = height;
+    
     surface->buggy_repeat = FALSE;
     if (strstr (ServerVendor (dpy), "X.Org") != NULL) {
 	if (VendorRelease (dpy) <= 60802000)
@@ -1855,19 +1875,8 @@ _cairo_xlib_surface_create_internal (Dis
     surface->dst_picture = None;
     surface->src_picture = None;
 
-    if (CAIRO_SURFACE_RENDER_HAS_CREATE_PICTURE (surface)) {
-	if (!format) {
-	    if (visual)
-		format = XRenderFindVisualFormat (dpy, visual);
-	    else if (depth == 1)
-		format = XRenderFindStandardFormat (dpy, PictStandardA1);
-	}
-    } else {
-	format = NULL;
-    }
-
     surface->visual = visual;
-    surface->xrender_format = format;
+    surface->xrender_format = xrender_format;
     surface->depth = depth;
 
     surface->have_clip_rects = FALSE;
diff --git a/src/cairo.h b/src/cairo.h
index b8738fc..980ecc0 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -1266,6 +1266,9 @@ typedef enum _cairo_surface_type {
 cairo_public cairo_surface_type_t
 cairo_surface_get_type (cairo_surface_t *surface);
 
+cairo_public cairo_content_t
+cairo_surface_get_content (cairo_surface_t *surface);
+
 #if CAIRO_HAS_PNG_FUNCTIONS
 
 cairo_public cairo_status_t
diff --git a/src/cairoint.h b/src/cairoint.h
index 86610e1..cebaa21 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -853,6 +853,8 @@ struct _cairo_surface {
      * hide their internal type from the user-level API. */
     cairo_surface_type_t type;
 
+    cairo_content_t content;
+
     unsigned int ref_count;
     cairo_status_t status;
     cairo_bool_t finished;
@@ -1645,7 +1647,8 @@ _cairo_surface_create_similar_solid (cai
 
 cairo_private void
 _cairo_surface_init (cairo_surface_t			*surface,
-		     const cairo_surface_backend_t	*backend);
+		     const cairo_surface_backend_t	*backend,
+		     cairo_content_t			 content);
 
 cairo_private cairo_clip_mode_t
 _cairo_surface_get_clip_mode (cairo_surface_t *surface);
diff --git a/src/test-fallback-surface.c b/src/test-fallback-surface.c
index 7d03710..1504aa7 100644
--- a/src/test-fallback-surface.c
+++ b/src/test-fallback-surface.c
@@ -82,7 +82,8 @@ _test_fallback_surface_create (cairo_con
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&surface->base, &test_fallback_surface_backend);
+    _cairo_surface_init (&surface->base, &test_fallback_surface_backend,
+			 content);
 
     surface->backing = backing;
 
diff --git a/src/test-meta-surface.c b/src/test-meta-surface.c
index 7698e49..ade7105 100644
--- a/src/test-meta-surface.c
+++ b/src/test-meta-surface.c
@@ -78,7 +78,8 @@ _test_meta_surface_create (cairo_content
     if (surface == NULL)
 	goto FAIL;
 
-    _cairo_surface_init (&surface->base, &test_meta_surface_backend);
+    _cairo_surface_init (&surface->base, &test_meta_surface_backend,
+			 content);
 
     surface->meta = _cairo_meta_surface_create (content, width, height);
     if (cairo_surface_status (surface->meta))
diff --git a/src/test-paginated-surface.c b/src/test-paginated-surface.c
index 73d5834..c00bac8 100644
--- a/src/test-paginated-surface.c
+++ b/src/test-paginated-surface.c
@@ -86,7 +86,8 @@ _test_paginated_surface_create_for_data 
 	return (cairo_surface_t *) &_cairo_surface_nil;
     }
 
-    _cairo_surface_init (&surface->base, &test_paginated_surface_backend);
+    _cairo_surface_init (&surface->base, &test_paginated_surface_backend,
+			 content);
 
     surface->target = target;
 
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 55785de..444fe32 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -1445,6 +1445,7 @@ cairo_test_for_target (cairo_test_t *tes
     char *srcdir;
     char *format;
     cairo_test_status_t ret;
+    cairo_content_t expected_content;
 
     /* Get the strings ready that we'll need. */
     srcdir = getenv ("srcdir");
@@ -1505,6 +1506,7 @@ cairo_test_for_target (cairo_test_t *tes
 	goto UNWIND_STRINGS;
     }
 
+    /* Check that we created a surface of the expected type. */
     if (cairo_surface_get_type (surface) != target->expected_type) {
 	cairo_test_log ("Error: Created surface is of type %d (expected %d)\n",
 			cairo_surface_get_type (surface), target->expected_type);
@@ -1512,6 +1514,22 @@ cairo_test_for_target (cairo_test_t *tes
 	goto UNWIND_SURFACE;
     }
 
+    /* Check that we created a surface of the expected content,
+     * (ignore the articifical
+     * CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED value).
+     */
+    expected_content = target->content;
+    if (expected_content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
+	expected_content = CAIRO_CONTENT_COLOR_ALPHA;
+
+    if (cairo_surface_get_content (surface) != expected_content) {
+	cairo_test_log ("Error: Created surface has content %d (expected %d)\n",
+			cairo_surface_get_content (surface), expected_content);
+	ret = CAIRO_TEST_FAILURE;
+	goto UNWIND_SURFACE;
+    }
+
+
     cairo_surface_set_device_offset (surface, dev_offset, dev_offset);
 
     cr = cairo_create (surface);
diff-tree 0796845ae6923f3ccef5df231b7d9a2c145063fd (from 11b2481862e15a2cdedae347eab4347f7b63f715)
Author: Carl Worth <cworth at cworth.org>
Date:   Wed May 24 14:03:49 2006 -0700

    Add new fallback-resolution test for bug in cairo_pdf_surface_set_dpi

diff --git a/test/.gitignore b/test/.gitignore
index 5588698..bf416d2 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -23,6 +23,8 @@ dash-scale
 dash-offset-negative
 dash-zero-length
 extend-reflect
+fallback-resolution
+fallback-resolution.pdf
 fill-and-stroke
 fill-and-stroke-alpha
 fill-and-stroke-alpha-add
diff --git a/test/Makefile.am b/test/Makefile.am
index fde3873..3cc6b2f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -20,6 +20,7 @@ dash-scale			\
 dash-offset-negative		\
 dash-zero-length		\
 extend-reflect			\
+fallback-resolution		\
 fill-and-stroke			\
 fill-and-stroke-alpha		\
 fill-and-stroke-alpha-add	\
diff --git a/test/fallback-resolution.c b/test/fallback-resolution.c
new file mode 100644
index 0000000..0028301
--- /dev/null
+++ b/test/fallback-resolution.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright © 2006 Red Hat, Inc.
+ *
+ * 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
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#include <stdio.h>
+#include <cairo.h>
+#include <cairo-pdf.h>
+#include <cairo-pdf-test.h>
+
+#include "cairo-test.h"
+
+/* This test exists to test cairo_surface_set_fallback_resolution
+ */
+
+#define INCHES_TO_POINTS(in) ((in) * 72.0)
+#define SIZE INCHES_TO_POINTS(1)
+
+int
+main (void)
+{
+    cairo_surface_t *surface;
+    cairo_t *cr;
+    cairo_status_t status;
+    char *filename;
+    double dpi[] = { 37.5, 75., 150., 300., 600. };
+    int i;
+
+    printf("\n");
+
+    filename = "fallback-resolution.pdf";
+
+    surface = cairo_pdf_surface_create (filename, SIZE, SIZE);
+
+    cr = cairo_create (surface);
+
+    /* Force image fallbacks before drawing anything. */
+    cairo_pdf_test_force_fallbacks ();
+
+    for (i = 0; i < sizeof(dpi) / sizeof (dpi[0]); i++) {
+	cairo_pdf_surface_set_dpi (surface, dpi[i], dpi[i]);
+	cairo_arc (cr, SIZE / 2.0, SIZE / 2.0,
+		   0.75 * SIZE / 2.0,
+		   0, 2.0 * M_PI);
+	cairo_fill (cr);
+
+	cairo_show_page (cr);
+    }
+
+    status = cairo_status (cr);
+
+    cairo_destroy (cr);
+    cairo_surface_destroy (surface);
+
+    if (status) {
+	cairo_test_log ("Failed to create pdf surface for file %s: %s\n",
+			filename, cairo_status_to_string (status));
+	return CAIRO_TEST_FAILURE;
+    }
+
+    printf ("fallback-resolution: Please check %s to ensure it looks correct.\n", filename);
+
+    return CAIRO_TEST_SUCCESS;
+}
diff-tree 11b2481862e15a2cdedae347eab4347f7b63f715 (from 65b9217cadcd09f1ed18aa0da38d0b72b6438780)
Author: Carl Worth <cworth at cworth.org>
Date:   Wed May 24 14:02:30 2006 -0700

    PDF: Add new, private test function: cairo_pdf_test_force_fallbacks

diff --git a/doc/public/Makefile.am b/doc/public/Makefile.am
index 289029f..98d3706 100644
--- a/doc/public/Makefile.am
+++ b/doc/public/Makefile.am
@@ -28,6 +28,7 @@ IGNORE_HFILES= 				\
 	cairo-hash-private.h		\
 	cairo-meta-surface-private.h	\
 	cairo-path-fixed-private.h 	\
+	cairo-pdf-test.h		\
 	cairo-private.h			\
 	cairo-win32-private.h		\
 	cairo-xlib-private.h		\
diff --git a/src/Makefile.am b/src/Makefile.am
index 29603a0..42ae71f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,7 +7,7 @@ endif
 
 if CAIRO_HAS_PDF_SURFACE
 libcairo_pdf_headers = cairo-pdf.h
-libcairo_pdf_sources = cairo-pdf-surface.c
+libcairo_pdf_sources = cairo-pdf-surface.c cairo-pdf-test.h
 libcairo_font_subset_sources = cairo-font-subset.c cairo-font-subset-private.h
 endif
 
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index fa530a0..8108993 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -38,6 +38,7 @@
 
 #include "cairoint.h"
 #include "cairo-pdf.h"
+#include "cairo-pdf-test.h"
 #include "cairo-scaled-font-subsets-private.h"
 #include "cairo-ft-private.h"
 #include "cairo-paginated-surface-private.h"
@@ -760,7 +761,7 @@ emit_image (cairo_pdf_surface_t		*surfac
      * future). */
 
     /* These are the only image formats we currently support, (which
-     * makes things a lot simpler here). This is enforeced through
+     * makes things a lot simpler here). This is enforced through
      * _analyze_operation which only accept source surfaces of
      * CONTENT_COLOR or CONTENT_COLOR_ALPHA.
      */
@@ -2022,11 +2023,34 @@ _pattern_supported (cairo_pattern_t *pat
     return FALSE;
 }
 
+static cairo_bool_t cairo_pdf_force_fallbacks = FALSE;
+
+/**
+ * cairo_pdf_test_force_fallbacks
+ *
+ * Force the PDF surface backend to use image fallbacks for every
+ * operation.
+ * 
+ * <note>
+ * This function is <emphasis>only</emphasis> intended for internal
+ * testing use within the cairo distribution. It is not installed in
+ * any public header file.
+ * </note>
+ **/
+void
+cairo_pdf_test_force_fallbacks (void)
+{
+    cairo_pdf_force_fallbacks = TRUE;
+}
+
 static cairo_int_status_t
 _operation_supported (cairo_pdf_surface_t *surface,
 		      cairo_operator_t op,
 		      cairo_pattern_t *pattern)
 {
+    if (cairo_pdf_force_fallbacks)
+	return FALSE;
+
     if (! _pattern_supported (pattern))
 	return FALSE;
 
diff --git a/src/cairo-pdf-test.h b/src/cairo-pdf-test.h
new file mode 100644
index 0000000..7299be3
--- /dev/null
+++ b/src/cairo-pdf-test.h
@@ -0,0 +1,55 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2006 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * 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 University of Southern
+ * California.
+ *
+ * Contributor(s):
+ *	Carl D. Worth <cworth at cworth.org>
+ */
+
+#ifndef CAIRO_PDF_TEST_H
+#define CAIRO_PDF_TEST_H
+
+#include <cairo.h>
+
+#if CAIRO_HAS_PDF_SURFACE
+
+#include <cairo-pdf.h>
+
+CAIRO_BEGIN_DECLS
+
+void
+cairo_pdf_test_force_fallbacks (void);
+
+CAIRO_END_DECLS
+
+#endif /* CAIRO_HAS_PDF_SURFACE */
+#endif /* CAIRO_PDF_TEST_H */
+
diff-tree 65b9217cadcd09f1ed18aa0da38d0b72b6438780 (from 5acce60291fe0b61a67ff1e803b6226db576c233)
Author: Carl Worth <cworth at cworth.org>
Date:   Wed May 24 11:37:05 2006 -0700

    cairo-xlib-test: Rename cairo_test_xlib function prefix to cairo_xlib_test

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 2bf60ad..042294a 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -154,7 +154,7 @@ struct _cairo_xlib_surface {
 static cairo_bool_t cairo_xlib_render_disabled = FALSE;
 
 /**
- * cairo_test_xlib_disable_render:
+ * cairo_xlib_test_disable_render:
  *
  * Disables the use of the RENDER extension.
  * 
@@ -165,7 +165,7 @@ static cairo_bool_t cairo_xlib_render_di
  * </note>
  **/
 void
-cairo_test_xlib_disable_render (void)
+cairo_xlib_test_disable_render (void)
 {
     cairo_xlib_render_disabled = TRUE;
 }
diff --git a/src/cairo-xlib-test.h b/src/cairo-xlib-test.h
index 44b986c..fc06ce9 100644
--- a/src/cairo-xlib-test.h
+++ b/src/cairo-xlib-test.h
@@ -46,7 +46,7 @@
 CAIRO_BEGIN_DECLS
 
 void
-cairo_test_xlib_disable_render (void);
+cairo_xlib_test_disable_render (void);
 
 CAIRO_END_DECLS
 
diff --git a/test/xlib-surface.c b/test/xlib-surface.c
index 1aea873..09b53c8 100644
--- a/test/xlib-surface.c
+++ b/test/xlib-surface.c
@@ -255,7 +255,7 @@ main (void)
 			      1, use_pixmap, set_size, offscreen))
 		    result = 1;
 
-    cairo_test_xlib_disable_render ();
+    cairo_xlib_test_disable_render ();
 
     for (set_size = 0; set_size <= 1; set_size++)
 	for (use_pixmap = 0; use_pixmap <= 1; use_pixmap++)
diff-tree 5acce60291fe0b61a67ff1e803b6226db576c233 (from a5a72676bd34ac6bfdf5e0bcfd3fb21fcbada673)
Author: Carl Worth <cworth at cworth.org>
Date:   Wed May 24 10:35:24 2006 -0700

    Typo fixes

diff --git a/test/pdf-features.c b/test/pdf-features.c
index aad4456..4488084 100644
--- a/test/pdf-features.c
+++ b/test/pdf-features.c
@@ -99,9 +99,9 @@ main (void)
 
     filename = "pdf-features.pdf";
 
-    /* The initial size passes here is the default size that will be
+    /* The initial size passed here is the default size that will be
      * inheritable by each page. That is, any page for which this
-     * initial size applies will not have its owne /MediaBox entry in
+     * initial size applies will not have its own /MediaBox entry in
      * its dictionary. */
     surface = cairo_pdf_surface_create (filename,
 					INCHES_TO_POINTS(8.5),


More information about the cairo-commit mailing list