1 /*
2 Copyright 2013-2017 Jay Sorg
3 
4 Permission to use, copy, modify, distribute, and sell this software and its
5 documentation for any purpose is hereby granted without fee, provided that
6 the above copyright notice appear in all copies and that both that
7 copyright notice and this permission notice appear in supporting
8 documentation.
9 
10 The above copyright notice and this permission notice shall be included in
11 all copies or substantial portions of the Software.
12 
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
16 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
17 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 
20 to deal with regions changing in xorg versions
21 
22 */
23 
24 #if defined(HAVE_CONFIG_H)
25 #include "config_ac.h"
26 #endif
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 
32 /* this should be before all X11 .h files */
33 #include <xorg-server.h>
34 #include <xorgVersion.h>
35 
36 /* all driver need this */
37 #include <xf86.h>
38 #include <xf86_OSproc.h>
39 
40 #include "rdpReg.h"
41 
42 /*
43 miRegionCopy      ->      RegionCopy
44 miTranslateRegion ->      RegionTranslate
45 miRegionNotEmpty  ->      RegionNotEmpty
46 miIntersect       ->      RegionIntersect
47 miRectIn          ->      RegionContainsRect
48 miRegionInit      ->      RegionInit
49 miRegionUninit    ->      RegionUninit
50 miRectsToRegion   ->      RegionFromRects
51 miRegionDestroy   ->      RegionDestroy
52 miRegionCreate    ->      RegionCreate
53 miUnion           ->      RegionUnion
54 miRegionExtents   ->      RegionExtents
55 miRegionReset     ->      RegionReset
56 miRegionBreak     ->      RegionBreak
57 */
58 
59 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1, 9, 0, 0, 0)
60 /* 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8 */
61 #define XRDP_REG 1
62 #else
63 /* 1.9, 1.10, 1.11, 1.12 */
64 #define XRDP_REG 2
65 #endif
66 
67 /*****************************************************************************/
68 Bool
rdpRegionCopy(RegionPtr dst,RegionPtr src)69 rdpRegionCopy(RegionPtr dst, RegionPtr src)
70 {
71 #if XRDP_REG == 1
72     return miRegionCopy(dst, src);
73 #else
74     return RegionCopy(dst, src);
75 #endif
76 }
77 
78 /*****************************************************************************/
79 void
rdpRegionTranslate(RegionPtr pReg,int x,int y)80 rdpRegionTranslate(RegionPtr pReg, int x, int y)
81 {
82 #if XRDP_REG == 1
83     miTranslateRegion(pReg, x, y);
84 #else
85     RegionTranslate(pReg, x, y);
86 #endif
87 }
88 
89 /*****************************************************************************/
90 Bool
rdpRegionNotEmpty(RegionPtr pReg)91 rdpRegionNotEmpty(RegionPtr pReg)
92 {
93 #if XRDP_REG == 1
94     return miRegionNotEmpty(pReg);
95 #else
96     return RegionNotEmpty(pReg);
97 #endif
98 }
99 
100 /*****************************************************************************/
101 Bool
rdpRegionIntersect(RegionPtr newReg,RegionPtr reg1,RegionPtr reg2)102 rdpRegionIntersect(RegionPtr newReg, RegionPtr reg1, RegionPtr reg2)
103 {
104 #if XRDP_REG == 1
105     return miIntersect(newReg, reg1, reg2);
106 #else
107     return RegionIntersect(newReg, reg1, reg2);
108 #endif
109 }
110 
111 /*****************************************************************************/
112 int
rdpRegionContainsRect(RegionPtr region,BoxPtr prect)113 rdpRegionContainsRect(RegionPtr region, BoxPtr prect)
114 {
115 #if XRDP_REG == 1
116     return miRectIn(region, prect);
117 #else
118     return RegionContainsRect(region, prect);
119 #endif
120 }
121 
122 /*****************************************************************************/
123 void
rdpRegionInit(RegionPtr pReg,BoxPtr rect,int size)124 rdpRegionInit(RegionPtr pReg, BoxPtr rect, int size)
125 {
126 #if XRDP_REG == 1
127     miRegionInit(pReg, rect, size);
128 #else
129     RegionInit(pReg, rect, size);
130 #endif
131 }
132 
133 /*****************************************************************************/
134 void
rdpRegionUninit(RegionPtr pReg)135 rdpRegionUninit(RegionPtr pReg)
136 {
137 #if XRDP_REG == 1
138     miRegionUninit(pReg);
139 #else
140     RegionUninit(pReg);
141 #endif
142 }
143 
144 /*****************************************************************************/
145 RegionPtr
rdpRegionFromRects(int nrects,xRectanglePtr prect,int ctype)146 rdpRegionFromRects(int nrects, xRectanglePtr prect, int ctype)
147 {
148 #if XRDP_REG == 1
149     return miRectsToRegion(nrects, prect, ctype);
150 #else
151     return RegionFromRects(nrects, prect, ctype);
152 #endif
153 }
154 
155 /*****************************************************************************/
156 void
rdpRegionDestroy(RegionPtr pReg)157 rdpRegionDestroy(RegionPtr pReg)
158 {
159 #if XRDP_REG == 1
160     miRegionDestroy(pReg);
161 #else
162     RegionDestroy(pReg);
163 #endif
164 }
165 
166 /*****************************************************************************/
167 RegionPtr
rdpRegionCreate(BoxPtr rect,int size)168 rdpRegionCreate(BoxPtr rect, int size)
169 {
170 #if XRDP_REG == 1
171     return miRegionCreate(rect, size);
172 #else
173     return RegionCreate(rect, size);
174 #endif
175 }
176 
177 /*****************************************************************************/
178 Bool
rdpRegionUnion(RegionPtr newReg,RegionPtr reg1,RegionPtr reg2)179 rdpRegionUnion(RegionPtr newReg, RegionPtr reg1, RegionPtr reg2)
180 {
181 #if XRDP_REG == 1
182     return miUnion(newReg, reg1, reg2);
183 #else
184     return RegionUnion(newReg, reg1, reg2);
185 #endif
186 }
187 
188 /*****************************************************************************/
189 Bool
rdpRegionSubtract(RegionPtr newReg,RegionPtr reg1,RegionPtr reg2)190 rdpRegionSubtract(RegionPtr newReg, RegionPtr reg1, RegionPtr reg2)
191 {
192 #if XRDP_REG == 1
193     return miSubtract(newReg, reg1, reg2);
194 #else
195     return RegionSubtract(newReg, reg1, reg2);
196 #endif
197 }
198 
199 /*****************************************************************************/
200 Bool
rdpRegionInverse(RegionPtr newReg,RegionPtr reg1,BoxPtr invRect)201 rdpRegionInverse(RegionPtr newReg, RegionPtr reg1, BoxPtr invRect)
202 {
203 #if XRDP_REG == 1
204     return miInverse(newReg, reg1, invRect);
205 #else
206     return RegionInverse(newReg, reg1, invRect);
207 #endif
208 }
209 
210 /*****************************************************************************/
211 BoxPtr
rdpRegionExtents(RegionPtr pReg)212 rdpRegionExtents(RegionPtr pReg)
213 {
214 #if XRDP_REG == 1
215     return miRegionExtents(pReg);
216 #else
217     return RegionExtents(pReg);
218 #endif
219 }
220 
221 /*****************************************************************************/
222 void
rdpRegionReset(RegionPtr pReg,BoxPtr pBox)223 rdpRegionReset(RegionPtr pReg, BoxPtr pBox)
224 {
225 #if XRDP_REG == 1
226     miRegionReset(pReg, pBox);
227 #else
228     RegionReset(pReg, pBox);
229 #endif
230 }
231 
232 /*****************************************************************************/
233 Bool
rdpRegionBreak(RegionPtr pReg)234 rdpRegionBreak(RegionPtr pReg)
235 {
236 #if XRDP_REG == 1
237     return miRegionBreak(pReg);
238 #else
239     return RegionBreak(pReg);
240 #endif
241 }
242 
243 /*****************************************************************************/
244 void
rdpRegionUnionRect(RegionPtr pReg,BoxPtr prect)245 rdpRegionUnionRect(RegionPtr pReg, BoxPtr prect)
246 {
247     RegionRec reg;
248 
249     rdpRegionInit(&reg, prect, 0);
250     rdpRegionUnion(pReg, pReg, &reg);
251     rdpRegionUninit(&reg);
252 }
253 
254 /*****************************************************************************/
255 int
rdpRegionPixelCount(RegionPtr pReg)256 rdpRegionPixelCount(RegionPtr pReg)
257 {
258     int index;
259     int count;
260     int rv;
261     BoxRec box;
262 
263     rv = 0;
264     count = REGION_NUM_RECTS(pReg);
265     for (index = 0; index < count; index++)
266     {
267         box = REGION_RECTS(pReg)[index];
268         rv += (box.x2 - box.x1) * (box.y2 - box.y1);
269     }
270     return rv;
271 }
272