[PATCH v2 weston 1/6] xwm: fix render format look up

Tiago Vignatti tiago.vignatti at intel.com
Mon Jul 16 07:32:22 PDT 2012


we were using wrong iterator for xcb_render_pictforminfo_t type, the
formats_reply->length; valgrind was shouting it loudly. Another issue this
patch addresses is that now find_depth returns the first util and valid format
that matches the desired depth; it doesn't continue through the loop until the
end.

This reverts part of commit 5ea11b69.

Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
 src/xwayland/window-manager.c |   49 +++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 17 deletions(-)

diff --git a/src/xwayland/window-manager.c b/src/xwayland/window-manager.c
index 6e032ea..b922e9b 100644
--- a/src/xwayland/window-manager.c
+++ b/src/xwayland/window-manager.c
@@ -963,6 +963,37 @@ weston_wm_handle_event(int fd, uint32_t mask, void *data)
 	return count;
 }
 
+static xcb_render_pictforminfo_t *
+find_depth (xcb_connection_t *c, int depth)
+{
+	xcb_render_query_pict_formats_reply_t *formats;
+	xcb_render_query_pict_formats_cookie_t cookie;
+	xcb_render_pictforminfo_iterator_t i;
+
+	cookie = xcb_render_query_pict_formats (c);
+	xcb_flush (c);
+
+	formats = xcb_render_query_pict_formats_reply (c, cookie, 0);
+	if (formats == NULL)
+		return NULL;
+
+	for (i = xcb_render_query_pict_formats_formats_iterator (formats);
+	     i.rem;
+	     xcb_render_pictforminfo_next (&i))
+	{
+		if (XCB_RENDER_PICT_TYPE_DIRECT != i.data->type)
+			continue;
+
+		if (depth != i.data->depth)
+			continue;
+
+		return i.data;
+	}
+
+	free (formats);
+	return NULL;
+}
+
 static void
 wxs_wm_get_resources(struct weston_wm *wm)
 {
@@ -1024,15 +1055,10 @@ wxs_wm_get_resources(struct weston_wm *wm)
 	xcb_xfixes_query_version_reply_t *xfixes_reply;
 	xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
 	xcb_intern_atom_reply_t *reply;
-	xcb_render_query_pict_formats_reply_t *formats_reply;
-	xcb_render_query_pict_formats_cookie_t formats_cookie;
-	xcb_render_pictforminfo_t *formats;
 	uint32_t i;
 
 	xcb_prefetch_extension_data (wm->conn, &xcb_xfixes_id);
 
-	formats_cookie = xcb_render_query_pict_formats(wm->conn);
-
 	for (i = 0; i < ARRAY_LENGTH(atoms); i++)
 		cookies[i] = xcb_intern_atom (wm->conn, 0,
 					      strlen(atoms[i].name),
@@ -1059,18 +1085,7 @@ wxs_wm_get_resources(struct weston_wm *wm)
 
 	free(xfixes_reply);
 
-	formats_reply = xcb_render_query_pict_formats_reply(wm->conn,
-							    formats_cookie, 0);
-	if (formats_reply == NULL)
-		return;
-
-	formats = xcb_render_query_pict_formats_formats(formats_reply);
-	for (i = 0; i < formats_reply->length; i++)
-		if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT &&
-		    formats[i].depth == 24)
-			wm->render_format = formats[i];
-
-	free(formats_reply);
+	wm->render_format = *(find_depth(wm->conn, 24));
 }
 
 static void
-- 
1.7.9.5



More information about the wayland-devel mailing list