#include "xcb_renderutil.h"
xcb_render_pictvisual_t *
xcb_render_util_find_visual_format (const xcb_render_query_pict_formats_reply_t *formats,
const xcb_visualid_t visual)
{
xcb_render_pictscreen_iterator_t screens;
xcb_render_pictdepth_iterator_t depths;
xcb_render_pictvisual_iterator_t visuals;
if (!formats)
return 0;
for (screens = xcb_render_query_pict_formats_screens_iterator(formats); screens.rem; xcb_render_pictscreen_next(&screens))
for (depths = xcb_render_pictscreen_depths_iterator(screens.data); depths.rem; xcb_render_pictdepth_next(&depths))
for (visuals = xcb_render_pictdepth_visuals_iterator(depths.data); visuals.rem; xcb_render_pictvisual_next(&visuals))
if (visuals.data->visual == visual)
return visuals.data;
return 0;
}
xcb_render_pictforminfo_t *
xcb_render_util_find_format (const xcb_render_query_pict_formats_reply_t *formats,
unsigned long mask,
const xcb_render_pictforminfo_t *template,
int count)
{
xcb_render_pictforminfo_iterator_t i;
if (!formats)
return 0;
for (i = xcb_render_query_pict_formats_formats_iterator(formats); i.rem; xcb_render_pictforminfo_next(&i))
{
if (mask & XCB_PICT_FORMAT_ID)
if (template->id != i.data->id)
continue;
if (mask & XCB_PICT_FORMAT_TYPE)
if (template->type != i.data->type)
continue;
if (mask & XCB_PICT_FORMAT_DEPTH)
if (template->depth != i.data->depth)
continue;
if (mask & XCB_PICT_FORMAT_RED)
if (template->direct.red_shift != i.data->direct.red_shift)
continue;
if (mask & XCB_PICT_FORMAT_RED_MASK)
if (template->direct.red_mask != i.data->direct.red_mask)
continue;
if (mask & XCB_PICT_FORMAT_GREEN)
if (template->direct.green_shift != i.data->direct.green_shift)
continue;
if (mask & XCB_PICT_FORMAT_GREEN_MASK)
if (template->direct.green_mask != i.data->direct.green_mask)
continue;
if (mask & XCB_PICT_FORMAT_BLUE)
if (template->direct.blue_shift != i.data->direct.blue_shift)
continue;
if (mask & XCB_PICT_FORMAT_BLUE_MASK)
if (template->direct.blue_mask != i.data->direct.blue_mask)
continue;
if (mask & XCB_PICT_FORMAT_ALPHA)
if (template->direct.alpha_shift != i.data->direct.alpha_shift)
continue;
if (mask & XCB_PICT_FORMAT_ALPHA_MASK)
if (template->direct.alpha_mask != i.data->direct.alpha_mask)
continue;
if (mask & XCB_PICT_FORMAT_COLORMAP)
if (template->colormap != i.data->colormap)
continue;
if (count-- == 0)
return i.data;
}
return 0;
}
xcb_render_pictforminfo_t *
xcb_render_util_find_standard_format (const xcb_render_query_pict_formats_reply_t *formats,
xcb_pict_standard_t format)
{
static const struct {
xcb_render_pictforminfo_t templ;
unsigned long mask;
} standardFormats[] = {
{
{
0,
XCB_RENDER_PICT_TYPE_DIRECT,
32,
{ 0 },
{
16,
0xff,
8,
0xff,
0,
0xff,
24,
0xff,
},
0,
},
XCB_PICT_FORMAT_TYPE |
XCB_PICT_FORMAT_DEPTH |
XCB_PICT_FORMAT_RED |
XCB_PICT_FORMAT_RED_MASK |
XCB_PICT_FORMAT_GREEN |
XCB_PICT_FORMAT_GREEN_MASK |
XCB_PICT_FORMAT_BLUE |
XCB_PICT_FORMAT_BLUE_MASK |
XCB_PICT_FORMAT_ALPHA |
XCB_PICT_FORMAT_ALPHA_MASK,
},
{
{
0,
XCB_RENDER_PICT_TYPE_DIRECT,
24,
{ 0 },
{
16,
0xff,
8,
0xff,
0,
0xff,
0,
0x00,
},
0,
},
XCB_PICT_FORMAT_TYPE |
XCB_PICT_FORMAT_DEPTH |
XCB_PICT_FORMAT_RED |
XCB_PICT_FORMAT_RED_MASK |
XCB_PICT_FORMAT_GREEN |
XCB_PICT_FORMAT_GREEN_MASK |
XCB_PICT_FORMAT_BLUE |
XCB_PICT_FORMAT_BLUE_MASK |
XCB_PICT_FORMAT_ALPHA_MASK,
},
{
{
0,
XCB_RENDER_PICT_TYPE_DIRECT,
8,
{ 0 },
{
0,
0x00,
0,
0x00,
0,
0x00,
0,
0xff,
},
0,
},
XCB_PICT_FORMAT_TYPE |
XCB_PICT_FORMAT_DEPTH |
XCB_PICT_FORMAT_RED_MASK |
XCB_PICT_FORMAT_GREEN_MASK |
XCB_PICT_FORMAT_BLUE_MASK |
XCB_PICT_FORMAT_ALPHA |
XCB_PICT_FORMAT_ALPHA_MASK,
},
{
{
0,
XCB_RENDER_PICT_TYPE_DIRECT,
4,
{ 0 },
{
0,
0x00,
0,
0x00,
0,
0x00,
0,
0x0f,
},
0,
},
XCB_PICT_FORMAT_TYPE |
XCB_PICT_FORMAT_DEPTH |
XCB_PICT_FORMAT_RED_MASK |
XCB_PICT_FORMAT_GREEN_MASK |
XCB_PICT_FORMAT_BLUE_MASK |
XCB_PICT_FORMAT_ALPHA |
XCB_PICT_FORMAT_ALPHA_MASK,
},
{
{
0,
XCB_RENDER_PICT_TYPE_DIRECT,
1,
{ 0 },
{
0,
0x00,
0,
0x00,
0,
0x00,
0,
0x01,
},
0,
},
XCB_PICT_FORMAT_TYPE |
XCB_PICT_FORMAT_DEPTH |
XCB_PICT_FORMAT_RED_MASK |
XCB_PICT_FORMAT_GREEN_MASK |
XCB_PICT_FORMAT_BLUE_MASK |
XCB_PICT_FORMAT_ALPHA |
XCB_PICT_FORMAT_ALPHA_MASK,
},
};
if (format < 0 || format >= sizeof(standardFormats) / sizeof(*standardFormats))
return 0;
return xcb_render_util_find_format (formats,
standardFormats[format].mask,
&standardFormats[format].templ,
0);
}