From 8bb3f7664d2a25be0dd57348fe78e268f40def4e Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 28 Oct 2003 12:15:03 +0000 Subject: [PATCH] Drop cairo_surface_create_similar_solid --- ChangeLog | 15 +++++++++++ src/cairo-gstate.c | 64 +++++++++++++++++++++++++-------------------- src/cairo-surface.c | 34 ++++++++++-------------- src/cairo.h | 14 ---------- src/cairo_gstate.c | 64 +++++++++++++++++++++++++-------------------- src/cairo_surface.c | 34 ++++++++++-------------- src/cairoint.h | 8 +++++- 7 files changed, 120 insertions(+), 113 deletions(-) diff --git a/ChangeLog b/ChangeLog index 427f3b35f..e70a0cd9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2003-10-28 Carl Worth + + * src/cairo_gstate.c (_cairo_gstate_ensure_source): + (_cairo_gstate_clip_and_composite_trapezoids): + (_cairo_gstate_clip): + (_cairo_gstate_show_surface): Track changes to + _cairo_surface_create_similar_solid. + + * src/cairo_surface.c (_cairo_surface_create_similar_solid): Now + that this function is internal, it can accept a cairo_color_t + which makes the interface much cleaner. + + * src/cairo.h: Remove problematic function + cairo_surface_create_similar_solid from the public API. + 2003-10-28 Carl Worth * src/cairo_surface.c (_cairo_surface_composite): diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c index 32a2cef46..77748f52c 100644 --- a/src/cairo-gstate.c +++ b/src/cairo-gstate.c @@ -1116,13 +1116,10 @@ _cairo_gstate_ensure_source (cairo_gstate_t *gstate) if (gstate->surface == NULL) return CAIRO_STATUS_NO_TARGET_SURFACE; - gstate->source = cairo_surface_create_similar_solid (gstate->surface, - CAIRO_FORMAT_ARGB32, - 1, 1, - gstate->color.red, - gstate->color.green, - gstate->color.blue, - gstate->color.alpha); + gstate->source = _cairo_surface_create_similar_solid (gstate->surface, + CAIRO_FORMAT_ARGB32, + 1, 1, + &gstate->color); if (gstate->source == NULL) return CAIRO_STATUS_NO_MEMORY; @@ -1191,18 +1188,22 @@ _cairo_gstate_clip_and_composite_trapezoids (cairo_gstate_t *gstate, cairo_trapezoid_t *t; int i; - cairo_surface_t *intermediate, *white; + cairo_surface_t *white, *intermediate; + cairo_color_t white_color, empty_color; - white = cairo_surface_create_similar_solid (gstate->surface, CAIRO_FORMAT_A8, - 1, 1, - 1.0, 1.0, 1.0, 1.0); + _cairo_color_init (&white_color); + white = _cairo_surface_create_similar_solid (gstate->surface, CAIRO_FORMAT_A8, + 1, 1, + &white_color); cairo_surface_set_repeat (white, 1); - intermediate = cairo_surface_create_similar_solid (gstate->clip.surface, - CAIRO_FORMAT_A8, - gstate->clip.width, - gstate->clip.height, - 0.0, 0.0, 0.0, 0.0); + _cairo_color_init (&empty_color); + _cairo_color_set_alpha (&empty_color, 0.); + intermediate = _cairo_surface_create_similar_solid (gstate->clip.surface, + CAIRO_FORMAT_A8, + gstate->clip.width, + gstate->clip.height, + &empty_color); /* Ugh. The cairo_composite/(Render) interface doesn't allow an offset for the trapezoids. Need to manually shift all @@ -1315,6 +1316,9 @@ _cairo_gstate_clip (cairo_gstate_t *gstate) cairo_status_t status; cairo_surface_t *alpha_one; cairo_traps_t traps; + cairo_color_t white_color; + + _cairo_color_init (&white_color); if (gstate->clip.surface == NULL) { double x1, y1, x2, y2; @@ -1324,16 +1328,16 @@ _cairo_gstate_clip (cairo_gstate_t *gstate) gstate->clip.y = floor (y1); gstate->clip.width = ceil (x2 - gstate->clip.x); gstate->clip.height = ceil (y2 - gstate->clip.y); - gstate->clip.surface = cairo_surface_create_similar_solid (gstate->surface, - CAIRO_FORMAT_A8, - gstate->clip.width, - gstate->clip.height, - 1.0, 1.0, 1.0, 1.0); + gstate->clip.surface = _cairo_surface_create_similar_solid (gstate->surface, + CAIRO_FORMAT_A8, + gstate->clip.width, + gstate->clip.height, + &white_color); } - alpha_one = cairo_surface_create_similar_solid (gstate->surface, CAIRO_FORMAT_A8, - 1, 1, - 0.0, 0.0, 0.0, 1.0); + alpha_one = _cairo_surface_create_similar_solid (gstate->surface, CAIRO_FORMAT_A8, + 1, 1, + &white_color); cairo_surface_set_repeat (alpha_one, 1); _cairo_traps_init (&traps); @@ -1367,13 +1371,15 @@ _cairo_gstate_show_surface (cairo_gstate_t *gstate, cairo_matrix_t image_to_device, device_to_image; double device_x, device_y; double device_width, device_height; + cairo_color_t alpha_color; if (gstate->alpha != 1.0) { - mask = cairo_surface_create_similar_solid (gstate->surface, - CAIRO_FORMAT_A8, - 1, 1, - 1.0, 1.0, 1.0, - gstate->alpha); + _cairo_color_init (&alpha_color); + _cairo_color_set_alpha (&alpha_color, gstate->alpha); + mask = _cairo_surface_create_similar_solid (gstate->surface, + CAIRO_FORMAT_A8, + 1, 1, + &alpha_color); if (mask == NULL) return CAIRO_STATUS_NO_MEMORY; diff --git a/src/cairo-surface.c b/src/cairo-surface.c index c62867969..377cf36d6 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -139,26 +139,27 @@ cairo_surface_create_similar (cairo_surface_t *other, int width, int height) { - return cairo_surface_create_similar_solid (other, format, width, height, 0, 0, 0, 0); + cairo_color_t empty; + + _cairo_color_init (&empty); + _cairo_color_set_rgb (&empty, 0., 0., 0.); + _cairo_color_set_alpha (&empty, 0.); + + return _cairo_surface_create_similar_solid (other, format, width, height, &empty); } cairo_surface_t * -cairo_surface_create_similar_solid (cairo_surface_t *other, - cairo_format_t format, - int width, - int height, - double red, - double green, - double blue, - double alpha) +_cairo_surface_create_similar_solid (cairo_surface_t *other, + cairo_format_t format, + int width, + int height, + cairo_color_t *color) { cairo_surface_t *surface = NULL; - cairo_color_t color; if (other->backend->create_similar) surface = other->backend->create_similar (other, format, width, height); - - if (!surface) { + if (surface == NULL) { char *data; int stride; @@ -174,16 +175,9 @@ cairo_surface_create_similar_solid (cairo_surface_t *other, surface->image_data = data; } - /* XXX: Initializing the color in this way assumes - non-pre-multiplied alpha. I'm not sure that that's what I want - to do or not. */ - _cairo_color_init (&color); - _cairo_color_set_rgb (&color, red, green, blue); - _cairo_color_set_alpha (&color, alpha); - _cairo_surface_fill_rectangle (surface, CAIRO_OPERATOR_SRC, &color, 0, 0, width, height); + _cairo_surface_fill_rectangle (surface, CAIRO_OPERATOR_SRC, color, 0, 0, width, height); return surface; } -slim_hidden_def(cairo_surface_create_similar_solid); void cairo_surface_reference (cairo_surface_t *surface) diff --git a/src/cairo.h b/src/cairo.h index b61059b0e..488adcb69 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -538,20 +538,6 @@ cairo_surface_create_similar (cairo_surface_t *other, int width, int height); -/* XXX: One problem with having RGB and A here in one function is that - it introduces the question of pre-multiplied vs. non-pre-multiplied - alpha. Do I want to export a cairo_color_t structure instead? So far, no - other public functions need it. */ -extern cairo_surface_t * __external_linkage -cairo_surface_create_similar_solid (cairo_surface_t *other, - cairo_format_t format, - int width, - int height, - double red, - double green, - double blue, - double alpha); - extern void __external_linkage cairo_surface_reference (cairo_surface_t *surface); diff --git a/src/cairo_gstate.c b/src/cairo_gstate.c index 32a2cef46..77748f52c 100644 --- a/src/cairo_gstate.c +++ b/src/cairo_gstate.c @@ -1116,13 +1116,10 @@ _cairo_gstate_ensure_source (cairo_gstate_t *gstate) if (gstate->surface == NULL) return CAIRO_STATUS_NO_TARGET_SURFACE; - gstate->source = cairo_surface_create_similar_solid (gstate->surface, - CAIRO_FORMAT_ARGB32, - 1, 1, - gstate->color.red, - gstate->color.green, - gstate->color.blue, - gstate->color.alpha); + gstate->source = _cairo_surface_create_similar_solid (gstate->surface, + CAIRO_FORMAT_ARGB32, + 1, 1, + &gstate->color); if (gstate->source == NULL) return CAIRO_STATUS_NO_MEMORY; @@ -1191,18 +1188,22 @@ _cairo_gstate_clip_and_composite_trapezoids (cairo_gstate_t *gstate, cairo_trapezoid_t *t; int i; - cairo_surface_t *intermediate, *white; + cairo_surface_t *white, *intermediate; + cairo_color_t white_color, empty_color; - white = cairo_surface_create_similar_solid (gstate->surface, CAIRO_FORMAT_A8, - 1, 1, - 1.0, 1.0, 1.0, 1.0); + _cairo_color_init (&white_color); + white = _cairo_surface_create_similar_solid (gstate->surface, CAIRO_FORMAT_A8, + 1, 1, + &white_color); cairo_surface_set_repeat (white, 1); - intermediate = cairo_surface_create_similar_solid (gstate->clip.surface, - CAIRO_FORMAT_A8, - gstate->clip.width, - gstate->clip.height, - 0.0, 0.0, 0.0, 0.0); + _cairo_color_init (&empty_color); + _cairo_color_set_alpha (&empty_color, 0.); + intermediate = _cairo_surface_create_similar_solid (gstate->clip.surface, + CAIRO_FORMAT_A8, + gstate->clip.width, + gstate->clip.height, + &empty_color); /* Ugh. The cairo_composite/(Render) interface doesn't allow an offset for the trapezoids. Need to manually shift all @@ -1315,6 +1316,9 @@ _cairo_gstate_clip (cairo_gstate_t *gstate) cairo_status_t status; cairo_surface_t *alpha_one; cairo_traps_t traps; + cairo_color_t white_color; + + _cairo_color_init (&white_color); if (gstate->clip.surface == NULL) { double x1, y1, x2, y2; @@ -1324,16 +1328,16 @@ _cairo_gstate_clip (cairo_gstate_t *gstate) gstate->clip.y = floor (y1); gstate->clip.width = ceil (x2 - gstate->clip.x); gstate->clip.height = ceil (y2 - gstate->clip.y); - gstate->clip.surface = cairo_surface_create_similar_solid (gstate->surface, - CAIRO_FORMAT_A8, - gstate->clip.width, - gstate->clip.height, - 1.0, 1.0, 1.0, 1.0); + gstate->clip.surface = _cairo_surface_create_similar_solid (gstate->surface, + CAIRO_FORMAT_A8, + gstate->clip.width, + gstate->clip.height, + &white_color); } - alpha_one = cairo_surface_create_similar_solid (gstate->surface, CAIRO_FORMAT_A8, - 1, 1, - 0.0, 0.0, 0.0, 1.0); + alpha_one = _cairo_surface_create_similar_solid (gstate->surface, CAIRO_FORMAT_A8, + 1, 1, + &white_color); cairo_surface_set_repeat (alpha_one, 1); _cairo_traps_init (&traps); @@ -1367,13 +1371,15 @@ _cairo_gstate_show_surface (cairo_gstate_t *gstate, cairo_matrix_t image_to_device, device_to_image; double device_x, device_y; double device_width, device_height; + cairo_color_t alpha_color; if (gstate->alpha != 1.0) { - mask = cairo_surface_create_similar_solid (gstate->surface, - CAIRO_FORMAT_A8, - 1, 1, - 1.0, 1.0, 1.0, - gstate->alpha); + _cairo_color_init (&alpha_color); + _cairo_color_set_alpha (&alpha_color, gstate->alpha); + mask = _cairo_surface_create_similar_solid (gstate->surface, + CAIRO_FORMAT_A8, + 1, 1, + &alpha_color); if (mask == NULL) return CAIRO_STATUS_NO_MEMORY; diff --git a/src/cairo_surface.c b/src/cairo_surface.c index c62867969..377cf36d6 100644 --- a/src/cairo_surface.c +++ b/src/cairo_surface.c @@ -139,26 +139,27 @@ cairo_surface_create_similar (cairo_surface_t *other, int width, int height) { - return cairo_surface_create_similar_solid (other, format, width, height, 0, 0, 0, 0); + cairo_color_t empty; + + _cairo_color_init (&empty); + _cairo_color_set_rgb (&empty, 0., 0., 0.); + _cairo_color_set_alpha (&empty, 0.); + + return _cairo_surface_create_similar_solid (other, format, width, height, &empty); } cairo_surface_t * -cairo_surface_create_similar_solid (cairo_surface_t *other, - cairo_format_t format, - int width, - int height, - double red, - double green, - double blue, - double alpha) +_cairo_surface_create_similar_solid (cairo_surface_t *other, + cairo_format_t format, + int width, + int height, + cairo_color_t *color) { cairo_surface_t *surface = NULL; - cairo_color_t color; if (other->backend->create_similar) surface = other->backend->create_similar (other, format, width, height); - - if (!surface) { + if (surface == NULL) { char *data; int stride; @@ -174,16 +175,9 @@ cairo_surface_create_similar_solid (cairo_surface_t *other, surface->image_data = data; } - /* XXX: Initializing the color in this way assumes - non-pre-multiplied alpha. I'm not sure that that's what I want - to do or not. */ - _cairo_color_init (&color); - _cairo_color_set_rgb (&color, red, green, blue); - _cairo_color_set_alpha (&color, alpha); - _cairo_surface_fill_rectangle (surface, CAIRO_OPERATOR_SRC, &color, 0, 0, width, height); + _cairo_surface_fill_rectangle (surface, CAIRO_OPERATOR_SRC, color, 0, 0, width, height); return surface; } -slim_hidden_def(cairo_surface_create_similar_solid); void cairo_surface_reference (cairo_surface_t *surface) diff --git a/src/cairoint.h b/src/cairoint.h index f583604ff..944e16c0c 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -890,6 +890,13 @@ extern cairo_status_t __internal_linkage _cairo_path_stroke_to_traps (cairo_path_t *path, cairo_gstate_t *gstate, cairo_traps_t *traps); /* cairo_surface.c */ +extern cairo_surface_t * __internal_linkage +_cairo_surface_create_similar_solid (cairo_surface_t *other, + cairo_format_t format, + int width, + int height, + cairo_color_t *color); + extern void __internal_linkage _cairo_surface_init (cairo_surface_t *surface, int width, @@ -1090,7 +1097,6 @@ slim_hidden_proto(cairo_restore) slim_hidden_proto(cairo_save) slim_hidden_proto(cairo_set_target_surface) slim_hidden_proto(cairo_surface_create_for_image) -slim_hidden_proto(cairo_surface_create_similar_solid) slim_hidden_proto(cairo_surface_destroy) slim_hidden_proto(cairo_surface_get_matrix) slim_hidden_proto(cairo_surface_set_matrix)