summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEnrico Weigelt, metux IT consult <enrico.weigelt@gr13.net>2016-06-30 17:45:45 +0200
committerUli Schlachter <psychon@znc.in>2016-07-02 13:35:38 +0200
commitf212db2fccfa3825d6a4dc55d5077e5fb756d50b (patch)
treec7a8ce7d7b4ee0dc055ec628ee88e30006139f48 /src
parent5bb43c92b3b35e9df8bdb8b14997e98c4a05d917 (diff)
core: fixed code duplication
We have two places where copying from box set to clip is implemented in the same way. Just move that to one function. Signed-off-by: Enrico Weigelt, metux IT consult <enrico.weigelt@gr13.net> Signed-off-by: Uli Schlachter <psychon@znc.in>
Diffstat (limited to 'src')
-rw-r--r--src/cairo-clip-boxes.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/src/cairo-clip-boxes.c b/src/cairo-clip-boxes.c
index 6e4b50d49..1d33cc892 100644
--- a/src/cairo-clip-boxes.c
+++ b/src/cairo-clip-boxes.c
@@ -264,6 +264,35 @@ _cairo_clip_intersect_box (cairo_clip_t *clip,
return _cairo_clip_intersect_rectangle_box (clip, &r, box);
}
+/**
+ * copy a box set to an clip
+ *
+ * @param box the box set to copy from
+ * @param clip the clip to copy to (return buffer)
+ * @result zero if the allocation failed - the clip will be set to all-clipped
+ * otherwise non-zero
+ */
+static cairo_bool_t
+_cairo_boxes_copy_to_clip (const cairo_boxes_t *boxes, cairo_clip_t *clip)
+{
+ /* XXX cow-boxes? */
+ if (boxes->num_boxes == 1) {
+ clip->boxes = &clip->embedded_box;
+ clip->boxes[0] = boxes->chunks.base[0];
+ clip->num_boxes = 1;
+ return TRUE;
+ }
+
+ clip->boxes = _cairo_boxes_to_array (boxes, &clip->num_boxes);
+ if (unlikely (clip->boxes == NULL))
+ {
+ _cairo_clip_set_all_clipped (clip);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
cairo_clip_t *
_cairo_clip_intersect_boxes (cairo_clip_t *clip,
const cairo_boxes_t *boxes)
@@ -301,13 +330,10 @@ _cairo_clip_intersect_boxes (cairo_clip_t *clip,
if (boxes->num_boxes == 0) {
clip = _cairo_clip_set_all_clipped (clip);
goto out;
- } else if (boxes->num_boxes == 1) {
- clip->boxes = &clip->embedded_box;
- clip->boxes[0] = boxes->chunks.base[0];
- clip->num_boxes = 1;
- } else {
- clip->boxes = _cairo_boxes_to_array (boxes, &clip->num_boxes);
}
+
+ _cairo_boxes_copy_to_clip (boxes, clip);
+
_cairo_boxes_extents (boxes, &limits);
_cairo_box_round_to_rectangle (&limits, &extents);
@@ -574,16 +600,8 @@ _cairo_clip_from_boxes (const cairo_boxes_t *boxes)
if (clip == NULL)
return _cairo_clip_set_all_clipped (clip);
- /* XXX cow-boxes? */
- if(boxes->num_boxes == 1) {
- clip->boxes = &clip->embedded_box;
- clip->boxes[0] = boxes->chunks.base[0];
- clip->num_boxes = 1;
- } else {
- clip->boxes = _cairo_boxes_to_array (boxes, &clip->num_boxes);
- if (clip->boxes == NULL)
- return _cairo_clip_set_all_clipped (clip);
- }
+ if (unlikely (! _cairo_boxes_copy_to_clip (boxes, clip)))
+ return clip;
_cairo_boxes_extents (boxes, &extents);
_cairo_box_round_to_rectangle (&extents, &clip->extents);