uint32_t _ecore_xcb_render_find_visual_id(int type, Eina_Bool check_alpha) { #ifdef ECORE_XCB_RENDER const xcb_render_query_pict_formats_reply_t *reply; xcb_render_pictvisual_t *visual = NULL; xcb_render_pictscreen_iterator_t screens; xcb_render_pictdepth_iterator_t depths; xcb_render_pictvisual_iterator_t visuals; #endif LOGFN(__FILE__, __LINE__, __FUNCTION__); CHECK_XCB_CONN; if (!_render_avail) return 0; #ifdef ECORE_XCB_RENDER reply = xcb_render_util_query_formats(_ecore_xcb_conn); if (!reply) return 0; for (screens = xcb_render_query_pict_formats_screens_iterator(reply); 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)) { xcb_render_pictforminfo_t temp; xcb_render_pictforminfo_t *format; visual = visuals.data; temp.id = visual->format; format = xcb_render_util_find_format(reply, XCB_PICT_FORMAT_ID, &temp, 0); if (!format) continue; if (format->type == type) { if (check_alpha) { if (format->direct.alpha_mask) return visual->visual; } else return visual->visual; } } } } #endif return 0; }
cairo_surface_t * _cairo_boilerplate_xcb_create_surface (const char *name, cairo_content_t content, int width, int height, int max_width, int max_height, cairo_boilerplate_mode_t mode, int id, void **closure) { xcb_screen_t *root; xcb_target_closure_t *xtc; xcb_connection_t *c; xcb_render_pictforminfo_t *render_format; xcb_pict_standard_t format; *closure = xtc = xmalloc (sizeof (xcb_target_closure_t)); if (width == 0) width = 1; if (height == 0) height = 1; xtc->c = c = xcb_connect(NULL,NULL); if (xcb_connection_has_error(c)) { fprintf (stderr, "Failed to connect to X server through XCB\n"); return NULL; } root = xcb_setup_roots_iterator(xcb_get_setup(c)).data; xtc->pixmap = xcb_generate_id (c); xcb_create_pixmap (c, 32, xtc->pixmap, root->root, width, height); switch (content) { case CAIRO_CONTENT_COLOR: format = XCB_PICT_STANDARD_RGB_24; break; case CAIRO_CONTENT_COLOR_ALPHA: format = XCB_PICT_STANDARD_ARGB_32; break; case CAIRO_CONTENT_ALPHA: /* would be XCB_PICT_STANDARD_A_8 */ default: fprintf (stderr, "Invalid content for XCB test: %d\n", content); return NULL; } render_format = xcb_render_util_find_standard_format (xcb_render_util_query_formats (c), format); if (render_format->id == 0) return NULL; return cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root, render_format, width, height); }
Eina_Bool _ecore_xcb_render_visual_supports_alpha(Ecore_X_Visual visual) { Eina_Bool ret = EINA_FALSE; #ifdef ECORE_XCB_RENDER const xcb_render_query_pict_formats_reply_t *reply; xcb_render_pictvisual_t *vis; #endif LOGFN(__FILE__, __LINE__, __FUNCTION__); CHECK_XCB_CONN; if (!visual) return EINA_FALSE; if (!_render_avail) return EINA_FALSE; #ifdef ECORE_XCB_RENDER reply = xcb_render_util_query_formats(_ecore_xcb_conn); if (!reply) return EINA_FALSE; vis = xcb_render_util_find_visual_format(reply, ((xcb_visualtype_t *)visual)->visual_id); if (vis) { xcb_render_pictforminfo_t temp; xcb_render_pictforminfo_t *format; temp.id = vis->format; format = xcb_render_util_find_format(reply, XCB_PICT_FORMAT_ID, &temp, 0); if ((format->type == XCB_RENDER_PICT_TYPE_DIRECT) && (format->direct.alpha_mask)) ret = EINA_TRUE; } #endif return ret; }
static cairo_surface_t * _cairo_boilerplate_xcb_create_surface (const char *name, cairo_content_t content, double width, double height, double max_width, double max_height, cairo_boilerplate_mode_t mode, int id, void **closure) { xcb_screen_t *root; xcb_target_closure_t *xtc; xcb_connection_t *c; xcb_render_pictforminfo_t *render_format; xcb_pict_standard_t format; xcb_void_cookie_t cookie; cairo_surface_t *surface; cairo_status_t status; *closure = xtc = xmalloc (sizeof (xcb_target_closure_t)); if (width == 0) width = 1; if (height == 0) height = 1; xtc->c = c = xcb_connect(NULL,NULL); if (xcb_connection_has_error(c)) { fprintf (stderr, "Failed to connect to X server through XCB\n"); return NULL; } root = xcb_setup_roots_iterator(xcb_get_setup(c)).data; xtc->pixmap = xcb_generate_id (c); switch (content) { case CAIRO_CONTENT_COLOR: cookie = xcb_create_pixmap_checked (c, 24, xtc->pixmap, root->root, width, height); format = XCB_PICT_STANDARD_RGB_24; break; case CAIRO_CONTENT_COLOR_ALPHA: cookie = xcb_create_pixmap_checked (c, 32, xtc->pixmap, root->root, width, height); format = XCB_PICT_STANDARD_ARGB_32; break; case CAIRO_CONTENT_ALPHA: /* would be XCB_PICT_STANDARD_A_8 */ default: fprintf (stderr, "Invalid content for XCB test: %d\n", content); return NULL; } /* slow, but sure */ if (xcb_request_check (c, cookie) != NULL) { xcb_disconnect (c); free (xtc); return NULL; } render_format = xcb_render_util_find_standard_format (xcb_render_util_query_formats (c), format); if (render_format->id == 0) return NULL; surface = cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root, render_format, width, height); status = cairo_surface_set_user_data (surface, &xcb_closure_key, xtc, NULL); if (status == CAIRO_STATUS_SUCCESS) return surface; cairo_surface_destroy (surface); surface = cairo_boilerplate_surface_create_in_error (status); _cairo_boilerplate_xcb_cleanup (xtc); return surface; }