[gtk-wayland v2 PATCH 1/3] update wl_visual related operations to eglconfig



From: Juan Zhao <juan j zhao intel com>

Because wl_visual related interfaces are removed in wayland, the code can not be compiled. 
We should replace them by the use of egl configs or shm format tokens. 
We also need to certificate the eglconfig before creating the egl context. 
Use environment parameter GTK_WAYLAN_PREMUL_CONF, GTK_WAYLAND_RGB_CONF and
 GTK_WAYLAND_ARGB_CONF to choose config for creating eglcontext.
https://bugzilla.gnome.org/show_bug.cgi?id=663550
---
 gdk/wayland/gdkcursor-wayland.c  |    6 +-
 gdk/wayland/gdkdisplay-wayland.c |   95 ++++++++++++++++++++++++++++----------
 gdk/wayland/gdkdisplay-wayland.h |    2 +-
 gdk/wayland/gdkscreen-wayland.c  |   20 ++++----
 gdk/wayland/gdkwindow-wayland.c  |    4 +-
 5 files changed, 86 insertions(+), 41 deletions(-)

diff --git a/gdk/wayland/gdkcursor-wayland.c b/gdk/wayland/gdkcursor-wayland.c
index 21b3bf5..2b0b05e 100644
--- a/gdk/wayland/gdkcursor-wayland.c
+++ b/gdk/wayland/gdkcursor-wayland.c
@@ -168,7 +168,7 @@ static GdkCursor *
 create_cursor(GdkDisplayWayland *display, GdkPixbuf *pixbuf, int x, int y)
 {
   GdkWaylandCursor *cursor;
-  struct wl_visual *visual;
+  uint32_t format;
   int stride, fd;
   char *filename;
   GError *error = NULL;
@@ -224,12 +224,12 @@ create_cursor(GdkDisplayWayland *display, GdkPixbuf *pixbuf, int x, int y)
   else
     memset (cursor->map, 0, 4);
 
-  visual = display->premultiplied_argb_visual;
+  format = WL_SHM_FORMAT_XRGB32;
   cursor->buffer = wl_shm_create_buffer(display->shm,
 					fd,
 					cursor->width,
 					cursor->height,
-					stride, visual);
+					stride, format);
 
   close(fd);
 
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index 8481e8b..6195e46 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -143,29 +143,8 @@ display_handle_mode(void *data,
 {
 }
 
-static void
-compositor_handle_visual(void *data,
-			 struct wl_compositor *compositor,
-			 uint32_t id, uint32_t token)
-{
-	GdkDisplayWayland *d = data;
-
-	switch (token) {
-	case WL_COMPOSITOR_VISUAL_ARGB32:
-		d->argb_visual = wl_visual_create(d->wl_display, id, 1);
-		break;
-	case WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32:
-		d->premultiplied_argb_visual =
-			wl_visual_create(d->wl_display, id, 1);
-		break;
-	case WL_COMPOSITOR_VISUAL_XRGB32:
-		d->rgb_visual = wl_visual_create(d->wl_display, id, 1);
-		break;
-	}
-}
-
 static const struct wl_compositor_listener compositor_listener = {
-	compositor_handle_visual,
+	NULL,
 };
 
 static const struct wl_output_listener output_listener = {
@@ -206,9 +185,47 @@ static gboolean
 gdk_display_init_egl(GdkDisplay *display)
 {
   GdkDisplayWayland *display_wayland = GDK_DISPLAY_WAYLAND (display);
-  EGLint major, minor, i;
+  EGLint major, minor, i, n=0;
+  EGLConfig* eglconfig;
   void *p;
 
+  static const EGLint premul_argb_cfg_attribs[] = {
+    EGL_SURFACE_TYPE,
+    EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT,
+    EGL_RED_SIZE, 1,
+    EGL_GREEN_SIZE, 1,
+    EGL_BLUE_SIZE, 1,
+    EGL_ALPHA_SIZE, 1,
+    EGL_DEPTH_SIZE, 1,
+    EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
+    EGL_NONE
+  };
+  
+  static const EGLint rgb_cfg_attribs[] = {
+    EGL_SURFACE_TYPE,
+    EGL_WINDOW_BIT | EGL_PIXMAP_BIT,
+    EGL_RED_SIZE, 1,
+    EGL_GREEN_SIZE, 1,
+    EGL_BLUE_SIZE, 1,
+    EGL_ALPHA_SIZE, 0,
+    EGL_DEPTH_SIZE, 1,
+    EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
+    EGL_NONE
+  };
+  static const EGLint argb_cfg_attribs[] = {
+    EGL_SURFACE_TYPE,
+    EGL_WINDOW_BIT | EGL_PIXMAP_BIT,
+    EGL_RED_SIZE, 1,
+    EGL_GREEN_SIZE, 1,
+    EGL_BLUE_SIZE, 1,
+    EGL_ALPHA_SIZE, 1,
+    EGL_DEPTH_SIZE, 1,
+    EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
+    EGL_NONE
+  };
+
+
+
   static const struct { const char *f; unsigned int offset; }
   extension_functions[] = {
     { "glEGLImageTargetTexture2DOES", offsetof(GdkDisplayWayland, image_target_texture_2d) },
@@ -224,9 +241,39 @@ gdk_display_init_egl(GdkDisplay *display)
   }
 
   eglBindAPI(EGL_OPENGL_API);
+  if (!eglChooseConfig(display_wayland->egl_display, premul_argb_cfg_attribs,
+       display_wayland->premultiplied_argb_config, 1, &n) || n != 1) {
+    fprintf(stderr, "failed to choose premul argb config\n");
+    display_wayland->premultiplied_argb_config = NULL;
+  }
+
+  if (!eglChooseConfig(display_wayland->egl_display, rgb_cfg_attribs,
+       display_wayland->rgb_config, 1, &n) || n != 1) {
+    fprintf(stderr, "failed to choose rgb config\n");
+    display_wayland->rgb_config = NULL;
+  }
+  if (!eglChooseConfig(display_wayland->egl_display, argb_cfg_attribs,
+       display_wayland->argb_config, 1, &n) || n != 1) {
+    fprintf(stderr, "failed to choose rgb config\n");
+    display_wayland->argb_config = NULL;
+  }
+
+  if (getenv("GTK_WAYLAND_PREMUL_CONF")){ 
+    eglconfig=display_wayland->premultiplied_argb_config;
+  }
+  else if(getenv("GTK_WAYLAND_RGB_CONF")){ 
+    eglconfig=display_wayland->rgb_config;
+  }
+  else if(getenv("GTK_WAYLAND_ARGB_CONF")){ 
+    eglconfig=display_wayland->argb_config;
+  }
+  else
+    eglconfig = NULL;
+
+
 
   display_wayland->egl_context =
-    eglCreateContext(display_wayland->egl_display, NULL, EGL_NO_CONTEXT, NULL);
+    eglCreateContext(display_wayland->egl_display, eglconfig?*eglconfig:NULL, EGL_NO_CONTEXT, NULL);
   if (display_wayland->egl_context == NULL) {
     fprintf(stderr, "failed to create context\n");
     return FALSE;
diff --git a/gdk/wayland/gdkdisplay-wayland.h b/gdk/wayland/gdkdisplay-wayland.h
index 787de8c..ea2aa8c 100644
--- a/gdk/wayland/gdkdisplay-wayland.h
+++ b/gdk/wayland/gdkdisplay-wayland.h
@@ -71,7 +71,7 @@ struct _GdkDisplayWayland
 
   /* Wayland fields below */
   struct wl_display *wl_display;
-  struct wl_visual *argb_visual, *premultiplied_argb_visual, *rgb_visual;
+  EGLConfig *argb_config, *premultiplied_argb_config, *rgb_config;
   struct wl_compositor *compositor;
   struct wl_shm *shm;
   struct wl_shell *shell;
diff --git a/gdk/wayland/gdkscreen-wayland.c b/gdk/wayland/gdkscreen-wayland.c
index 26f426d..3c8029d 100644
--- a/gdk/wayland/gdkscreen-wayland.c
+++ b/gdk/wayland/gdkscreen-wayland.c
@@ -349,7 +349,7 @@ typedef struct _GdkWaylandVisualClass	GdkWaylandVisualClass;
 struct _GdkWaylandVisual
 {
   GdkVisual visual;
-  struct wl_visual *wl_visual;
+  EGLConfig *wl_egl_config;
 };
 
 struct _GdkWaylandVisualClass
@@ -451,7 +451,7 @@ gdk_wayland_screen_list_visuals (GdkScreen *screen)
 #define GDK_WAYLAND_VISUAL(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WAYLAND_VISUAL, GdkWaylandVisual))
 
 static GdkVisual *
-gdk_wayland_visual_new (GdkScreen *screen, struct wl_visual *wl_visual)
+gdk_wayland_visual_new (GdkScreen *screen, EGLConfig *wl_egl_config)
 {
   GdkVisual *visual;
 
@@ -460,7 +460,7 @@ gdk_wayland_visual_new (GdkScreen *screen, struct wl_visual *wl_visual)
   visual->type = GDK_VISUAL_TRUE_COLOR;
   visual->depth = 32;
 
-  GDK_WAYLAND_VISUAL (visual)->wl_visual = wl_visual;
+  GDK_WAYLAND_VISUAL (visual)->wl_egl_config = wl_egl_config;
 
   return visual;
 }
@@ -471,7 +471,7 @@ _gdk_wayland_screen_new (GdkDisplay *display)
   GdkScreen *screen;
   GdkScreenWayland *screen_wayland;
   GdkDisplayWayland *display_wayland;
-  struct wl_visual *visual;
+  EGLConfig *eglconfig;
 
   display_wayland = GDK_DISPLAY_WAYLAND (display);
 
@@ -482,15 +482,15 @@ _gdk_wayland_screen_new (GdkDisplay *display)
   screen_wayland->width = 8192;
   screen_wayland->height = 8192;
 
-  visual = display_wayland->argb_visual;
-  screen_wayland->argb_visual = gdk_wayland_visual_new (screen, visual);
+  eglconfig = display_wayland->argb_config;
+  screen_wayland->argb_visual = gdk_wayland_visual_new (screen, eglconfig);
 
-  visual = display_wayland->premultiplied_argb_visual;
+  eglconfig = display_wayland->premultiplied_argb_config;
   screen_wayland->premultiplied_argb_visual =
-    gdk_wayland_visual_new (screen, visual);
+    gdk_wayland_visual_new (screen, eglconfig);
 
-  visual = display_wayland->rgb_visual;
-  screen_wayland->rgb_visual = gdk_wayland_visual_new (screen, visual);
+  eglconfig = display_wayland->rgb_config;
+  screen_wayland->rgb_visual = gdk_wayland_visual_new (screen, eglconfig);
 
   screen_wayland->root_window =
     _gdk_wayland_screen_create_root_window (screen,
diff --git a/gdk/wayland/gdkwindow-wayland.c b/gdk/wayland/gdkwindow-wayland.c
index 653059e..3653fa3 100644
--- a/gdk/wayland/gdkwindow-wayland.c
+++ b/gdk/wayland/gdkwindow-wayland.c
@@ -387,15 +387,13 @@ gdk_wayland_create_cairo_surface (GdkDisplayWayland *display,
 {
   GdkWaylandCairoSurfaceData *data;
   cairo_surface_t *surface;
-  struct wl_visual *visual;
 
   data = g_new (GdkWaylandCairoSurfaceData, 1);
   data->display = display;
   data->buffer = NULL;
-  visual = display->premultiplied_argb_visual;
   data->width = width;
   data->height = height;
-  data->pixmap = wl_egl_pixmap_create(width, height, visual, 0);
+  data->pixmap = wl_egl_pixmap_create(width, height, 0);
   data->image =
     display->create_image(display->egl_display, NULL, EGL_NATIVE_PIXMAP_KHR,
 			  (EGLClientBuffer) data->pixmap, NULL);
-- 
1.7.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]