Skip to content

Commit

Permalink
gstate: Skip ops with a clear mask.
Browse files Browse the repository at this point in the history
As pointed out by Benjamin Otte, these are expensive no-ops that we can
trivially detect, just so long as we remember the semantics of extend
modes.
  • Loading branch information
Chris Wilson committed Jan 22, 2010
1 parent c2ef452 commit 4d52be3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cairo-gstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,12 @@ _cairo_gstate_mask (cairo_gstate_t *gstate,
if (_cairo_pattern_is_opaque (mask, NULL))
return _cairo_gstate_paint (gstate);

if (_cairo_pattern_is_clear (mask) &&
_cairo_operator_bounded_by_mask (gstate->op))
{
return CAIRO_STATUS_SUCCESS;
}

_cairo_gstate_copy_transformed_source (gstate, &source_pattern.base);
_cairo_gstate_copy_transformed_mask (gstate, &mask_pattern.base, mask);

Expand Down
23 changes: 23 additions & 0 deletions src/cairo-pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,29 @@ _cairo_pattern_is_opaque (const cairo_pattern_t *abstract_pattern,
return FALSE;
}

cairo_bool_t
_cairo_pattern_is_clear (const cairo_pattern_t *abstract_pattern)
{
const cairo_pattern_union_t *pattern;

if (abstract_pattern->has_component_alpha)
return FALSE;

pattern = (cairo_pattern_union_t *) abstract_pattern;
switch (pattern->type) {
case CAIRO_PATTERN_TYPE_SOLID:
return pattern->solid.color.alpha_short == 0x0000;
case CAIRO_PATTERN_TYPE_SURFACE:
return pattern->surface.surface->is_clear &&
pattern->surface.surface->content & CAIRO_CONTENT_ALPHA;
default:
ASSERT_NOT_REACHED;
case CAIRO_PATTERN_TYPE_LINEAR:
case CAIRO_PATTERN_TYPE_RADIAL:
return FALSE;
}
}

/**
* _cairo_pattern_analyze_filter:
* @pattern: surface pattern
Expand Down
3 changes: 3 additions & 0 deletions src/cairoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,9 @@ cairo_private cairo_bool_t
_cairo_pattern_is_opaque (const cairo_pattern_t *pattern,
const cairo_rectangle_int_t *extents);

cairo_private cairo_bool_t
_cairo_pattern_is_clear (const cairo_pattern_t *pattern);

enum {
CAIRO_PATTERN_ACQUIRE_NONE = 0x0,
CAIRO_PATTERN_ACQUIRE_NO_REFLECT = 0x1,
Expand Down

0 comments on commit 4d52be3

Please sign in to comment.