[PATCH weston 2/3] window: Bring back support for rgb windows

Ander Conselvan de Oliveira ander.conselvan.de.oliveira at intel.com
Wed Dec 5 05:14:05 PST 2012


This let us test overlays with toytoolkit applications. We can't just
rely on the opaque region, because a drmModeSetPlane() call will fail
if we use an ARGB bo because of the format check.

This reverts commits 067fd605345355094953d8e355fcfd0935304039,
fedc527723128ee08f443c8955d75d7cd0d956a6 and partially reverts
010f98b0839e4eb8dd18056289590c1d0cb61ed5.

---
Hi,

I'm thinking that with this we could move all the things we added to
simple-egl to test scanout surfaces, overlays and what not into a
toytoolkit client and make simple-egl simple again. Perhaps just rename
transformed to plane_test or something and add it all there.
---
 clients/window.c |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 clients/window.h |    5 +++++
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/clients/window.c b/clients/window.c
index 20d09d5..5f9603e 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -93,8 +93,11 @@ struct display {
 	struct text_cursor_position *text_cursor_position;
 	struct workspace_manager *workspace_manager;
 	EGLDisplay dpy;
+	EGLConfig rgb_config;
 	EGLConfig argb_config;
+	EGLContext rgb_ctx;
 	EGLContext argb_ctx;
+	cairo_device_t *rgb_device;
 	cairo_device_t *argb_device;
 	uint32_t serial;
 
@@ -454,6 +457,8 @@ egl_window_surface_acquire(struct toysurface *base, EGLContext ctx)
 	if (!ctx) {
 		if (device == surface->display->argb_device)
 			ctx = surface->display->argb_ctx;
+		else if (device == surface->display->rgb_device)
+			ctx = surface->display->rgb_ctx;
 		else
 			assert(0);
 	}
@@ -505,6 +510,8 @@ egl_window_surface_create(struct display *display,
 			  struct rectangle *rectangle)
 {
 	struct egl_window_surface *surface;
+	cairo_device_t *device;
+	EGLConfig config;
 
 	if (display->dpy == EGL_NO_DISPLAY)
 		return NULL;
@@ -519,6 +526,14 @@ egl_window_surface_create(struct display *display,
 	surface->base.release = egl_window_surface_release;
 	surface->base.destroy = egl_window_surface_destroy;
 
+	if (flags & SURFACE_OPAQUE) {
+		device = display->rgb_device;
+		config = display->rgb_config;
+	} else {
+		device = display->argb_device;
+		config = display->argb_config;
+	}
+
 	surface->display = display;
 	surface->surface = wl_surface;
 
@@ -526,13 +541,12 @@ egl_window_surface_create(struct display *display,
 						   rectangle->width,
 						   rectangle->height);
 
-	surface->egl_surface = eglCreateWindowSurface(display->dpy,
-						      display->argb_config,
+	surface->egl_surface = eglCreateWindowSurface(display->dpy, config,
 						      surface->egl_window,
 						      NULL);
 
 	surface->cairo_surface =
-		cairo_gl_surface_create_for_egl(display->argb_device,
+		cairo_gl_surface_create_for_egl(device,
 						surface->egl_surface,
 						rectangle->width,
 						rectangle->height);
@@ -3418,6 +3432,12 @@ window_set_output_handler(struct window *window,
 }
 
 void
+window_set_transparent(struct window *window, int transparent)
+{
+	window->transparent = transparent;
+}
+
+void
 window_set_title(struct window *window, const char *title)
 {
 	free(window->title);
@@ -4090,6 +4110,17 @@ init_egl(struct display *d)
 		EGL_NONE
 	};
 
+	static const EGLint rgb_cfg_attribs[] = {
+		EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+		EGL_RED_SIZE, 1,
+		EGL_GREEN_SIZE, 1,
+		EGL_BLUE_SIZE, 1,
+		EGL_ALPHA_SIZE, 0,
+		EGL_DEPTH_SIZE, 1,
+		EGL_RENDERABLE_TYPE, GL_BIT,
+		EGL_NONE
+	};
+
 #ifdef USE_CAIRO_GLESV2
 	static const EGLint context_attribs[] = {
 		EGL_CONTEXT_CLIENT_VERSION, 2,
@@ -4118,6 +4149,18 @@ init_egl(struct display *d)
 		return -1;
 	}
 
+	if (!eglChooseConfig(d->dpy, rgb_cfg_attribs,
+			     &d->rgb_config, 1, &n) || n != 1) {
+		fprintf(stderr, "failed to choose rgb config\n");
+		return -1;
+	}
+
+	d->rgb_ctx = eglCreateContext(d->dpy, d->rgb_config,
+				      EGL_NO_CONTEXT, context_attribs);
+	if (d->rgb_ctx == NULL) {
+		fprintf(stderr, "failed to create context\n");
+		return -1;
+	}
 	d->argb_ctx = eglCreateContext(d->dpy, d->argb_config,
 				       EGL_NO_CONTEXT, context_attribs);
 	if (d->argb_ctx == NULL) {
@@ -4130,6 +4173,12 @@ init_egl(struct display *d)
 		return -1;
 	}
 
+	d->rgb_device = cairo_egl_device_create(d->dpy, d->rgb_ctx);
+	if (cairo_device_status(d->rgb_device) != CAIRO_STATUS_SUCCESS) {
+		fprintf(stderr, "failed to get cairo egl rgb device\n");
+		return -1;
+	}
+
 	d->argb_device = cairo_egl_device_create(d->dpy, d->argb_ctx);
 	if (cairo_device_status(d->argb_device) != CAIRO_STATUS_SUCCESS) {
 		fprintf(stderr, "failed to get cairo egl argb device\n");
@@ -4143,6 +4192,7 @@ static void
 fini_egl(struct display *display)
 {
 	cairo_device_destroy(display->argb_device);
+	cairo_device_destroy(display->rgb_device);
 
 	eglMakeCurrent(display->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
 		       EGL_NO_CONTEXT);
@@ -4374,6 +4424,12 @@ display_create_data_source(struct display *display)
 }
 
 EGLConfig
+display_get_rgb_egl_config(struct display *d)
+{
+	return d->rgb_config;
+}
+
+EGLConfig
 display_get_argb_egl_config(struct display *d)
 {
 	return d->argb_config;
diff --git a/clients/window.h b/clients/window.h
index 29bba30..be9114d 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -112,6 +112,9 @@ EGLDisplay
 display_get_egl_display(struct display *d);
 
 EGLConfig
+display_get_rgb_egl_config(struct display *d);
+
+EGLConfig
 display_get_argb_egl_config(struct display *d);
 
 int
@@ -266,6 +269,8 @@ window_move(struct window *window, struct input *input, uint32_t time);
 void
 window_get_allocation(struct window *window, struct rectangle *allocation);
 void
+window_set_transparent(struct window *window, int transparent);
+void
 window_schedule_redraw(struct window *window);
 void
 window_schedule_resize(struct window *window, int width, int height);
-- 
1.7.10.4



More information about the wayland-devel mailing list