| 1 |
/* Copyright © 2000 Keith Packard |
| 2 |
* |
| 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. |
| 12 |
* |
| 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. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifdef HAVE_CONFIG_H |
| 23 |
#include "config.h" |
| 24 |
#endif |
| 25 |
|
| 26 |
#include "xcb_renderutil.h" |
| 27 |
|
| 28 |
xcb_render_pictvisual_t * |
| 29 |
xcb_render_util_find_visual_format (const xcb_render_query_pict_formats_reply_t *formats, |
| 30 |
const xcb_visualid_t visual) |
| 31 |
{ |
| 32 |
xcb_render_pictscreen_iterator_t screens; |
| 33 |
xcb_render_pictdepth_iterator_t depths; |
| 34 |
xcb_render_pictvisual_iterator_t visuals; |
| 35 |
if (!formats) |
| 36 |
return 0; |
| 37 |
for (screens = xcb_render_query_pict_formats_screens_iterator(formats); screens.rem; xcb_render_pictscreen_next(&screens)) |
| 38 |
for (depths = xcb_render_pictscreen_depths_iterator(screens.data); depths.rem; xcb_render_pictdepth_next(&depths)) |
| 39 |
for (visuals = xcb_render_pictdepth_visuals_iterator(depths.data); visuals.rem; xcb_render_pictvisual_next(&visuals)) |
| 40 |
if (visuals.data->visual == visual) |
| 41 |
return visuals.data; |
| 42 |
return 0; |
| 43 |
} |
| 44 |
|
| 45 |
xcb_render_pictforminfo_t * |
| 46 |
xcb_render_util_find_format (const xcb_render_query_pict_formats_reply_t *formats, |
| 47 |
unsigned long mask, |
| 48 |
const xcb_render_pictforminfo_t *ptemplate, |
| 49 |
int count) |
| 50 |
{ |
| 51 |
xcb_render_pictforminfo_iterator_t i; |
| 52 |
if (!formats) |
| 53 |
return 0; |
| 54 |
for (i = xcb_render_query_pict_formats_formats_iterator(formats); i.rem; xcb_render_pictforminfo_next(&i)) |
| 55 |
{ |
| 56 |
if (mask & XCB_PICT_FORMAT_ID) |
| 57 |
if (ptemplate->id != i.data->id) |
| 58 |
continue; |
| 59 |
if (mask & XCB_PICT_FORMAT_TYPE) |
| 60 |
if (ptemplate->type != i.data->type) |
| 61 |
continue; |
| 62 |
if (mask & XCB_PICT_FORMAT_DEPTH) |
| 63 |
if (ptemplate->depth != i.data->depth) |
| 64 |
continue; |
| 65 |
if (mask & XCB_PICT_FORMAT_RED) |
| 66 |
if (ptemplate->direct.red_shift != i.data->direct.red_shift) |
| 67 |
continue; |
| 68 |
if (mask & XCB_PICT_FORMAT_RED_MASK) |
| 69 |
if (ptemplate->direct.red_mask != i.data->direct.red_mask) |
| 70 |
continue; |
| 71 |
if (mask & XCB_PICT_FORMAT_GREEN) |
| 72 |
if (ptemplate->direct.green_shift != i.data->direct.green_shift) |
| 73 |
continue; |
| 74 |
if (mask & XCB_PICT_FORMAT_GREEN_MASK) |
| 75 |
if (ptemplate->direct.green_mask != i.data->direct.green_mask) |
| 76 |
continue; |
| 77 |
if (mask & XCB_PICT_FORMAT_BLUE) |
| 78 |
if (ptemplate->direct.blue_shift != i.data->direct.blue_shift) |
| 79 |
continue; |
| 80 |
if (mask & XCB_PICT_FORMAT_BLUE_MASK) |
| 81 |
if (ptemplate->direct.blue_mask != i.data->direct.blue_mask) |
| 82 |
continue; |
| 83 |
if (mask & XCB_PICT_FORMAT_ALPHA) |
| 84 |
if (ptemplate->direct.alpha_shift != i.data->direct.alpha_shift) |
| 85 |
continue; |
| 86 |
if (mask & XCB_PICT_FORMAT_ALPHA_MASK) |
| 87 |
if (ptemplate->direct.alpha_mask != i.data->direct.alpha_mask) |
| 88 |
continue; |
| 89 |
if (mask & XCB_PICT_FORMAT_COLORMAP) |
| 90 |
if (ptemplate->colormap != i.data->colormap) |
| 91 |
continue; |
| 92 |
if (count-- == 0) |
| 93 |
return i.data; |
| 94 |
} |
| 95 |
return 0; |
| 96 |
} |
| 97 |
|
| 98 |
xcb_render_pictforminfo_t * |
| 99 |
xcb_render_util_find_standard_format (const xcb_render_query_pict_formats_reply_t *formats, |
| 100 |
xcb_pict_standard_t format) |
| 101 |
{ |
| 102 |
static const struct { |
| 103 |
xcb_render_pictforminfo_t templ; |
| 104 |
unsigned long mask; |
| 105 |
} standardFormats[] = { |
| 106 |
/* XCB_PICT_STANDARD_ARGB_32 */ |
| 107 |
{ |
| 108 |
{ |
| 109 |
0, /* id */ |
| 110 |
XCB_RENDER_PICT_TYPE_DIRECT, /* type */ |
| 111 |
32, /* depth */ |
| 112 |
{ 0 }, /* pad */ |
| 113 |
{ /* direct */ |
| 114 |
16, /* direct.red */ |
| 115 |
0xff, /* direct.red_mask */ |
| 116 |
8, /* direct.green */ |
| 117 |
0xff, /* direct.green_mask */ |
| 118 |
0, /* direct.blue */ |
| 119 |
0xff, /* direct.blue_mask */ |
| 120 |
24, /* direct.alpha */ |
| 121 |
0xff, /* direct.alpha_mask */ |
| 122 |
}, |
| 123 |
0, /* colormap */ |
| 124 |
}, |
| 125 |
XCB_PICT_FORMAT_TYPE | |
| 126 |
XCB_PICT_FORMAT_DEPTH | |
| 127 |
XCB_PICT_FORMAT_RED | |
| 128 |
XCB_PICT_FORMAT_RED_MASK | |
| 129 |
XCB_PICT_FORMAT_GREEN | |
| 130 |
XCB_PICT_FORMAT_GREEN_MASK | |
| 131 |
XCB_PICT_FORMAT_BLUE | |
| 132 |
XCB_PICT_FORMAT_BLUE_MASK | |
| 133 |
XCB_PICT_FORMAT_ALPHA | |
| 134 |
XCB_PICT_FORMAT_ALPHA_MASK, |
| 135 |
}, |
| 136 |
/* XCB_PICT_STANDARD_RGB_24 */ |
| 137 |
{ |
| 138 |
{ |
| 139 |
0, /* id */ |
| 140 |
XCB_RENDER_PICT_TYPE_DIRECT, /* type */ |
| 141 |
24, /* depth */ |
| 142 |
{ 0 }, /* pad */ |
| 143 |
{ /* direct */ |
| 144 |
16, /* direct.red */ |
| 145 |
0xff, /* direct.red_MASK */ |
| 146 |
8, /* direct.green */ |
| 147 |
0xff, /* direct.green_MASK */ |
| 148 |
0, /* direct.blue */ |
| 149 |
0xff, /* direct.blue_MASK */ |
| 150 |
0, /* direct.alpha */ |
| 151 |
0x00, /* direct.alpha_MASK */ |
| 152 |
}, |
| 153 |
0, /* colormap */ |
| 154 |
}, |
| 155 |
XCB_PICT_FORMAT_TYPE | |
| 156 |
XCB_PICT_FORMAT_DEPTH | |
| 157 |
XCB_PICT_FORMAT_RED | |
| 158 |
XCB_PICT_FORMAT_RED_MASK | |
| 159 |
XCB_PICT_FORMAT_GREEN | |
| 160 |
XCB_PICT_FORMAT_GREEN_MASK | |
| 161 |
XCB_PICT_FORMAT_BLUE | |
| 162 |
XCB_PICT_FORMAT_BLUE_MASK | |
| 163 |
XCB_PICT_FORMAT_ALPHA_MASK, |
| 164 |
}, |
| 165 |
/* XCB_PICT_STANDARD_A_8 */ |
| 166 |
{ |
| 167 |
{ |
| 168 |
0, /* id */ |
| 169 |
XCB_RENDER_PICT_TYPE_DIRECT, /* type */ |
| 170 |
8, /* depth */ |
| 171 |
{ 0 }, /* pad */ |
| 172 |
{ /* direct */ |
| 173 |
0, /* direct.red */ |
| 174 |
0x00, /* direct.red_MASK */ |
| 175 |
0, /* direct.green */ |
| 176 |
0x00, /* direct.green_MASK */ |
| 177 |
0, /* direct.blue */ |
| 178 |
0x00, /* direct.blue_MASK */ |
| 179 |
0, /* direct.alpha */ |
| 180 |
0xff, /* direct.alpha_MASK */ |
| 181 |
}, |
| 182 |
0, /* colormap */ |
| 183 |
}, |
| 184 |
XCB_PICT_FORMAT_TYPE | |
| 185 |
XCB_PICT_FORMAT_DEPTH | |
| 186 |
XCB_PICT_FORMAT_RED_MASK | |
| 187 |
XCB_PICT_FORMAT_GREEN_MASK | |
| 188 |
XCB_PICT_FORMAT_BLUE_MASK | |
| 189 |
XCB_PICT_FORMAT_ALPHA | |
| 190 |
XCB_PICT_FORMAT_ALPHA_MASK, |
| 191 |
}, |
| 192 |
/* XCB_PICT_STANDARD_A_4 */ |
| 193 |
{ |
| 194 |
{ |
| 195 |
0, /* id */ |
| 196 |
XCB_RENDER_PICT_TYPE_DIRECT, /* type */ |
| 197 |
4, /* depth */ |
| 198 |
{ 0 }, /* pad */ |
| 199 |
{ /* direct */ |
| 200 |
0, /* direct.red */ |
| 201 |
0x00, /* direct.red_MASK */ |
| 202 |
0, /* direct.green */ |
| 203 |
0x00, /* direct.green_MASK */ |
| 204 |
0, /* direct.blue */ |
| 205 |
0x00, /* direct.blue_MASK */ |
| 206 |
0, /* direct.alpha */ |
| 207 |
0x0f, /* direct.alpha_MASK */ |
| 208 |
}, |
| 209 |
0, /* colormap */ |
| 210 |
}, |
| 211 |
XCB_PICT_FORMAT_TYPE | |
| 212 |
XCB_PICT_FORMAT_DEPTH | |
| 213 |
XCB_PICT_FORMAT_RED_MASK | |
| 214 |
XCB_PICT_FORMAT_GREEN_MASK | |
| 215 |
XCB_PICT_FORMAT_BLUE_MASK | |
| 216 |
XCB_PICT_FORMAT_ALPHA | |
| 217 |
XCB_PICT_FORMAT_ALPHA_MASK, |
| 218 |
}, |
| 219 |
/* XCB_PICT_STANDARD_A_1 */ |
| 220 |
{ |
| 221 |
{ |
| 222 |
0, /* id */ |
| 223 |
XCB_RENDER_PICT_TYPE_DIRECT, /* type */ |
| 224 |
1, /* depth */ |
| 225 |
{ 0 }, /* pad */ |
| 226 |
{ /* direct */ |
| 227 |
0, /* direct.red */ |
| 228 |
0x00, /* direct.red_MASK */ |
| 229 |
0, /* direct.green */ |
| 230 |
0x00, /* direct.green_MASK */ |
| 231 |
0, /* direct.blue */ |
| 232 |
0x00, /* direct.blue_MASK */ |
| 233 |
0, /* direct.alpha */ |
| 234 |
0x01, /* direct.alpha_MASK */ |
| 235 |
}, |
| 236 |
0, /* colormap */ |
| 237 |
}, |
| 238 |
XCB_PICT_FORMAT_TYPE | |
| 239 |
XCB_PICT_FORMAT_DEPTH | |
| 240 |
XCB_PICT_FORMAT_RED_MASK | |
| 241 |
XCB_PICT_FORMAT_GREEN_MASK | |
| 242 |
XCB_PICT_FORMAT_BLUE_MASK | |
| 243 |
XCB_PICT_FORMAT_ALPHA | |
| 244 |
XCB_PICT_FORMAT_ALPHA_MASK, |
| 245 |
}, |
| 246 |
}; |
| 247 |
|
| 248 |
if (format < 0 || format >= sizeof(standardFormats) / sizeof(*standardFormats)) |
| 249 |
return 0; |
| 250 |
|
| 251 |
return xcb_render_util_find_format (formats, |
| 252 |
standardFormats[format].mask, |
| 253 |
&standardFormats[format].templ, |
| 254 |
0); |
| 255 |
} |