[ecore] merged svn latest code (svn54830)
[profile/ivi/ecore.git] / src / lib / ecore_x / xcb / ecore_xcb_region.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #include <pixman.h>
6
7 #include "ecore_xcb_private.h"
8
9 /*
10  * [x] XCreateRegion
11  * [ ] XPolygonRegion
12  * [x] XSetRegion
13  * [x] XDestroyRegion
14  *
15  * [x] XOffsetRegion
16  * [ ] XShrinkRegion
17  *
18  * [ ] XClipBox
19  * [x] XIntersectRegion
20  * [x] XUnionRegion
21  * [x] XUnionRectWithRegion
22  * [x] XSubtractRegion
23  * [ ] XXorRegion
24  *
25  * [x] XEmptyRegion
26  * [x] XEqualRegion
27  *
28  * [x] XPointInRegion
29  * [x] XRectInRegion
30  */
31
32 EAPI Ecore_X_XRegion *
33 ecore_x_xregion_new()
34 {
35    pixman_region16_t *region;
36
37    region = (pixman_region16_t *)malloc (sizeof (pixman_region16_t));
38    if (!region)
39       return NULL;
40
41    pixman_region_init(region);
42
43    return (Ecore_X_XRegion *)region;
44 } /* ecore_x_xregion_new */
45
46 EAPI void
47 ecore_x_xregion_free(Ecore_X_XRegion *region)
48 {
49    if (!region)
50       return;
51
52    pixman_region_fini(region);
53    free(region);
54 } /* ecore_x_xregion_free */
55
56 EAPI Eina_Bool
57 ecore_x_xregion_set(Ecore_X_XRegion *region, Ecore_X_GC gc)
58 {
59    xcb_rectangle_t *rects;
60    pixman_box16_t *boxes;
61    int num;
62    int i;
63
64    if (!region)
65       return 0;
66
67    boxes = pixman_region_rectangles ((pixman_region16_t *)region, &num);
68
69    if (!boxes || (num == 0))
70       return 0;
71
72    rects = (xcb_rectangle_t *)malloc(sizeof(xcb_rectangle_t) * num);
73    if (!rects)
74       return 0;
75
76    for (i = 0; i < num; i++)
77      {
78         rects[i].x = boxes[i].x1;
79         rects[i].y = boxes[i].y1;
80         rects[i].width = boxes[i].x2 - boxes[i].x1 + 1;
81         rects[i].height = boxes[i].y2 - boxes[i].y1 + 1;
82      }
83
84    xcb_set_clip_rectangles(_ecore_xcb_conn,
85                            XCB_CLIP_ORDERING_YX_BANDED,
86                            gc,
87                            0, 0,
88                            num,
89                            rects);
90    return 1;
91 } /* ecore_x_xregion_set */
92
93 EAPI void
94 ecore_x_xregion_translate(Ecore_X_XRegion *region, int x, int y)
95 {
96    if (!region)
97       return;
98
99    pixman_region_translate((pixman_region16_t *)region, x, y);
100 } /* ecore_x_xregion_translate */
101
102 EAPI Eina_Bool
103 ecore_x_xregion_intersect(Ecore_X_XRegion *dst, Ecore_X_XRegion *r1, Ecore_X_XRegion *r2)
104 {
105    return pixman_region_intersect((pixman_region16_t *)dst, (pixman_region16_t *)r1, (pixman_region16_t *)r2);
106 } /* ecore_x_xregion_intersect */
107
108 EAPI Eina_Bool
109 ecore_x_xregion_union(Ecore_X_XRegion *dst, Ecore_X_XRegion *r1, Ecore_X_XRegion *r2)
110 {
111    return pixman_region_union((pixman_region16_t *)dst, (pixman_region16_t *)r1, (pixman_region16_t *)r2);
112 } /* ecore_x_xregion_union */
113
114 EAPI Eina_Bool
115 ecore_x_xregion_union_rect(Ecore_X_XRegion *dst, Ecore_X_XRegion *src, Ecore_X_Rectangle *rect)
116 {
117    return pixman_region_union_rect((pixman_region16_t *)dst, (pixman_region16_t *)src,
118                                    rect->x, rect->y, rect->width, rect->height);
119 } /* ecore_x_xregion_union_rect */
120
121 EAPI Eina_Bool
122 ecore_x_xregion_subtract(Ecore_X_XRegion *dst, Ecore_X_XRegion *rm, Ecore_X_XRegion *rs)
123 {
124    return pixman_region_subtract((pixman_region16_t *)dst, (pixman_region16_t *)rm, (pixman_region16_t *)rs);
125 } /* ecore_x_xregion_subtract */
126
127 EAPI Eina_Bool
128 ecore_x_xregion_is_empty(Ecore_X_XRegion *region)
129 {
130    if (!region)
131       return 1;
132
133    return !pixman_region_not_empty((pixman_region16_t *)region);
134 } /* ecore_x_xregion_is_empty */
135
136 EAPI Eina_Bool
137 ecore_x_xregion_is_equal(Ecore_X_XRegion *r1, Ecore_X_XRegion *r2)
138 {
139    if (!r1 || !r2)
140       return 0;
141
142    return pixman_region_equal((pixman_region16_t *)r1, (pixman_region16_t *)r2);
143 } /* ecore_x_xregion_is_equal */
144
145 EAPI Eina_Bool
146 ecore_x_xregion_point_contain(Ecore_X_XRegion *region, int x, int y)
147 {
148    if (!region)
149       return 0;
150
151    return pixman_region_contains_point((pixman_region16_t *)region, x, y, NULL);
152 } /* ecore_x_xregion_point_contain */
153
154 EAPI Eina_Bool
155 ecore_x_xregion_rect_contain(Ecore_X_XRegion *region, Ecore_X_Rectangle *rect)
156 {
157    pixman_box16_t box;
158
159    if (!region || !rect)
160       return 0;
161
162    box.x1 = rect->x;
163    box.y1 = rect->y;
164    box.x2 = rect->x + rect->width - 1;
165    box.y2 = rect->y + rect->height - 1;
166
167    return pixman_region_contains_rectangle((pixman_region16_t *)region, &box);
168 } /* ecore_x_xregion_rect_contain */
169