mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-05 05:18:01 +02:00
pattern: Add convenience patterns for stock colours
By preallocating in our data segment a couple of solid patterns for the stock colours, it becomes more convenient when using those in surface operations, such as when clearing.
This commit is contained in:
parent
9eb98e1dc5
commit
29bedde904
11 changed files with 54 additions and 70 deletions
|
|
@ -947,7 +947,6 @@ _cairo_clip_path_get_surface (cairo_clip_path_t *clip_path,
|
|||
cairo_surface_t *target)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_pattern_union_t pattern;
|
||||
cairo_status_t status;
|
||||
const cairo_rectangle_int_t *clip_extents = &clip_path->extents;
|
||||
cairo_clip_path_t *prev;
|
||||
|
|
@ -980,10 +979,6 @@ _cairo_clip_path_get_surface (cairo_clip_path_t *clip_path,
|
|||
if (unlikely (surface->status))
|
||||
return surface;
|
||||
|
||||
_cairo_pattern_init_solid (&pattern.solid,
|
||||
CAIRO_COLOR_WHITE,
|
||||
CAIRO_CONTENT_COLOR);
|
||||
|
||||
status = _cairo_clip_path_to_region (clip_path);
|
||||
if (unlikely (_cairo_status_is_error (status)))
|
||||
goto BAIL;
|
||||
|
|
@ -1014,7 +1009,7 @@ _cairo_clip_path_get_surface (cairo_clip_path_t *clip_path,
|
|||
}
|
||||
status = _cairo_surface_fill (surface,
|
||||
CAIRO_OPERATOR_OVER,
|
||||
&pattern.base,
|
||||
&_cairo_pattern_white.base,
|
||||
&clip_path->path,
|
||||
clip_path->fill_rule,
|
||||
clip_path->tolerance,
|
||||
|
|
@ -1051,7 +1046,7 @@ _cairo_clip_path_get_surface (cairo_clip_path_t *clip_path,
|
|||
}
|
||||
status = _cairo_surface_fill (surface,
|
||||
CAIRO_OPERATOR_IN,
|
||||
&pattern.base,
|
||||
&_cairo_pattern_white.base,
|
||||
&prev->path,
|
||||
prev->fill_rule,
|
||||
prev->tolerance,
|
||||
|
|
@ -1070,9 +1065,10 @@ _cairo_clip_path_get_surface (cairo_clip_path_t *clip_path,
|
|||
goto NEXT_PATH;
|
||||
} else {
|
||||
cairo_surface_t *prev_surface;
|
||||
cairo_surface_pattern_t pattern;
|
||||
|
||||
prev_surface = _cairo_clip_path_get_surface (prev, target);
|
||||
_cairo_pattern_init_for_surface (&pattern.surface, prev_surface);
|
||||
_cairo_pattern_init_for_surface (&pattern, prev_surface);
|
||||
cairo_surface_destroy (prev_surface);
|
||||
|
||||
cairo_matrix_init_translate (&pattern.base.matrix,
|
||||
|
|
@ -1142,7 +1138,6 @@ _cairo_clip_combine_with_surface (cairo_clip_t *clip,
|
|||
cairo_surface_t *dst,
|
||||
const cairo_rectangle_int_t *extents)
|
||||
{
|
||||
cairo_pattern_union_t pattern;
|
||||
cairo_clip_path_t *clip_path = clip->path;
|
||||
cairo_bool_t need_translate;
|
||||
cairo_status_t status;
|
||||
|
|
@ -1152,8 +1147,9 @@ _cairo_clip_combine_with_surface (cairo_clip_t *clip,
|
|||
if (clip_path->surface != NULL &&
|
||||
clip_path->surface->backend == dst->backend)
|
||||
{
|
||||
_cairo_pattern_init_for_surface (&pattern.surface,
|
||||
clip_path->surface);
|
||||
cairo_surface_pattern_t pattern;
|
||||
|
||||
_cairo_pattern_init_for_surface (&pattern, clip_path->surface);
|
||||
cairo_matrix_init_translate (&pattern.base.matrix,
|
||||
extents->x - clip_path->extents.x,
|
||||
extents->y - clip_path->extents.y);
|
||||
|
|
@ -1167,10 +1163,6 @@ _cairo_clip_combine_with_surface (cairo_clip_t *clip,
|
|||
return status;
|
||||
}
|
||||
|
||||
_cairo_pattern_init_solid (&pattern.solid,
|
||||
CAIRO_COLOR_WHITE,
|
||||
CAIRO_CONTENT_COLOR);
|
||||
|
||||
need_translate = extents->x | extents->y;
|
||||
do {
|
||||
status = _cairo_clip_path_to_region (clip_path);
|
||||
|
|
@ -1183,8 +1175,9 @@ _cairo_clip_combine_with_surface (cairo_clip_t *clip,
|
|||
if (clip_path->surface != NULL &&
|
||||
clip_path->surface->backend == dst->backend)
|
||||
{
|
||||
_cairo_pattern_init_for_surface (&pattern.surface,
|
||||
clip_path->surface);
|
||||
cairo_surface_pattern_t pattern;
|
||||
|
||||
_cairo_pattern_init_for_surface (&pattern, clip_path->surface);
|
||||
cairo_matrix_init_translate (&pattern.base.matrix,
|
||||
extents->x - clip_path->extents.x,
|
||||
extents->y - clip_path->extents.y);
|
||||
|
|
@ -1211,7 +1204,7 @@ _cairo_clip_combine_with_surface (cairo_clip_t *clip,
|
|||
}
|
||||
status = _cairo_surface_fill (dst,
|
||||
CAIRO_OPERATOR_IN,
|
||||
&pattern.base,
|
||||
&_cairo_pattern_white.base,
|
||||
&clip_path->path,
|
||||
clip_path->fill_rule,
|
||||
clip_path->tolerance,
|
||||
|
|
|
|||
|
|
@ -624,7 +624,6 @@ _cairo_gl_surface_show_glyphs_via_mask (cairo_gl_surface_t *dst,
|
|||
cairo_gl_context_t *ctx;
|
||||
cairo_surface_t *mask;
|
||||
cairo_status_t status;
|
||||
cairo_solid_pattern_t solid;
|
||||
cairo_bool_t has_component_alpha;
|
||||
int i;
|
||||
|
||||
|
|
@ -665,9 +664,9 @@ _cairo_gl_surface_show_glyphs_via_mask (cairo_gl_surface_t *dst,
|
|||
glyphs[i].y -= glyph_extents->y;
|
||||
}
|
||||
|
||||
_cairo_pattern_init_solid (&solid, CAIRO_COLOR_WHITE, CAIRO_CONTENT_COLOR_ALPHA);
|
||||
status = _render_glyphs ((cairo_gl_surface_t *) mask, 0, 0,
|
||||
CAIRO_OPERATOR_ADD, &solid.base,
|
||||
CAIRO_OPERATOR_ADD,
|
||||
&_cairo_pattern_white.base,
|
||||
glyphs, num_glyphs, glyph_extents,
|
||||
scaled_font, &has_component_alpha,
|
||||
NULL, remaining_glyphs);
|
||||
|
|
@ -712,7 +711,6 @@ _cairo_gl_surface_show_glyphs (void *abstract_dst,
|
|||
cairo_rectangle_int_t surface_extents;
|
||||
cairo_rectangle_int_t extents;
|
||||
cairo_region_t *clip_region = NULL;
|
||||
cairo_solid_pattern_t solid_pattern;
|
||||
cairo_bool_t overlap, use_mask = FALSE;
|
||||
cairo_bool_t has_component_alpha;
|
||||
cairo_status_t status;
|
||||
|
|
@ -769,9 +767,7 @@ _cairo_gl_surface_show_glyphs (void *abstract_dst,
|
|||
* mask IN clip ? 0 : dest
|
||||
*/
|
||||
if (op == CAIRO_OPERATOR_CLEAR) {
|
||||
_cairo_pattern_init_solid (&solid_pattern, CAIRO_COLOR_WHITE,
|
||||
CAIRO_CONTENT_COLOR);
|
||||
source = &solid_pattern.base;
|
||||
source = &_cairo_pattern_white.base;
|
||||
op = CAIRO_OPERATOR_DEST_OUT;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1149,7 +1149,6 @@ BAIL:
|
|||
cairo_status_t
|
||||
_cairo_gstate_fill (cairo_gstate_t *gstate, cairo_path_fixed_t *path)
|
||||
{
|
||||
cairo_pattern_union_t pattern;
|
||||
cairo_clip_t clip;
|
||||
cairo_status_t status;
|
||||
|
||||
|
|
@ -1163,16 +1162,14 @@ _cairo_gstate_fill (cairo_gstate_t *gstate, cairo_path_fixed_t *path)
|
|||
if (_cairo_operator_bounded_by_mask (gstate->op))
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
_cairo_pattern_init_solid (&pattern.solid,
|
||||
CAIRO_COLOR_TRANSPARENT,
|
||||
CAIRO_CONTENT_COLOR_ALPHA);
|
||||
status = _cairo_surface_paint (gstate->target,
|
||||
CAIRO_OPERATOR_CLEAR,
|
||||
&pattern.base,
|
||||
&_cairo_pattern_clear.base,
|
||||
_gstate_get_clip (gstate, &clip));
|
||||
} else {
|
||||
_cairo_gstate_copy_transformed_source (gstate, &pattern.base);
|
||||
cairo_pattern_union_t pattern;
|
||||
|
||||
_cairo_gstate_copy_transformed_source (gstate, &pattern.base);
|
||||
status = _cairo_surface_fill (gstate->target,
|
||||
gstate->op,
|
||||
&pattern.base,
|
||||
|
|
|
|||
|
|
@ -68,6 +68,30 @@ const cairo_solid_pattern_t _cairo_pattern_black = {
|
|||
CAIRO_CONTENT_COLOR, /* content */
|
||||
};
|
||||
|
||||
const cairo_solid_pattern_t _cairo_pattern_clear = {
|
||||
{ CAIRO_PATTERN_TYPE_SOLID, /* type */
|
||||
CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */
|
||||
CAIRO_STATUS_SUCCESS, /* status */
|
||||
{ 0, 0, 0, NULL }, /* user_data */
|
||||
{ 1., 0., 0., 1., 0., 0., }, /* matrix */
|
||||
CAIRO_FILTER_DEFAULT, /* filter */
|
||||
CAIRO_EXTEND_GRADIENT_DEFAULT}, /* extend */
|
||||
{ 0., 0., 0., 0., 0, 0, 0, 0 },/* color (double rgba, short rgba) */
|
||||
CAIRO_CONTENT_ALPHA, /* content */
|
||||
};
|
||||
|
||||
const cairo_solid_pattern_t _cairo_pattern_white = {
|
||||
{ CAIRO_PATTERN_TYPE_SOLID, /* type */
|
||||
CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */
|
||||
CAIRO_STATUS_SUCCESS, /* status */
|
||||
{ 0, 0, 0, NULL }, /* user_data */
|
||||
{ 1., 0., 0., 1., 0., 0., }, /* matrix */
|
||||
CAIRO_FILTER_DEFAULT, /* filter */
|
||||
CAIRO_EXTEND_GRADIENT_DEFAULT}, /* extend */
|
||||
{ 1., 1., 1., 1., 0xffff, 0xffff, 0xffff, 0xffff },/* color (double rgba, short rgba) */
|
||||
CAIRO_CONTENT_COLOR_ALPHA, /* content */
|
||||
};
|
||||
|
||||
/**
|
||||
* _cairo_pattern_set_error:
|
||||
* @pattern: a pattern
|
||||
|
|
|
|||
|
|
@ -2070,7 +2070,6 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font,
|
|||
cairo_surface_t *mask = NULL;
|
||||
cairo_format_t mask_format = CAIRO_FORMAT_A1; /* shut gcc up */
|
||||
cairo_surface_pattern_t mask_pattern;
|
||||
cairo_solid_pattern_t white_pattern;
|
||||
int i;
|
||||
|
||||
/* These operators aren't interpreted the same way by the backends;
|
||||
|
|
@ -2105,8 +2104,6 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font,
|
|||
|
||||
/* Font display routine either does not exist or failed. */
|
||||
|
||||
_cairo_pattern_init_solid (&white_pattern, CAIRO_COLOR_WHITE, CAIRO_CONTENT_COLOR);
|
||||
|
||||
_cairo_scaled_font_freeze_cache (scaled_font);
|
||||
|
||||
for (i = 0; i < num_glyphs; i++) {
|
||||
|
|
@ -2167,7 +2164,7 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font,
|
|||
* never any component alpha here.
|
||||
*/
|
||||
status = _cairo_surface_composite (CAIRO_OPERATOR_SOURCE,
|
||||
&white_pattern.base,
|
||||
&_cairo_pattern_white.base,
|
||||
&mask_pattern.base,
|
||||
new_mask,
|
||||
0, 0,
|
||||
|
|
@ -2203,7 +2200,7 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font,
|
|||
glyph_pattern.base.has_component_alpha = TRUE;
|
||||
|
||||
status = _cairo_surface_composite (CAIRO_OPERATOR_ADD,
|
||||
&white_pattern.base,
|
||||
&_cairo_pattern_white.base,
|
||||
&glyph_pattern.base,
|
||||
mask,
|
||||
0, 0,
|
||||
|
|
@ -2237,8 +2234,6 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font,
|
|||
CLEANUP_MASK:
|
||||
_cairo_scaled_font_thaw_cache (scaled_font);
|
||||
|
||||
_cairo_pattern_fini (&white_pattern.base);
|
||||
|
||||
if (mask != NULL)
|
||||
cairo_surface_destroy (mask);
|
||||
return _cairo_scaled_font_set_error (scaled_font, status);
|
||||
|
|
|
|||
|
|
@ -127,7 +127,6 @@ _create_composite_mask_pattern (cairo_surface_pattern_t *mask_pattern,
|
|||
{
|
||||
cairo_surface_t *mask;
|
||||
cairo_region_t *clip_region = NULL;
|
||||
cairo_solid_pattern_t solid;
|
||||
cairo_status_t status;
|
||||
cairo_bool_t clip_surface = FALSE;
|
||||
|
||||
|
|
@ -156,9 +155,8 @@ _create_composite_mask_pattern (cairo_surface_pattern_t *mask_pattern,
|
|||
if (unlikely (mask->status))
|
||||
return mask->status;
|
||||
|
||||
_cairo_pattern_init_solid (&solid, CAIRO_COLOR_WHITE, CAIRO_CONTENT_ALPHA);
|
||||
status = draw_func (draw_closure, CAIRO_OPERATOR_ADD,
|
||||
&solid.base, mask,
|
||||
&_cairo_pattern_white.base, mask,
|
||||
extents->x, extents->y,
|
||||
extents,
|
||||
clip_region);
|
||||
|
|
@ -416,7 +414,6 @@ _clip_and_composite (cairo_clip_t *clip,
|
|||
cairo_surface_t *dst,
|
||||
const cairo_rectangle_int_t *extents)
|
||||
{
|
||||
cairo_solid_pattern_t solid_pattern;
|
||||
cairo_status_t status;
|
||||
|
||||
if (_cairo_rectangle_empty (extents))
|
||||
|
|
@ -424,9 +421,7 @@ _clip_and_composite (cairo_clip_t *clip,
|
|||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
if (op == CAIRO_OPERATOR_CLEAR) {
|
||||
_cairo_pattern_init_solid (&solid_pattern, CAIRO_COLOR_WHITE,
|
||||
CAIRO_CONTENT_COLOR);
|
||||
src = &solid_pattern.base;
|
||||
src = &_cairo_pattern_white.base;
|
||||
op = CAIRO_OPERATOR_DEST_OUT;
|
||||
}
|
||||
|
||||
|
|
@ -487,7 +482,6 @@ _composite_trap_region (cairo_clip_t *clip,
|
|||
const cairo_rectangle_int_t *extents)
|
||||
{
|
||||
cairo_status_t status;
|
||||
cairo_solid_pattern_t solid_pattern;
|
||||
cairo_surface_pattern_t mask_pattern;
|
||||
cairo_pattern_t *mask = NULL;
|
||||
int mask_x = 0, mask_y =0;
|
||||
|
|
@ -501,9 +495,7 @@ _composite_trap_region (cairo_clip_t *clip,
|
|||
return clip_surface->status;
|
||||
|
||||
if (op == CAIRO_OPERATOR_CLEAR) {
|
||||
_cairo_pattern_init_solid (&solid_pattern, CAIRO_COLOR_WHITE,
|
||||
CAIRO_CONTENT_COLOR);
|
||||
src = &solid_pattern.base;
|
||||
src = &_cairo_pattern_white.base;
|
||||
op = CAIRO_OPERATOR_DEST_OUT;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -410,7 +410,6 @@ _vg_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper,
|
|||
cairo_vg_surface_t,
|
||||
clipper);
|
||||
cairo_vg_surface_t *mask;
|
||||
cairo_solid_pattern_t white;
|
||||
cairo_status_t status;
|
||||
|
||||
if (path == NULL) {
|
||||
|
|
@ -429,9 +428,9 @@ _vg_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper,
|
|||
if (unlikely (mask->base.status))
|
||||
return mask->base.status;
|
||||
|
||||
_cairo_pattern_init_solid (&white, CAIRO_COLOR_WHITE, CAIRO_CONTENT_ALPHA);
|
||||
status = _cairo_surface_fill (&mask->base,
|
||||
CAIRO_OPERATOR_SOURCE, &white.base,
|
||||
CAIRO_OPERATOR_SOURCE,
|
||||
_cairo_pattern_white.base,
|
||||
path, fill_rule, tolerance, antialias,
|
||||
NULL);
|
||||
if (status) {
|
||||
|
|
|
|||
|
|
@ -439,13 +439,9 @@ _cairo_win32_printing_surface_paint_recording_pattern (cairo_win32_surface_t *
|
|||
|
||||
old_content = surface->content;
|
||||
if (recording_surface->base.content == CAIRO_CONTENT_COLOR) {
|
||||
cairo_pattern_t *source;
|
||||
cairo_solid_pattern_t black;
|
||||
|
||||
surface->content = CAIRO_CONTENT_COLOR;
|
||||
_cairo_pattern_init_solid (&black, CAIRO_COLOR_BLACK, CAIRO_CONTENT_COLOR);
|
||||
source = (cairo_pattern_t*) &black;
|
||||
status = _cairo_win32_printing_surface_paint_solid_pattern (surface, source);
|
||||
status = _cairo_win32_printing_surface_paint_solid_pattern (surface,
|
||||
&_cairo_pattern_black.base);
|
||||
if (status)
|
||||
return status;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2706,7 +2706,6 @@ _cairo_xcb_surface_show_glyphs (void *abstract_dst,
|
|||
cairo_surface_attributes_t attributes;
|
||||
cairo_xcb_surface_t *src = NULL;
|
||||
|
||||
cairo_solid_pattern_t solid_pattern;
|
||||
cairo_region_t *clip_region = NULL;
|
||||
|
||||
if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE_TEXT (dst) || dst->xrender_format.id == XCB_NONE)
|
||||
|
|
@ -2759,9 +2758,7 @@ _cairo_xcb_surface_show_glyphs (void *abstract_dst,
|
|||
* so PictOpClear was never used with CompositeText before.
|
||||
*/
|
||||
if (op == CAIRO_OPERATOR_CLEAR) {
|
||||
_cairo_pattern_init_solid (&solid_pattern, CAIRO_COLOR_WHITE,
|
||||
CAIRO_CONTENT_COLOR);
|
||||
src_pattern = &solid_pattern.base;
|
||||
src_pattern = &_cairo_pattern_white.base;
|
||||
op = CAIRO_OPERATOR_DEST_OUT;
|
||||
}
|
||||
|
||||
|
|
@ -2826,8 +2823,6 @@ _cairo_xcb_surface_show_glyphs (void *abstract_dst,
|
|||
BAIL:
|
||||
if (src)
|
||||
_cairo_pattern_release_surface (src_pattern, &src->base, &attributes);
|
||||
if (src_pattern == &solid_pattern.base)
|
||||
_cairo_pattern_fini (&solid_pattern.base);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4397,8 +4397,6 @@ _cairo_xlib_surface_show_glyphs (void *abstract_dst,
|
|||
cairo_xlib_surface_t *src = NULL;
|
||||
cairo_region_t *clip_region = NULL;
|
||||
|
||||
cairo_solid_pattern_t solid_pattern;
|
||||
|
||||
if (! CAIRO_SURFACE_RENDER_HAS_COMPOSITE_TEXT (dst))
|
||||
return UNSUPPORTED ("XRender does not support CompositeText");
|
||||
|
||||
|
|
@ -4478,9 +4476,7 @@ _cairo_xlib_surface_show_glyphs (void *abstract_dst,
|
|||
* so PictOpClear was never used with CompositeText before.
|
||||
*/
|
||||
if (op == CAIRO_OPERATOR_CLEAR) {
|
||||
_cairo_pattern_init_solid (&solid_pattern, CAIRO_COLOR_WHITE,
|
||||
CAIRO_CONTENT_COLOR);
|
||||
src_pattern = &solid_pattern.base;
|
||||
src_pattern = &_cairo_pattern_white.base;
|
||||
op = CAIRO_OPERATOR_DEST_OUT;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -871,8 +871,9 @@ extern const cairo_private cairo_surface_backend_t _cairo_image_surface_backend;
|
|||
#define CAIRO_EXTEND_GRADIENT_DEFAULT CAIRO_EXTEND_PAD
|
||||
#define CAIRO_FILTER_DEFAULT CAIRO_FILTER_GOOD
|
||||
|
||||
extern const cairo_private cairo_solid_pattern_t _cairo_pattern_clear;
|
||||
extern const cairo_private cairo_solid_pattern_t _cairo_pattern_black;
|
||||
|
||||
extern const cairo_private cairo_solid_pattern_t _cairo_pattern_white;
|
||||
|
||||
typedef struct _cairo_surface_attributes {
|
||||
cairo_matrix_t matrix;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue