[PATCH weston] gl-renderer: If an XRGB format is requested but unavailable, try ARGB

Derek Foreman derekf at osg.samsung.com
Tue May 5 06:52:20 PDT 2015


Recent versions of Mesa have stopped exposing XRGB visuals for gl on
some Intel GPUs.  While this may be changed in Mesa eventually, it's
not impossible that some other hardware in the future won't provide
XRGB visuals either.

Let's try again with an ARGB visual if XRGB is unavailable.  Since
we're not changing the scanout buffer format, and our current
rendering loop always results in saturated alpha in the frame buffer,
it should be Just Fine(tm) - and probably better than just exiting.

Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
---
 src/gl-renderer.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index ae3122f..e0b0145 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -934,6 +934,14 @@ output_rotate_damage(struct weston_output *output,
 	go->border_damage[go->buffer_damage_index] = border_status;
 }
 
+/* NOTE: We now allow falling back to ARGB  gl visual ids when XRGB is
+ * unavailable, so we're assuming the background has no transparency
+ * and that everything with a blend, like drop shadows, will have something
+ * opaque (like the background) drawn underneath it.
+ *
+ * Depending on the underlying hardware, violating that assumption could
+ * result in seeing through to another display plane.
+ */
 static void
 gl_renderer_repaint_output(struct weston_output *output,
 			      pixman_region32_t *output_damage)
@@ -1897,6 +1905,18 @@ log_egl_config_info(EGLDisplay egldpy, EGLConfig eglconfig)
 		weston_log_continue(" unknown\n");
 }
 
+static bool
+fallback_format(EGLint *format)
+{
+	char *fourcc = (char *)format;
+
+	if (fourcc[0] != 'X')
+		return false;
+
+	fourcc[0] = 'A';
+	return true;
+}
+
 static int
 egl_choose_config(struct gl_renderer *gr, const EGLint *attribs,
 		  const EGLint *visual_id,
@@ -1904,6 +1924,7 @@ egl_choose_config(struct gl_renderer *gr, const EGLint *attribs,
 {
 	EGLint count = 0;
 	EGLint matched = 0;
+	EGLint fallback_id;
 	EGLConfig *configs;
 	int i;
 
@@ -1937,6 +1958,28 @@ egl_choose_config(struct gl_renderer *gr, const EGLint *attribs,
 		return 0;
 	}
 
+	fallback_id = *visual_id;
+	if (!fallback_format(&fallback_id))
+		goto out;
+
+	weston_log("Attempting fallback from XRGB to ARGB visual\n");
+
+	for (i = 0; i < matched; ++i) {
+		EGLint id;
+
+		if (!eglGetConfigAttrib(gr->egl_display,
+				configs[i], EGL_NATIVE_VISUAL_ID,
+				&id))
+			continue;
+		if (id != 0 && id != fallback_id)
+			continue;
+
+		*config_out = configs[i];
+
+		free(configs);
+		return 0;
+	}
+
 out:
 	free(configs);
 	return -1;
-- 
2.1.4



More information about the wayland-devel mailing list