diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2008-05-09 15:29:10 +0200 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2008-05-09 15:54:19 +0200 |
commit | 11a0884168afe341d53e5c86a49aa48a0142e6ef (patch) | |
tree | d870cc680029bb91bb15b29e01e633b968c43ce0 | |
parent | 08334be905edf5f557250e5946bd61391823da27 (diff) |
Add CAIRO_INTERNAL_SURFACE_TYPE_NULL and cairo_nul_surface_create()
It creates a surface that does nothing. This can be used with
cairo-analysis-surface, to compute bounds of cairo drawings without doing any
actual drawings.
-rw-r--r-- | src/cairo-analysis-surface-private.h | 4 | ||||
-rw-r--r-- | src/cairo-analysis-surface.c | 55 | ||||
-rw-r--r-- | src/cairo-types-private.h | 3 |
3 files changed, 61 insertions, 1 deletions
diff --git a/src/cairo-analysis-surface-private.h b/src/cairo-analysis-surface-private.h index dff8a873..b756a4b5 100644 --- a/src/cairo-analysis-surface-private.h +++ b/src/cairo-analysis-surface-private.h @@ -66,4 +66,8 @@ cairo_private void _cairo_analysis_surface_get_bounding_box (cairo_surface_t *surface, cairo_box_t *bbox); + +cairo_private cairo_surface_t * +_cairo_null_surface_create (cairo_content_t content); + #endif /* CAIRO_ANALYSIS_SURFACE_H */ diff --git a/src/cairo-analysis-surface.c b/src/cairo-analysis-surface.c index 2dc149d4..ad1ca3c9 100644 --- a/src/cairo-analysis-surface.c +++ b/src/cairo-analysis-surface.c @@ -748,3 +748,58 @@ _cairo_analysis_surface_get_bounding_box (cairo_surface_t *abstract_surface, *bbox = surface->page_bbox; } + +/* null surface type: a surface that does nothing (has no side effects, yay!) */ + +static cairo_int_status_t +_return_success (void) +{ + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t cairo_null_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_NULL, + + NULL, /* create_similar */ + NULL, /* finish */ + NULL, /* acquire_source_image */ + NULL, /* release_source_image */ + NULL, /* acquire_dest_image */ + NULL, /* release_dest_image */ + NULL, /* clone_similar */ + NULL, /* composite */ + NULL, /* fill_rectangles */ + NULL, /* composite_trapezoids */ + NULL, /* copy_page */ + NULL, /* show_page */ + _return_success, /* set_clip_region */ + NULL, /* intersect_clip_path */ + NULL, /* get_extents */ + NULL, /* old_show_glyphs */ + NULL, /* get_font_options */ + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + NULL, /* scaled_font_fini */ + NULL, /* scaled_glyph_fini */ + _return_success, /* paint */ + _return_success, /* mask */ + _return_success, /* stroke */ + _return_success, /* fill */ + _return_success, /* show_glyphs */ + NULL /* snapshot */ +}; + +cairo_surface_t * +_cairo_null_surface_create (cairo_content_t content) +{ + cairo_surface_t *surface; + + surface = malloc (sizeof (cairo_surface_t)); + if (surface == NULL) { + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + _cairo_surface_init (surface, &cairo_null_surface_backend, content); + + return surface; +} diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h index 64f09b9f..45c158bf 100644 --- a/src/cairo-types-private.h +++ b/src/cairo-types-private.h @@ -148,7 +148,8 @@ typedef enum _cairo_internal_surface_type { CAIRO_INTERNAL_SURFACE_TYPE_ANALYSIS, CAIRO_INTERNAL_SURFACE_TYPE_TEST_META, CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK, - CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED + CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED, + CAIRO_INTERNAL_SURFACE_TYPE_NULL } cairo_internal_surface_type_t; typedef struct _cairo_region cairo_region_t; |