summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2005-05-06 13:23:41 +0000
committerCarl Worth <cworth@cworth.org>2005-05-06 13:23:41 +0000
commitd6fc5ee5e97f60972ec80fcfc52f0cf8b780d2a9 (patch)
tree9adec3ec1e637a1cca92ba8e36f3aac661217d74
parentcea1de7579fad18ca6c9ec9bb29660970ec283b3 (diff)
Remove cairo_set_target_surface and all other backend-specific cairo_set_target functions. Require a cairo_surface_t* to call cairo_create.
Port to use new cairo_create interface. Rewrite all tests that were using cairo_set_target_surface to instead create a temporary cairo_t, (eventually to be replaced with cairo_begin_group).
-rw-r--r--ChangeLog42
-rw-r--r--src/cairo-glitz.h4
-rw-r--r--src/cairo-gstate.c28
-rw-r--r--src/cairo-pdf.h18
-rw-r--r--src/cairo-ps.h8
-rw-r--r--src/cairo-quartz-surface.c24
-rw-r--r--src/cairo-quartz.h6
-rw-r--r--src/cairo-surface.c2
-rw-r--r--src/cairo-win32.h4
-rw-r--r--src/cairo-xcb.h7
-rw-r--r--src/cairo-xlib.h7
-rw-r--r--src/cairo.c429
-rw-r--r--src/cairo.h86
-rw-r--r--src/cairoint.h11
-rw-r--r--test/cairo-test.c100
-rw-r--r--test/clip-nesting.c9
-rw-r--r--test/mask.c10
-rw-r--r--test/path-data.c13
-rw-r--r--test/pdf-surface.c13
-rw-r--r--test/pixman-rotate.c35
-rw-r--r--test/scale-source-surface-paint.c1
-rw-r--r--test/self-copy.c2
-rw-r--r--test/source-clip.c5
-rw-r--r--test/source-surface-scale-paint.c1
-rw-r--r--test/surface-pattern.c25
25 files changed, 245 insertions, 645 deletions
diff --git a/ChangeLog b/ChangeLog
index f1bae874..c7f57764 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,45 @@
+2005-05-06 Carl Worth <cworth@cworth.org>
+
+ * src/cairo.c: (cairo_create), (cairo_save), (cairo_get_target):
+ * src/cairo.h:
+ * src/cairoint.h:
+ * src/cairo-gstate.c: (_cairo_gstate_create), (_cairo_gstate_init),
+ (_cairo_gstate_get_target):
+ * src/cairo-glitz.h:
+ * src/cairo-pdf.h:
+ * src/cairo-ps.h:
+ * src/cairo-quartz-surface.c:
+ * src/cairo-quartz.h:
+ * src/cairo-surface.c: (_cairo_surface_begin):
+ * src/cairo-win32.h:
+ * src/cairo-xcb.h:
+ * src/cairo-xlib.h: Remove cairo_set_target_surface and all other
+ backend-specific cairo_set_target functions. Require a
+ cairo_surface_t* to call cairo_create.
+
+ * test/cairo-test.c: (create_image_surface), (cleanup_image),
+ (create_glitz_surface), (cleanup_glitz), (create_quartz_surface),
+ (cleanup_quartz), (create_win32_surface), (cleanup_win32),
+ (create_xcb_surface), (cleanup_xcb), (create_xlib_surface),
+ (cleanup_xlib), (cairo_test_for_target), (cairo_test_real):
+
+ Port to use new cairo_create interface.
+
+ * test/clip-nesting.c: (draw):
+ * test/mask.c: (mask_polygon), (draw):
+ * test/path-data.c: (main):
+ * test/pdf-surface.c: (main):
+ * test/pixman-rotate.c: (draw):
+ * test/scale-source-surface-paint.c: (draw):
+ * test/self-copy.c: (draw):
+ * test/source-clip.c: (draw):
+ * test/source-surface-scale-paint.c: (draw):
+ * test/surface-pattern.c: (draw):
+
+ Rewrite all tests that were using cairo_set_target_surface to
+ instead create a temporary cairo_t, (eventually to be replaced
+ with cairo_begin_group).
+
2005-05-05 Owen Taylor <otaylor@redhat.com>
* src/cairo.[ch] doc/public/cairo-sections.txt: Add
diff --git a/src/cairo-glitz.h b/src/cairo-glitz.h
index f1917eb2..33620c07 100644
--- a/src/cairo-glitz.h
+++ b/src/cairo-glitz.h
@@ -45,10 +45,6 @@
CAIRO_BEGIN_DECLS
-void
-cairo_set_target_glitz (cairo_t *cr,
- glitz_surface_t *surface);
-
cairo_surface_t *
cairo_glitz_surface_create (glitz_surface_t *surface);
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 68d41d09..b77b6e24 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -42,6 +42,10 @@
#include "cairo-gstate-private.h"
static cairo_status_t
+_cairo_gstate_set_target_surface (cairo_gstate_t *gstate,
+ cairo_surface_t *surface);
+
+static cairo_status_t
_cairo_gstate_clip_and_composite_trapezoids (cairo_gstate_t *gstate,
cairo_pattern_t *src,
cairo_operator_t operator,
@@ -58,7 +62,7 @@ static void
_cairo_gstate_unset_font (cairo_gstate_t *gstate);
cairo_gstate_t *
-_cairo_gstate_create ()
+_cairo_gstate_create (cairo_surface_t *target)
{
cairo_status_t status;
cairo_gstate_t *gstate;
@@ -67,7 +71,7 @@ _cairo_gstate_create ()
if (gstate)
{
- status = _cairo_gstate_init (gstate);
+ status = _cairo_gstate_init (gstate, target);
if (status) {
free (gstate);
return NULL;
@@ -78,8 +82,11 @@ _cairo_gstate_create ()
}
cairo_status_t
-_cairo_gstate_init (cairo_gstate_t *gstate)
+_cairo_gstate_init (cairo_gstate_t *gstate,
+ cairo_surface_t *target)
{
+ cairo_status_t status;
+
gstate->operator = CAIRO_GSTATE_OPERATOR_DEFAULT;
gstate->tolerance = CAIRO_GSTATE_TOLERANCE_DEFAULT;
@@ -118,6 +125,10 @@ _cairo_gstate_init (cairo_gstate_t *gstate)
gstate->next = NULL;
+ status = _cairo_gstate_set_target_surface (gstate, target);
+ if (status)
+ return status;
+
return CAIRO_STATUS_SUCCESS;
}
@@ -337,7 +348,7 @@ _cairo_gstate_end_group (cairo_gstate_t *gstate)
}
*/
-cairo_status_t
+static cairo_status_t
_cairo_gstate_set_target_surface (cairo_gstate_t *gstate, cairo_surface_t *surface)
{
cairo_status_t status;
@@ -376,19 +387,12 @@ _cairo_gstate_set_target_surface (cairo_gstate_t *gstate, cairo_surface_t *surfa
return CAIRO_STATUS_SUCCESS;
}
-/* XXX: Need to decide the memory mangement semantics of this
- function. Should it reference the surface again? */
cairo_surface_t *
-_cairo_gstate_get_target_surface (cairo_gstate_t *gstate)
+_cairo_gstate_get_target (cairo_gstate_t *gstate)
{
if (gstate == NULL)
return NULL;
-/* XXX: Do we want this?
- if (gstate->surface)
- _cairo_surface_reference (gstate->surface);
-*/
-
return gstate->surface;
}
diff --git a/src/cairo-pdf.h b/src/cairo-pdf.h
index 8c6bcbf8..3dc1845d 100644
--- a/src/cairo-pdf.h
+++ b/src/cairo-pdf.h
@@ -45,24 +45,6 @@
CAIRO_BEGIN_DECLS
-void
-cairo_set_target_pdf (cairo_t *cr,
- FILE *fp,
- double width_inches,
- double height_inches,
- double x_pixels_per_inch,
- double y_pixels_per_inch);
-
-void
-cairo_set_target_pdf_for_callback (cairo_t *cr,
- cairo_write_func_t write_func,
- cairo_destroy_func_t destroy_closure_func,
- void *closure,
- double width_inches,
- double height_inches,
- double x_pixels_per_inch,
- double y_pixels_per_inch);
-
cairo_surface_t *
cairo_pdf_surface_create (FILE *fp,
double width_inches,
diff --git a/src/cairo-ps.h b/src/cairo-ps.h
index 88382920..e375398b 100644
--- a/src/cairo-ps.h
+++ b/src/cairo-ps.h
@@ -45,14 +45,6 @@
CAIRO_BEGIN_DECLS
-void
-cairo_set_target_ps (cairo_t *cr,
- FILE *file,
- double width_inches,
- double height_inches,
- double x_pixels_per_inch,
- double y_pixels_per_inch);
-
/* PS-surface functions */
cairo_surface_t *
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 6cb6b5a4..01dee786 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -58,30 +58,6 @@ ImageDataReleaseFunc(void *info, const void *data, size_t size)
}
}
-
-void
-cairo_set_target_quartz_context(cairo_t * cr,
- CGContextRef context,
- int width, int height)
-{
- cairo_surface_t *surface;
-
-
- if (cr->status && cr->status != CAIRO_STATUS_NO_TARGET_SURFACE)
- return;
-
- surface = cairo_quartz_surface_create(context, width, height);
- if (surface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- return;
- }
-
- cairo_set_target_surface(cr, surface);
-
- /* cairo_set_target_surface takes a reference, so we must destroy ours */
- cairo_surface_destroy(surface);
-}
-
static cairo_surface_t *_cairo_quartz_surface_create_similar(void
*abstract_src,
cairo_format_t
diff --git a/src/cairo-quartz.h b/src/cairo-quartz.h
index 5afd4642..006aee7b 100644
--- a/src/cairo-quartz.h
+++ b/src/cairo-quartz.h
@@ -45,12 +45,6 @@
CAIRO_BEGIN_DECLS
-void
-cairo_set_target_quartz_context( cairo_t *cr,
- CGContextRef context,
- int width,
- int height);
-
cairo_surface_t *
cairo_quartz_surface_create ( CGContextRef context,
int width,
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 51635d8a..94ef7cca 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -126,7 +126,7 @@ _cairo_surface_begin_internal (cairo_surface_t *surface,
cairo_private cairo_status_t
_cairo_surface_begin (cairo_surface_t *surface)
{
- return _cairo_surface_begin_internal (surface, FALSE);
+ return _cairo_surface_begin_internal (surface, FALSE);
}
/**
diff --git a/src/cairo-win32.h b/src/cairo-win32.h
index 535e62cb..521fee74 100644
--- a/src/cairo-win32.h
+++ b/src/cairo-win32.h
@@ -44,10 +44,6 @@
CAIRO_BEGIN_DECLS
-void
-cairo_set_target_win32 (cairo_t *cr,
- HDC hdc);
-
cairo_surface_t *
cairo_win32_surface_create (HDC hdc);
diff --git a/src/cairo-xcb.h b/src/cairo-xcb.h
index 4e0236db..b7625b18 100644
--- a/src/cairo-xcb.h
+++ b/src/cairo-xcb.h
@@ -46,13 +46,6 @@
CAIRO_BEGIN_DECLS
-void
-cairo_set_target_xcb (cairo_t *cr,
- XCBConnection *dpy,
- XCBDRAWABLE drawable,
- XCBVISUALTYPE *visual,
- cairo_format_t format);
-
cairo_surface_t *
cairo_xcb_surface_create (XCBConnection *dpy,
XCBDRAWABLE drawable,
diff --git a/src/cairo-xlib.h b/src/cairo-xlib.h
index 3dee5ddf..9c574ea3 100644
--- a/src/cairo-xlib.h
+++ b/src/cairo-xlib.h
@@ -46,13 +46,6 @@
CAIRO_BEGIN_DECLS
-/* XXX: This should be renamed to cairo_set_target_xlib to match the
- * other backends */
-void
-cairo_set_target_drawable (cairo_t *cr,
- Display *dpy,
- Drawable drawable);
-
cairo_surface_t *
cairo_xlib_surface_create_for_pixmap (Display *dpy,
Pixmap pixmap,
diff --git a/src/cairo.c b/src/cairo.c
index f6fdcf2b..b2b61387 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -74,20 +74,36 @@ cairo_sane_state (cairo_t *cr)
#endif
-/**
+/*
* cairo_create:
+ * @target: target surface for the context
*
- * Creates a new #cairo_t with default values. The target
- * surface must be set on the #cairo_t with cairo_set_target_surface(),
- * or a backend-specific function like cairo_set_target_image() before
- * drawing with the #cairo_t.
+ * Creates a new #cairo_t with all graphics state parameters set to
+ * default values and with @target as a target surface. The target
+ * surface should be constructed with a backend-specific function such
+ * as cairo_image_surface_create (or any other
+ * cairo_<backend>_surface_create variant).
+ *
+ * This function references @target, so you can immediately
+ * call cairo_surface_destroy() on it if you don't need to
+ * maintain a separate reference to it.
+ *
+ * Note that there are restrictions on using the same surface in
+ * multiple contexts at the same time. If, after creating @cr_a with
+ * @surface you also create @cr_b with the same surface, you must
+ * ensure that @cr_b has finished using @surface before resuming use
+ * of @cr_a. Currently, the only way time at which this is guaranteed
+ * is when the the last reference to @cr_b is released with
+ * cairo_destroy(). (XXX: We need to add a cairo_finish() call to
+ * provide a way to achieve this explicitly). See also the
+ * %CAIRO_STATUS_BAD_NESTING status.
*
* Return value: a newly allocated #cairo_t with a reference
* count of 1. The initial reference count should be released
* with cairo_destroy() when you are done using the #cairo_t.
- **/
+ */
cairo_t *
-cairo_create (void)
+cairo_create (cairo_surface_t *target)
{
cairo_t *cr;
@@ -98,12 +114,18 @@ cairo_create (void)
cr->status = CAIRO_STATUS_SUCCESS;
cr->ref_count = 1;
- cr->gstate = _cairo_gstate_create ();
+ _cairo_path_fixed_init (&cr->path);
+
+ if (target == NULL) {
+ cr->gstate = NULL;
+ cr->status = CAIRO_STATUS_NULL_POINTER;
+ return cr;
+ }
+
+ cr->gstate = _cairo_gstate_create (target);
if (cr->gstate == NULL)
cr->status = CAIRO_STATUS_NO_MEMORY;
- _cairo_path_fixed_init (&cr->path);
-
CAIRO_CHECK_SANITY (cr);
return cr;
}
@@ -180,11 +202,7 @@ cairo_save (cairo_t *cr)
if (cr->status)
return;
- if (cr->gstate) {
- top = _cairo_gstate_clone (cr->gstate);
- } else {
- top = _cairo_gstate_create ();
- }
+ top = _cairo_gstate_clone (cr->gstate);
if (top == NULL) {
cr->status = CAIRO_STATUS_NO_MEMORY;
@@ -291,366 +309,6 @@ cairo_pop_group (cairo_t *cr)
*/
/**
- * cairo_set_target_surface:
- * @cr: a #cairo_t
- * @surface: a #cairo_surface_t
- *
- * Directs output for a #cairo_t to a given surface. The surface
- * will be referenced by the #cairo_t, so you can immediately
- * call cairo_surface_destroy() on it if you don't need to
- * keep a reference to it around.
- *
- * Note that there are restrictions on using the same surface in
- * multiple contexts at the same time. If, after setting @surface as
- * the target surface of @cr_a, you set it as the target surface of
- * @cr_b, you must finish using @cr_b and unset the target surface
- * before resuming using @cr_a. Unsetting the target surface happens
- * automatically when the last reference to the context is released
- * with cairo_destroy(), or you can call cairo_set_target_surface
- * (@cr_b, %NULL) explicitly. See also the %CAIRO_STATUS_BAD_NESTING
- * status.
- **/
-void
-cairo_set_target_surface (cairo_t *cr, cairo_surface_t *surface)
-{
- CAIRO_CHECK_SANITY (cr);
- if (cr->status)
- return;
-
- cr->status = _cairo_gstate_set_target_surface (cr->gstate, surface);
- CAIRO_CHECK_SANITY (cr);
-}
-slim_hidden_def(cairo_set_target_surface);
-
-/**
- * cairo_set_target_image:
- * @cr: a #cairo_t
- * @data: a pointer to a buffer supplied by the application
- * in which to write contents.
- * @format: the format of pixels in the buffer
- * @width: the width of the image to be stored in the buffer
- * @height: the eight of the image to be stored in the buffer
- * @stride: the number of bytes between the start of rows
- * in the buffer. Having this be specified separate from @width
- * allows for padding at the end of rows, or for writing
- * to a subportion of a larger image.
- *
- * Directs output for a #cairo_t to an in-memory image. The output
- * buffer must be kept around until the #cairo_t is destroyed or set
- * to to have a different target. The initial contents of @buffer
- * will be used as the inital image contents; you must explicitly
- * clear the buffer, using, for example, cairo_rectangle() and
- * cairo_fill() if you want it cleared.
- **/
-void
-cairo_set_target_image (cairo_t *cr,
- unsigned char *data,
- cairo_format_t format,
- int width,
- int height,
- int stride)
-{
- cairo_surface_t *surface;
-
- CAIRO_CHECK_SANITY (cr);
- if (cr->status)
- return;
-
- surface = cairo_image_surface_create_for_data (data,
- format,
- width, height, stride);
- if (surface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- CAIRO_CHECK_SANITY (cr);
- return;
- }
-
- cairo_set_target_surface (cr, surface);
-
- cairo_surface_destroy (surface);
- CAIRO_CHECK_SANITY (cr);
-}
-
-/**
- * cairo_set_target_image_no_data:
- * @cr: a #cairo_t
- * @format: the format of pixels in the buffer
- * @width: the width of the image to be stored in the buffer
- * @height: the eight of the image to be stored in the buffer
- *
- * Directs output for a #cairo_t to an implicit image surface of the
- * given format that will be created and owned by the cairo
- * context. The initial contents of the target surface will be
- * cleared to 0 in all channels, (ie. transparent black).
- *
- * NOTE: This function has an unconventional name, but that will be
- * straightened out in a future change in which all set_target
- * functions will be renamed.
- **/
-void
-cairo_set_target_image_no_data (cairo_t *cr,
- cairo_format_t format,
- int width,
- int height)
-{
- cairo_surface_t *surface;
-
- CAIRO_CHECK_SANITY (cr);
- if (cr->status)
- return;
-
- surface = cairo_image_surface_create (format, width, height);
- if (surface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- CAIRO_CHECK_SANITY (cr);
- return;
- }
-
- cairo_set_target_surface (cr, surface);
-
- cairo_surface_destroy (surface);
- CAIRO_CHECK_SANITY (cr);
-}
-
-#ifdef CAIRO_HAS_GLITZ_SURFACE
-
-#include "cairo-glitz.h"
-
-void
-cairo_set_target_glitz (cairo_t *cr, glitz_surface_t *surface)
-{
- cairo_surface_t *crsurface;
-
- CAIRO_CHECK_SANITY (cr);
- if (cr->status)
- return;
-
- crsurface = cairo_glitz_surface_create (surface);
- if (crsurface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- return;
- }
-
- cairo_set_target_surface (cr, crsurface);
-
- cairo_surface_destroy (crsurface);
-
- CAIRO_CHECK_SANITY (cr);
-}
-#endif /* CAIRO_HAS_GLITZ_SURFACE */
-
-#ifdef CAIRO_HAS_PDF_SURFACE
-
-#include "cairo-pdf.h"
-
-void
-cairo_set_target_pdf_for_callback (cairo_t *cr,
- cairo_write_func_t write,
- cairo_destroy_func_t destroy_closure,
- void *closure,
- double width_inches,
- double height_inches,
- double x_pixels_per_inch,
- double y_pixels_per_inch)
-{
- cairo_surface_t *surface;
-
- CAIRO_CHECK_SANITY (cr);
- if (cr->status)
- return;
-
- surface = cairo_pdf_surface_create_for_callback (write,
- destroy_closure, closure,
- width_inches, height_inches,
- x_pixels_per_inch, y_pixels_per_inch);
- if (surface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- return;
- }
-
- cairo_set_target_surface (cr, surface);
-
- /* cairo_set_target_surface takes a reference, so we must destroy ours */
- cairo_surface_destroy (surface);
-}
-
-void
-cairo_set_target_pdf (cairo_t *cr,
- FILE *fp,
- double width_inches,
- double height_inches,
- double x_pixels_per_inch,
- double y_pixels_per_inch)
-{
- cairo_surface_t *surface;
-
- CAIRO_CHECK_SANITY (cr);
- if (cr->status)
- return;
-
- surface = cairo_pdf_surface_create (fp,
- width_inches, height_inches,
- x_pixels_per_inch,
- y_pixels_per_inch);
- if (surface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- return;
- }
-
- cairo_set_target_surface (cr, surface);
-
- /* cairo_set_target_surface takes a reference, so we must destroy ours */
- cairo_surface_destroy (surface);
-}
-#endif /* CAIRO_HAS_PDF_SURFACE */
-
-#ifdef CAIRO_HAS_PS_SURFACE
-
-#include "cairo-ps.h"
-
-/**
- * cairo_set_target_ps:
- * @cr: a #cairo_t
- * @file: an open, writeable file
- * @width_inches: width of the output page, in inches
- * @height_inches: height of the output page, in inches
- * @x_pixels_per_inch: X resolution to use for image fallbacks;
- * not all cairo drawing can be represented in a postscript
- * file, so cairo will write out images for some portions
- * of the output.
- * @y_pixels_per_inch: Y resolution to use for image fallbacks.
- *
- * Directs output for a #cairo_t to a postscript file. The file must
- * be kept open until the #cairo_t is destroyed or set to have a
- * different target, and then must be closed by the application.
- **/
-void
-cairo_set_target_ps (cairo_t *cr,
- FILE *file,
- double width_inches,
- double height_inches,
- double x_pixels_per_inch,
- double y_pixels_per_inch)
-{
- cairo_surface_t *surface;
-
- surface = cairo_ps_surface_create (file,
- width_inches, height_inches,
- x_pixels_per_inch, y_pixels_per_inch);
- if (surface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- return;
- }
-
- cairo_set_target_surface (cr, surface);
-
- /* cairo_set_target_surface takes a reference, so we must destroy ours */
- cairo_surface_destroy (surface);
-}
-#endif /* CAIRO_HAS_PS_SURFACE */
-
-#ifdef CAIRO_HAS_WIN32_SURFACE
-
-#include "cairo-win32.h"
-
-void
-cairo_set_target_win32 (cairo_t *cr,
- HDC hdc)
-{
- cairo_surface_t *surface;
-
- if (cr->status && cr->status != CAIRO_STATUS_NO_TARGET_SURFACE)
- return;
-
- surface = cairo_win32_surface_create (hdc);
- if (surface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- return;
- }
-
- cairo_set_target_surface (cr, surface);
-
- /* cairo_set_target_surface takes a reference, so we must destroy ours */
- cairo_surface_destroy (surface);
-}
-#endif /* CAIRO_HAS_WIN32_SURFACE */
-
-#ifdef CAIRO_HAS_XCB_SURFACE
-
-#include "cairo-xcb.h"
-
-void
-cairo_set_target_xcb (cairo_t *cr,
- XCBConnection *dpy,
- XCBDRAWABLE drawable,
- XCBVISUALTYPE *visual,
- cairo_format_t format)
-{
- cairo_surface_t *surface;
-
- if (cr->status && cr->status != CAIRO_STATUS_NO_TARGET_SURFACE)
- return;
-
- surface = cairo_xcb_surface_create (dpy, drawable, visual, format);
- if (surface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- return;
- }
-
- cairo_set_target_surface (cr, surface);
-
- /* cairo_set_target_surface takes a reference, so we must destroy ours */
- cairo_surface_destroy (surface);
-}
-#endif /* CAIRO_HAS_XCB_SURFACE */
-
-#ifdef CAIRO_HAS_XLIB_SURFACE
-
-#include "cairo-xlib.h"
-
-/**
- * cairo_set_target_drawable:
- * @cr: a #cairo_t
- * @dpy: an X display
- * @drawable: a window or pixmap on the default screen of @dpy
- *
- * Directs output for a #cairo_t to an Xlib drawable. @drawable must
- * be a Window or Pixmap on the default screen of @dpy using the
- * default colormap and visual. Using this function is slow because
- * the function must retrieve information about @drawable from the X
- * server.
-
- * The combination of cairo_xlib_surface_create() and
- * cairo_set_target_surface() is somewhat more flexible, although
- * it still is slow.
- **/
-void
-cairo_set_target_drawable (cairo_t *cr,
- Display *dpy,
- Drawable drawable)
-{
- cairo_surface_t *surface;
-
- if (cr->status && cr->status != CAIRO_STATUS_NO_TARGET_SURFACE)
- return;
-
- surface = cairo_xlib_surface_create (dpy, drawable,
- DefaultVisual (dpy, DefaultScreen (dpy)),
- 0,
- DefaultColormap (dpy, DefaultScreen (dpy)));
- if (surface == NULL) {
- cr->status = CAIRO_STATUS_NO_MEMORY;
- return;
- }
-
- cairo_set_target_surface (cr, surface);
-
- /* cairo_set_target_surface takes a reference, so we must destroy ours */
- cairo_surface_destroy (surface);
-}
-#endif /* CAIRO_HAS_XLIB_SURFACE */
-
-/**
* cairo_set_operator:
* @cr: a #cairo_t
* @op: a compositing operator, specified as a #cairo_operator_t
@@ -2444,23 +2102,26 @@ cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix)
DEPRECATE(cairo_current_matrix, cairo_get_matrix);
/**
- * cairo_get_target_surface:
+ * cairo_get_target:
* @cr: a cairo context
*
- * Gets the current target surface, as set by cairo_set_target_surface().
+ * Gets the target surface for the cairo context as passed to
+ * cairo_create().
*
- * Return value: the current target surface.
- *
- * WARNING: This function is scheduled to be removed as part of the
- * upcoming API Shakeup.
+ * Return value: the target surface, (or NULL if @cr is in an error
+ * state). This object is owned by cairo. To keep a reference to it,
+ * you must call cairo_pattern_reference().
**/
cairo_surface_t *
-cairo_get_target_surface (cairo_t *cr)
+cairo_get_target (cairo_t *cr)
{
CAIRO_CHECK_SANITY (cr);
- return _cairo_gstate_get_target_surface (cr->gstate);
+ if (cr->status)
+ return NULL;
+
+ return _cairo_gstate_get_target (cr->gstate);
}
-DEPRECATE (cairo_current_target_surface, cairo_get_target_surface);
+DEPRECATE (cairo_current_target_surface, cairo_get_target);
void
cairo_get_path (cairo_t *cr,
diff --git a/src/cairo.h b/src/cairo.h
index 6bbbb8d1..f8ce4dd5 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -143,7 +143,7 @@ typedef struct _cairo_user_data_key {
* target surface for two different cairo contexts at once,
* and more drawing was done on the first context before the
* surface was unset as the target for the second context.
- * See the documentation for cairo_set_target_surface()
+ * See the documentation for cairo_create().
*
* #cairo_status_t is used to indicate errors that can occur when
* using Cairo. In some cases it is returned directly by functions.
@@ -200,7 +200,7 @@ typedef cairo_status_t (*cairo_read_func_t) (void *closure,
/* Functions for manipulating state objects */
cairo_t *
-cairo_create (void);
+cairo_create (cairo_surface_t *target);
void
cairo_reference (cairo_t *cr);
@@ -227,55 +227,6 @@ cairo_pop_group (cairo_t *cr);
*/
/* Modify state */
-void
-cairo_set_target_surface (cairo_t *cr, cairo_surface_t *surface);
-
-/**
- * cairo_format_t
- * @CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with
- * alpha in the upper 8 bits, then red, then green, then blue.
- * The 32-bit quantities are stored native-endian. Pre-multiplied
- * alpha is used. (That is, 50% transparent red is 0x80800000,
- * not 0x80ff0000.)
- * @CAIRO_FORMAT_RGB24: each pixel is a 32-bit quantity, with
- * the upper 8 bits unused. Red, Green, and Blue are stored
- * in the remaining 24 bits in that order.
- * @CAIRO_FORMAT_A8: each pixel is a 8-bit quantity holding
- * an alpha value.
- * @CAIRO_FORMAT_A1: each pixel is a 1-bit quantity holding
- * an alpha value. Pixels are packed together into 32-bit
- * quantities. The ordering of the bits matches the
- * endianess of the platform. On a big-endian machine, the
- * first pixel is in the uppermost bit, on a little-endian
- * machine the first pixel is in the least-significant bit.
- *
- * #cairo_format_t is used to identify the memory format of
- * image data.
- */
-typedef enum cairo_format {
- CAIRO_FORMAT_ARGB32,
- CAIRO_FORMAT_RGB24,
- CAIRO_FORMAT_A8,
- CAIRO_FORMAT_A1
-} cairo_format_t;
-
-/* XXX: The naming of these two functions is reversed from their
- * cairo_image_surface_create counterparts. We'll fix this when
- * we eliminate all the cairo_set_target functions.
- */
-void
-cairo_set_target_image (cairo_t *cr,
- unsigned char *data,
- cairo_format_t format,
- int width,
- int height,
- int stride);
-
-void
-cairo_set_target_image_no_data (cairo_t *cr,
- cairo_format_t format,
- int width,
- int height);
typedef enum cairo_operator {
CAIRO_OPERATOR_CLEAR,
@@ -844,7 +795,7 @@ cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix);
/* XXX: Need to decide the memory management semantics of this
function. Should it reference the surface again? */
cairo_surface_t *
-cairo_get_target_surface (cairo_t *cr);
+cairo_get_target (cairo_t *cr);
typedef void (cairo_move_to_func_t) (void *closure,
double x, double y);
@@ -991,8 +942,37 @@ cairo_status_string (cairo_t *cr);
/* Surface manipulation */
+/**
+ * cairo_format_t
+ * @CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with
+ * alpha in the upper 8 bits, then red, then green, then blue.
+ * The 32-bit quantities are stored native-endian. Pre-multiplied
+ * alpha is used. (That is, 50% transparent red is 0x80800000,
+ * not 0x80ff0000.)
+ * @CAIRO_FORMAT_RGB24: each pixel is a 32-bit quantity, with
+ * the upper 8 bits unused. Red, Green, and Blue are stored
+ * in the remaining 24 bits in that order.
+ * @CAIRO_FORMAT_A8: each pixel is a 8-bit quantity holding
+ * an alpha value.
+ * @CAIRO_FORMAT_A1: each pixel is a 1-bit quantity holding
+ * an alpha value. Pixels are packed together into 32-bit
+ * quantities. The ordering of the bits matches the
+ * endianess of the platform. On a big-endian machine, the
+ * first pixel is in the uppermost bit, on a little-endian
+ * machine the first pixel is in the least-significant bit.
+ *
+ * #cairo_format_t is used to identify the memory format of
+ * image data.
+ */
+typedef enum cairo_format {
+ CAIRO_FORMAT_ARGB32,
+ CAIRO_FORMAT_RGB24,
+ CAIRO_FORMAT_A8,
+ CAIRO_FORMAT_A1
+} cairo_format_t;
+
/* XXX: I want to remove this function, (replace with
- cairo_set_target_scratch or similar). */
+ cairo_begin_group and friends). */
cairo_surface_t *
cairo_surface_create_similar (cairo_surface_t *other,
cairo_format_t format,
diff --git a/src/cairoint.h b/src/cairoint.h
index 84f7b255..e1370622 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -926,10 +926,11 @@ _cairo_fixed_integer_ceil (cairo_fixed_t f);
/* cairo_gstate.c */
cairo_private cairo_gstate_t *
-_cairo_gstate_create (void);
+_cairo_gstate_create (cairo_surface_t *target);
cairo_private cairo_status_t
-_cairo_gstate_init (cairo_gstate_t *gstate);
+_cairo_gstate_init (cairo_gstate_t *gstate,
+ cairo_surface_t *target);
cairo_private cairo_status_t
_cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other);
@@ -952,11 +953,8 @@ _cairo_gstate_begin_group (cairo_gstate_t *gstate);
cairo_private cairo_status_t
_cairo_gstate_end_group (cairo_gstate_t *gstate);
-cairo_private cairo_status_t
-_cairo_gstate_set_target_surface (cairo_gstate_t *gstate, cairo_surface_t *surface);
-
cairo_private cairo_surface_t *
-_cairo_gstate_get_target_surface (cairo_gstate_t *gstate);
+_cairo_gstate_get_target (cairo_gstate_t *gstate);
cairo_private cairo_status_t
_cairo_gstate_set_source (cairo_gstate_t *gstate, cairo_pattern_t *source);
@@ -1818,7 +1816,6 @@ slim_hidden_proto(cairo_new_path)
slim_hidden_proto(cairo_rel_line_to)
slim_hidden_proto(cairo_restore)
slim_hidden_proto(cairo_save)
-slim_hidden_proto(cairo_set_target_surface)
slim_hidden_proto(cairo_stroke_preserve)
slim_hidden_proto(cairo_surface_destroy)
slim_hidden_proto(cairo_surface_get_matrix)
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 8e7a8474..b02a6166 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -95,97 +95,94 @@ xunlink (const char *pathname)
}
}
-typedef cairo_test_status_t
-(*cairo_test_set_target_t) (cairo_t *cr, int width, int height, void **closure);
+typedef cairo_surface_t *
+(*cairo_test_create_target_surface_t) (int width, int height, void **closure);
typedef void
(*cairo_test_cleanup_target_t) (void *closure);
typedef struct _cairo_test_target
{
- const char *name;
- cairo_test_set_target_t set_target;
- cairo_test_cleanup_target_t cleanup_target;
- void *closure;
+ const char *name;
+ cairo_test_create_target_surface_t create_target_surface;
+ cairo_test_cleanup_target_t cleanup_target;
+ void *closure;
} cairo_test_target_t;
-static cairo_test_status_t
-set_image_target (cairo_t *cr, int width, int height, void **closure)
+static cairo_surface_t *
+create_image_surface (int width, int height, void **closure)
{
- unsigned char *png_buf;
int stride = 4 * width;
+ unsigned char *buf;
- png_buf = xcalloc (stride * height, 1);
-
- cairo_set_target_image (cr, png_buf, CAIRO_FORMAT_ARGB32,
- width, height, stride);
+ *closure = buf = xcalloc (stride * height, 1);
- *closure = png_buf;
-
- return CAIRO_TEST_SUCCESS;
+ return cairo_image_surface_create_for_data (buf,
+ CAIRO_FORMAT_ARGB32,
+ width, height, stride);
}
static void
-cleanup_image_target (void *closure)
+cleanup_image (void *closure)
{
- unsigned char *png_buf = closure;
+ unsigned char *buf = closure;
- free (png_buf);
+ free (buf);
}
/* XXX: Someone who knows glitz better than I do should fix this up to
* work. */
#if 0 /* #ifdef CAIRO_HAS_GLITZ_SURFACE */
-static cairo_test_status_t
-set_glitz_target (cairo_t *cr, int width, int height, void **closure)
+static cairo_surface_t *
+create_glitz_surface (int width, int height, void **closure)
{
#error Not yet implemented
}
static void
-cleanup_glitz_target (cairo_t *cr)
+cleanup_glitz (cairo_t *cr)
{
#error Not yet implemented
}
#endif
#ifdef CAIRO_HAS_QUARTZ_SURFACE
-static cairo_test_status_t
-set_quartz_target (cairo_t *cr, int width, int height, void **closure)
+static cairo_surface_t *
+create_quartz_surface (int width, int height, void **closure)
{
#error Not yet implemented
}
static void
-cleanup_quartz_target (void *closure)
+cleanup_quartz (void *closure)
{
#error Not yet implemented
}
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
-static cairo_test_status_t
-set_win32_target (cairo_t *cr, int width, int height, void **closure)
+static cairo_surface_t *
+create_win32_surface (int width, int height, void **closure)
{
#error Not yet implemented
}
static void
-cleanup_win32_target (void *closure)
+cleanup_win32 (void *closure)
{
#error Not yet implemented
}
#endif
#ifdef CAIRO_HAS_XCB_SURFACE
-static cairo_test_status_t
-set_xcb_target (cairo_t *cr, int width, int height, void **closure)
+static cairo_surface_t *
+create_xcb_surface (int width, int height, void **closure)
{
#error Not yet implemented
}
static void
-cleanup_xcb_target (void *closure)
+cleanup_xcb (void *closure)
{
#error Not yet implemented
}
@@ -198,8 +195,8 @@ typedef struct _xlib_target_closure
Pixmap pixmap;
} xlib_target_closure_t;
-static cairo_test_status_t
-set_xlib_target (cairo_t *cr, int width, int height, void **closure)
+static cairo_surface_t *
+create_xlib_surface (int width, int height, void **closure)
{
xlib_target_closure_t *xtc;
cairo_surface_t *surface;
@@ -215,22 +212,21 @@ set_xlib_target (cairo_t *cr, int width, int height, void **closure)
xtc->dpy = dpy = XOpenDisplay (0);
if (xtc->dpy == NULL) {
fprintf (stderr, "Failed to open display: %s\n", XDisplayName(0));
- return CAIRO_TEST_FAILURE;
+ return NULL;
}
xtc->pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
width, height, 32);
surface = cairo_xlib_surface_create_for_pixmap (dpy, xtc->pixmap,
- CAIRO_FORMAT_ARGB32);
+ CAIRO_FORMAT_ARGB32);
cairo_xlib_surface_set_size (surface, width, height);
- cairo_set_target_surface (cr, surface);
- return CAIRO_TEST_SUCCESS;
+ return surface;
}
static void
-cleanup_xlib_target (void *closure)
+cleanup_xlib (void *closure)
{
xlib_target_closure_t *xtc = closure;
@@ -245,6 +241,7 @@ cairo_test_for_target (cairo_test_t *test,
cairo_test_target_t *target)
{
cairo_test_status_t status;
+ cairo_surface_t *surface;
cairo_t *cr;
char *png_name, *ref_name, *diff_name;
char *srcdir;
@@ -263,16 +260,15 @@ cairo_test_for_target (cairo_test_t *test,
target->name, CAIRO_TEST_DIFF_SUFFIX);
/* Run the actual drawing code. */
- cr = cairo_create ();
-
- status = (target->set_target) (cr,
- test->width, test->height,
- &target->closure);
- if (status) {
+ surface = (target->create_target_surface) (test->width, test->height,
+ &target->closure);
+ if (surface == NULL) {
fprintf (stderr, "Error: Failed to set %s target\n", target->name);
return CAIRO_TEST_FAILURE;
}
+ cr = cairo_create (surface);
+
cairo_save (cr);
cairo_set_source_rgba (cr, 0, 0, 0, 0);
cairo_set_operator (cr, CAIRO_OPERATOR_SRC);
@@ -298,10 +294,12 @@ cairo_test_for_target (cairo_test_t *test,
return CAIRO_TEST_SUCCESS;
}
- cairo_surface_write_to_png (cairo_get_target_surface (cr), png_name);
+ cairo_surface_write_to_png (surface, png_name);
cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+
target->cleanup_target (target->closure);
pixels_changed = image_diff (png_name, ref_name, diff_name);
@@ -330,21 +328,21 @@ cairo_test_real (cairo_test_t *test, cairo_test_draw_function_t draw)
cairo_test_status_t status, ret;
cairo_test_target_t targets[] =
{
- { "image", set_image_target, cleanup_image_target},
+ { "image", create_image_surface, cleanup_image},
#if 0 /* #ifdef CAIRO_HAS_GLITZ_SURFACE */
- { "glitz", set_glitz_target, cleanup_glitz_target},
+ { "glitz", create_glitz_surface, cleanup_glitz},
#endif
#ifdef CAIRO_HAS_QUARTZ_SURFACE
- { "quartz", set_quartz_target, cleanup_quart_target},
+ { "quartz", create_quartz_surface, cleanup_quartz},
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
- { "win32", set_win32_target, cleanup_win32_target},
+ { "win32", create_win32_surface, cleanup_win32},
#endif
#ifdef CAIRO_HAS_XCB_SURFACE
- { "xcb", set_xcb_target, cleanup_xcb_target},
+ { "xcb", create_xcb_surface, cleanup_xcb},
#endif
#ifdef CAIRO_HAS_XLIB_SURFACE
- { "xlib", set_xlib_target, cleanup_xlib_target},
+ { "xlib", create_xlib_surface, cleanup_xlib},
#endif
};
char *log_name;
diff --git a/test/clip-nesting.c b/test/clip-nesting.c
index 03760b01..80197803 100644
--- a/test/clip-nesting.c
+++ b/test/clip-nesting.c
@@ -43,10 +43,9 @@ draw (cairo_t *cr, int width, int height)
cairo_surface_t *target_surface;
cairo_t *cr2, *cr3;
- target_surface = cairo_get_target_surface (cr);
+ target_surface = cairo_get_target (cr);
- cr2 = cairo_create ();
- cairo_set_target_surface (cr2, target_surface);
+ cr2 = cairo_create (target_surface);
/* Draw a diagonal line and clip to it */
@@ -70,9 +69,7 @@ draw (cairo_t *cr, int width, int height)
/* But doesn't affect another cairo_t that we create temporarily for
* the same surface
*/
- cr3 = cairo_create ();
-
- cairo_set_target_surface (cr3, target_surface);
+ cr3 = cairo_create (target_surface);
cairo_set_source_rgb (cr3, 1, 1, 1); /* White */
cairo_rectangle (cr3,
SIZE - BORDER - LINE_WIDTH, BORDER,
diff --git a/test/mask.c b/test/mask.c
index 45765a67..d306c26e 100644
--- a/test/mask.c
+++ b/test/mask.c
@@ -73,11 +73,10 @@ mask_polygon (cairo_t *cr, int x, int y)
cairo_surface_t *mask_surface;
cairo_t *cr2;
- mask_surface = cairo_surface_create_similar (cairo_get_target_surface (cr),
+ mask_surface = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_FORMAT_A8,
WIDTH, HEIGHT);
- cr2 = cairo_create ();
- cairo_set_target_surface (cr2, mask_surface);
+ cr2 = cairo_create (mask_surface);
cairo_save (cr2);
cairo_set_source_rgba (cr2, 0, 0, 0, 0); /* transparent */
@@ -196,11 +195,10 @@ draw (cairo_t *cr, int width, int height)
/* Some of our drawing is unbounded, so we draw each test to
* a temporary surface and copy over.
*/
- tmp_surface = cairo_surface_create_similar (cairo_get_target_surface (cr),
+ tmp_surface = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_FORMAT_ARGB32,
IMAGE_WIDTH, IMAGE_HEIGHT);
- cr2 = cairo_create ();
- cairo_set_target_surface (cr2, tmp_surface);
+ cr2 = cairo_create (tmp_surface);
tmp_pattern = cairo_pattern_create_for_surface (tmp_surface);
cairo_set_source (cr, tmp_pattern);
diff --git a/test/path-data.c b/test/path-data.c
index db30e8f5..b2d7edbf 100644
--- a/test/path-data.c
+++ b/test/path-data.c
@@ -140,15 +140,18 @@ main (void)
cairo_t *cr;
cairo_path_data_t data;
cairo_path_t path;
+ cairo_surface_t *surface;
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
/* Test a few error cases for cairo_append_path_data */
- cr = cairo_create ();
+ cr = cairo_create (surface);
cairo_append_path (cr, NULL);
if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
return 1;
cairo_destroy (cr);
- cr = cairo_create ();
+ cr = cairo_create (surface);
path.data = NULL;
path.num_data = 0;
cairo_append_path (cr, &path);
@@ -156,7 +159,7 @@ main (void)
return 1;
cairo_destroy (cr);
- cr = cairo_create ();
+ cr = cairo_create (surface);
/* Intentionally insert bogus header.length value (otherwise would be 2) */
data.header.type = CAIRO_PATH_MOVE_TO;
data.header.length = 1;
@@ -168,12 +171,14 @@ main (void)
cairo_destroy (cr);
/* And test the degnerate case */
- cr = cairo_create ();
+ cr = cairo_create (surface);
path.num_data = 0;
cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
return 1;
cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+
return cairo_test (&test, draw);
}
diff --git a/test/pdf-surface.c b/test/pdf-surface.c
index 6da15e23..970c77da 100644
--- a/test/pdf-surface.c
+++ b/test/pdf-surface.c
@@ -37,6 +37,7 @@ main (void)
cairo_t *cr;
const char *filename = "pdf-surface.pdf";
FILE *file;
+ cairo_surface_t *surface;
file = fopen (filename, "w");
if (!file) {
@@ -44,12 +45,11 @@ main (void)
return CAIRO_TEST_FAILURE;
}
- cr = cairo_create ();
-
- cairo_set_target_pdf (cr, file,
- 297 / 25.4,
- 210 / 25.4,
- 300.0, 300.0);
+ surface = cairo_pdf_surface_create (file,
+ 297 / 25.4,
+ 210 / 25.4,
+ 300.0, 300.0);
+ cr = cairo_create (surface);
cairo_rectangle (cr, 10, 10, 100, 100);
cairo_set_source_rgb (cr, 1, 0, 0);
@@ -57,6 +57,7 @@ main (void)
cairo_show_page (cr);
+ cairo_surface_destroy (surface);
cairo_destroy (cr);
fclose (file);
diff --git a/test/pixman-rotate.c b/test/pixman-rotate.c
index e45c5cf2..5c6fe414 100644
--- a/test/pixman-rotate.c
+++ b/test/pixman-rotate.c
@@ -24,25 +24,25 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
- cairo_surface_t *target, *stamp;
+ cairo_surface_t *stamp;
+ cairo_t *cr2;
- target = cairo_get_target_surface (cr);
- cairo_surface_reference (target);
-
- stamp = cairo_surface_create_similar (target, CAIRO_FORMAT_ARGB32,
+ stamp = cairo_surface_create_similar (cairo_get_target (cr),
+ CAIRO_FORMAT_ARGB32,
WIDTH, HEIGHT);
- cairo_set_target_surface (cr, stamp);
- cairo_new_path (cr);
- cairo_rectangle (cr, WIDTH / 4, HEIGHT / 4, WIDTH / 2, HEIGHT / 2);
- cairo_set_source_rgba (cr, 1, 0, 0, 0.8);
- cairo_fill (cr);
-
- cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
- cairo_set_line_width (cr, 2);
- cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_stroke (cr);
-
- cairo_set_target_surface (cr, target);
+ cr2 = cairo_create (stamp);
+ {
+ cairo_new_path (cr2);
+ cairo_rectangle (cr2, WIDTH / 4, HEIGHT / 4, WIDTH / 2, HEIGHT / 2);
+ cairo_set_source_rgba (cr2, 1, 0, 0, 0.8);
+ cairo_fill (cr2);
+
+ cairo_rectangle (cr2, 0, 0, WIDTH, HEIGHT);
+ cairo_set_line_width (cr2, 2);
+ cairo_set_source_rgb (cr2, 0, 0, 0);
+ cairo_stroke (cr2);
+ }
+ cairo_destroy (cr2);
/* Draw a translucent rectangle for reference where the rotated
* image should be. */
@@ -64,7 +64,6 @@ draw (cairo_t *cr, int width, int height)
cairo_show_page (cr);
cairo_surface_destroy (stamp);
- cairo_surface_destroy (target);
return CAIRO_TEST_SUCCESS;
}
diff --git a/test/scale-source-surface-paint.c b/test/scale-source-surface-paint.c
index 4b722b41..7b1cc382 100644
--- a/test/scale-source-surface-paint.c
+++ b/test/scale-source-surface-paint.c
@@ -42,7 +42,6 @@ draw (cairo_t *cr, int width, int height)
0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff,
0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff
};
- int i;
surface = cairo_image_surface_create_for_data ((unsigned char *) data,
CAIRO_FORMAT_ARGB32, 4, 4, 16);
diff --git a/test/self-copy.c b/test/self-copy.c
index abb13271..3ad406ec 100644
--- a/test/self-copy.c
+++ b/test/self-copy.c
@@ -55,7 +55,7 @@ draw (cairo_t *cr, int width, int height)
/* Create a pattern with the target surface as the source,
* offset by SIZE/2
*/
- pattern = cairo_pattern_create_for_surface (cairo_get_target_surface (cr));
+ pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
cairo_matrix_init_translate (&matrix, - SIZE / 2, - SIZE / 2);
cairo_pattern_set_matrix (pattern, &matrix);
diff --git a/test/source-clip.c b/test/source-clip.c
index ec4c68f6..73be6b43 100644
--- a/test/source-clip.c
+++ b/test/source-clip.c
@@ -42,12 +42,11 @@ draw (cairo_t *cr, int width, int height)
cairo_surface_t *source_surface;
cairo_t *cr2;
- source_surface = cairo_surface_create_similar (cairo_get_target_surface (cr),
+ source_surface = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_FORMAT_ARGB32,
SIZE, SIZE);
- cr2 = cairo_create ();
- cairo_set_target_surface (cr2, source_surface);
+ cr2 = cairo_create (source_surface);
/* Fill the source surface with solid black */
cairo_set_source_rgb (cr2, 0, 0, 0);
diff --git a/test/source-surface-scale-paint.c b/test/source-surface-scale-paint.c
index 1bf769d2..9862ba59 100644
--- a/test/source-surface-scale-paint.c
+++ b/test/source-surface-scale-paint.c
@@ -42,7 +42,6 @@ draw (cairo_t *cr, int width, int height)
0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff,
0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff
};
- int i;
surface = cairo_image_surface_create_for_data ((unsigned char *) data,
CAIRO_FORMAT_ARGB32, 4, 4, 16);
diff --git a/test/surface-pattern.c b/test/surface-pattern.c
index 826b3ecd..4f91d433 100644
--- a/test/surface-pattern.c
+++ b/test/surface-pattern.c
@@ -35,25 +35,24 @@ static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
cairo_surface_t *surface;
+ cairo_t *cr2;
cairo_pattern_t *pattern;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
6, 6);
- cairo_save (cr);
+ cr2 = cairo_create (surface);
{
- cairo_set_target_surface (cr, surface);
-
- cairo_rectangle (cr, 0, 0, 3, 3);
- cairo_rectangle (cr, 3, 3, 3, 3);
- cairo_set_source_rgb (cr, 1, 1, 0);
- cairo_fill (cr);
-
- cairo_rectangle (cr, 3, 0, 3, 3);
- cairo_rectangle (cr, 0, 3, 3, 3);
- cairo_set_source_rgb (cr, 0, 0, 1);
- cairo_fill (cr);
+ cairo_rectangle (cr2, 0, 0, 3, 3);
+ cairo_rectangle (cr2, 3, 3, 3, 3);
+ cairo_set_source_rgb (cr2, 1, 1, 0);
+ cairo_fill (cr2);
+
+ cairo_rectangle (cr2, 3, 0, 3, 3);
+ cairo_rectangle (cr2, 0, 3, 3, 3);
+ cairo_set_source_rgb (cr2, 0, 0, 1);
+ cairo_fill (cr2);
}
- cairo_restore (cr);
+ cairo_destroy (cr2);
pattern = cairo_pattern_create_for_surface (surface);
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);