Drop cairo_surface_create_similar_solid

This commit is contained in:
Carl Worth 2003-10-28 12:15:03 +00:00
parent 01378dab3e
commit 8bb3f7664d
7 changed files with 120 additions and 113 deletions

View file

@ -1,3 +1,18 @@
2003-10-28 Carl Worth <cworth@isi.edu>
* 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 <cworth@isi.edu>
* src/cairo_surface.c (_cairo_surface_composite):

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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