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 * Junyan He <junyan.he@linux.intel.com>
28 /** @file glamor_trapezoid.c
30 * Trapezoid acceleration implementation
33 #include "glamor_priv.h"
39 * Creates an appropriate picture for temp mask use.
42 glamor_create_mask_picture(ScreenPtr screen
,
44 PictFormatPtr pict_format
,
45 CARD16 width
, CARD16 height
)
52 if (dst
->polyEdge
== PolyEdgeSharp
)
53 pict_format
= PictureMatchFormat(screen
, 1, PICT_a1
);
55 pict_format
= PictureMatchFormat(screen
, 8, PICT_a8
);
60 pixmap
= glamor_create_pixmap(screen
, 0, 0,
62 GLAMOR_CREATE_PIXMAP_CPU
);
66 picture
= CreatePicture(0, &pixmap
->drawable
, pict_format
,
67 0, 0, serverClient
, &error
);
68 glamor_destroy_pixmap(pixmap
);
73 * glamor_trapezoids will generate trapezoid mask accumulating in
77 glamor_trapezoids(CARD8 op
,
78 PicturePtr src
, PicturePtr dst
,
79 PictFormatPtr mask_format
, INT16 x_src
, INT16 y_src
,
80 int ntrap
, xTrapezoid
*traps
)
82 ScreenPtr screen
= dst
->pDrawable
->pScreen
;
87 int width
, height
, stride
;
89 pixman_image_t
*image
= NULL
;
91 /* If a mask format wasn't provided, we get to choose, but behavior should
92 * be as if there was no temporary mask the traps were accumulated into.
95 if (dst
->polyEdge
== PolyEdgeSharp
)
96 mask_format
= PictureMatchFormat(screen
, 1, PICT_a1
);
98 mask_format
= PictureMatchFormat(screen
, 8, PICT_a8
);
99 for (; ntrap
; ntrap
--, traps
++)
100 glamor_trapezoids(op
, src
, dst
, mask_format
, x_src
,
105 miTrapezoidBounds(ntrap
, traps
, &bounds
);
107 if (bounds
.y1
>= bounds
.y2
|| bounds
.x1
>= bounds
.x2
)
110 x_dst
= traps
[0].left
.p1
.x
>> 16;
111 y_dst
= traps
[0].left
.p1
.y
>> 16;
113 width
= bounds
.x2
- bounds
.x1
;
114 height
= bounds
.y2
- bounds
.y1
;
115 stride
= PixmapBytePad(width
, mask_format
->depth
);
117 picture
= glamor_create_mask_picture(screen
, dst
, mask_format
,
122 image
= pixman_image_create_bits(picture
->format
,
123 width
, height
, NULL
, stride
);
125 FreePicture(picture
, 0);
129 for (; ntrap
; ntrap
--, traps
++)
130 pixman_rasterize_trapezoid(image
,
131 (pixman_trapezoid_t
*) traps
,
132 -bounds
.x1
, -bounds
.y1
);
134 pixmap
= glamor_get_drawable_pixmap(picture
->pDrawable
);
136 screen
->ModifyPixmapHeader(pixmap
, width
, height
,
138 BitsPerPixel(mask_format
->depth
),
141 pixman_image_get_data(image
));
143 x_rel
= bounds
.x1
+ x_src
- x_dst
;
144 y_rel
= bounds
.y1
+ y_src
- y_dst
;
146 CompositePicture(op
, src
, picture
, dst
,
149 bounds
.x1
, bounds
.y1
,
150 bounds
.x2
- bounds
.x1
, bounds
.y2
- bounds
.y1
);
153 pixman_image_unref(image
);
155 FreePicture(picture
, 0);