mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-03 04:17:59 +02:00
clip: Remove the redundant _cairo_clip_init_rectangle()
As _cairo_clip_init_rectangle() is equivalent and more importantly more
clearly written as:
_cairo_clip_init(&clip);
if (status = _cairo_clip_rectangle(&clip, &rect)) {
_cairo_clip_fini(&fini);
return status;
}
perform the transformation and in the process catch a few mistakes along
error paths.
This commit is contained in:
parent
61ad28fe7d
commit
1ddcd5cf31
5 changed files with 30 additions and 47 deletions
|
|
@ -76,10 +76,6 @@ struct _cairo_clip {
|
|||
cairo_private void
|
||||
_cairo_clip_init (cairo_clip_t *clip);
|
||||
|
||||
cairo_private cairo_status_t
|
||||
_cairo_clip_init_rectangle (cairo_clip_t *clip,
|
||||
const cairo_rectangle_int_t *rect);
|
||||
|
||||
cairo_private_no_warn cairo_clip_t *
|
||||
_cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other);
|
||||
|
||||
|
|
|
|||
|
|
@ -164,35 +164,25 @@ _cairo_clip_intersect_rectangle (cairo_clip_t *clip,
|
|||
status = _cairo_path_fixed_close_path (&clip_path->path);
|
||||
assert (status == CAIRO_STATUS_SUCCESS);
|
||||
|
||||
clip_path->extents = *rect;
|
||||
clip_path->fill_rule = CAIRO_FILL_RULE_WINDING;
|
||||
clip_path->tolerance = 1;
|
||||
clip_path->antialias = CAIRO_ANTIALIAS_DEFAULT;
|
||||
clip_path->flags |= CAIRO_CLIP_PATH_IS_BOX;
|
||||
|
||||
clip_path->extents = *rect;
|
||||
if (clip_path->prev != NULL) {
|
||||
if (! _cairo_rectangle_intersect (&clip_path->extents,
|
||||
&clip_path->prev->extents))
|
||||
{
|
||||
_cairo_clip_set_all_clipped (clip);
|
||||
}
|
||||
}
|
||||
|
||||
/* could preallocate the region if it proves worthwhile */
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* XXX consider accepting a matrix, no users yet. */
|
||||
cairo_status_t
|
||||
_cairo_clip_init_rectangle (cairo_clip_t *clip,
|
||||
const cairo_rectangle_int_t *rect)
|
||||
{
|
||||
_cairo_clip_init (clip);
|
||||
|
||||
if (rect == NULL)
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
if (rect->width == 0 || rect->height == 0) {
|
||||
_cairo_clip_set_all_clipped (clip);
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return _cairo_clip_intersect_rectangle (clip, rect);
|
||||
}
|
||||
|
||||
cairo_clip_t *
|
||||
_cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other)
|
||||
{
|
||||
|
|
@ -361,6 +351,7 @@ _cairo_clip_path_reapply_clip_path_transform (cairo_clip_t *clip,
|
|||
status = _cairo_path_fixed_init_copy (&clip_path->path,
|
||||
&other_path->path);
|
||||
if (unlikely (status)) {
|
||||
clip->path = clip->path->prev;
|
||||
_cairo_clip_path_destroy (clip_path);
|
||||
return status;
|
||||
}
|
||||
|
|
@ -403,6 +394,7 @@ _cairo_clip_path_reapply_clip_path_translate (cairo_clip_t *clip,
|
|||
status = _cairo_path_fixed_init_copy (&clip_path->path,
|
||||
&other_path->path);
|
||||
if (unlikely (status)) {
|
||||
clip->path = clip->path->prev;
|
||||
_cairo_clip_path_destroy (clip_path);
|
||||
return status;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -277,17 +277,17 @@ _paint_fallback_image (cairo_paginated_surface_t *surface,
|
|||
* filtering (if possible) to avoid introducing potential artifacts. */
|
||||
pattern.base.filter = CAIRO_FILTER_NEAREST;
|
||||
|
||||
status = _cairo_clip_init_rectangle (&clip, rect);
|
||||
if (unlikely (status))
|
||||
goto CLEANUP_IMAGE;
|
||||
|
||||
status = _cairo_surface_paint (surface->target,
|
||||
CAIRO_OPERATOR_SOURCE,
|
||||
&pattern.base, &clip);
|
||||
|
||||
_cairo_clip_reset (&clip);
|
||||
_cairo_clip_init (&clip);
|
||||
status = _cairo_clip_rectangle (&clip, rect);
|
||||
if (likely (status == CAIRO_STATUS_SUCCESS)) {
|
||||
status = _cairo_surface_paint (surface->target,
|
||||
CAIRO_OPERATOR_SOURCE,
|
||||
&pattern.base, &clip);
|
||||
}
|
||||
|
||||
_cairo_clip_fini (&clip);
|
||||
_cairo_pattern_fini (&pattern.base);
|
||||
|
||||
CLEANUP_IMAGE:
|
||||
cairo_surface_destroy (image);
|
||||
|
||||
|
|
|
|||
|
|
@ -130,6 +130,9 @@ cairo_recording_surface_create (cairo_content_t content,
|
|||
|
||||
recording_surface->content = content;
|
||||
|
||||
recording_surface->unbounded = TRUE;
|
||||
_cairo_clip_init (&recording_surface->clip);
|
||||
|
||||
/* unbounded -> 'infinite' extents */
|
||||
if (extents != NULL) {
|
||||
recording_surface->extents_pixels = *extents;
|
||||
|
|
@ -140,16 +143,14 @@ cairo_recording_surface_create (cairo_content_t content,
|
|||
recording_surface->extents.width = ceil (extents->x + extents->width) - recording_surface->extents.x;
|
||||
recording_surface->extents.height = ceil (extents->y + extents->height) - recording_surface->extents.y;
|
||||
|
||||
status = _cairo_clip_init_rectangle (&recording_surface->clip, &recording_surface->extents);
|
||||
status = _cairo_clip_rectangle (&recording_surface->clip,
|
||||
&recording_surface->extents);
|
||||
if (unlikely (status)) {
|
||||
free (recording_surface);
|
||||
return _cairo_surface_create_in_error (status);
|
||||
}
|
||||
|
||||
recording_surface->unbounded = FALSE;
|
||||
} else {
|
||||
recording_surface->unbounded = TRUE;
|
||||
_cairo_clip_init (&recording_surface->clip);
|
||||
}
|
||||
|
||||
_cairo_array_init (&recording_surface->commands, sizeof (cairo_command_t *));
|
||||
|
|
@ -191,8 +192,6 @@ _cairo_recording_surface_finish (void *abstract_surface)
|
|||
for (i = 0; i < num_elements; i++) {
|
||||
cairo_command_t *command = elements[i];
|
||||
|
||||
_cairo_clip_reset (&command->header.clip);
|
||||
|
||||
switch (command->header.type) {
|
||||
case CAIRO_COMMAND_PAINT:
|
||||
_cairo_pattern_fini_snapshot (&command->paint.source.base);
|
||||
|
|
|
|||
|
|
@ -113,11 +113,9 @@ _cairo_surface_wrapper_paint (cairo_surface_wrapper_t *wrapper,
|
|||
&wrapper->target->device_transform);
|
||||
if (unlikely (status))
|
||||
goto FINISH;
|
||||
} else {
|
||||
_cairo_clip_init_copy (&clip_copy, clip);
|
||||
}
|
||||
|
||||
dev_clip = &clip_copy;
|
||||
dev_clip = &clip_copy;
|
||||
}
|
||||
|
||||
_copy_transformed_pattern (&source_copy.base, source, &wrapper->target->device_transform_inverse);
|
||||
source = &source_copy.base;
|
||||
|
|
@ -156,12 +154,9 @@ _cairo_surface_wrapper_mask (cairo_surface_wrapper_t *wrapper,
|
|||
if (unlikely (status))
|
||||
goto FINISH;
|
||||
|
||||
} else {
|
||||
_cairo_clip_init_copy (&clip_copy, clip);
|
||||
dev_clip = &clip_copy;
|
||||
}
|
||||
|
||||
dev_clip = &clip_copy;
|
||||
|
||||
_copy_transformed_pattern (&source_copy.base, source, &wrapper->target->device_transform_inverse);
|
||||
source = &source_copy.base;
|
||||
|
||||
|
|
@ -422,11 +417,12 @@ _cairo_surface_wrapper_show_text_glyphs (cairo_surface_wrapper_t *wrapper,
|
|||
int i;
|
||||
|
||||
if (clip != NULL) {
|
||||
dev_clip = &clip_copy;
|
||||
status = _cairo_clip_init_copy_transformed (&clip_copy, clip,
|
||||
&wrapper->target->device_transform);
|
||||
if (unlikely (status))
|
||||
goto FINISH;
|
||||
|
||||
dev_clip = &clip_copy;
|
||||
}
|
||||
|
||||
dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue