1 /* Copyright © 2000 Keith Packard
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation, and that the name of Keith Packard not be used in
8 * advertising or publicity pertaining to distribution of the software without
9 * specific, written prior permission. Keith Packard makes no
10 * representations about the suitability of this software for any purpose. It
11 * is provided "as is" without express or implied warranty.
13 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
14 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
15 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
17 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
22 #include "xcb_renderutil.h"
24 xcb_render_pictvisual_t *
25 xcb_render_util_find_visual_format (const xcb_render_query_pict_formats_reply_t *formats,
26 const xcb_visualid_t visual)
28 xcb_render_pictscreen_iterator_t screens;
29 xcb_render_pictdepth_iterator_t depths;
30 xcb_render_pictvisual_iterator_t visuals;
33 for (screens = xcb_render_query_pict_formats_screens_iterator(formats); screens.rem; xcb_render_pictscreen_next(&screens))
34 for (depths = xcb_render_pictscreen_depths_iterator(screens.data); depths.rem; xcb_render_pictdepth_next(&depths))
35 for (visuals = xcb_render_pictdepth_visuals_iterator(depths.data); visuals.rem; xcb_render_pictvisual_next(&visuals))
36 if (visuals.data->visual == visual)
41 xcb_render_pictforminfo_t *
42 xcb_render_util_find_format (const xcb_render_query_pict_formats_reply_t *formats,
44 const xcb_render_pictforminfo_t *template,
47 xcb_render_pictforminfo_iterator_t i;
50 for (i = xcb_render_query_pict_formats_formats_iterator(formats); i.rem; xcb_render_pictforminfo_next(&i))
52 if (mask & XCB_PICT_FORMAT_ID)
53 if (template->id != i.data->id)
55 if (mask & XCB_PICT_FORMAT_TYPE)
56 if (template->type != i.data->type)
58 if (mask & XCB_PICT_FORMAT_DEPTH)
59 if (template->depth != i.data->depth)
61 if (mask & XCB_PICT_FORMAT_RED)
62 if (template->direct.red_shift != i.data->direct.red_shift)
64 if (mask & XCB_PICT_FORMAT_RED_MASK)
65 if (template->direct.red_mask != i.data->direct.red_mask)
67 if (mask & XCB_PICT_FORMAT_GREEN)
68 if (template->direct.green_shift != i.data->direct.green_shift)
70 if (mask & XCB_PICT_FORMAT_GREEN_MASK)
71 if (template->direct.green_mask != i.data->direct.green_mask)
73 if (mask & XCB_PICT_FORMAT_BLUE)
74 if (template->direct.blue_shift != i.data->direct.blue_shift)
76 if (mask & XCB_PICT_FORMAT_BLUE_MASK)
77 if (template->direct.blue_mask != i.data->direct.blue_mask)
79 if (mask & XCB_PICT_FORMAT_ALPHA)
80 if (template->direct.alpha_shift != i.data->direct.alpha_shift)
82 if (mask & XCB_PICT_FORMAT_ALPHA_MASK)
83 if (template->direct.alpha_mask != i.data->direct.alpha_mask)
85 if (mask & XCB_PICT_FORMAT_COLORMAP)
86 if (template->colormap != i.data->colormap)
94 xcb_render_pictforminfo_t *
95 xcb_render_util_find_standard_format (const xcb_render_query_pict_formats_reply_t *formats,
96 xcb_pict_standard_t format)
99 xcb_render_pictforminfo_t templ;
101 } standardFormats[] = {
102 /* XCB_PICT_STANDARD_ARGB_32 */
106 XCB_RENDER_PICT_TYPE_DIRECT, /* type */
111 0xff, /* direct.red_mask */
112 8, /* direct.green */
113 0xff, /* direct.green_mask */
115 0xff, /* direct.blue_mask */
116 24, /* direct.alpha */
117 0xff, /* direct.alpha_mask */
121 XCB_PICT_FORMAT_TYPE |
122 XCB_PICT_FORMAT_DEPTH |
123 XCB_PICT_FORMAT_RED |
124 XCB_PICT_FORMAT_RED_MASK |
125 XCB_PICT_FORMAT_GREEN |
126 XCB_PICT_FORMAT_GREEN_MASK |
127 XCB_PICT_FORMAT_BLUE |
128 XCB_PICT_FORMAT_BLUE_MASK |
129 XCB_PICT_FORMAT_ALPHA |
130 XCB_PICT_FORMAT_ALPHA_MASK,
132 /* XCB_PICT_STANDARD_RGB_24 */
136 XCB_RENDER_PICT_TYPE_DIRECT, /* type */
141 0xff, /* direct.red_MASK */
142 8, /* direct.green */
143 0xff, /* direct.green_MASK */
145 0xff, /* direct.blue_MASK */
146 0, /* direct.alpha */
147 0x00, /* direct.alpha_MASK */
151 XCB_PICT_FORMAT_TYPE |
152 XCB_PICT_FORMAT_DEPTH |
153 XCB_PICT_FORMAT_RED |
154 XCB_PICT_FORMAT_RED_MASK |
155 XCB_PICT_FORMAT_GREEN |
156 XCB_PICT_FORMAT_GREEN_MASK |
157 XCB_PICT_FORMAT_BLUE |
158 XCB_PICT_FORMAT_BLUE_MASK |
159 XCB_PICT_FORMAT_ALPHA_MASK,
161 /* XCB_PICT_STANDARD_A_8 */
165 XCB_RENDER_PICT_TYPE_DIRECT, /* type */
170 0x00, /* direct.red_MASK */
171 0, /* direct.green */
172 0x00, /* direct.green_MASK */
174 0x00, /* direct.blue_MASK */
175 0, /* direct.alpha */
176 0xff, /* direct.alpha_MASK */
180 XCB_PICT_FORMAT_TYPE |
181 XCB_PICT_FORMAT_DEPTH |
182 XCB_PICT_FORMAT_RED_MASK |
183 XCB_PICT_FORMAT_GREEN_MASK |
184 XCB_PICT_FORMAT_BLUE_MASK |
185 XCB_PICT_FORMAT_ALPHA |
186 XCB_PICT_FORMAT_ALPHA_MASK,
188 /* XCB_PICT_STANDARD_A_4 */
192 XCB_RENDER_PICT_TYPE_DIRECT, /* type */
197 0x00, /* direct.red_MASK */
198 0, /* direct.green */
199 0x00, /* direct.green_MASK */
201 0x00, /* direct.blue_MASK */
202 0, /* direct.alpha */
203 0x0f, /* direct.alpha_MASK */
207 XCB_PICT_FORMAT_TYPE |
208 XCB_PICT_FORMAT_DEPTH |
209 XCB_PICT_FORMAT_RED_MASK |
210 XCB_PICT_FORMAT_GREEN_MASK |
211 XCB_PICT_FORMAT_BLUE_MASK |
212 XCB_PICT_FORMAT_ALPHA |
213 XCB_PICT_FORMAT_ALPHA_MASK,
215 /* XCB_PICT_STANDARD_A_1 */
219 XCB_RENDER_PICT_TYPE_DIRECT, /* type */
224 0x00, /* direct.red_MASK */
225 0, /* direct.green */
226 0x00, /* direct.green_MASK */
228 0x00, /* direct.blue_MASK */
229 0, /* direct.alpha */
230 0x01, /* direct.alpha_MASK */
234 XCB_PICT_FORMAT_TYPE |
235 XCB_PICT_FORMAT_DEPTH |
236 XCB_PICT_FORMAT_RED_MASK |
237 XCB_PICT_FORMAT_GREEN_MASK |
238 XCB_PICT_FORMAT_BLUE_MASK |
239 XCB_PICT_FORMAT_ALPHA |
240 XCB_PICT_FORMAT_ALPHA_MASK,
244 if (format < 0 || format >= sizeof(standardFormats) / sizeof(*standardFormats))
247 return xcb_render_util_find_format (formats,
248 standardFormats[format].mask,
249 &standardFormats[format].templ,