Optionally provide a pattern to use for creating a similar solid surface.

_cairo_surface_create_similar_solid() creates a fresh pattern to wrap
color, however sometimes the caller already has that pattern available.
In those circumstances we can pass the pattern as well as the color and
avoid the extra allocation.
This commit is contained in:
Chris Wilson 2007-04-19 11:56:15 +01:00
parent ef60e7c651
commit 41c6eebcd1
5 changed files with 26 additions and 13 deletions

View file

@ -404,7 +404,8 @@ _cairo_clip_intersect_mask (cairo_clip_t *clip,
CAIRO_CONTENT_ALPHA,
surface_rect.width,
surface_rect.height,
CAIRO_COLOR_WHITE);
CAIRO_COLOR_WHITE,
NULL);
if (surface->status)
return CAIRO_STATUS_NO_MEMORY;

View file

@ -1002,7 +1002,8 @@ _cairo_glitz_surface_fill_rectangles (void *abstract_dst,
_cairo_surface_create_similar_solid (&dst->base,
CAIRO_CONTENT_COLOR_ALPHA,
1, 1,
(cairo_color_t *) color);
(cairo_color_t *) color,
NULL);
if (src->base.status)
return CAIRO_STATUS_NO_MEMORY;

View file

@ -1250,7 +1250,8 @@ _cairo_pattern_acquire_surface_for_solid (cairo_solid_pattern_t *pattern,
CAIRO_CONTENT_COLOR :
CAIRO_CONTENT_COLOR_ALPHA,
1, 1,
&pattern->color);
&pattern->color,
&pattern->base);
if ((*out)->status)
return CAIRO_STATUS_NO_MEMORY;

View file

@ -288,7 +288,8 @@ cairo_surface_create_similar (cairo_surface_t *other,
return _cairo_surface_create_similar_solid (other, content,
width, height,
CAIRO_COLOR_TRANSPARENT);
CAIRO_COLOR_TRANSPARENT,
NULL);
}
slim_hidden_def (cairo_surface_create_similar);
@ -297,7 +298,8 @@ _cairo_surface_create_similar_solid (cairo_surface_t *other,
cairo_content_t content,
int width,
int height,
const cairo_color_t *color)
const cairo_color_t *color,
cairo_pattern_t *pattern)
{
cairo_status_t status;
cairo_surface_t *surface;
@ -310,19 +312,23 @@ _cairo_surface_create_similar_solid (cairo_surface_t *other,
return (cairo_surface_t*) &_cairo_surface_nil;
}
source = _cairo_pattern_create_solid (color);
if (source->status) {
cairo_surface_destroy (surface);
_cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_surface_t*) &_cairo_surface_nil;
}
if (pattern == NULL) {
source = _cairo_pattern_create_solid (color);
if (source->status) {
cairo_surface_destroy (surface);
_cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_surface_t*) &_cairo_surface_nil;
}
} else
source = pattern;
status = _cairo_surface_paint (surface,
color == CAIRO_COLOR_TRANSPARENT ?
CAIRO_OPERATOR_CLEAR :
CAIRO_OPERATOR_SOURCE, source);
cairo_pattern_destroy (source);
if (source != pattern)
cairo_pattern_destroy (source);
if (status) {
cairo_surface_destroy (surface);

View file

@ -1851,12 +1851,16 @@ _cairo_surface_create_similar_scratch (cairo_surface_t *other,
int width,
int height);
/* Note: the color_pattern argument is optional - if provided it will reuse
* that pattern instead of creating a very short-lived fresh solid pattern
*/
cairo_private cairo_surface_t *
_cairo_surface_create_similar_solid (cairo_surface_t *other,
cairo_content_t content,
int width,
int height,
const cairo_color_t *color);
const cairo_color_t *color,
cairo_pattern_t *color_pattern);
cairo_private void
_cairo_surface_init (cairo_surface_t *surface,