2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Zhigang Gong <zhigang.gong@linux.intel.com>
26 * original author is Chris Wilson at sna.
30 #include "glamor_priv.h"
34 /** @file glamor_compositerects.
36 * compositeRects acceleration implementation
40 bound(int16_t a
, uint16_t b
)
42 int v
= (int) a
+ (int) b
;
50 _pixman_region_init_clipped_rectangles(pixman_region16_t
* region
,
51 unsigned int num_rects
,
53 int tx
, int ty
, BoxPtr extents
)
55 pixman_box16_t stack_boxes
[64], *boxes
= stack_boxes
;
59 if (num_rects
> ARRAY_SIZE(stack_boxes
)) {
60 boxes
= xallocarray(num_rects
, sizeof(pixman_box16_t
));
65 for (i
= j
= 0; i
< num_rects
; i
++) {
66 boxes
[j
].x1
= rects
[i
].x
+ tx
;
67 if (boxes
[j
].x1
< extents
->x1
)
68 boxes
[j
].x1
= extents
->x1
;
70 boxes
[j
].y1
= rects
[i
].y
+ ty
;
71 if (boxes
[j
].y1
< extents
->y1
)
72 boxes
[j
].y1
= extents
->y1
;
74 boxes
[j
].x2
= bound(rects
[i
].x
+ tx
, rects
[i
].width
);
75 if (boxes
[j
].x2
> extents
->x2
)
76 boxes
[j
].x2
= extents
->x2
;
78 boxes
[j
].y2
= bound(rects
[i
].y
+ ty
, rects
[i
].height
);
79 if (boxes
[j
].y2
> extents
->y2
)
80 boxes
[j
].y2
= extents
->y2
;
82 if (boxes
[j
].x2
> boxes
[j
].x1
&& boxes
[j
].y2
> boxes
[j
].y1
)
88 ret
= pixman_region_init_rects(region
, boxes
, j
);
90 if (boxes
!= stack_boxes
)
93 DEBUGF("%s: nrects=%d, region=(%d, %d), (%d, %d) x %d\n",
94 __FUNCTION__
, num_rects
,
95 region
->extents
.x1
, region
->extents
.y1
,
96 region
->extents
.x2
, region
->extents
.y2
, j
);
101 glamor_composite_rectangles(CARD8 op
,
103 xRenderColor
* color
,
104 int num_rects
, xRectangle
*rects
)
107 struct glamor_pixmap_private
*priv
;
108 pixman_region16_t region
;
109 pixman_box16_t
*boxes
;
111 PicturePtr source
= NULL
;
112 Bool need_free_region
= FALSE
;
114 DEBUGF("%s(op=%d, %08x x %d [(%d, %d)x(%d, %d) ...])\n",
116 (color
->alpha
>> 8 << 24) |
117 (color
->red
>> 8 << 16) |
118 (color
->green
>> 8 << 8) |
119 (color
->blue
>> 8 << 0),
120 num_rects
, rects
[0].x
, rects
[0].y
, rects
[0].width
, rects
[0].height
);
125 if (RegionNil(dst
->pCompositeClip
)) {
126 DEBUGF("%s: empty clip, skipping\n", __FUNCTION__
);
130 if ((color
->red
| color
->green
| color
->blue
| color
->alpha
) <= 0x00ff) {
133 case PictOpOutReverse
:
136 case PictOpInReverse
:
140 case PictOpAtopReverse
:
144 op
= PictOpOverReverse
;
148 if (color
->alpha
<= 0x00ff) {
151 case PictOpOutReverse
:
153 case PictOpInReverse
:
156 case PictOpAtopReverse
:
160 op
= PictOpOverReverse
;
164 else if (color
->alpha
>= 0xff00) {
169 case PictOpInReverse
:
171 case PictOpOutReverse
:
174 case PictOpAtopReverse
:
175 op
= PictOpOverReverse
;
182 DEBUGF("%s: converted to op %d\n", __FUNCTION__
, op
);
184 if (!_pixman_region_init_clipped_rectangles(®ion
,
188 &dst
->pCompositeClip
->extents
))
190 DEBUGF("%s: allocation failed for region\n", __FUNCTION__
);
194 pixmap
= glamor_get_drawable_pixmap(dst
->pDrawable
);
195 priv
= glamor_get_pixmap_private(pixmap
);
197 if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(priv
))
200 DEBUGF("%s: fallback, dst has an alpha-map\n", __FUNCTION__
);
204 need_free_region
= TRUE
;
206 DEBUGF("%s: drawable extents (%d, %d),(%d, %d) x %d\n",
208 RegionExtents(®ion
)->x1
, RegionExtents(®ion
)->y1
,
209 RegionExtents(®ion
)->x2
, RegionExtents(®ion
)->y2
,
210 RegionNumRects(®ion
));
212 if (dst
->pCompositeClip
->data
&&
213 (!pixman_region_intersect(®ion
, ®ion
, dst
->pCompositeClip
) ||
214 RegionNil(®ion
))) {
215 DEBUGF("%s: zero-intersection between rectangles and clip\n",
217 pixman_region_fini(®ion
);
221 DEBUGF("%s: clipped extents (%d, %d),(%d, %d) x %d\n",
223 RegionExtents(®ion
)->x1
, RegionExtents(®ion
)->y1
,
224 RegionExtents(®ion
)->x2
, RegionExtents(®ion
)->y2
,
225 RegionNumRects(®ion
));
227 boxes
= pixman_region_rectangles(®ion
, &num_boxes
);
228 if (op
== PictOpSrc
|| op
== PictOpClear
) {
231 pixman_region_translate(®ion
, -dst
->pDrawable
->x
, -dst
->pDrawable
->y
);
233 DEBUGF("%s: drawable extents (%d, %d),(%d, %d)\n",
234 __FUNCTION__
, dst_x
, dst_y
,
235 RegionExtents(®ion
)->x1
, RegionExtents(®ion
)->y1
,
236 RegionExtents(®ion
)->x2
, RegionExtents(®ion
)->y2
);
238 if (op
== PictOpClear
)
241 miRenderColorToPixel(dst
->pFormat
, color
, &pixel
);
242 glamor_solid_boxes(dst
->pDrawable
, boxes
, num_boxes
, pixel
);
247 if (_X_LIKELY(glamor_pixmap_priv_is_small(priv
))) {
250 source
= CreateSolidPicture(0, color
, &error
);
253 if (glamor_composite_clipped_region(op
, source
,
256 ®ion
, 0, 0, 0, 0, 0, 0))
261 miCompositeRects(op
, dst
, color
, num_rects
, rects
);
263 /* XXX xserver-1.8: CompositeRects is not tracked by Damage, so we must
264 * manually append the damaged regions ourselves.
266 DamageRegionAppend(&pixmap
->drawable
, ®ion
);
267 DamageRegionProcessPending(&pixmap
->drawable
);
269 if (need_free_region
)
270 pixman_region_fini(®ion
);
272 FreePicture(source
, 0);