1*4882a593Smuzhiyun #include <stdlib.h>
2*4882a593Smuzhiyun #include <stdint.h> /* For INT16_MAX */
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun #include "glamor_priv.h"
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun static void
7*4882a593Smuzhiyun glamor_get_transform_extent_from_box(struct pixman_box32 *box,
8*4882a593Smuzhiyun struct pixman_transform *transform);
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun static inline glamor_pixmap_private *
__glamor_large(glamor_pixmap_private * pixmap_priv)11*4882a593Smuzhiyun __glamor_large(glamor_pixmap_private *pixmap_priv) {
12*4882a593Smuzhiyun assert(glamor_pixmap_priv_is_large(pixmap_priv));
13*4882a593Smuzhiyun return pixmap_priv;
14*4882a593Smuzhiyun }
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun /**
17*4882a593Smuzhiyun * Clip the boxes regards to each pixmap's block array.
18*4882a593Smuzhiyun *
19*4882a593Smuzhiyun * Should translate the region to relative coords to the pixmap,
20*4882a593Smuzhiyun * start at (0,0).
21*4882a593Smuzhiyun */
22*4882a593Smuzhiyun #if 0
23*4882a593Smuzhiyun //#define DEBUGF(str, ...) do {} while(0)
24*4882a593Smuzhiyun #define DEBUGF(str, ...) ErrorF(str, ##__VA_ARGS__)
25*4882a593Smuzhiyun //#define DEBUGRegionPrint(x) do {} while (0)
26*4882a593Smuzhiyun #define DEBUGRegionPrint RegionPrint
27*4882a593Smuzhiyun #endif
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun static glamor_pixmap_clipped_regions *
__glamor_compute_clipped_regions(int block_w,int block_h,int block_stride,int x,int y,int w,int h,RegionPtr region,int * n_region,int reverse,int upsidedown)30*4882a593Smuzhiyun __glamor_compute_clipped_regions(int block_w,
31*4882a593Smuzhiyun int block_h,
32*4882a593Smuzhiyun int block_stride,
33*4882a593Smuzhiyun int x, int y,
34*4882a593Smuzhiyun int w, int h,
35*4882a593Smuzhiyun RegionPtr region,
36*4882a593Smuzhiyun int *n_region, int reverse, int upsidedown)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun glamor_pixmap_clipped_regions *clipped_regions;
39*4882a593Smuzhiyun BoxPtr extent;
40*4882a593Smuzhiyun int start_x, start_y, end_x, end_y;
41*4882a593Smuzhiyun int start_block_x, start_block_y;
42*4882a593Smuzhiyun int end_block_x, end_block_y;
43*4882a593Smuzhiyun int loop_start_block_x, loop_start_block_y;
44*4882a593Smuzhiyun int loop_end_block_x, loop_end_block_y;
45*4882a593Smuzhiyun int loop_block_stride;
46*4882a593Smuzhiyun int i, j, delta_i, delta_j;
47*4882a593Smuzhiyun RegionRec temp_region;
48*4882a593Smuzhiyun RegionPtr current_region;
49*4882a593Smuzhiyun int block_idx;
50*4882a593Smuzhiyun int k = 0;
51*4882a593Smuzhiyun int temp_block_idx;
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun extent = RegionExtents(region);
54*4882a593Smuzhiyun start_x = MAX(x, extent->x1);
55*4882a593Smuzhiyun start_y = MAX(y, extent->y1);
56*4882a593Smuzhiyun end_x = MIN(x + w, extent->x2);
57*4882a593Smuzhiyun end_y = MIN(y + h, extent->y2);
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun DEBUGF("start compute clipped regions:\n");
60*4882a593Smuzhiyun DEBUGF("block w %d h %d x %d y %d w %d h %d, block_stride %d \n",
61*4882a593Smuzhiyun block_w, block_h, x, y, w, h, block_stride);
62*4882a593Smuzhiyun DEBUGRegionPrint(region);
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun DEBUGF("start_x %d start_y %d end_x %d end_y %d \n", start_x, start_y,
65*4882a593Smuzhiyun end_x, end_y);
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun if (start_x >= end_x || start_y >= end_y) {
68*4882a593Smuzhiyun *n_region = 0;
69*4882a593Smuzhiyun return NULL;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun start_block_x = (start_x - x) / block_w;
73*4882a593Smuzhiyun start_block_y = (start_y - y) / block_h;
74*4882a593Smuzhiyun end_block_x = (end_x - x) / block_w;
75*4882a593Smuzhiyun end_block_y = (end_y - y) / block_h;
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun clipped_regions = calloc((end_block_x - start_block_x + 1)
78*4882a593Smuzhiyun * (end_block_y - start_block_y + 1),
79*4882a593Smuzhiyun sizeof(*clipped_regions));
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun DEBUGF("startx %d starty %d endx %d endy %d \n",
82*4882a593Smuzhiyun start_x, start_y, end_x, end_y);
83*4882a593Smuzhiyun DEBUGF("start_block_x %d end_block_x %d \n", start_block_x, end_block_x);
84*4882a593Smuzhiyun DEBUGF("start_block_y %d end_block_y %d \n", start_block_y, end_block_y);
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun if (!reverse) {
87*4882a593Smuzhiyun loop_start_block_x = start_block_x;
88*4882a593Smuzhiyun loop_end_block_x = end_block_x + 1;
89*4882a593Smuzhiyun delta_i = 1;
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun else {
92*4882a593Smuzhiyun loop_start_block_x = end_block_x;
93*4882a593Smuzhiyun loop_end_block_x = start_block_x - 1;
94*4882a593Smuzhiyun delta_i = -1;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun if (!upsidedown) {
98*4882a593Smuzhiyun loop_start_block_y = start_block_y;
99*4882a593Smuzhiyun loop_end_block_y = end_block_y + 1;
100*4882a593Smuzhiyun delta_j = 1;
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun else {
103*4882a593Smuzhiyun loop_start_block_y = end_block_y;
104*4882a593Smuzhiyun loop_end_block_y = start_block_y - 1;
105*4882a593Smuzhiyun delta_j = -1;
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun loop_block_stride = delta_j * block_stride;
109*4882a593Smuzhiyun block_idx = (loop_start_block_y - delta_j) * block_stride;
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun for (j = loop_start_block_y; j != loop_end_block_y; j += delta_j) {
112*4882a593Smuzhiyun block_idx += loop_block_stride;
113*4882a593Smuzhiyun temp_block_idx = block_idx + loop_start_block_x;
114*4882a593Smuzhiyun for (i = loop_start_block_x;
115*4882a593Smuzhiyun i != loop_end_block_x; i += delta_i, temp_block_idx += delta_i) {
116*4882a593Smuzhiyun BoxRec temp_box;
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun temp_box.x1 = x + i * block_w;
119*4882a593Smuzhiyun temp_box.y1 = y + j * block_h;
120*4882a593Smuzhiyun temp_box.x2 = MIN(temp_box.x1 + block_w, end_x);
121*4882a593Smuzhiyun temp_box.y2 = MIN(temp_box.y1 + block_h, end_y);
122*4882a593Smuzhiyun RegionInitBoxes(&temp_region, &temp_box, 1);
123*4882a593Smuzhiyun DEBUGF("block idx %d \n", temp_block_idx);
124*4882a593Smuzhiyun DEBUGRegionPrint(&temp_region);
125*4882a593Smuzhiyun current_region = RegionCreate(NULL, 4);
126*4882a593Smuzhiyun RegionIntersect(current_region, &temp_region, region);
127*4882a593Smuzhiyun DEBUGF("i %d j %d region: \n", i, j);
128*4882a593Smuzhiyun DEBUGRegionPrint(current_region);
129*4882a593Smuzhiyun if (RegionNumRects(current_region)) {
130*4882a593Smuzhiyun clipped_regions[k].region = current_region;
131*4882a593Smuzhiyun clipped_regions[k].block_idx = temp_block_idx;
132*4882a593Smuzhiyun k++;
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun else
135*4882a593Smuzhiyun RegionDestroy(current_region);
136*4882a593Smuzhiyun RegionUninit(&temp_region);
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun *n_region = k;
141*4882a593Smuzhiyun return clipped_regions;
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun /**
145*4882a593Smuzhiyun * Do a two round clipping,
146*4882a593Smuzhiyun * first is to clip the region regard to current pixmap's
147*4882a593Smuzhiyun * block array. Then for each clipped region, do a inner
148*4882a593Smuzhiyun * block clipping. This is to make sure the final result
149*4882a593Smuzhiyun * will be shapped by inner_block_w and inner_block_h, and
150*4882a593Smuzhiyun * the final region also will not cross the pixmap's block
151*4882a593Smuzhiyun * boundary.
152*4882a593Smuzhiyun *
153*4882a593Smuzhiyun * This is mainly used by transformation support when do
154*4882a593Smuzhiyun * compositing.
155*4882a593Smuzhiyun */
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun glamor_pixmap_clipped_regions *
glamor_compute_clipped_regions_ext(PixmapPtr pixmap,RegionPtr region,int * n_region,int inner_block_w,int inner_block_h,int reverse,int upsidedown)158*4882a593Smuzhiyun glamor_compute_clipped_regions_ext(PixmapPtr pixmap,
159*4882a593Smuzhiyun RegionPtr region,
160*4882a593Smuzhiyun int *n_region,
161*4882a593Smuzhiyun int inner_block_w, int inner_block_h,
162*4882a593Smuzhiyun int reverse, int upsidedown)
163*4882a593Smuzhiyun {
164*4882a593Smuzhiyun glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
165*4882a593Smuzhiyun glamor_pixmap_clipped_regions *clipped_regions, *inner_regions,
166*4882a593Smuzhiyun *result_regions;
167*4882a593Smuzhiyun int i, j, x, y, k, inner_n_regions;
168*4882a593Smuzhiyun int width, height;
169*4882a593Smuzhiyun BoxPtr box_array;
170*4882a593Smuzhiyun BoxRec small_box;
171*4882a593Smuzhiyun int block_w, block_h;
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun DEBUGF("ext called \n");
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun if (glamor_pixmap_priv_is_small(pixmap_priv)) {
176*4882a593Smuzhiyun clipped_regions = calloc(1, sizeof(*clipped_regions));
177*4882a593Smuzhiyun if (clipped_regions == NULL) {
178*4882a593Smuzhiyun *n_region = 0;
179*4882a593Smuzhiyun return NULL;
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun clipped_regions[0].region = RegionCreate(NULL, 1);
182*4882a593Smuzhiyun clipped_regions[0].block_idx = 0;
183*4882a593Smuzhiyun RegionCopy(clipped_regions[0].region, region);
184*4882a593Smuzhiyun *n_region = 1;
185*4882a593Smuzhiyun block_w = pixmap->drawable.width;
186*4882a593Smuzhiyun block_h = pixmap->drawable.height;
187*4882a593Smuzhiyun box_array = &small_box;
188*4882a593Smuzhiyun small_box.x1 = small_box.y1 = 0;
189*4882a593Smuzhiyun small_box.x2 = block_w;
190*4882a593Smuzhiyun small_box.y2 = block_h;
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun else {
193*4882a593Smuzhiyun glamor_pixmap_private *priv = __glamor_large(pixmap_priv);
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun clipped_regions = __glamor_compute_clipped_regions(priv->block_w,
196*4882a593Smuzhiyun priv->block_h,
197*4882a593Smuzhiyun priv->block_wcnt,
198*4882a593Smuzhiyun 0, 0,
199*4882a593Smuzhiyun pixmap->drawable.width,
200*4882a593Smuzhiyun pixmap->drawable.height,
201*4882a593Smuzhiyun region, n_region,
202*4882a593Smuzhiyun reverse, upsidedown);
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun if (clipped_regions == NULL) {
205*4882a593Smuzhiyun *n_region = 0;
206*4882a593Smuzhiyun return NULL;
207*4882a593Smuzhiyun }
208*4882a593Smuzhiyun block_w = priv->block_w;
209*4882a593Smuzhiyun block_h = priv->block_h;
210*4882a593Smuzhiyun box_array = priv->box_array;
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun if (inner_block_w >= block_w && inner_block_h >= block_h)
213*4882a593Smuzhiyun return clipped_regions;
214*4882a593Smuzhiyun result_regions = calloc(*n_region
215*4882a593Smuzhiyun * ((block_w + inner_block_w - 1) /
216*4882a593Smuzhiyun inner_block_w)
217*4882a593Smuzhiyun * ((block_h + inner_block_h - 1) /
218*4882a593Smuzhiyun inner_block_h), sizeof(*result_regions));
219*4882a593Smuzhiyun k = 0;
220*4882a593Smuzhiyun for (i = 0; i < *n_region; i++) {
221*4882a593Smuzhiyun x = box_array[clipped_regions[i].block_idx].x1;
222*4882a593Smuzhiyun y = box_array[clipped_regions[i].block_idx].y1;
223*4882a593Smuzhiyun width = box_array[clipped_regions[i].block_idx].x2 - x;
224*4882a593Smuzhiyun height = box_array[clipped_regions[i].block_idx].y2 - y;
225*4882a593Smuzhiyun inner_regions = __glamor_compute_clipped_regions(inner_block_w,
226*4882a593Smuzhiyun inner_block_h,
227*4882a593Smuzhiyun 0, x, y,
228*4882a593Smuzhiyun width,
229*4882a593Smuzhiyun height,
230*4882a593Smuzhiyun clipped_regions[i].
231*4882a593Smuzhiyun region,
232*4882a593Smuzhiyun &inner_n_regions,
233*4882a593Smuzhiyun reverse, upsidedown);
234*4882a593Smuzhiyun for (j = 0; j < inner_n_regions; j++) {
235*4882a593Smuzhiyun result_regions[k].region = inner_regions[j].region;
236*4882a593Smuzhiyun result_regions[k].block_idx = clipped_regions[i].block_idx;
237*4882a593Smuzhiyun k++;
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun free(inner_regions);
240*4882a593Smuzhiyun }
241*4882a593Smuzhiyun *n_region = k;
242*4882a593Smuzhiyun free(clipped_regions);
243*4882a593Smuzhiyun return result_regions;
244*4882a593Smuzhiyun }
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun /*
247*4882a593Smuzhiyun *
248*4882a593Smuzhiyun * For the repeat pad mode, we can simply convert the region and
249*4882a593Smuzhiyun * let the out-of-box region can cover the needed edge of the source/mask
250*4882a593Smuzhiyun * Then apply a normal clip we can get what we want.
251*4882a593Smuzhiyun */
252*4882a593Smuzhiyun static RegionPtr
_glamor_convert_pad_region(RegionPtr region,int w,int h)253*4882a593Smuzhiyun _glamor_convert_pad_region(RegionPtr region, int w, int h)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun RegionPtr pad_region;
256*4882a593Smuzhiyun int nrect;
257*4882a593Smuzhiyun BoxPtr box;
258*4882a593Smuzhiyun int overlap;
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun nrect = RegionNumRects(region);
261*4882a593Smuzhiyun box = RegionRects(region);
262*4882a593Smuzhiyun pad_region = RegionCreate(NULL, 4);
263*4882a593Smuzhiyun if (pad_region == NULL)
264*4882a593Smuzhiyun return NULL;
265*4882a593Smuzhiyun while (nrect--) {
266*4882a593Smuzhiyun BoxRec pad_box;
267*4882a593Smuzhiyun RegionRec temp_region;
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun pad_box = *box;
270*4882a593Smuzhiyun if (pad_box.x1 < 0 && pad_box.x2 <= 0)
271*4882a593Smuzhiyun pad_box.x2 = 1;
272*4882a593Smuzhiyun else if (pad_box.x1 >= w && pad_box.x2 > w)
273*4882a593Smuzhiyun pad_box.x1 = w - 1;
274*4882a593Smuzhiyun if (pad_box.y1 < 0 && pad_box.y2 <= 0)
275*4882a593Smuzhiyun pad_box.y2 = 1;
276*4882a593Smuzhiyun else if (pad_box.y1 >= h && pad_box.y2 > h)
277*4882a593Smuzhiyun pad_box.y1 = h - 1;
278*4882a593Smuzhiyun RegionInitBoxes(&temp_region, &pad_box, 1);
279*4882a593Smuzhiyun RegionAppend(pad_region, &temp_region);
280*4882a593Smuzhiyun RegionUninit(&temp_region);
281*4882a593Smuzhiyun box++;
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun RegionValidate(pad_region, &overlap);
284*4882a593Smuzhiyun return pad_region;
285*4882a593Smuzhiyun }
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun /*
288*4882a593Smuzhiyun * For one type of large pixmap, its one direction is not exceed the
289*4882a593Smuzhiyun * size limitation, and in another word, on one direction it has only
290*4882a593Smuzhiyun * one block.
291*4882a593Smuzhiyun *
292*4882a593Smuzhiyun * This case of reflect repeating, we can optimize it and avoid repeat
293*4882a593Smuzhiyun * clip on that direction. We can just enlarge the repeat box and can
294*4882a593Smuzhiyun * cover all the dest region on that direction. But latter, we need to
295*4882a593Smuzhiyun * fixup the clipped result to get a correct coords for the subsequent
296*4882a593Smuzhiyun * processing. This function is to do the coords correction.
297*4882a593Smuzhiyun *
298*4882a593Smuzhiyun * */
299*4882a593Smuzhiyun static void
_glamor_largepixmap_reflect_fixup(short * xy1,short * xy2,int wh)300*4882a593Smuzhiyun _glamor_largepixmap_reflect_fixup(short *xy1, short *xy2, int wh)
301*4882a593Smuzhiyun {
302*4882a593Smuzhiyun int odd1, odd2;
303*4882a593Smuzhiyun int c1, c2;
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun if (*xy2 - *xy1 > wh) {
306*4882a593Smuzhiyun *xy1 = 0;
307*4882a593Smuzhiyun *xy2 = wh;
308*4882a593Smuzhiyun return;
309*4882a593Smuzhiyun }
310*4882a593Smuzhiyun modulus(*xy1, wh, c1);
311*4882a593Smuzhiyun odd1 = ((*xy1 - c1) / wh) & 0x1;
312*4882a593Smuzhiyun modulus(*xy2, wh, c2);
313*4882a593Smuzhiyun odd2 = ((*xy2 - c2) / wh) & 0x1;
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun if (odd1 && odd2) {
316*4882a593Smuzhiyun *xy1 = wh - c2;
317*4882a593Smuzhiyun *xy2 = wh - c1;
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun else if (odd1 && !odd2) {
320*4882a593Smuzhiyun *xy1 = 0;
321*4882a593Smuzhiyun *xy2 = MAX(c2, wh - c1);
322*4882a593Smuzhiyun }
323*4882a593Smuzhiyun else if (!odd1 && odd2) {
324*4882a593Smuzhiyun *xy2 = wh;
325*4882a593Smuzhiyun *xy1 = MIN(c1, wh - c2);
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun else {
328*4882a593Smuzhiyun *xy1 = c1;
329*4882a593Smuzhiyun *xy2 = c2;
330*4882a593Smuzhiyun }
331*4882a593Smuzhiyun }
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun /**
334*4882a593Smuzhiyun * Clip the boxes regards to each pixmap's block array.
335*4882a593Smuzhiyun *
336*4882a593Smuzhiyun * Should translate the region to relative coords to the pixmap,
337*4882a593Smuzhiyun * start at (0,0).
338*4882a593Smuzhiyun *
339*4882a593Smuzhiyun * @is_transform: if it is set, it has a transform matrix.
340*4882a593Smuzhiyun *
341*4882a593Smuzhiyun */
342*4882a593Smuzhiyun static glamor_pixmap_clipped_regions *
_glamor_compute_clipped_regions(PixmapPtr pixmap,glamor_pixmap_private * pixmap_priv,RegionPtr region,int * n_region,int repeat_type,int is_transform,int reverse,int upsidedown)343*4882a593Smuzhiyun _glamor_compute_clipped_regions(PixmapPtr pixmap,
344*4882a593Smuzhiyun glamor_pixmap_private *pixmap_priv,
345*4882a593Smuzhiyun RegionPtr region, int *n_region,
346*4882a593Smuzhiyun int repeat_type, int is_transform,
347*4882a593Smuzhiyun int reverse, int upsidedown)
348*4882a593Smuzhiyun {
349*4882a593Smuzhiyun glamor_pixmap_clipped_regions *clipped_regions;
350*4882a593Smuzhiyun BoxPtr extent;
351*4882a593Smuzhiyun int i, j;
352*4882a593Smuzhiyun RegionPtr current_region;
353*4882a593Smuzhiyun int pixmap_width, pixmap_height;
354*4882a593Smuzhiyun int m;
355*4882a593Smuzhiyun BoxRec repeat_box;
356*4882a593Smuzhiyun RegionRec repeat_region;
357*4882a593Smuzhiyun int right_shift = 0;
358*4882a593Smuzhiyun int down_shift = 0;
359*4882a593Smuzhiyun int x_center_shift = 0, y_center_shift = 0;
360*4882a593Smuzhiyun glamor_pixmap_private *priv;
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun DEBUGRegionPrint(region);
363*4882a593Smuzhiyun if (glamor_pixmap_priv_is_small(pixmap_priv)) {
364*4882a593Smuzhiyun clipped_regions = calloc(1, sizeof(*clipped_regions));
365*4882a593Smuzhiyun clipped_regions[0].region = RegionCreate(NULL, 1);
366*4882a593Smuzhiyun clipped_regions[0].block_idx = 0;
367*4882a593Smuzhiyun RegionCopy(clipped_regions[0].region, region);
368*4882a593Smuzhiyun *n_region = 1;
369*4882a593Smuzhiyun return clipped_regions;
370*4882a593Smuzhiyun }
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun priv = __glamor_large(pixmap_priv);
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun pixmap_width = pixmap->drawable.width;
375*4882a593Smuzhiyun pixmap_height = pixmap->drawable.height;
376*4882a593Smuzhiyun if (repeat_type == 0 || repeat_type == RepeatPad) {
377*4882a593Smuzhiyun RegionPtr saved_region = NULL;
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun if (repeat_type == RepeatPad) {
380*4882a593Smuzhiyun saved_region = region;
381*4882a593Smuzhiyun region =
382*4882a593Smuzhiyun _glamor_convert_pad_region(saved_region, pixmap_width,
383*4882a593Smuzhiyun pixmap_height);
384*4882a593Smuzhiyun if (region == NULL) {
385*4882a593Smuzhiyun *n_region = 0;
386*4882a593Smuzhiyun return NULL;
387*4882a593Smuzhiyun }
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun clipped_regions = __glamor_compute_clipped_regions(priv->block_w,
390*4882a593Smuzhiyun priv->block_h,
391*4882a593Smuzhiyun priv->block_wcnt,
392*4882a593Smuzhiyun 0, 0,
393*4882a593Smuzhiyun pixmap->drawable.width,
394*4882a593Smuzhiyun pixmap->drawable.height,
395*4882a593Smuzhiyun region, n_region,
396*4882a593Smuzhiyun reverse, upsidedown);
397*4882a593Smuzhiyun if (saved_region)
398*4882a593Smuzhiyun RegionDestroy(region);
399*4882a593Smuzhiyun return clipped_regions;
400*4882a593Smuzhiyun }
401*4882a593Smuzhiyun extent = RegionExtents(region);
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun x_center_shift = extent->x1 / pixmap_width;
404*4882a593Smuzhiyun if (x_center_shift < 0)
405*4882a593Smuzhiyun x_center_shift--;
406*4882a593Smuzhiyun if (abs(x_center_shift) & 1)
407*4882a593Smuzhiyun x_center_shift++;
408*4882a593Smuzhiyun y_center_shift = extent->y1 / pixmap_height;
409*4882a593Smuzhiyun if (y_center_shift < 0)
410*4882a593Smuzhiyun y_center_shift--;
411*4882a593Smuzhiyun if (abs(y_center_shift) & 1)
412*4882a593Smuzhiyun y_center_shift++;
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun if (extent->x1 < 0)
415*4882a593Smuzhiyun right_shift = ((-extent->x1 + pixmap_width - 1) / pixmap_width);
416*4882a593Smuzhiyun if (extent->y1 < 0)
417*4882a593Smuzhiyun down_shift = ((-extent->y1 + pixmap_height - 1) / pixmap_height);
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun if (right_shift != 0 || down_shift != 0) {
420*4882a593Smuzhiyun if (repeat_type == RepeatReflect) {
421*4882a593Smuzhiyun right_shift = (right_shift + 1) & ~1;
422*4882a593Smuzhiyun down_shift = (down_shift + 1) & ~1;
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun RegionTranslate(region, right_shift * pixmap_width,
425*4882a593Smuzhiyun down_shift * pixmap_height);
426*4882a593Smuzhiyun }
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun extent = RegionExtents(region);
429*4882a593Smuzhiyun /* Tile a large pixmap to another large pixmap.
430*4882a593Smuzhiyun * We can't use the target large pixmap as the
431*4882a593Smuzhiyun * loop variable, instead we need to loop for all
432*4882a593Smuzhiyun * the blocks in the tile pixmap.
433*4882a593Smuzhiyun *
434*4882a593Smuzhiyun * simulate repeat each single block to cover the
435*4882a593Smuzhiyun * target's blocks. Two special case:
436*4882a593Smuzhiyun * a block_wcnt == 1 or block_hcnt ==1, then we
437*4882a593Smuzhiyun * only need to loop one direction as the other
438*4882a593Smuzhiyun * direction is fully included in the first block.
439*4882a593Smuzhiyun *
440*4882a593Smuzhiyun * For the other cases, just need to start
441*4882a593Smuzhiyun * from a proper shiftx/shifty, and then increase
442*4882a593Smuzhiyun * y by tile_height each time to walk trhough the
443*4882a593Smuzhiyun * target block and then walk trhough the target
444*4882a593Smuzhiyun * at x direction by increate tile_width each time.
445*4882a593Smuzhiyun *
446*4882a593Smuzhiyun * This way, we can consolidate all the sub blocks
447*4882a593Smuzhiyun * of the target boxes into one tile source's block.
448*4882a593Smuzhiyun *
449*4882a593Smuzhiyun * */
450*4882a593Smuzhiyun m = 0;
451*4882a593Smuzhiyun clipped_regions = calloc(priv->block_wcnt * priv->block_hcnt,
452*4882a593Smuzhiyun sizeof(*clipped_regions));
453*4882a593Smuzhiyun if (clipped_regions == NULL) {
454*4882a593Smuzhiyun *n_region = 0;
455*4882a593Smuzhiyun return NULL;
456*4882a593Smuzhiyun }
457*4882a593Smuzhiyun if (right_shift != 0 || down_shift != 0) {
458*4882a593Smuzhiyun DEBUGF("region to be repeated shifted \n");
459*4882a593Smuzhiyun DEBUGRegionPrint(region);
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun DEBUGF("repeat pixmap width %d height %d \n", pixmap_width, pixmap_height);
462*4882a593Smuzhiyun DEBUGF("extent x1 %d y1 %d x2 %d y2 %d \n", extent->x1, extent->y1,
463*4882a593Smuzhiyun extent->x2, extent->y2);
464*4882a593Smuzhiyun for (j = 0; j < priv->block_hcnt; j++) {
465*4882a593Smuzhiyun for (i = 0; i < priv->block_wcnt; i++) {
466*4882a593Smuzhiyun int dx = pixmap_width;
467*4882a593Smuzhiyun int dy = pixmap_height;
468*4882a593Smuzhiyun int idx;
469*4882a593Smuzhiyun int shift_x;
470*4882a593Smuzhiyun int shift_y;
471*4882a593Smuzhiyun int saved_y1, saved_y2;
472*4882a593Smuzhiyun int x_idx = 0, y_idx = 0, saved_y_idx = 0;
473*4882a593Smuzhiyun RegionRec temp_region;
474*4882a593Smuzhiyun BoxRec reflect_repeat_box;
475*4882a593Smuzhiyun BoxPtr valid_repeat_box;
476*4882a593Smuzhiyun
477*4882a593Smuzhiyun shift_x = (extent->x1 / pixmap_width) * pixmap_width;
478*4882a593Smuzhiyun shift_y = (extent->y1 / pixmap_height) * pixmap_height;
479*4882a593Smuzhiyun idx = j * priv->block_wcnt + i;
480*4882a593Smuzhiyun if (repeat_type == RepeatReflect) {
481*4882a593Smuzhiyun x_idx = (extent->x1 / pixmap_width);
482*4882a593Smuzhiyun y_idx = (extent->y1 / pixmap_height);
483*4882a593Smuzhiyun }
484*4882a593Smuzhiyun
485*4882a593Smuzhiyun /* Construct a rect to clip the target region. */
486*4882a593Smuzhiyun repeat_box.x1 = shift_x + priv->box_array[idx].x1;
487*4882a593Smuzhiyun repeat_box.y1 = shift_y + priv->box_array[idx].y1;
488*4882a593Smuzhiyun if (priv->block_wcnt == 1) {
489*4882a593Smuzhiyun repeat_box.x2 = extent->x2;
490*4882a593Smuzhiyun dx = extent->x2 - repeat_box.x1;
491*4882a593Smuzhiyun }
492*4882a593Smuzhiyun else
493*4882a593Smuzhiyun repeat_box.x2 = shift_x + priv->box_array[idx].x2;
494*4882a593Smuzhiyun if (priv->block_hcnt == 1) {
495*4882a593Smuzhiyun repeat_box.y2 = extent->y2;
496*4882a593Smuzhiyun dy = extent->y2 - repeat_box.y1;
497*4882a593Smuzhiyun }
498*4882a593Smuzhiyun else
499*4882a593Smuzhiyun repeat_box.y2 = shift_y + priv->box_array[idx].y2;
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun current_region = RegionCreate(NULL, 4);
502*4882a593Smuzhiyun RegionInit(&temp_region, NULL, 4);
503*4882a593Smuzhiyun DEBUGF("init repeat box %d %d %d %d \n",
504*4882a593Smuzhiyun repeat_box.x1, repeat_box.y1, repeat_box.x2, repeat_box.y2);
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun if (repeat_type == RepeatNormal) {
507*4882a593Smuzhiyun saved_y1 = repeat_box.y1;
508*4882a593Smuzhiyun saved_y2 = repeat_box.y2;
509*4882a593Smuzhiyun for (; repeat_box.x1 < extent->x2;
510*4882a593Smuzhiyun repeat_box.x1 += dx, repeat_box.x2 += dx) {
511*4882a593Smuzhiyun repeat_box.y1 = saved_y1;
512*4882a593Smuzhiyun repeat_box.y2 = saved_y2;
513*4882a593Smuzhiyun for (repeat_box.y1 = saved_y1, repeat_box.y2 = saved_y2;
514*4882a593Smuzhiyun repeat_box.y1 < extent->y2;
515*4882a593Smuzhiyun repeat_box.y1 += dy, repeat_box.y2 += dy) {
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun RegionInitBoxes(&repeat_region, &repeat_box, 1);
518*4882a593Smuzhiyun DEBUGF("Start to clip repeat region: \n");
519*4882a593Smuzhiyun DEBUGRegionPrint(&repeat_region);
520*4882a593Smuzhiyun RegionIntersect(&temp_region, &repeat_region, region);
521*4882a593Smuzhiyun DEBUGF("clip result:\n");
522*4882a593Smuzhiyun DEBUGRegionPrint(&temp_region);
523*4882a593Smuzhiyun RegionAppend(current_region, &temp_region);
524*4882a593Smuzhiyun RegionUninit(&repeat_region);
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun }
527*4882a593Smuzhiyun }
528*4882a593Smuzhiyun else if (repeat_type == RepeatReflect) {
529*4882a593Smuzhiyun saved_y1 = repeat_box.y1;
530*4882a593Smuzhiyun saved_y2 = repeat_box.y2;
531*4882a593Smuzhiyun saved_y_idx = y_idx;
532*4882a593Smuzhiyun for (;; repeat_box.x1 += dx, repeat_box.x2 += dx) {
533*4882a593Smuzhiyun repeat_box.y1 = saved_y1;
534*4882a593Smuzhiyun repeat_box.y2 = saved_y2;
535*4882a593Smuzhiyun y_idx = saved_y_idx;
536*4882a593Smuzhiyun reflect_repeat_box.x1 = (x_idx & 1) ?
537*4882a593Smuzhiyun ((2 * x_idx + 1) * dx - repeat_box.x2) : repeat_box.x1;
538*4882a593Smuzhiyun reflect_repeat_box.x2 = (x_idx & 1) ?
539*4882a593Smuzhiyun ((2 * x_idx + 1) * dx - repeat_box.x1) : repeat_box.x2;
540*4882a593Smuzhiyun valid_repeat_box = &reflect_repeat_box;
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun if (valid_repeat_box->x1 >= extent->x2)
543*4882a593Smuzhiyun break;
544*4882a593Smuzhiyun for (repeat_box.y1 = saved_y1, repeat_box.y2 = saved_y2;;
545*4882a593Smuzhiyun repeat_box.y1 += dy, repeat_box.y2 += dy) {
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun DEBUGF("x_idx %d y_idx %d dx %d dy %d\n", x_idx, y_idx,
548*4882a593Smuzhiyun dx, dy);
549*4882a593Smuzhiyun DEBUGF("repeat box %d %d %d %d \n", repeat_box.x1,
550*4882a593Smuzhiyun repeat_box.y1, repeat_box.x2, repeat_box.y2);
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun if (priv->block_hcnt > 1) {
553*4882a593Smuzhiyun reflect_repeat_box.y1 = (y_idx & 1) ?
554*4882a593Smuzhiyun ((2 * y_idx + 1) * dy -
555*4882a593Smuzhiyun repeat_box.y2) : repeat_box.y1;
556*4882a593Smuzhiyun reflect_repeat_box.y2 =
557*4882a593Smuzhiyun (y_idx & 1) ? ((2 * y_idx + 1) * dy -
558*4882a593Smuzhiyun repeat_box.y1) : repeat_box.y2;
559*4882a593Smuzhiyun }
560*4882a593Smuzhiyun else {
561*4882a593Smuzhiyun reflect_repeat_box.y1 = repeat_box.y1;
562*4882a593Smuzhiyun reflect_repeat_box.y2 = repeat_box.y2;
563*4882a593Smuzhiyun }
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun DEBUGF("valid_repeat_box x1 %d y1 %d \n",
566*4882a593Smuzhiyun valid_repeat_box->x1, valid_repeat_box->y1);
567*4882a593Smuzhiyun if (valid_repeat_box->y1 >= extent->y2)
568*4882a593Smuzhiyun break;
569*4882a593Smuzhiyun RegionInitBoxes(&repeat_region, valid_repeat_box, 1);
570*4882a593Smuzhiyun DEBUGF("start to clip repeat[reflect] region: \n");
571*4882a593Smuzhiyun DEBUGRegionPrint(&repeat_region);
572*4882a593Smuzhiyun RegionIntersect(&temp_region, &repeat_region, region);
573*4882a593Smuzhiyun DEBUGF("result:\n");
574*4882a593Smuzhiyun DEBUGRegionPrint(&temp_region);
575*4882a593Smuzhiyun if (is_transform && RegionNumRects(&temp_region)) {
576*4882a593Smuzhiyun BoxRec temp_box;
577*4882a593Smuzhiyun BoxPtr temp_extent;
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun temp_extent = RegionExtents(&temp_region);
580*4882a593Smuzhiyun if (priv->block_wcnt > 1) {
581*4882a593Smuzhiyun if (x_idx & 1) {
582*4882a593Smuzhiyun temp_box.x1 =
583*4882a593Smuzhiyun ((2 * x_idx + 1) * dx -
584*4882a593Smuzhiyun temp_extent->x2);
585*4882a593Smuzhiyun temp_box.x2 =
586*4882a593Smuzhiyun ((2 * x_idx + 1) * dx -
587*4882a593Smuzhiyun temp_extent->x1);
588*4882a593Smuzhiyun }
589*4882a593Smuzhiyun else {
590*4882a593Smuzhiyun temp_box.x1 = temp_extent->x1;
591*4882a593Smuzhiyun temp_box.x2 = temp_extent->x2;
592*4882a593Smuzhiyun }
593*4882a593Smuzhiyun modulus(temp_box.x1, pixmap_width, temp_box.x1);
594*4882a593Smuzhiyun modulus(temp_box.x2, pixmap_width, temp_box.x2);
595*4882a593Smuzhiyun if (temp_box.x2 == 0)
596*4882a593Smuzhiyun temp_box.x2 = pixmap_width;
597*4882a593Smuzhiyun }
598*4882a593Smuzhiyun else {
599*4882a593Smuzhiyun temp_box.x1 = temp_extent->x1;
600*4882a593Smuzhiyun temp_box.x2 = temp_extent->x2;
601*4882a593Smuzhiyun _glamor_largepixmap_reflect_fixup(&temp_box.x1,
602*4882a593Smuzhiyun &temp_box.x2,
603*4882a593Smuzhiyun pixmap_width);
604*4882a593Smuzhiyun }
605*4882a593Smuzhiyun
606*4882a593Smuzhiyun if (priv->block_hcnt > 1) {
607*4882a593Smuzhiyun if (y_idx & 1) {
608*4882a593Smuzhiyun temp_box.y1 =
609*4882a593Smuzhiyun ((2 * y_idx + 1) * dy -
610*4882a593Smuzhiyun temp_extent->y2);
611*4882a593Smuzhiyun temp_box.y2 =
612*4882a593Smuzhiyun ((2 * y_idx + 1) * dy -
613*4882a593Smuzhiyun temp_extent->y1);
614*4882a593Smuzhiyun }
615*4882a593Smuzhiyun else {
616*4882a593Smuzhiyun temp_box.y1 = temp_extent->y1;
617*4882a593Smuzhiyun temp_box.y2 = temp_extent->y2;
618*4882a593Smuzhiyun }
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun modulus(temp_box.y1, pixmap_height,
621*4882a593Smuzhiyun temp_box.y1);
622*4882a593Smuzhiyun modulus(temp_box.y2, pixmap_height,
623*4882a593Smuzhiyun temp_box.y2);
624*4882a593Smuzhiyun if (temp_box.y2 == 0)
625*4882a593Smuzhiyun temp_box.y2 = pixmap_height;
626*4882a593Smuzhiyun }
627*4882a593Smuzhiyun else {
628*4882a593Smuzhiyun temp_box.y1 = temp_extent->y1;
629*4882a593Smuzhiyun temp_box.y2 = temp_extent->y2;
630*4882a593Smuzhiyun _glamor_largepixmap_reflect_fixup(&temp_box.y1,
631*4882a593Smuzhiyun &temp_box.y2,
632*4882a593Smuzhiyun pixmap_height);
633*4882a593Smuzhiyun }
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun RegionInitBoxes(&temp_region, &temp_box, 1);
636*4882a593Smuzhiyun RegionTranslate(&temp_region,
637*4882a593Smuzhiyun x_center_shift * pixmap_width,
638*4882a593Smuzhiyun y_center_shift * pixmap_height);
639*4882a593Smuzhiyun DEBUGF("for transform result:\n");
640*4882a593Smuzhiyun DEBUGRegionPrint(&temp_region);
641*4882a593Smuzhiyun }
642*4882a593Smuzhiyun RegionAppend(current_region, &temp_region);
643*4882a593Smuzhiyun RegionUninit(&repeat_region);
644*4882a593Smuzhiyun y_idx++;
645*4882a593Smuzhiyun }
646*4882a593Smuzhiyun x_idx++;
647*4882a593Smuzhiyun }
648*4882a593Smuzhiyun }
649*4882a593Smuzhiyun DEBUGF("dx %d dy %d \n", dx, dy);
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun if (RegionNumRects(current_region)) {
652*4882a593Smuzhiyun
653*4882a593Smuzhiyun if ((right_shift != 0 || down_shift != 0) &&
654*4882a593Smuzhiyun !(is_transform && repeat_type == RepeatReflect))
655*4882a593Smuzhiyun RegionTranslate(current_region, -right_shift * pixmap_width,
656*4882a593Smuzhiyun -down_shift * pixmap_height);
657*4882a593Smuzhiyun clipped_regions[m].region = current_region;
658*4882a593Smuzhiyun clipped_regions[m].block_idx = idx;
659*4882a593Smuzhiyun m++;
660*4882a593Smuzhiyun }
661*4882a593Smuzhiyun else
662*4882a593Smuzhiyun RegionDestroy(current_region);
663*4882a593Smuzhiyun RegionUninit(&temp_region);
664*4882a593Smuzhiyun }
665*4882a593Smuzhiyun }
666*4882a593Smuzhiyun
667*4882a593Smuzhiyun if (right_shift != 0 || down_shift != 0)
668*4882a593Smuzhiyun RegionTranslate(region, -right_shift * pixmap_width,
669*4882a593Smuzhiyun -down_shift * pixmap_height);
670*4882a593Smuzhiyun *n_region = m;
671*4882a593Smuzhiyun
672*4882a593Smuzhiyun return clipped_regions;
673*4882a593Smuzhiyun }
674*4882a593Smuzhiyun
675*4882a593Smuzhiyun glamor_pixmap_clipped_regions *
glamor_compute_clipped_regions(PixmapPtr pixmap,RegionPtr region,int * n_region,int repeat_type,int reverse,int upsidedown)676*4882a593Smuzhiyun glamor_compute_clipped_regions(PixmapPtr pixmap,
677*4882a593Smuzhiyun RegionPtr region,
678*4882a593Smuzhiyun int *n_region, int repeat_type,
679*4882a593Smuzhiyun int reverse, int upsidedown)
680*4882a593Smuzhiyun {
681*4882a593Smuzhiyun glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
682*4882a593Smuzhiyun return _glamor_compute_clipped_regions(pixmap, priv, region, n_region, repeat_type,
683*4882a593Smuzhiyun 0, reverse, upsidedown);
684*4882a593Smuzhiyun }
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun /* XXX overflow still exist. maybe we need to change to use region32.
687*4882a593Smuzhiyun * by default. Or just use region32 for repeat cases?
688*4882a593Smuzhiyun **/
689*4882a593Smuzhiyun static glamor_pixmap_clipped_regions *
glamor_compute_transform_clipped_regions(PixmapPtr pixmap,struct pixman_transform * transform,RegionPtr region,int * n_region,int dx,int dy,int repeat_type,int reverse,int upsidedown)690*4882a593Smuzhiyun glamor_compute_transform_clipped_regions(PixmapPtr pixmap,
691*4882a593Smuzhiyun struct pixman_transform *transform,
692*4882a593Smuzhiyun RegionPtr region, int *n_region,
693*4882a593Smuzhiyun int dx, int dy, int repeat_type,
694*4882a593Smuzhiyun int reverse, int upsidedown)
695*4882a593Smuzhiyun {
696*4882a593Smuzhiyun glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
697*4882a593Smuzhiyun BoxPtr temp_extent;
698*4882a593Smuzhiyun struct pixman_box32 temp_box;
699*4882a593Smuzhiyun struct pixman_box16 short_box;
700*4882a593Smuzhiyun RegionPtr temp_region;
701*4882a593Smuzhiyun glamor_pixmap_clipped_regions *ret;
702*4882a593Smuzhiyun
703*4882a593Smuzhiyun temp_region = RegionCreate(NULL, 4);
704*4882a593Smuzhiyun temp_extent = RegionExtents(region);
705*4882a593Smuzhiyun DEBUGF("dest region \n");
706*4882a593Smuzhiyun DEBUGRegionPrint(region);
707*4882a593Smuzhiyun /* dx/dy may exceed MAX SHORT. we have to use
708*4882a593Smuzhiyun * a box32 to represent it.*/
709*4882a593Smuzhiyun temp_box.x1 = temp_extent->x1 + dx;
710*4882a593Smuzhiyun temp_box.x2 = temp_extent->x2 + dx;
711*4882a593Smuzhiyun temp_box.y1 = temp_extent->y1 + dy;
712*4882a593Smuzhiyun temp_box.y2 = temp_extent->y2 + dy;
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun DEBUGF("source box %d %d %d %d \n", temp_box.x1, temp_box.y1, temp_box.x2,
715*4882a593Smuzhiyun temp_box.y2);
716*4882a593Smuzhiyun if (transform)
717*4882a593Smuzhiyun glamor_get_transform_extent_from_box(&temp_box, transform);
718*4882a593Smuzhiyun if (repeat_type == RepeatNone) {
719*4882a593Smuzhiyun if (temp_box.x1 < 0)
720*4882a593Smuzhiyun temp_box.x1 = 0;
721*4882a593Smuzhiyun if (temp_box.y1 < 0)
722*4882a593Smuzhiyun temp_box.y1 = 0;
723*4882a593Smuzhiyun temp_box.x2 = MIN(temp_box.x2, pixmap->drawable.width);
724*4882a593Smuzhiyun temp_box.y2 = MIN(temp_box.y2, pixmap->drawable.height);
725*4882a593Smuzhiyun }
726*4882a593Smuzhiyun /* Now copy back the box32 to a box16 box, avoiding overflow. */
727*4882a593Smuzhiyun short_box.x1 = MIN(temp_box.x1, INT16_MAX);
728*4882a593Smuzhiyun short_box.y1 = MIN(temp_box.y1, INT16_MAX);
729*4882a593Smuzhiyun short_box.x2 = MIN(temp_box.x2, INT16_MAX);
730*4882a593Smuzhiyun short_box.y2 = MIN(temp_box.y2, INT16_MAX);
731*4882a593Smuzhiyun RegionInitBoxes(temp_region, &short_box, 1);
732*4882a593Smuzhiyun DEBUGF("copy to temp source region \n");
733*4882a593Smuzhiyun DEBUGRegionPrint(temp_region);
734*4882a593Smuzhiyun ret = _glamor_compute_clipped_regions(pixmap,
735*4882a593Smuzhiyun priv,
736*4882a593Smuzhiyun temp_region,
737*4882a593Smuzhiyun n_region,
738*4882a593Smuzhiyun repeat_type, 1, reverse, upsidedown);
739*4882a593Smuzhiyun DEBUGF("n_regions = %d \n", *n_region);
740*4882a593Smuzhiyun RegionDestroy(temp_region);
741*4882a593Smuzhiyun
742*4882a593Smuzhiyun return ret;
743*4882a593Smuzhiyun }
744*4882a593Smuzhiyun
745*4882a593Smuzhiyun /*
746*4882a593Smuzhiyun * As transform and repeatpad mode.
747*4882a593Smuzhiyun * We may get a clipped result which in multipe regions.
748*4882a593Smuzhiyun * It's not easy to do a 2nd round clipping just as we do
749*4882a593Smuzhiyun * without transform/repeatPad. As it's not easy to reverse
750*4882a593Smuzhiyun * the 2nd round clipping result with a transform/repeatPad mode,
751*4882a593Smuzhiyun * or even impossible for some transformation.
752*4882a593Smuzhiyun *
753*4882a593Smuzhiyun * So we have to merge the fragmental region into one region
754*4882a593Smuzhiyun * if the clipped result cross the region boundary.
755*4882a593Smuzhiyun */
756*4882a593Smuzhiyun static void
glamor_merge_clipped_regions(PixmapPtr pixmap,glamor_pixmap_private * pixmap_priv,int repeat_type,glamor_pixmap_clipped_regions * clipped_regions,int * n_regions,int * need_clean_fbo)757*4882a593Smuzhiyun glamor_merge_clipped_regions(PixmapPtr pixmap,
758*4882a593Smuzhiyun glamor_pixmap_private *pixmap_priv,
759*4882a593Smuzhiyun int repeat_type,
760*4882a593Smuzhiyun glamor_pixmap_clipped_regions *clipped_regions,
761*4882a593Smuzhiyun int *n_regions, int *need_clean_fbo)
762*4882a593Smuzhiyun {
763*4882a593Smuzhiyun BoxRec temp_box, copy_box;
764*4882a593Smuzhiyun RegionPtr temp_region;
765*4882a593Smuzhiyun glamor_pixmap_private *temp_priv;
766*4882a593Smuzhiyun PixmapPtr temp_pixmap;
767*4882a593Smuzhiyun int overlap;
768*4882a593Smuzhiyun int i;
769*4882a593Smuzhiyun int pixmap_width, pixmap_height;
770*4882a593Smuzhiyun glamor_pixmap_private *priv;
771*4882a593Smuzhiyun
772*4882a593Smuzhiyun priv = __glamor_large(pixmap_priv);
773*4882a593Smuzhiyun pixmap_width = pixmap->drawable.width;
774*4882a593Smuzhiyun pixmap_height =pixmap->drawable.height;
775*4882a593Smuzhiyun
776*4882a593Smuzhiyun temp_region = RegionCreate(NULL, 4);
777*4882a593Smuzhiyun for (i = 0; i < *n_regions; i++) {
778*4882a593Smuzhiyun DEBUGF("Region %d:\n", i);
779*4882a593Smuzhiyun DEBUGRegionPrint(clipped_regions[i].region);
780*4882a593Smuzhiyun RegionAppend(temp_region, clipped_regions[i].region);
781*4882a593Smuzhiyun }
782*4882a593Smuzhiyun
783*4882a593Smuzhiyun RegionValidate(temp_region, &overlap);
784*4882a593Smuzhiyun DEBUGF("temp region: \n");
785*4882a593Smuzhiyun DEBUGRegionPrint(temp_region);
786*4882a593Smuzhiyun
787*4882a593Smuzhiyun temp_box = *RegionExtents(temp_region);
788*4882a593Smuzhiyun
789*4882a593Smuzhiyun DEBUGF("need copy region: \n");
790*4882a593Smuzhiyun DEBUGF("%d %d %d %d \n", temp_box.x1, temp_box.y1, temp_box.x2,
791*4882a593Smuzhiyun temp_box.y2);
792*4882a593Smuzhiyun temp_pixmap =
793*4882a593Smuzhiyun glamor_create_pixmap(pixmap->drawable.pScreen,
794*4882a593Smuzhiyun temp_box.x2 - temp_box.x1,
795*4882a593Smuzhiyun temp_box.y2 - temp_box.y1,
796*4882a593Smuzhiyun pixmap->drawable.depth,
797*4882a593Smuzhiyun GLAMOR_CREATE_PIXMAP_FIXUP);
798*4882a593Smuzhiyun if (temp_pixmap == NULL) {
799*4882a593Smuzhiyun assert(0);
800*4882a593Smuzhiyun return;
801*4882a593Smuzhiyun }
802*4882a593Smuzhiyun
803*4882a593Smuzhiyun temp_priv = glamor_get_pixmap_private(temp_pixmap);
804*4882a593Smuzhiyun assert(glamor_pixmap_priv_is_small(temp_priv));
805*4882a593Smuzhiyun
806*4882a593Smuzhiyun priv->box = temp_box;
807*4882a593Smuzhiyun if (temp_box.x1 >= 0 && temp_box.x2 <= pixmap_width
808*4882a593Smuzhiyun && temp_box.y1 >= 0 && temp_box.y2 <= pixmap_height) {
809*4882a593Smuzhiyun int dx, dy;
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun copy_box.x1 = 0;
812*4882a593Smuzhiyun copy_box.y1 = 0;
813*4882a593Smuzhiyun copy_box.x2 = temp_box.x2 - temp_box.x1;
814*4882a593Smuzhiyun copy_box.y2 = temp_box.y2 - temp_box.y1;
815*4882a593Smuzhiyun dx = temp_box.x1;
816*4882a593Smuzhiyun dy = temp_box.y1;
817*4882a593Smuzhiyun glamor_copy(&pixmap->drawable,
818*4882a593Smuzhiyun &temp_pixmap->drawable,
819*4882a593Smuzhiyun NULL, ©_box, 1, dx, dy, 0, 0, 0, NULL);
820*4882a593Smuzhiyun // glamor_solid(temp_pixmap, 0, 0, temp_pixmap->drawable.width,
821*4882a593Smuzhiyun // temp_pixmap->drawable.height, GXcopy, 0xffffffff, 0xff00);
822*4882a593Smuzhiyun }
823*4882a593Smuzhiyun else {
824*4882a593Smuzhiyun for (i = 0; i < *n_regions; i++) {
825*4882a593Smuzhiyun BoxPtr box;
826*4882a593Smuzhiyun int nbox;
827*4882a593Smuzhiyun
828*4882a593Smuzhiyun box = REGION_RECTS(clipped_regions[i].region);
829*4882a593Smuzhiyun nbox = REGION_NUM_RECTS(clipped_regions[i].region);
830*4882a593Smuzhiyun while (nbox--) {
831*4882a593Smuzhiyun int dx, dy, c, d;
832*4882a593Smuzhiyun
833*4882a593Smuzhiyun DEBUGF("box x1 %d y1 %d x2 %d y2 %d \n",
834*4882a593Smuzhiyun box->x1, box->y1, box->x2, box->y2);
835*4882a593Smuzhiyun modulus(box->x1, pixmap_width, c);
836*4882a593Smuzhiyun dx = c - (box->x1 - temp_box.x1);
837*4882a593Smuzhiyun copy_box.x1 = box->x1 - temp_box.x1;
838*4882a593Smuzhiyun copy_box.x2 = box->x2 - temp_box.x1;
839*4882a593Smuzhiyun
840*4882a593Smuzhiyun modulus(box->y1, pixmap_height, d);
841*4882a593Smuzhiyun dy = d - (box->y1 - temp_box.y1);
842*4882a593Smuzhiyun copy_box.y1 = box->y1 - temp_box.y1;
843*4882a593Smuzhiyun copy_box.y2 = box->y2 - temp_box.y1;
844*4882a593Smuzhiyun
845*4882a593Smuzhiyun DEBUGF("copying box %d %d %d %d, dx %d dy %d\n",
846*4882a593Smuzhiyun copy_box.x1, copy_box.y1, copy_box.x2,
847*4882a593Smuzhiyun copy_box.y2, dx, dy);
848*4882a593Smuzhiyun
849*4882a593Smuzhiyun glamor_copy(&pixmap->drawable,
850*4882a593Smuzhiyun &temp_pixmap->drawable,
851*4882a593Smuzhiyun NULL, ©_box, 1, dx, dy, 0, 0, 0, NULL);
852*4882a593Smuzhiyun
853*4882a593Smuzhiyun box++;
854*4882a593Smuzhiyun }
855*4882a593Smuzhiyun }
856*4882a593Smuzhiyun //glamor_solid(temp_pixmap, 0, 0, temp_pixmap->drawable.width,
857*4882a593Smuzhiyun // temp_pixmap->drawable.height, GXcopy, 0xffffffff, 0xff);
858*4882a593Smuzhiyun }
859*4882a593Smuzhiyun /* The first region will be released at caller side. */
860*4882a593Smuzhiyun for (i = 1; i < *n_regions; i++)
861*4882a593Smuzhiyun RegionDestroy(clipped_regions[i].region);
862*4882a593Smuzhiyun RegionDestroy(temp_region);
863*4882a593Smuzhiyun priv->box = temp_box;
864*4882a593Smuzhiyun priv->fbo = glamor_pixmap_detach_fbo(temp_priv);
865*4882a593Smuzhiyun DEBUGF("priv box x1 %d y1 %d x2 %d y2 %d \n",
866*4882a593Smuzhiyun priv->box.x1, priv->box.y1, priv->box.x2, priv->box.y2);
867*4882a593Smuzhiyun glamor_destroy_pixmap(temp_pixmap);
868*4882a593Smuzhiyun *need_clean_fbo = 1;
869*4882a593Smuzhiyun *n_regions = 1;
870*4882a593Smuzhiyun }
871*4882a593Smuzhiyun
872*4882a593Smuzhiyun /**
873*4882a593Smuzhiyun * Given an expected transformed block width and block height,
874*4882a593Smuzhiyun *
875*4882a593Smuzhiyun * This function calculate a new block width and height which
876*4882a593Smuzhiyun * guarantee the transform result will not exceed the given
877*4882a593Smuzhiyun * block width and height.
878*4882a593Smuzhiyun *
879*4882a593Smuzhiyun * For large block width and height (> 2048), we choose a
880*4882a593Smuzhiyun * smaller new width and height and to reduce the cross region
881*4882a593Smuzhiyun * boundary and can avoid some overhead.
882*4882a593Smuzhiyun *
883*4882a593Smuzhiyun **/
884*4882a593Smuzhiyun static Bool
glamor_get_transform_block_size(struct pixman_transform * transform,int block_w,int block_h,int * transformed_block_w,int * transformed_block_h)885*4882a593Smuzhiyun glamor_get_transform_block_size(struct pixman_transform *transform,
886*4882a593Smuzhiyun int block_w, int block_h,
887*4882a593Smuzhiyun int *transformed_block_w,
888*4882a593Smuzhiyun int *transformed_block_h)
889*4882a593Smuzhiyun {
890*4882a593Smuzhiyun double a, b, c, d, e, f, g, h;
891*4882a593Smuzhiyun double scale;
892*4882a593Smuzhiyun int width, height;
893*4882a593Smuzhiyun
894*4882a593Smuzhiyun a = pixman_fixed_to_double(transform->matrix[0][0]);
895*4882a593Smuzhiyun b = pixman_fixed_to_double(transform->matrix[0][1]);
896*4882a593Smuzhiyun c = pixman_fixed_to_double(transform->matrix[1][0]);
897*4882a593Smuzhiyun d = pixman_fixed_to_double(transform->matrix[1][1]);
898*4882a593Smuzhiyun scale = pixman_fixed_to_double(transform->matrix[2][2]);
899*4882a593Smuzhiyun if (block_w > 2048) {
900*4882a593Smuzhiyun /* For large block size, we shrink it to smaller box,
901*4882a593Smuzhiyun * thus latter we may get less cross boundary regions and
902*4882a593Smuzhiyun * thus can avoid some extra copy.
903*4882a593Smuzhiyun *
904*4882a593Smuzhiyun **/
905*4882a593Smuzhiyun width = block_w / 4;
906*4882a593Smuzhiyun height = block_h / 4;
907*4882a593Smuzhiyun }
908*4882a593Smuzhiyun else {
909*4882a593Smuzhiyun width = block_w - 2;
910*4882a593Smuzhiyun height = block_h - 2;
911*4882a593Smuzhiyun }
912*4882a593Smuzhiyun e = a + b;
913*4882a593Smuzhiyun f = c + d;
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun g = a - b;
916*4882a593Smuzhiyun h = c - d;
917*4882a593Smuzhiyun
918*4882a593Smuzhiyun e = MIN(block_w, floor(width * scale) / MAX(fabs(e), fabs(g)));
919*4882a593Smuzhiyun f = MIN(block_h, floor(height * scale) / MAX(fabs(f), fabs(h)));
920*4882a593Smuzhiyun *transformed_block_w = MIN(e, f) - 1;
921*4882a593Smuzhiyun *transformed_block_h = *transformed_block_w;
922*4882a593Smuzhiyun if (*transformed_block_w <= 0 || *transformed_block_h <= 0)
923*4882a593Smuzhiyun return FALSE;
924*4882a593Smuzhiyun DEBUGF("original block_w/h %d %d, fixed %d %d \n", block_w, block_h,
925*4882a593Smuzhiyun *transformed_block_w, *transformed_block_h);
926*4882a593Smuzhiyun return TRUE;
927*4882a593Smuzhiyun }
928*4882a593Smuzhiyun
929*4882a593Smuzhiyun #define VECTOR_FROM_POINT(p, x, y) do {\
930*4882a593Smuzhiyun p.v[0] = x; \
931*4882a593Smuzhiyun p.v[1] = y; \
932*4882a593Smuzhiyun p.v[2] = 1.0; } while (0)
933*4882a593Smuzhiyun static void
glamor_get_transform_extent_from_box(struct pixman_box32 * box,struct pixman_transform * transform)934*4882a593Smuzhiyun glamor_get_transform_extent_from_box(struct pixman_box32 *box,
935*4882a593Smuzhiyun struct pixman_transform *transform)
936*4882a593Smuzhiyun {
937*4882a593Smuzhiyun struct pixman_f_vector p0, p1, p2, p3;
938*4882a593Smuzhiyun float min_x, min_y, max_x, max_y;
939*4882a593Smuzhiyun
940*4882a593Smuzhiyun struct pixman_f_transform ftransform;
941*4882a593Smuzhiyun
942*4882a593Smuzhiyun VECTOR_FROM_POINT(p0, box->x1, box->y1);
943*4882a593Smuzhiyun VECTOR_FROM_POINT(p1, box->x2, box->y1);
944*4882a593Smuzhiyun VECTOR_FROM_POINT(p2, box->x2, box->y2);
945*4882a593Smuzhiyun VECTOR_FROM_POINT(p3, box->x1, box->y2);
946*4882a593Smuzhiyun
947*4882a593Smuzhiyun pixman_f_transform_from_pixman_transform(&ftransform, transform);
948*4882a593Smuzhiyun pixman_f_transform_point(&ftransform, &p0);
949*4882a593Smuzhiyun pixman_f_transform_point(&ftransform, &p1);
950*4882a593Smuzhiyun pixman_f_transform_point(&ftransform, &p2);
951*4882a593Smuzhiyun pixman_f_transform_point(&ftransform, &p3);
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun min_x = MIN(p0.v[0], p1.v[0]);
954*4882a593Smuzhiyun min_x = MIN(min_x, p2.v[0]);
955*4882a593Smuzhiyun min_x = MIN(min_x, p3.v[0]);
956*4882a593Smuzhiyun
957*4882a593Smuzhiyun min_y = MIN(p0.v[1], p1.v[1]);
958*4882a593Smuzhiyun min_y = MIN(min_y, p2.v[1]);
959*4882a593Smuzhiyun min_y = MIN(min_y, p3.v[1]);
960*4882a593Smuzhiyun
961*4882a593Smuzhiyun max_x = MAX(p0.v[0], p1.v[0]);
962*4882a593Smuzhiyun max_x = MAX(max_x, p2.v[0]);
963*4882a593Smuzhiyun max_x = MAX(max_x, p3.v[0]);
964*4882a593Smuzhiyun
965*4882a593Smuzhiyun max_y = MAX(p0.v[1], p1.v[1]);
966*4882a593Smuzhiyun max_y = MAX(max_y, p2.v[1]);
967*4882a593Smuzhiyun max_y = MAX(max_y, p3.v[1]);
968*4882a593Smuzhiyun box->x1 = floor(min_x) - 1;
969*4882a593Smuzhiyun box->y1 = floor(min_y) - 1;
970*4882a593Smuzhiyun box->x2 = ceil(max_x) + 1;
971*4882a593Smuzhiyun box->y2 = ceil(max_y) + 1;
972*4882a593Smuzhiyun }
973*4882a593Smuzhiyun
974*4882a593Smuzhiyun static void
_glamor_process_transformed_clipped_region(PixmapPtr pixmap,glamor_pixmap_private * priv,int repeat_type,glamor_pixmap_clipped_regions * clipped_regions,int * n_regions,int * need_clean_fbo)975*4882a593Smuzhiyun _glamor_process_transformed_clipped_region(PixmapPtr pixmap,
976*4882a593Smuzhiyun glamor_pixmap_private *priv,
977*4882a593Smuzhiyun int repeat_type,
978*4882a593Smuzhiyun glamor_pixmap_clipped_regions *
979*4882a593Smuzhiyun clipped_regions, int *n_regions,
980*4882a593Smuzhiyun int *need_clean_fbo)
981*4882a593Smuzhiyun {
982*4882a593Smuzhiyun int shift_x, shift_y;
983*4882a593Smuzhiyun
984*4882a593Smuzhiyun if (*n_regions != 1) {
985*4882a593Smuzhiyun /* Merge all source regions into one region. */
986*4882a593Smuzhiyun glamor_merge_clipped_regions(pixmap, priv, repeat_type,
987*4882a593Smuzhiyun clipped_regions, n_regions,
988*4882a593Smuzhiyun need_clean_fbo);
989*4882a593Smuzhiyun }
990*4882a593Smuzhiyun else {
991*4882a593Smuzhiyun glamor_set_pixmap_fbo_current(priv, clipped_regions[0].block_idx);
992*4882a593Smuzhiyun if (repeat_type == RepeatReflect || repeat_type == RepeatNormal) {
993*4882a593Smuzhiyun /* The required source areas are in one region,
994*4882a593Smuzhiyun * we need to shift the corresponding box's coords to proper position,
995*4882a593Smuzhiyun * thus we can calculate the relative coords correctly.*/
996*4882a593Smuzhiyun BoxPtr temp_box;
997*4882a593Smuzhiyun int rem;
998*4882a593Smuzhiyun
999*4882a593Smuzhiyun temp_box = RegionExtents(clipped_regions[0].region);
1000*4882a593Smuzhiyun modulus(temp_box->x1, pixmap->drawable.width, rem);
1001*4882a593Smuzhiyun shift_x = (temp_box->x1 - rem) / pixmap->drawable.width;
1002*4882a593Smuzhiyun modulus(temp_box->y1, pixmap->drawable.height, rem);
1003*4882a593Smuzhiyun shift_y = (temp_box->y1 - rem) / pixmap->drawable.height;
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun if (shift_x != 0) {
1006*4882a593Smuzhiyun __glamor_large(priv)->box.x1 +=
1007*4882a593Smuzhiyun shift_x * pixmap->drawable.width;
1008*4882a593Smuzhiyun __glamor_large(priv)->box.x2 +=
1009*4882a593Smuzhiyun shift_x * pixmap->drawable.width;
1010*4882a593Smuzhiyun }
1011*4882a593Smuzhiyun if (shift_y != 0) {
1012*4882a593Smuzhiyun __glamor_large(priv)->box.y1 +=
1013*4882a593Smuzhiyun shift_y * pixmap->drawable.height;
1014*4882a593Smuzhiyun __glamor_large(priv)->box.y2 +=
1015*4882a593Smuzhiyun shift_y * pixmap->drawable.height;
1016*4882a593Smuzhiyun }
1017*4882a593Smuzhiyun }
1018*4882a593Smuzhiyun }
1019*4882a593Smuzhiyun }
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun Bool
glamor_composite_largepixmap_region(CARD8 op,PicturePtr source,PicturePtr mask,PicturePtr dest,PixmapPtr source_pixmap,PixmapPtr mask_pixmap,PixmapPtr dest_pixmap,RegionPtr region,Bool force_clip,INT16 x_source,INT16 y_source,INT16 x_mask,INT16 y_mask,INT16 x_dest,INT16 y_dest,CARD16 width,CARD16 height)1022*4882a593Smuzhiyun glamor_composite_largepixmap_region(CARD8 op,
1023*4882a593Smuzhiyun PicturePtr source,
1024*4882a593Smuzhiyun PicturePtr mask,
1025*4882a593Smuzhiyun PicturePtr dest,
1026*4882a593Smuzhiyun PixmapPtr source_pixmap,
1027*4882a593Smuzhiyun PixmapPtr mask_pixmap,
1028*4882a593Smuzhiyun PixmapPtr dest_pixmap,
1029*4882a593Smuzhiyun RegionPtr region, Bool force_clip,
1030*4882a593Smuzhiyun INT16 x_source,
1031*4882a593Smuzhiyun INT16 y_source,
1032*4882a593Smuzhiyun INT16 x_mask,
1033*4882a593Smuzhiyun INT16 y_mask,
1034*4882a593Smuzhiyun INT16 x_dest, INT16 y_dest,
1035*4882a593Smuzhiyun CARD16 width, CARD16 height)
1036*4882a593Smuzhiyun {
1037*4882a593Smuzhiyun ScreenPtr screen = dest_pixmap->drawable.pScreen;
1038*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
1039*4882a593Smuzhiyun glamor_pixmap_private *source_pixmap_priv = glamor_get_pixmap_private(source_pixmap);
1040*4882a593Smuzhiyun glamor_pixmap_private *mask_pixmap_priv = glamor_get_pixmap_private(mask_pixmap);
1041*4882a593Smuzhiyun glamor_pixmap_private *dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap);
1042*4882a593Smuzhiyun glamor_pixmap_clipped_regions *clipped_dest_regions;
1043*4882a593Smuzhiyun glamor_pixmap_clipped_regions *clipped_source_regions;
1044*4882a593Smuzhiyun glamor_pixmap_clipped_regions *clipped_mask_regions;
1045*4882a593Smuzhiyun int n_dest_regions;
1046*4882a593Smuzhiyun int n_mask_regions;
1047*4882a593Smuzhiyun int n_source_regions;
1048*4882a593Smuzhiyun int i, j, k;
1049*4882a593Smuzhiyun int need_clean_source_fbo = 0;
1050*4882a593Smuzhiyun int need_clean_mask_fbo = 0;
1051*4882a593Smuzhiyun int is_normal_source_fbo = 0;
1052*4882a593Smuzhiyun int is_normal_mask_fbo = 0;
1053*4882a593Smuzhiyun int fixed_block_width, fixed_block_height;
1054*4882a593Smuzhiyun int dest_block_width, dest_block_height;
1055*4882a593Smuzhiyun int null_source, null_mask;
1056*4882a593Smuzhiyun glamor_pixmap_private *need_free_source_pixmap_priv = NULL;
1057*4882a593Smuzhiyun glamor_pixmap_private *need_free_mask_pixmap_priv = NULL;
1058*4882a593Smuzhiyun int source_repeat_type = 0, mask_repeat_type = 0;
1059*4882a593Smuzhiyun int ok = TRUE;
1060*4882a593Smuzhiyun
1061*4882a593Smuzhiyun if (source_pixmap == dest_pixmap) {
1062*4882a593Smuzhiyun glamor_fallback("source and dest pixmaps are the same\n");
1063*4882a593Smuzhiyun return FALSE;
1064*4882a593Smuzhiyun }
1065*4882a593Smuzhiyun if (mask_pixmap == dest_pixmap) {
1066*4882a593Smuzhiyun glamor_fallback("mask and dest pixmaps are the same\n");
1067*4882a593Smuzhiyun return FALSE;
1068*4882a593Smuzhiyun }
1069*4882a593Smuzhiyun
1070*4882a593Smuzhiyun if (source->repeat)
1071*4882a593Smuzhiyun source_repeat_type = source->repeatType;
1072*4882a593Smuzhiyun else
1073*4882a593Smuzhiyun source_repeat_type = RepeatNone;
1074*4882a593Smuzhiyun
1075*4882a593Smuzhiyun if (mask && mask->repeat)
1076*4882a593Smuzhiyun mask_repeat_type = mask->repeatType;
1077*4882a593Smuzhiyun else
1078*4882a593Smuzhiyun mask_repeat_type = RepeatNone;
1079*4882a593Smuzhiyun
1080*4882a593Smuzhiyun if (glamor_pixmap_priv_is_large(dest_pixmap_priv)) {
1081*4882a593Smuzhiyun dest_block_width = __glamor_large(dest_pixmap_priv)->block_w;
1082*4882a593Smuzhiyun dest_block_height = __glamor_large(dest_pixmap_priv)->block_h;
1083*4882a593Smuzhiyun } else {
1084*4882a593Smuzhiyun dest_block_width = dest_pixmap->drawable.width;
1085*4882a593Smuzhiyun dest_block_height = dest_pixmap->drawable.height;
1086*4882a593Smuzhiyun }
1087*4882a593Smuzhiyun fixed_block_width = dest_block_width;
1088*4882a593Smuzhiyun fixed_block_height = dest_block_height;
1089*4882a593Smuzhiyun
1090*4882a593Smuzhiyun /* If we got an totally out-of-box region for a source or mask
1091*4882a593Smuzhiyun * region without repeat, we need to set it as null_source and
1092*4882a593Smuzhiyun * give it a solid color (0,0,0,0). */
1093*4882a593Smuzhiyun null_source = 0;
1094*4882a593Smuzhiyun null_mask = 0;
1095*4882a593Smuzhiyun RegionTranslate(region, -dest->pDrawable->x, -dest->pDrawable->y);
1096*4882a593Smuzhiyun
1097*4882a593Smuzhiyun /* need to transform the dest region to the correct sourcei/mask region.
1098*4882a593Smuzhiyun * it's a little complex, as one single edge of the
1099*4882a593Smuzhiyun * target region may be transformed to cross a block boundary of the
1100*4882a593Smuzhiyun * source or mask. Then it's impossible to handle it as usual way.
1101*4882a593Smuzhiyun * We may have to split the original dest region to smaller region, and
1102*4882a593Smuzhiyun * make sure each region's transformed region can fit into one texture,
1103*4882a593Smuzhiyun * and then continue this loop again, and each time when a transformed region
1104*4882a593Smuzhiyun * cross the bound, we need to copy it to a single pixmap and do the composition
1105*4882a593Smuzhiyun * with the new pixmap. If the transformed region doesn't cross a source/mask's
1106*4882a593Smuzhiyun * boundary then we don't need to copy.
1107*4882a593Smuzhiyun *
1108*4882a593Smuzhiyun */
1109*4882a593Smuzhiyun if (source_pixmap_priv
1110*4882a593Smuzhiyun && source->transform
1111*4882a593Smuzhiyun && glamor_pixmap_priv_is_large(source_pixmap_priv)) {
1112*4882a593Smuzhiyun int source_transformed_block_width, source_transformed_block_height;
1113*4882a593Smuzhiyun
1114*4882a593Smuzhiyun if (!glamor_get_transform_block_size(source->transform,
1115*4882a593Smuzhiyun __glamor_large(source_pixmap_priv)->block_w,
1116*4882a593Smuzhiyun __glamor_large(source_pixmap_priv)->block_h,
1117*4882a593Smuzhiyun &source_transformed_block_width,
1118*4882a593Smuzhiyun &source_transformed_block_height))
1119*4882a593Smuzhiyun {
1120*4882a593Smuzhiyun DEBUGF("source block size less than 1, fallback.\n");
1121*4882a593Smuzhiyun RegionTranslate(region, dest->pDrawable->x, dest->pDrawable->y);
1122*4882a593Smuzhiyun return FALSE;
1123*4882a593Smuzhiyun }
1124*4882a593Smuzhiyun fixed_block_width =
1125*4882a593Smuzhiyun min(fixed_block_width, source_transformed_block_width);
1126*4882a593Smuzhiyun fixed_block_height =
1127*4882a593Smuzhiyun min(fixed_block_height, source_transformed_block_height);
1128*4882a593Smuzhiyun DEBUGF("new source block size %d x %d \n", fixed_block_width,
1129*4882a593Smuzhiyun fixed_block_height);
1130*4882a593Smuzhiyun }
1131*4882a593Smuzhiyun
1132*4882a593Smuzhiyun if (mask_pixmap_priv
1133*4882a593Smuzhiyun && mask->transform && glamor_pixmap_priv_is_large(mask_pixmap_priv)) {
1134*4882a593Smuzhiyun int mask_transformed_block_width, mask_transformed_block_height;
1135*4882a593Smuzhiyun
1136*4882a593Smuzhiyun if (!glamor_get_transform_block_size(mask->transform,
1137*4882a593Smuzhiyun __glamor_large(mask_pixmap_priv)->block_w,
1138*4882a593Smuzhiyun __glamor_large(mask_pixmap_priv)->block_h,
1139*4882a593Smuzhiyun &mask_transformed_block_width,
1140*4882a593Smuzhiyun &mask_transformed_block_height)) {
1141*4882a593Smuzhiyun DEBUGF("mask block size less than 1, fallback.\n");
1142*4882a593Smuzhiyun RegionTranslate(region, dest->pDrawable->x, dest->pDrawable->y);
1143*4882a593Smuzhiyun return FALSE;
1144*4882a593Smuzhiyun }
1145*4882a593Smuzhiyun fixed_block_width =
1146*4882a593Smuzhiyun min(fixed_block_width, mask_transformed_block_width);
1147*4882a593Smuzhiyun fixed_block_height =
1148*4882a593Smuzhiyun min(fixed_block_height, mask_transformed_block_height);
1149*4882a593Smuzhiyun DEBUGF("new mask block size %d x %d \n", fixed_block_width,
1150*4882a593Smuzhiyun fixed_block_height);
1151*4882a593Smuzhiyun }
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun /*compute the correct block width and height whose transformed source/mask
1154*4882a593Smuzhiyun *region can fit into one texture.*/
1155*4882a593Smuzhiyun if (force_clip || fixed_block_width < dest_block_width
1156*4882a593Smuzhiyun || fixed_block_height < dest_block_height)
1157*4882a593Smuzhiyun clipped_dest_regions =
1158*4882a593Smuzhiyun glamor_compute_clipped_regions_ext(dest_pixmap, region,
1159*4882a593Smuzhiyun &n_dest_regions,
1160*4882a593Smuzhiyun fixed_block_width,
1161*4882a593Smuzhiyun fixed_block_height, 0, 0);
1162*4882a593Smuzhiyun else
1163*4882a593Smuzhiyun clipped_dest_regions = glamor_compute_clipped_regions(dest_pixmap,
1164*4882a593Smuzhiyun region,
1165*4882a593Smuzhiyun &n_dest_regions,
1166*4882a593Smuzhiyun 0, 0, 0);
1167*4882a593Smuzhiyun DEBUGF("dest clipped result %d region: \n", n_dest_regions);
1168*4882a593Smuzhiyun if (source_pixmap_priv
1169*4882a593Smuzhiyun && (source_pixmap_priv == dest_pixmap_priv ||
1170*4882a593Smuzhiyun source_pixmap_priv == mask_pixmap_priv)
1171*4882a593Smuzhiyun && glamor_pixmap_priv_is_large(source_pixmap_priv)) {
1172*4882a593Smuzhiyun /* XXX self-copy... */
1173*4882a593Smuzhiyun need_free_source_pixmap_priv = source_pixmap_priv;
1174*4882a593Smuzhiyun source_pixmap_priv = malloc(sizeof(*source_pixmap_priv));
1175*4882a593Smuzhiyun *source_pixmap_priv = *need_free_source_pixmap_priv;
1176*4882a593Smuzhiyun need_free_source_pixmap_priv = source_pixmap_priv;
1177*4882a593Smuzhiyun }
1178*4882a593Smuzhiyun assert(mask_pixmap_priv != dest_pixmap_priv);
1179*4882a593Smuzhiyun
1180*4882a593Smuzhiyun for (i = 0; i < n_dest_regions; i++) {
1181*4882a593Smuzhiyun DEBUGF("dest region %d idx %d\n", i,
1182*4882a593Smuzhiyun clipped_dest_regions[i].block_idx);
1183*4882a593Smuzhiyun DEBUGRegionPrint(clipped_dest_regions[i].region);
1184*4882a593Smuzhiyun glamor_set_pixmap_fbo_current(dest_pixmap_priv,
1185*4882a593Smuzhiyun clipped_dest_regions[i].block_idx);
1186*4882a593Smuzhiyun if (source_pixmap_priv &&
1187*4882a593Smuzhiyun glamor_pixmap_priv_is_large(source_pixmap_priv)) {
1188*4882a593Smuzhiyun if (!source->transform && source_repeat_type != RepeatPad) {
1189*4882a593Smuzhiyun RegionTranslate(clipped_dest_regions[i].region,
1190*4882a593Smuzhiyun x_source - x_dest, y_source - y_dest);
1191*4882a593Smuzhiyun clipped_source_regions =
1192*4882a593Smuzhiyun glamor_compute_clipped_regions(source_pixmap,
1193*4882a593Smuzhiyun clipped_dest_regions[i].
1194*4882a593Smuzhiyun region, &n_source_regions,
1195*4882a593Smuzhiyun source_repeat_type, 0, 0);
1196*4882a593Smuzhiyun is_normal_source_fbo = 1;
1197*4882a593Smuzhiyun }
1198*4882a593Smuzhiyun else {
1199*4882a593Smuzhiyun clipped_source_regions =
1200*4882a593Smuzhiyun glamor_compute_transform_clipped_regions(source_pixmap,
1201*4882a593Smuzhiyun source->transform,
1202*4882a593Smuzhiyun clipped_dest_regions
1203*4882a593Smuzhiyun [i].region,
1204*4882a593Smuzhiyun &n_source_regions,
1205*4882a593Smuzhiyun x_source - x_dest,
1206*4882a593Smuzhiyun y_source - y_dest,
1207*4882a593Smuzhiyun source_repeat_type,
1208*4882a593Smuzhiyun 0, 0);
1209*4882a593Smuzhiyun is_normal_source_fbo = 0;
1210*4882a593Smuzhiyun if (n_source_regions == 0) {
1211*4882a593Smuzhiyun /* Pad the out-of-box region to (0,0,0,0). */
1212*4882a593Smuzhiyun null_source = 1;
1213*4882a593Smuzhiyun n_source_regions = 1;
1214*4882a593Smuzhiyun }
1215*4882a593Smuzhiyun else
1216*4882a593Smuzhiyun _glamor_process_transformed_clipped_region
1217*4882a593Smuzhiyun (source_pixmap, source_pixmap_priv, source_repeat_type,
1218*4882a593Smuzhiyun clipped_source_regions, &n_source_regions,
1219*4882a593Smuzhiyun &need_clean_source_fbo);
1220*4882a593Smuzhiyun }
1221*4882a593Smuzhiyun DEBUGF("source clipped result %d region: \n", n_source_regions);
1222*4882a593Smuzhiyun for (j = 0; j < n_source_regions; j++) {
1223*4882a593Smuzhiyun if (is_normal_source_fbo)
1224*4882a593Smuzhiyun glamor_set_pixmap_fbo_current(source_pixmap_priv,
1225*4882a593Smuzhiyun clipped_source_regions[j].block_idx);
1226*4882a593Smuzhiyun
1227*4882a593Smuzhiyun if (mask_pixmap_priv &&
1228*4882a593Smuzhiyun glamor_pixmap_priv_is_large(mask_pixmap_priv)) {
1229*4882a593Smuzhiyun if (is_normal_mask_fbo && is_normal_source_fbo) {
1230*4882a593Smuzhiyun /* both mask and source are normal fbo box without transform or repeatpad.
1231*4882a593Smuzhiyun * The region is clipped against source and then we clip it against mask here.*/
1232*4882a593Smuzhiyun DEBUGF("source region %d idx %d\n", j,
1233*4882a593Smuzhiyun clipped_source_regions[j].block_idx);
1234*4882a593Smuzhiyun DEBUGRegionPrint(clipped_source_regions[j].region);
1235*4882a593Smuzhiyun RegionTranslate(clipped_source_regions[j].region,
1236*4882a593Smuzhiyun -x_source + x_mask, -y_source + y_mask);
1237*4882a593Smuzhiyun clipped_mask_regions =
1238*4882a593Smuzhiyun glamor_compute_clipped_regions(mask_pixmap,
1239*4882a593Smuzhiyun clipped_source_regions
1240*4882a593Smuzhiyun [j].region,
1241*4882a593Smuzhiyun &n_mask_regions,
1242*4882a593Smuzhiyun mask_repeat_type, 0,
1243*4882a593Smuzhiyun 0);
1244*4882a593Smuzhiyun is_normal_mask_fbo = 1;
1245*4882a593Smuzhiyun }
1246*4882a593Smuzhiyun else if (is_normal_mask_fbo && !is_normal_source_fbo) {
1247*4882a593Smuzhiyun assert(n_source_regions == 1);
1248*4882a593Smuzhiyun /* The source fbo is not a normal fbo box, it has transform or repeatpad.
1249*4882a593Smuzhiyun * the valid clip region should be the clip dest region rather than the
1250*4882a593Smuzhiyun * clip source region.*/
1251*4882a593Smuzhiyun RegionTranslate(clipped_dest_regions[i].region,
1252*4882a593Smuzhiyun -x_dest + x_mask, -y_dest + y_mask);
1253*4882a593Smuzhiyun clipped_mask_regions =
1254*4882a593Smuzhiyun glamor_compute_clipped_regions(mask_pixmap,
1255*4882a593Smuzhiyun clipped_dest_regions
1256*4882a593Smuzhiyun [i].region,
1257*4882a593Smuzhiyun &n_mask_regions,
1258*4882a593Smuzhiyun mask_repeat_type, 0,
1259*4882a593Smuzhiyun 0);
1260*4882a593Smuzhiyun is_normal_mask_fbo = 1;
1261*4882a593Smuzhiyun }
1262*4882a593Smuzhiyun else {
1263*4882a593Smuzhiyun /* This mask region has transform or repeatpad, we need clip it against the previous
1264*4882a593Smuzhiyun * valid region rather than the mask region. */
1265*4882a593Smuzhiyun if (!is_normal_source_fbo)
1266*4882a593Smuzhiyun clipped_mask_regions =
1267*4882a593Smuzhiyun glamor_compute_transform_clipped_regions
1268*4882a593Smuzhiyun (mask_pixmap, mask->transform,
1269*4882a593Smuzhiyun clipped_dest_regions[i].region,
1270*4882a593Smuzhiyun &n_mask_regions, x_mask - x_dest,
1271*4882a593Smuzhiyun y_mask - y_dest, mask_repeat_type, 0, 0);
1272*4882a593Smuzhiyun else
1273*4882a593Smuzhiyun clipped_mask_regions =
1274*4882a593Smuzhiyun glamor_compute_transform_clipped_regions
1275*4882a593Smuzhiyun (mask_pixmap, mask->transform,
1276*4882a593Smuzhiyun clipped_source_regions[j].region,
1277*4882a593Smuzhiyun &n_mask_regions, x_mask - x_source,
1278*4882a593Smuzhiyun y_mask - y_source, mask_repeat_type, 0, 0);
1279*4882a593Smuzhiyun is_normal_mask_fbo = 0;
1280*4882a593Smuzhiyun if (n_mask_regions == 0) {
1281*4882a593Smuzhiyun /* Pad the out-of-box region to (0,0,0,0). */
1282*4882a593Smuzhiyun null_mask = 1;
1283*4882a593Smuzhiyun n_mask_regions = 1;
1284*4882a593Smuzhiyun }
1285*4882a593Smuzhiyun else
1286*4882a593Smuzhiyun _glamor_process_transformed_clipped_region
1287*4882a593Smuzhiyun (mask_pixmap, mask_pixmap_priv, mask_repeat_type,
1288*4882a593Smuzhiyun clipped_mask_regions, &n_mask_regions,
1289*4882a593Smuzhiyun &need_clean_mask_fbo);
1290*4882a593Smuzhiyun }
1291*4882a593Smuzhiyun DEBUGF("mask clipped result %d region: \n", n_mask_regions);
1292*4882a593Smuzhiyun
1293*4882a593Smuzhiyun #define COMPOSITE_REGION(region) do { \
1294*4882a593Smuzhiyun if (!glamor_composite_clipped_region(op, \
1295*4882a593Smuzhiyun null_source ? NULL : source, \
1296*4882a593Smuzhiyun null_mask ? NULL : mask, dest, \
1297*4882a593Smuzhiyun null_source ? NULL : source_pixmap, \
1298*4882a593Smuzhiyun null_mask ? NULL : mask_pixmap, \
1299*4882a593Smuzhiyun dest_pixmap, region, \
1300*4882a593Smuzhiyun x_source, y_source, x_mask, y_mask, \
1301*4882a593Smuzhiyun x_dest, y_dest)) { \
1302*4882a593Smuzhiyun assert(0); \
1303*4882a593Smuzhiyun } \
1304*4882a593Smuzhiyun } while(0)
1305*4882a593Smuzhiyun
1306*4882a593Smuzhiyun for (k = 0; k < n_mask_regions; k++) {
1307*4882a593Smuzhiyun DEBUGF("mask region %d idx %d\n", k,
1308*4882a593Smuzhiyun clipped_mask_regions[k].block_idx);
1309*4882a593Smuzhiyun DEBUGRegionPrint(clipped_mask_regions[k].region);
1310*4882a593Smuzhiyun if (is_normal_mask_fbo) {
1311*4882a593Smuzhiyun glamor_set_pixmap_fbo_current(mask_pixmap_priv,
1312*4882a593Smuzhiyun clipped_mask_regions[k].
1313*4882a593Smuzhiyun block_idx);
1314*4882a593Smuzhiyun DEBUGF("mask fbo off %d %d \n",
1315*4882a593Smuzhiyun __glamor_large(mask_pixmap_priv)->box.x1,
1316*4882a593Smuzhiyun __glamor_large(mask_pixmap_priv)->box.y1);
1317*4882a593Smuzhiyun DEBUGF("start composite mask hasn't transform.\n");
1318*4882a593Smuzhiyun RegionTranslate(clipped_mask_regions[k].region,
1319*4882a593Smuzhiyun x_dest - x_mask +
1320*4882a593Smuzhiyun dest->pDrawable->x,
1321*4882a593Smuzhiyun y_dest - y_mask +
1322*4882a593Smuzhiyun dest->pDrawable->y);
1323*4882a593Smuzhiyun COMPOSITE_REGION(clipped_mask_regions[k].region);
1324*4882a593Smuzhiyun }
1325*4882a593Smuzhiyun else if (!is_normal_mask_fbo && !is_normal_source_fbo) {
1326*4882a593Smuzhiyun DEBUGF
1327*4882a593Smuzhiyun ("start composite both mask and source have transform.\n");
1328*4882a593Smuzhiyun RegionTranslate(clipped_dest_regions[i].region,
1329*4882a593Smuzhiyun dest->pDrawable->x,
1330*4882a593Smuzhiyun dest->pDrawable->y);
1331*4882a593Smuzhiyun COMPOSITE_REGION(clipped_dest_regions[i].region);
1332*4882a593Smuzhiyun }
1333*4882a593Smuzhiyun else {
1334*4882a593Smuzhiyun DEBUGF
1335*4882a593Smuzhiyun ("start composite only mask has transform.\n");
1336*4882a593Smuzhiyun RegionTranslate(clipped_source_regions[j].region,
1337*4882a593Smuzhiyun x_dest - x_source +
1338*4882a593Smuzhiyun dest->pDrawable->x,
1339*4882a593Smuzhiyun y_dest - y_source +
1340*4882a593Smuzhiyun dest->pDrawable->y);
1341*4882a593Smuzhiyun COMPOSITE_REGION(clipped_source_regions[j].region);
1342*4882a593Smuzhiyun }
1343*4882a593Smuzhiyun RegionDestroy(clipped_mask_regions[k].region);
1344*4882a593Smuzhiyun }
1345*4882a593Smuzhiyun free(clipped_mask_regions);
1346*4882a593Smuzhiyun if (null_mask)
1347*4882a593Smuzhiyun null_mask = 0;
1348*4882a593Smuzhiyun if (need_clean_mask_fbo) {
1349*4882a593Smuzhiyun assert(is_normal_mask_fbo == 0);
1350*4882a593Smuzhiyun glamor_destroy_fbo(glamor_priv, mask_pixmap_priv->fbo);
1351*4882a593Smuzhiyun mask_pixmap_priv->fbo = NULL;
1352*4882a593Smuzhiyun need_clean_mask_fbo = 0;
1353*4882a593Smuzhiyun }
1354*4882a593Smuzhiyun }
1355*4882a593Smuzhiyun else {
1356*4882a593Smuzhiyun if (is_normal_source_fbo) {
1357*4882a593Smuzhiyun RegionTranslate(clipped_source_regions[j].region,
1358*4882a593Smuzhiyun -x_source + x_dest + dest->pDrawable->x,
1359*4882a593Smuzhiyun -y_source + y_dest +
1360*4882a593Smuzhiyun dest->pDrawable->y);
1361*4882a593Smuzhiyun COMPOSITE_REGION(clipped_source_regions[j].region);
1362*4882a593Smuzhiyun }
1363*4882a593Smuzhiyun else {
1364*4882a593Smuzhiyun /* Source has transform or repeatPad. dest regions is the right
1365*4882a593Smuzhiyun * region to do the composite. */
1366*4882a593Smuzhiyun RegionTranslate(clipped_dest_regions[i].region,
1367*4882a593Smuzhiyun dest->pDrawable->x, dest->pDrawable->y);
1368*4882a593Smuzhiyun COMPOSITE_REGION(clipped_dest_regions[i].region);
1369*4882a593Smuzhiyun }
1370*4882a593Smuzhiyun }
1371*4882a593Smuzhiyun if (clipped_source_regions && clipped_source_regions[j].region)
1372*4882a593Smuzhiyun RegionDestroy(clipped_source_regions[j].region);
1373*4882a593Smuzhiyun }
1374*4882a593Smuzhiyun free(clipped_source_regions);
1375*4882a593Smuzhiyun if (null_source)
1376*4882a593Smuzhiyun null_source = 0;
1377*4882a593Smuzhiyun if (need_clean_source_fbo) {
1378*4882a593Smuzhiyun assert(is_normal_source_fbo == 0);
1379*4882a593Smuzhiyun glamor_destroy_fbo(glamor_priv, source_pixmap_priv->fbo);
1380*4882a593Smuzhiyun source_pixmap_priv->fbo = NULL;
1381*4882a593Smuzhiyun need_clean_source_fbo = 0;
1382*4882a593Smuzhiyun }
1383*4882a593Smuzhiyun }
1384*4882a593Smuzhiyun else {
1385*4882a593Smuzhiyun if (mask_pixmap_priv &&
1386*4882a593Smuzhiyun glamor_pixmap_priv_is_large(mask_pixmap_priv)) {
1387*4882a593Smuzhiyun if (!mask->transform && mask_repeat_type != RepeatPad) {
1388*4882a593Smuzhiyun RegionTranslate(clipped_dest_regions[i].region,
1389*4882a593Smuzhiyun x_mask - x_dest, y_mask - y_dest);
1390*4882a593Smuzhiyun clipped_mask_regions =
1391*4882a593Smuzhiyun glamor_compute_clipped_regions(mask_pixmap,
1392*4882a593Smuzhiyun clipped_dest_regions[i].
1393*4882a593Smuzhiyun region, &n_mask_regions,
1394*4882a593Smuzhiyun mask_repeat_type, 0, 0);
1395*4882a593Smuzhiyun is_normal_mask_fbo = 1;
1396*4882a593Smuzhiyun }
1397*4882a593Smuzhiyun else {
1398*4882a593Smuzhiyun clipped_mask_regions =
1399*4882a593Smuzhiyun glamor_compute_transform_clipped_regions
1400*4882a593Smuzhiyun (mask_pixmap, mask->transform,
1401*4882a593Smuzhiyun clipped_dest_regions[i].region, &n_mask_regions,
1402*4882a593Smuzhiyun x_mask - x_dest, y_mask - y_dest, mask_repeat_type, 0,
1403*4882a593Smuzhiyun 0);
1404*4882a593Smuzhiyun is_normal_mask_fbo = 0;
1405*4882a593Smuzhiyun if (n_mask_regions == 0) {
1406*4882a593Smuzhiyun /* Pad the out-of-box region to (0,0,0,0). */
1407*4882a593Smuzhiyun null_mask = 1;
1408*4882a593Smuzhiyun n_mask_regions = 1;
1409*4882a593Smuzhiyun }
1410*4882a593Smuzhiyun else
1411*4882a593Smuzhiyun _glamor_process_transformed_clipped_region
1412*4882a593Smuzhiyun (mask_pixmap, mask_pixmap_priv, mask_repeat_type,
1413*4882a593Smuzhiyun clipped_mask_regions, &n_mask_regions,
1414*4882a593Smuzhiyun &need_clean_mask_fbo);
1415*4882a593Smuzhiyun }
1416*4882a593Smuzhiyun
1417*4882a593Smuzhiyun for (k = 0; k < n_mask_regions; k++) {
1418*4882a593Smuzhiyun DEBUGF("mask region %d idx %d\n", k,
1419*4882a593Smuzhiyun clipped_mask_regions[k].block_idx);
1420*4882a593Smuzhiyun DEBUGRegionPrint(clipped_mask_regions[k].region);
1421*4882a593Smuzhiyun if (is_normal_mask_fbo) {
1422*4882a593Smuzhiyun glamor_set_pixmap_fbo_current(mask_pixmap_priv,
1423*4882a593Smuzhiyun clipped_mask_regions[k].
1424*4882a593Smuzhiyun block_idx);
1425*4882a593Smuzhiyun RegionTranslate(clipped_mask_regions[k].region,
1426*4882a593Smuzhiyun x_dest - x_mask + dest->pDrawable->x,
1427*4882a593Smuzhiyun y_dest - y_mask + dest->pDrawable->y);
1428*4882a593Smuzhiyun COMPOSITE_REGION(clipped_mask_regions[k].region);
1429*4882a593Smuzhiyun }
1430*4882a593Smuzhiyun else {
1431*4882a593Smuzhiyun RegionTranslate(clipped_dest_regions[i].region,
1432*4882a593Smuzhiyun dest->pDrawable->x, dest->pDrawable->y);
1433*4882a593Smuzhiyun COMPOSITE_REGION(clipped_dest_regions[i].region);
1434*4882a593Smuzhiyun }
1435*4882a593Smuzhiyun RegionDestroy(clipped_mask_regions[k].region);
1436*4882a593Smuzhiyun }
1437*4882a593Smuzhiyun free(clipped_mask_regions);
1438*4882a593Smuzhiyun if (null_mask)
1439*4882a593Smuzhiyun null_mask = 0;
1440*4882a593Smuzhiyun if (need_clean_mask_fbo) {
1441*4882a593Smuzhiyun glamor_destroy_fbo(glamor_priv, mask_pixmap_priv->fbo);
1442*4882a593Smuzhiyun mask_pixmap_priv->fbo = NULL;
1443*4882a593Smuzhiyun need_clean_mask_fbo = 0;
1444*4882a593Smuzhiyun }
1445*4882a593Smuzhiyun }
1446*4882a593Smuzhiyun else {
1447*4882a593Smuzhiyun RegionTranslate(clipped_dest_regions[i].region,
1448*4882a593Smuzhiyun dest->pDrawable->x, dest->pDrawable->y);
1449*4882a593Smuzhiyun COMPOSITE_REGION(clipped_dest_regions[i].region);
1450*4882a593Smuzhiyun }
1451*4882a593Smuzhiyun }
1452*4882a593Smuzhiyun RegionDestroy(clipped_dest_regions[i].region);
1453*4882a593Smuzhiyun }
1454*4882a593Smuzhiyun free(clipped_dest_regions);
1455*4882a593Smuzhiyun free(need_free_source_pixmap_priv);
1456*4882a593Smuzhiyun free(need_free_mask_pixmap_priv);
1457*4882a593Smuzhiyun ok = TRUE;
1458*4882a593Smuzhiyun return ok;
1459*4882a593Smuzhiyun }
1460