1 /* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
2 /* cairo - a vector graphics library with display and print output
4 * Copyright © 2005 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it either under the terms of the GNU Lesser General Public
8 * License version 2.1 as published by the Free Software Foundation
9 * (the "LGPL") or, at your option, under the terms of the Mozilla
10 * Public License Version 1.1 (the "MPL"). If you do not alter this
11 * notice, a recipient may use your version of this file under either
12 * the MPL or the LGPL.
14 * You should have received a copy of the LGPL along with this library
15 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * You should have received a copy of the MPL along with this library
18 * in the file COPYING-MPL-1.1
20 * The contents of this file are subject to the Mozilla Public License
21 * Version 1.1 (the "License"); you may not use this file except in
22 * compliance with the License. You may obtain a copy of the License at
23 * http://www.mozilla.org/MPL/
25 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27 * the specific language governing rights and limitations.
29 * The Original Code is the cairo graphics library.
31 * The Initial Developer of the Original Code is Red Hat, Inc.
34 * Owen Taylor <otaylor@redhat.com>
35 * Vladimir Vukicevic <vladimir@pobox.com>
41 _cairo_region_init (cairo_region_t
*region
)
43 pixman_region32_init (®ion
->rgn
);
47 _cairo_region_init_rect (cairo_region_t
*region
,
48 cairo_rectangle_int_t
*rect
)
50 pixman_region32_init_rect (®ion
->rgn
,
52 rect
->width
, rect
->height
);
56 _cairo_region_init_boxes (cairo_region_t
*region
,
57 cairo_box_int_t
*boxes
,
60 pixman_box32_t stack_pboxes
[CAIRO_STACK_ARRAY_LENGTH (pixman_box32_t
)];
61 pixman_box32_t
*pboxes
= stack_pboxes
;
62 cairo_int_status_t status
= CAIRO_STATUS_SUCCESS
;
65 if (count
> ARRAY_LENGTH(stack_pboxes
)) {
66 pboxes
= _cairo_malloc_ab (count
, sizeof(pixman_box32_t
));
68 return _cairo_error (CAIRO_STATUS_NO_MEMORY
);
71 for (i
= 0; i
< count
; i
++) {
72 pboxes
[i
].x1
= boxes
[i
].p1
.x
;
73 pboxes
[i
].y1
= boxes
[i
].p1
.y
;
74 pboxes
[i
].x2
= boxes
[i
].p2
.x
;
75 pboxes
[i
].y2
= boxes
[i
].p2
.y
;
78 if (!pixman_region32_init_rects (®ion
->rgn
, pboxes
, count
))
79 status
= _cairo_error (CAIRO_STATUS_NO_MEMORY
);
81 if (pboxes
!= stack_pboxes
)
88 _cairo_region_fini (cairo_region_t
*region
)
90 pixman_region32_fini (®ion
->rgn
);
94 _cairo_region_copy (cairo_region_t
*dst
, cairo_region_t
*src
)
96 if (!pixman_region32_copy (&dst
->rgn
, &src
->rgn
))
97 return _cairo_error (CAIRO_STATUS_NO_MEMORY
);
99 return CAIRO_STATUS_SUCCESS
;
103 _cairo_region_num_boxes (cairo_region_t
*region
)
105 return pixman_region32_n_rects (®ion
->rgn
);
109 _cairo_region_get_boxes (cairo_region_t
*region
, int *num_boxes
, cairo_box_int_t
**boxes
)
112 pixman_box32_t
*pboxes
;
113 cairo_box_int_t
*cboxes
;
116 pboxes
= pixman_region32_rectangles (®ion
->rgn
, &nboxes
);
121 return CAIRO_STATUS_SUCCESS
;
124 cboxes
= _cairo_malloc_ab (nboxes
, sizeof(cairo_box_int_t
));
126 return _cairo_error (CAIRO_STATUS_NO_MEMORY
);
128 for (i
= 0; i
< nboxes
; i
++) {
129 cboxes
[i
].p1
.x
= pboxes
[i
].x1
;
130 cboxes
[i
].p1
.y
= pboxes
[i
].y1
;
131 cboxes
[i
].p2
.x
= pboxes
[i
].x2
;
132 cboxes
[i
].p2
.y
= pboxes
[i
].y2
;
138 return CAIRO_STATUS_SUCCESS
;
142 _cairo_region_boxes_fini (cairo_region_t
*region
, cairo_box_int_t
*boxes
)
148 * _cairo_region_get_extents:
149 * @region: a #cairo_region_t
150 * @rect: rectangle into which to store the extents
152 * Gets the bounding box of a region as a #cairo_rectangle_int_t
155 _cairo_region_get_extents (cairo_region_t
*region
, cairo_rectangle_int_t
*extents
)
157 pixman_box32_t
*pextents
= pixman_region32_extents (®ion
->rgn
);
159 extents
->x
= pextents
->x1
;
160 extents
->y
= pextents
->y1
;
161 extents
->width
= pextents
->x2
- pextents
->x1
;
162 extents
->height
= pextents
->y2
- pextents
->y1
;
166 _cairo_region_subtract (cairo_region_t
*dst
, cairo_region_t
*a
, cairo_region_t
*b
)
168 if (!pixman_region32_subtract (&dst
->rgn
, &a
->rgn
, &b
->rgn
))
169 return _cairo_error (CAIRO_STATUS_NO_MEMORY
);
171 return CAIRO_STATUS_SUCCESS
;
175 _cairo_region_intersect (cairo_region_t
*dst
, cairo_region_t
*a
, cairo_region_t
*b
)
177 if (!pixman_region32_intersect (&dst
->rgn
, &a
->rgn
, &b
->rgn
))
178 return _cairo_error (CAIRO_STATUS_NO_MEMORY
);
180 return CAIRO_STATUS_SUCCESS
;
184 _cairo_region_union_rect (cairo_region_t
*dst
,
186 cairo_rectangle_int_t
*rect
)
188 if (!pixman_region32_union_rect (&dst
->rgn
, &src
->rgn
,
190 rect
->width
, rect
->height
))
191 return _cairo_error (CAIRO_STATUS_NO_MEMORY
);
193 return CAIRO_STATUS_SUCCESS
;
197 _cairo_region_not_empty (cairo_region_t
*region
)
199 return (cairo_bool_t
) pixman_region32_not_empty (®ion
->rgn
);
203 _cairo_region_translate (cairo_region_t
*region
,
206 pixman_region32_translate (®ion
->rgn
, x
, y
);
209 pixman_region_overlap_t
210 _cairo_region_contains_rectangle (cairo_region_t
*region
,
211 const cairo_rectangle_int_t
*rect
)
217 pbox
.x2
= rect
->x
+ rect
->width
;
218 pbox
.y2
= rect
->y
+ rect
->height
;
220 return pixman_region32_contains_rectangle (®ion
->rgn
, &pbox
);