diff options
| author | emersion <contact@emersion.fr> | 2017-11-02 16:59:57 +0100 | 
|---|---|---|
| committer | emersion <contact@emersion.fr> | 2017-11-02 16:59:57 +0100 | 
| commit | bb76f5264080be36138ec7c3e4dc3d83ed37d858 (patch) | |
| tree | 3160a6fd7e7aa2e4c3d275acb8523c8bc76538b7 /xwayland/xwm.c | |
| parent | 3f4ad47421721c5df576e1a99e487a28a6318f82 (diff) | |
| download | wlroots-bb76f5264080be36138ec7c3e4dc3d83ed37d858.tar.xz | |
Fetch xcb_render_pictformat_t at startup
Diffstat (limited to 'xwayland/xwm.c')
| -rw-r--r-- | xwayland/xwm.c | 47 | 
1 files changed, 28 insertions, 19 deletions
diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 9d6bc347..9b75879e 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1175,7 +1175,7 @@ static void xwm_get_visual_and_colormap(struct wlr_xwm *xwm) {  	}  	if (visualtype == NULL) { -		wlr_log(L_DEBUG, "no 32 bit visualtype\n"); +		wlr_log(L_DEBUG, "No 32 bit visualtype\n");  		return;  	} @@ -1188,42 +1188,50 @@ static void xwm_get_visual_and_colormap(struct wlr_xwm *xwm) {  		xwm->visual_id);  } -void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, -		uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { -	if (xwm->cursor) { -		xcb_free_cursor(xwm->xcb_conn, xwm->cursor); -	} - -	stride *= 4; -	int depth = 32; - -	xcb_pixmap_t pix = xcb_generate_id(xwm->xcb_conn); -	xcb_create_pixmap(xwm->xcb_conn, depth, pix, xwm->screen->root, width, -		height); - +static void xwm_get_render_format(struct wlr_xwm *xwm) {  	xcb_render_query_pict_formats_cookie_t cookie =  		xcb_render_query_pict_formats(xwm->xcb_conn); -	xcb_generic_error_t *err = NULL;  	xcb_render_query_pict_formats_reply_t *reply = -		xcb_render_query_pict_formats_reply(xwm->xcb_conn, cookie, &err); +		xcb_render_query_pict_formats_reply(xwm->xcb_conn, cookie, NULL);  	xcb_render_pictforminfo_t *formats =  		xcb_render_query_pict_formats_formats(reply);  	int len = xcb_render_query_pict_formats_formats_length(reply);  	xcb_render_pictforminfo_t *format = NULL;  	for (int i = 0; i < len; ++i) { -		if (formats[i].depth == depth) { +		if (formats[i].depth == 32) {  			format = &formats[i];  			break;  		}  		// TODO: segfaults when not found  	}  	if (format == NULL) { -		wlr_log(L_ERROR, "Cannot find %d-bit depth render format", depth); +		wlr_log(L_DEBUG, "No 32 bit render format"); +		return; +	} + +	xwm->render_format_id = format->id; +} + +void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, +		uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { +	if (!xwm->render_format_id) { +		wlr_log(L_ERROR, "Cannot set xwm cursor: no render format available");  		return;  	} +	if (xwm->cursor) { +		xcb_free_cursor(xwm->xcb_conn, xwm->cursor); +	} + +	stride *= 4; +	int depth = 32; + +	xcb_pixmap_t pix = xcb_generate_id(xwm->xcb_conn); +	xcb_create_pixmap(xwm->xcb_conn, depth, pix, xwm->screen->root, width, +		height);  	xcb_render_picture_t pic = xcb_generate_id(xwm->xcb_conn); -	xcb_render_create_picture(xwm->xcb_conn, pic, pix, format->id, 0, 0); +	xcb_render_create_picture(xwm->xcb_conn, pic, pix, xwm->render_format_id, +		0, 0);  	xcb_gcontext_t gc = xcb_generate_id(xwm->xcb_conn);  	xcb_create_gc(xwm->xcb_conn, gc, pix, 0, NULL); @@ -1280,6 +1288,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {  	xwm_get_resources(xwm);  	xwm_get_visual_and_colormap(xwm); +	xwm_get_render_format(xwm);  	uint32_t values[] = {  		XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |  | 
