1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | #ifdef HAVE_DIX_CONFIG_H1 |
24 | #include <dix-config.h> |
25 | #endif |
26 | |
27 | #include "mi.h" |
28 | #include "scrnintstr.h" |
29 | #include "gcstruct.h" |
30 | #include "pixmap.h" |
31 | #include "pixmapstr.h" |
32 | #include "windowstr.h" |
33 | |
34 | void |
35 | miCopyRegion(DrawablePtr pSrcDrawable, |
36 | DrawablePtr pDstDrawable, |
37 | GCPtr pGC, |
38 | RegionPtr pDstRegion, |
39 | int dx, int dy, miCopyProc copyProc, Pixel bitPlane, void *closure) |
40 | { |
41 | int careful; |
42 | Bool reverse; |
43 | Bool upsidedown; |
44 | BoxPtr pbox; |
45 | int nbox; |
46 | BoxPtr pboxNew1, pboxNew2, pboxBase, pboxNext, pboxTmp; |
47 | |
48 | pbox = RegionRects(pDstRegion); |
49 | nbox = RegionNumRects(pDstRegion); |
50 | |
51 | |
52 | |
53 | |
54 | careful = ((pSrcDrawable == pDstDrawable) || |
| 9 | | Assuming 'pSrcDrawable' is equal to 'pDstDrawable' | |
|
55 | ((pSrcDrawable->type == DRAWABLE_WINDOW0) && |
56 | (pDstDrawable->type == DRAWABLE_WINDOW0))); |
57 | |
58 | pboxNew1 = NULL((void*)0); |
59 | pboxNew2 = NULL((void*)0); |
60 | if (careful && dy < 0) { |
| |
| |
61 | upsidedown = TRUE1; |
62 | |
63 | if (nbox > 1) { |
| |
| |
64 | |
65 | pboxNew1 = (BoxPtr) malloc(sizeof(BoxRec) * nbox); |
| |
66 | if (!pboxNew1) |
| 15 | | Assuming 'pboxNew1' is non-null | |
|
| |
67 | return; |
68 | pboxBase = pboxNext = pbox + nbox - 1; |
69 | while (pboxBase >= pbox) { |
| 17 | | Assuming 'pboxBase' is < 'pbox' | |
|
| 18 | | Loop condition is false. Execution continues on line 78 | |
|
70 | while ((pboxNext >= pbox) && (pboxBase->y1 == pboxNext->y1)) |
71 | pboxNext--; |
72 | pboxTmp = pboxNext + 1; |
73 | while (pboxTmp <= pboxBase) { |
74 | *pboxNew1++ = *pboxTmp++; |
75 | } |
76 | pboxBase = pboxNext; |
77 | } |
78 | pboxNew1 -= nbox; |
79 | pbox = pboxNew1; |
| 19 | | Potential leak of memory pointed to by 'pboxNew1' |
|
80 | } |
81 | } |
82 | else { |
83 | |
84 | upsidedown = FALSE0; |
85 | } |
86 | |
87 | if (careful && dx < 0) { |
88 | |
89 | if (dy <= 0) |
90 | reverse = TRUE1; |
91 | else |
92 | reverse = FALSE0; |
93 | |
94 | if (nbox > 1) { |
95 | |
96 | pboxNew2 = (BoxPtr) malloc(sizeof(BoxRec) * nbox); |
97 | if (!pboxNew2) { |
98 | free(pboxNew1); |
99 | return; |
100 | } |
101 | pboxBase = pboxNext = pbox; |
102 | while (pboxBase < pbox + nbox) { |
103 | while ((pboxNext < pbox + nbox) && |
104 | (pboxNext->y1 == pboxBase->y1)) |
105 | pboxNext++; |
106 | pboxTmp = pboxNext; |
107 | while (pboxTmp != pboxBase) { |
108 | *pboxNew2++ = *--pboxTmp; |
109 | } |
110 | pboxBase = pboxNext; |
111 | } |
112 | pboxNew2 -= nbox; |
113 | pbox = pboxNew2; |
114 | } |
115 | } |
116 | else { |
117 | |
118 | reverse = FALSE0; |
119 | } |
120 | |
121 | (*copyProc) (pSrcDrawable, |
122 | pDstDrawable, |
123 | pGC, |
124 | pbox, nbox, dx, dy, reverse, upsidedown, bitPlane, closure); |
125 | |
126 | free(pboxNew1); |
127 | free(pboxNew2); |
128 | } |
129 | |
130 | RegionPtr |
131 | miDoCopy(DrawablePtr pSrcDrawable, |
132 | DrawablePtr pDstDrawable, |
133 | GCPtr pGC, |
134 | int xIn, |
135 | int yIn, |
136 | int widthSrc, |
137 | int heightSrc, |
138 | int xOut, int yOut, miCopyProc copyProc, Pixel bitPlane, void *closure) |
139 | { |
140 | RegionPtr prgnSrcClip = NULL((void*)0); |
141 | Bool freeSrcClip = FALSE0; |
142 | RegionPtr prgnExposed = NULL((void*)0); |
143 | RegionRec rgnDst; |
144 | int dx; |
145 | int dy; |
146 | int numRects; |
147 | int box_x1; |
148 | int box_y1; |
149 | int box_x2; |
150 | int box_y2; |
151 | Bool fastSrc = FALSE0; |
152 | Bool fastDst = FALSE0; |
153 | Bool fastExpose = FALSE0; |
154 | |
155 | |
156 | |
157 | if (pDstDrawable->type == DRAWABLE_WINDOW0 && |
158 | !((WindowPtr) pDstDrawable)->realized) { |
159 | return NULL((void*)0); |
160 | } |
161 | |
162 | if (pSrcDrawable->pScreen->SourceValidate) { |
| |
163 | (*pSrcDrawable->pScreen->SourceValidate) (pSrcDrawable, xIn, yIn, |
164 | widthSrc, heightSrc, |
165 | pGC->subWindowMode); |
166 | } |
167 | |
168 | |
169 | if (pSrcDrawable->type == DRAWABLE_PIXMAP1) { |
| |
170 | if ((pSrcDrawable == pDstDrawable) && (!pGC->clientClip)) |
171 | prgnSrcClip = miGetCompositeClip(pGC)((pGC)->pCompositeClip); |
172 | else |
173 | fastSrc = TRUE1; |
174 | } |
175 | else { |
176 | if (pGC->subWindowMode == IncludeInferiors1) { |
| |
177 | |
178 | |
179 | |
180 | |
181 | if (!((WindowPtr) pSrcDrawable)->parent && |
182 | RegionNotEmpty(&((WindowPtr) pSrcDrawable)->borderClip)) { |
183 | |
184 | |
185 | |
186 | |
187 | fastSrc = TRUE1; |
188 | } |
189 | else if ((pSrcDrawable == pDstDrawable) && (!pGC->clientClip)) { |
190 | prgnSrcClip = miGetCompositeClip(pGC)((pGC)->pCompositeClip); |
191 | } |
192 | else { |
193 | prgnSrcClip = NotClippedByChildren((WindowPtr) pSrcDrawable); |
194 | freeSrcClip = TRUE1; |
195 | } |
196 | } |
197 | else { |
198 | prgnSrcClip = &((WindowPtr) pSrcDrawable)->clipList; |
199 | } |
200 | } |
201 | |
202 | xIn += pSrcDrawable->x; |
203 | yIn += pSrcDrawable->y; |
204 | |
205 | xOut += pDstDrawable->x; |
206 | yOut += pDstDrawable->y; |
207 | |
208 | box_x1 = xIn; |
209 | box_y1 = yIn; |
210 | box_x2 = xIn + widthSrc; |
211 | box_y2 = yIn + heightSrc; |
212 | |
213 | dx = xIn - xOut; |
214 | dy = yIn - yOut; |
215 | |
216 | |
217 | if (fastSrc) { |
| |
218 | RegionPtr cclip; |
219 | |
220 | fastExpose = TRUE1; |
221 | |
222 | |
223 | |
224 | |
225 | if (box_x1 < pSrcDrawable->x) { |
226 | box_x1 = pSrcDrawable->x; |
227 | fastExpose = FALSE0; |
228 | } |
229 | if (box_y1 < pSrcDrawable->y) { |
230 | box_y1 = pSrcDrawable->y; |
231 | fastExpose = FALSE0; |
232 | } |
233 | if (box_x2 > pSrcDrawable->x + (int) pSrcDrawable->width) { |
234 | box_x2 = pSrcDrawable->x + (int) pSrcDrawable->width; |
235 | fastExpose = FALSE0; |
236 | } |
237 | if (box_y2 > pSrcDrawable->y + (int) pSrcDrawable->height) { |
238 | box_y2 = pSrcDrawable->y + (int) pSrcDrawable->height; |
239 | fastExpose = FALSE0; |
240 | } |
241 | |
242 | |
243 | box_x1 -= dx; |
244 | box_x2 -= dx; |
245 | box_y1 -= dy; |
246 | box_y2 -= dy; |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | cclip = miGetCompositeClip(pGC)((pGC)->pCompositeClip); |
253 | if (RegionNumRects(cclip) == 1) { |
254 | BoxPtr pBox = RegionRects(cclip); |
255 | |
256 | if (box_x1 < pBox->x1) |
257 | box_x1 = pBox->x1; |
258 | if (box_x2 > pBox->x2) |
259 | box_x2 = pBox->x2; |
260 | if (box_y1 < pBox->y1) |
261 | box_y1 = pBox->y1; |
262 | if (box_y2 > pBox->y2) |
263 | box_y2 = pBox->y2; |
264 | fastDst = TRUE1; |
265 | } |
266 | } |
267 | |
268 | |
269 | if (box_x1 >= box_x2 || box_y1 >= box_y2) { |
270 | RegionNull(&rgnDst); |
271 | } |
272 | else { |
273 | BoxRec box; |
274 | |
275 | box.x1 = box_x1; |
276 | box.y1 = box_y1; |
277 | box.x2 = box_x2; |
278 | box.y2 = box_y2; |
279 | RegionInit(&rgnDst, &box, 1); |
280 | } |
281 | |
282 | |
283 | if (!fastSrc) { |
| |
284 | RegionIntersect(&rgnDst, &rgnDst, prgnSrcClip); |
285 | RegionTranslate(&rgnDst, -dx, -dy); |
286 | } |
287 | |
288 | |
289 | if (!fastDst) { |
| |
290 | RegionIntersect(&rgnDst, &rgnDst, miGetCompositeClip(pGC)((pGC)->pCompositeClip)); |
291 | } |
292 | |
293 | |
294 | numRects = RegionNumRects(&rgnDst); |
295 | if (numRects && widthSrc && heightSrc) |
| |
296 | miCopyRegion(pSrcDrawable, pDstDrawable, pGC, |
| |
297 | &rgnDst, dx, dy, copyProc, bitPlane, closure); |
298 | |
299 | |
300 | if (!fastExpose && pGC->fExpose) |
301 | prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, |
302 | xIn - pSrcDrawable->x, |
303 | yIn - pSrcDrawable->y, |
304 | widthSrc, heightSrc, |
305 | xOut - pDstDrawable->x, |
306 | yOut - pDstDrawable->y); |
307 | RegionUninit(&rgnDst); |
308 | if (freeSrcClip) |
309 | RegionDestroy(prgnSrcClip); |
310 | return prgnExposed; |
311 | } |