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).
This commit is contained in:
Carl Worth 2005-05-06 13:23:41 +00:00
parent cea1de7579
commit d6fc5ee5e9
25 changed files with 244 additions and 644 deletions

View file

@ -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

View file

@ -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);

View file

@ -41,6 +41,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,
@ -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;
}

View file

@ -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,

View file

@ -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 *

View file

@ -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

View file

@ -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,

View file

@ -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);
}
/**

View file

@ -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);

View file

@ -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,

View file

@ -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,

View file

@ -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;
@ -290,366 +308,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
@ -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,

View file

@ -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,

View file

@ -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)

View file

@ -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);
*closure = buf = xcalloc (stride * height, 1);
cairo_set_target_image (cr, png_buf, CAIRO_FORMAT_ARGB32,
width, height, stride);
*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;

View file

@ -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,

View file

@ -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);

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
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 (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);
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;
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);