Allocate the correct pattern type on the stack.

Instead of allocating the union of all possible pattern types, just
allocate the specific pattern as used by the function in order to trim
the stack space consumption and flag potential misuse.
This commit is contained in:
Chris Wilson 2008-05-28 15:42:09 +01:00
parent 74c1e9b545
commit ad9a334e2c
10 changed files with 32 additions and 31 deletions

View file

@ -274,13 +274,13 @@ _cairo_clip_combine_to_surface (cairo_clip_t *clip,
int dst_y,
const cairo_rectangle_int_t *extents)
{
cairo_pattern_union_t pattern;
cairo_surface_pattern_t pattern;
cairo_status_t status;
if (clip->all_clipped)
return CAIRO_STATUS_SUCCESS;
_cairo_pattern_init_for_surface (&pattern.surface, clip->surface);
_cairo_pattern_init_for_surface (&pattern, clip->surface);
status = _cairo_surface_composite (op,
&pattern.base,

View file

@ -958,7 +958,7 @@ _cairo_glitz_pattern_acquire_surfaces (cairo_pattern_t *src,
cairo_glitz_surface_attributes_t *mattr)
{
cairo_int_status_t status;
cairo_pattern_union_t tmp;
cairo_solid_pattern_t tmp;
/* If src and mask are both solid, then the mask alpha can be
* combined into src and mask can be ignored. */
@ -977,7 +977,7 @@ _cairo_glitz_pattern_acquire_surfaces (cairo_pattern_t *src,
combined = src_solid->color;
_cairo_color_multiply_alpha (&combined, mask_solid->color.alpha);
_cairo_pattern_init_solid (&tmp.solid, &combined,
_cairo_pattern_init_solid (&tmp, &combined,
CAIRO_COLOR_IS_OPAQUE (&combined) ?
CAIRO_CONTENT_COLOR :
CAIRO_CONTENT_COLOR_ALPHA);

View file

@ -1688,7 +1688,7 @@ _cairo_ps_surface_flatten_image_transparency (cairo_ps_surface_t *surface,
{
const cairo_color_t *background_color;
cairo_surface_t *opaque;
cairo_pattern_union_t pattern;
cairo_surface_pattern_t pattern;
cairo_status_t status;
if (surface->content == CAIRO_CONTENT_COLOR_ALPHA)
@ -1702,7 +1702,7 @@ _cairo_ps_surface_flatten_image_transparency (cairo_ps_surface_t *surface,
if (opaque->status)
return opaque->status;
_cairo_pattern_init_for_surface (&pattern.surface, &image->base);
_cairo_pattern_init_for_surface (&pattern, &image->base);
status = _cairo_surface_fill_rectangle (opaque,
CAIRO_OPERATOR_SOURCE,

View file

@ -2155,7 +2155,7 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
cairo_surface_t *gradient_surf = NULL;
cairo_t *gradient_surf_cr = NULL;
cairo_pattern_union_t surface_pattern;
cairo_surface_pattern_t surface_pattern;
cairo_int_status_t status;
/* Render the gradient to a surface */
@ -2172,9 +2172,9 @@ _cairo_quartz_surface_mask_with_generic (cairo_quartz_surface_t *surface,
if (status)
goto BAIL;
_cairo_pattern_init_for_surface (&surface_pattern.surface, gradient_surf);
_cairo_pattern_init_for_surface (&surface_pattern, gradient_surf);
status = _cairo_quartz_surface_mask_with_surface (surface, op, source, &surface_pattern.surface);
status = _cairo_quartz_surface_mask_with_surface (surface, op, source, &surface_pattern);
_cairo_pattern_fini (&surface_pattern.base);

View file

@ -358,7 +358,7 @@ _clip_and_composite (cairo_clip_t *clip,
cairo_surface_t *dst,
const cairo_rectangle_int_t *extents)
{
cairo_pattern_union_t solid_pattern;
cairo_solid_pattern_t solid_pattern;
cairo_status_t status;
if (_cairo_rectangle_empty (extents))
@ -366,7 +366,7 @@ _clip_and_composite (cairo_clip_t *clip,
return CAIRO_STATUS_SUCCESS;
if (op == CAIRO_OPERATOR_CLEAR) {
_cairo_pattern_init_solid (&solid_pattern.solid, CAIRO_COLOR_WHITE,
_cairo_pattern_init_solid (&solid_pattern, CAIRO_COLOR_WHITE,
CAIRO_CONTENT_COLOR);
src = &solid_pattern.base;
op = CAIRO_OPERATOR_DEST_OUT;
@ -415,14 +415,14 @@ _composite_trap_region (cairo_clip_t *clip,
cairo_rectangle_int_t *extents)
{
cairo_status_t status;
cairo_pattern_union_t solid_pattern;
cairo_pattern_union_t mask;
cairo_solid_pattern_t solid_pattern;
cairo_surface_pattern_t mask;
int num_rects = _cairo_region_num_boxes (trap_region);
unsigned int clip_serial;
cairo_surface_t *clip_surface = clip ? clip->surface : NULL;
if (clip_surface && op == CAIRO_OPERATOR_CLEAR) {
_cairo_pattern_init_solid (&solid_pattern.solid, CAIRO_COLOR_WHITE,
_cairo_pattern_init_solid (&solid_pattern, CAIRO_COLOR_WHITE,
CAIRO_CONTENT_COLOR);
src = &solid_pattern.base;
op = CAIRO_OPERATOR_DEST_OUT;
@ -444,7 +444,7 @@ _composite_trap_region (cairo_clip_t *clip,
}
if (clip_surface)
_cairo_pattern_init_for_surface (&mask.surface, clip_surface);
_cairo_pattern_init_for_surface (&mask, clip_surface);
status = _cairo_surface_composite (op,
src,
@ -487,13 +487,13 @@ _composite_traps_draw_func (void *closure,
const cairo_rectangle_int_t *extents)
{
cairo_composite_traps_info_t *info = closure;
cairo_pattern_union_t pattern;
cairo_solid_pattern_t pattern;
cairo_status_t status;
if (dst_x != 0 || dst_y != 0)
_cairo_traps_translate (info->traps, - dst_x, - dst_y);
_cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE,
_cairo_pattern_init_solid (&pattern, CAIRO_COLOR_WHITE,
CAIRO_CONTENT_COLOR);
if (!src)
src = &pattern.base;
@ -929,7 +929,7 @@ _cairo_surface_old_show_glyphs_draw_func (void *closure
const cairo_rectangle_int_t *extents)
{
cairo_show_glyphs_info_t *glyph_info = closure;
cairo_pattern_union_t pattern;
cairo_solid_pattern_t pattern;
cairo_status_t status;
/* Modifying the glyph array is fine because we know that this function
@ -946,7 +946,7 @@ _cairo_surface_old_show_glyphs_draw_func (void *closure
}
}
_cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE,
_cairo_pattern_init_solid (&pattern, CAIRO_COLOR_WHITE,
CAIRO_CONTENT_COLOR);
if (!src)
src = &pattern.base;
@ -1032,7 +1032,7 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface)
{
cairo_surface_t *snapshot;
cairo_status_t status;
cairo_pattern_union_t pattern;
cairo_surface_pattern_t pattern;
cairo_image_surface_t *image;
void *image_extra;
@ -1050,7 +1050,7 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface)
return snapshot;
}
_cairo_pattern_init_for_surface (&pattern.surface, &image->base);
_cairo_pattern_init_for_surface (&pattern, &image->base);
status = _cairo_surface_composite (CAIRO_OPERATOR_SOURCE,
&pattern.base,

View file

@ -494,7 +494,6 @@ _cairo_win32_printing_surface_paint_image_pattern (cairo_win32_surface_t *surf
cairo_image_surface_t *image;
void *image_extra;
cairo_surface_t *opaque_surface;
cairo_pattern_union_t opaque_pattern;
cairo_image_surface_t *opaque_image = NULL;
BITMAPINFO bi;
cairo_matrix_t m;
@ -538,6 +537,8 @@ _cairo_win32_printing_surface_paint_image_pattern (cairo_win32_surface_t *surf
}
if (image->format != CAIRO_FORMAT_RGB24) {
cairo_surface_pattern_t opaque_pattern;
opaque_surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
image->width,
image->height);
@ -546,7 +547,7 @@ _cairo_win32_printing_surface_paint_image_pattern (cairo_win32_surface_t *surf
goto FINISH3;
}
_cairo_pattern_init_for_surface (&opaque_pattern.surface, &image->base);
_cairo_pattern_init_for_surface (&opaque_pattern, &image->base);
status = _cairo_surface_fill_rectangle (opaque_surface,
CAIRO_OPERATOR_SOURCE,

View file

@ -446,7 +446,7 @@ _cairo_win32_surface_clone_similar (void *abstract_surface,
cairo_content_t src_content;
cairo_surface_t *new_surface;
cairo_status_t status;
cairo_pattern_union_t pattern;
cairo_surface_pattern_t pattern;
src_content = cairo_surface_get_content(src);
new_surface =
@ -455,7 +455,7 @@ _cairo_win32_surface_clone_similar (void *abstract_surface,
if (cairo_surface_status(new_surface))
return cairo_surface_status(new_surface);
_cairo_pattern_init_for_surface (&pattern.surface, src);
_cairo_pattern_init_for_surface (&pattern, src);
status = _cairo_surface_composite (CAIRO_OPERATOR_SOURCE,
&pattern.base,

View file

@ -2332,7 +2332,7 @@ _cairo_xcb_surface_show_glyphs (void *abstract_dst,
cairo_xcb_surface_show_glyphs_func_t show_glyphs_func;
cairo_pattern_union_t solid_pattern;
cairo_solid_pattern_t solid_pattern;
if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE_TEXT (dst) || dst->xrender_format.id == XCB_NONE)
return CAIRO_INT_STATUS_UNSUPPORTED;
@ -2395,7 +2395,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.solid, CAIRO_COLOR_WHITE,
_cairo_pattern_init_solid (&solid_pattern, CAIRO_COLOR_WHITE,
CAIRO_CONTENT_COLOR);
src_pattern = &solid_pattern.base;
op = CAIRO_OPERATOR_DEST_OUT;

View file

@ -3586,7 +3586,7 @@ _cairo_xlib_surface_show_glyphs (void *abstract_dst,
cairo_xlib_surface_font_private_t *font_private;
cairo_pattern_union_t solid_pattern;
cairo_solid_pattern_t solid_pattern;
if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE_TEXT (dst) || !dst->xrender_format)
return CAIRO_INT_STATUS_UNSUPPORTED;
@ -3642,7 +3642,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.solid, CAIRO_COLOR_WHITE,
_cairo_pattern_init_solid (&solid_pattern, CAIRO_COLOR_WHITE,
CAIRO_CONTENT_COLOR);
src_pattern = &solid_pattern.base;
op = CAIRO_OPERATOR_DEST_OUT;

View file

@ -1985,7 +1985,7 @@ cairo_paint_with_alpha (cairo_t *cr,
{
cairo_status_t status;
cairo_color_t color;
cairo_pattern_union_t pattern;
cairo_solid_pattern_t pattern;
if (cr->status)
return;
@ -2000,7 +2000,7 @@ cairo_paint_with_alpha (cairo_t *cr,
}
_cairo_color_init_rgba (&color, 1., 1., 1., alpha);
_cairo_pattern_init_solid (&pattern.solid, &color, CAIRO_CONTENT_ALPHA);
_cairo_pattern_init_solid (&pattern, &color, CAIRO_CONTENT_ALPHA);
status = _cairo_gstate_mask (cr->gstate, &pattern.base);
if (status)