[PATCH weston 2/4] clients & tests: use eglGetPlatformDisplayEXT when supported

Jonny Lamb jonny.lamb at collabora.co.uk
Wed Feb 25 04:42:11 PST 2015


---
 clients/nested-client.c   | 36 +++++++++++++++++++++++++++++++++++-
 clients/simple-egl.c      | 30 +++++++++++++++++++++++++++++-
 clients/subsurfaces.c     | 35 ++++++++++++++++++++++++++++++++++-
 clients/window.c          | 34 +++++++++++++++++++++++++++++++++-
 tests/buffer-count-test.c | 33 +++++++++++++++++++++++++++++++--
 5 files changed, 162 insertions(+), 6 deletions(-)

diff --git a/clients/nested-client.c b/clients/nested-client.c
index 7f237e6..9f373b1 100644
--- a/clients/nested-client.c
+++ b/clients/nested-client.c
@@ -31,6 +31,7 @@
 
 #include <GLES2/gl2.h>
 #include <EGL/egl.h>
+#include <EGL/eglext.h>
 
 struct window;
 struct seat;
@@ -238,6 +239,14 @@ static const struct wl_registry_listener registry_listener = {
 	registry_handle_global_remove
 };
 
+#ifdef EGL_EXT_platform_base
+static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
+#endif
+
+#ifndef EGL_PLATFORM_WAYLAND_KHR
+#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
+#endif
+
 static struct nested_client *
 nested_client_create(void)
 {
@@ -261,6 +270,10 @@ nested_client_create(void)
 
 	struct nested_client *client;
 
+#ifdef EGL_EXT_platform_base
+	const char *extensions;
+#endif
+
 	client = malloc(sizeof *client);
 	if (client == NULL)
 		return NULL;
@@ -277,7 +290,28 @@ nested_client_create(void)
 	/* get globals */
 	wl_display_roundtrip(client->display);
 
-	client->egl_display = eglGetDisplay(client->display);
+#ifdef EGL_EXT_platform_base
+	extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+
+	if (strstr(extensions, "EGL_EXT_platform_wayland")
+	    || strstr(extensions, "EGL_KHR_platform_wayland")) {
+		get_platform_display =
+			(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
+	} else {
+		fprintf(stderr, "error: no wayland egl support\n");
+		return NULL;
+	}
+
+	if (get_platform_display) {
+		client->egl_display = get_platform_display(EGL_PLATFORM_WAYLAND_KHR,
+							   client->display, NULL);
+	} else {
+#endif
+		client->egl_display = eglGetDisplay(client->display);
+#ifdef EGL_EXT_platform_base
+	}
+#endif
+
 	if (client->egl_display == NULL)
 		return NULL;
 
diff --git a/clients/simple-egl.c b/clients/simple-egl.c
index d3c205f..20c3f27 100644
--- a/clients/simple-egl.c
+++ b/clients/simple-egl.c
@@ -125,6 +125,14 @@ static const char *frag_shader_text =
 
 static int running = 1;
 
+#ifdef EGL_EXT_platform_base
+static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
+#endif
+
+#ifndef EGL_PLATFORM_WAYLAND_KHR
+#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
+#endif
+
 static void
 init_egl(struct display *display, struct window *window)
 {
@@ -151,7 +159,27 @@ init_egl(struct display *display, struct window *window)
 	if (window->opaque || window->buffer_size == 16)
 		config_attribs[9] = 0;
 
-	display->egl.dpy = eglGetDisplay(display->display);
+#ifdef EGL_EXT_platform_base
+	extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+
+	if (strstr(extensions, "EGL_EXT_platform_wayland")
+	    || strstr(extensions, "EGL_KHR_platform_wayland")) {
+		get_platform_display =
+			(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
+	} else {
+		fprintf(stderr, "error: no wayland egl support\n");
+		exit(1);
+	}
+
+	if (get_platform_display) {
+		display->egl.dpy = get_platform_display(EGL_PLATFORM_WAYLAND_KHR,
+							display->display, NULL);
+	} else {
+#endif
+		display->egl.dpy = eglGetDisplay(display->display);
+#ifdef EGL_EXT_platform_base
+	}
+#endif
 	assert(display->egl.dpy);
 
 	ret = eglInitialize(display->egl.dpy, &major, &minor);
diff --git a/clients/subsurfaces.c b/clients/subsurfaces.c
index fcbe496..fedc1bf 100644
--- a/clients/subsurfaces.c
+++ b/clients/subsurfaces.c
@@ -38,6 +38,7 @@
 #include <wayland-egl.h>
 #include <GLES2/gl2.h>
 #include <EGL/egl.h>
+#include <EGL/eglext.h>
 
 #include "window.h"
 
@@ -189,6 +190,14 @@ egl_print_config_info(struct egl_state *egl)
 		printf(" unknown\n");
 }
 
+#ifdef EGL_EXT_platform_base
+static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
+#endif
+
+#ifndef EGL_PLATFORM_WAYLAND_KHR
+#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
+#endif
+
 static struct egl_state *
 egl_state_create(struct wl_display *display)
 {
@@ -212,10 +221,34 @@ egl_state_create(struct wl_display *display)
 	EGLint major, minor, n;
 	EGLBoolean ret;
 
+#ifdef EGL_EXT_platform_base
+	const char *extensions;
+
+	extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+
+	if (strstr(extensions, "EGL_EXT_platform_wayland")
+	    || strstr(extensions, "EGL_KHR_platform_wayland")) {
+		get_platform_display =
+			(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
+	} else {
+		fprintf(stderr, "error: no wayland egl support\n");
+		exit(1);
+	}
+#endif
+
 	egl = calloc(1, sizeof *egl);
 	assert(egl);
 
-	egl->dpy = eglGetDisplay(display);
+#ifdef EGL_EXT_platform_base
+	if (get_platform_display) {
+		egl->dpy = get_platform_display(EGL_PLATFORM_WAYLAND_KHR,
+						display, NULL);
+	} else {
+#endif
+		egl->dpy = eglGetDisplay(display);
+#ifdef EGL_EXT_platform_base
+	}
+#endif
 	assert(egl->dpy);
 
 	ret = eglInitialize(egl->dpy, &major, &minor);
diff --git a/clients/window.c b/clients/window.c
index c5082ba..dcff578 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -5348,6 +5348,15 @@ static const struct wl_registry_listener registry_listener = {
 };
 
 #ifdef HAVE_CAIRO_EGL
+
+#ifdef EGL_EXT_platform_base
+static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
+#endif
+
+#ifndef EGL_PLATFORM_WAYLAND_KHR
+#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
+#endif
+
 static int
 init_egl(struct display *d)
 {
@@ -5382,7 +5391,30 @@ init_egl(struct display *d)
 	EGLint api = EGL_OPENGL_API;
 #endif
 
-	d->dpy = eglGetDisplay(d->display);
+#ifdef EGL_EXT_platform_base
+	const char *extensions;
+
+	extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+
+	if (strstr(extensions, "EGL_EXT_platform_wayland")
+	    || strstr(extensions, "EGL_KHR_platform_wayland")) {
+		get_platform_display =
+			(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
+	} else {
+		fprintf(stderr, "error: no wayland egl support\n");
+		return -1;
+	}
+
+	if (get_platform_display) {
+		d->dpy = get_platform_display(EGL_PLATFORM_WAYLAND_KHR,
+					      d->display, NULL);
+	} else {
+#endif
+		d->dpy = eglGetDisplay(d->display);
+#if EGL_EXT_platform_base
+	}
+#endif
+
 	if (!eglInitialize(d->dpy, &major, &minor)) {
 		fprintf(stderr, "failed to initialize EGL\n");
 		return -1;
diff --git a/tests/buffer-count-test.c b/tests/buffer-count-test.c
index 43fb089..06f0db3 100644
--- a/tests/buffer-count-test.c
+++ b/tests/buffer-count-test.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <EGL/egl.h>
+#include <EGL/eglext.h>
 #include <wayland-egl.h>
 #include <GLES2/gl2.h>
 
@@ -41,6 +42,10 @@ struct test_data {
 	EGLSurface egl_surface;
 };
 
+#ifdef EGL_EXT_platform_base
+static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
+#endif
+
 static int
 init_egl(struct test_data *test_data)
 {
@@ -66,8 +71,32 @@ init_egl(struct test_data *test_data)
 	EGLint major, minor, n;
 	EGLBoolean ret;
 
-	test_data->egl_dpy = eglGetDisplay((EGLNativeDisplayType)
-					   test_data->client->wl_display);
+#ifdef EGL_EXT_platform_base
+	const char *extensions;
+
+	extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+
+	if (strstr(extensions, "EGL_EXT_platform_wayland")
+	    || strstr(extensions, "EGL_KHR_platform_wayland")) {
+		get_platform_display =
+			(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
+	} else {
+		fprintf(stderr, "error: no wayland egl support\n");
+		return -1;
+	}
+
+	if (get_platform_display) {
+		test_data->egl_dpy = get_platform_display(EGL_PLATFORM_WAYLAND_EXT,
+							  test_data->client->wl_display,
+							  NULL);
+	} else {
+#endif
+		test_data->egl_dpy = eglGetDisplay((EGLNativeDisplayType)
+						   test_data->client->wl_display);
+#ifdef EGL_EXT_platform_base
+	}
+#endif
+
 	if (!test_data->egl_dpy)
 		fail("eglGetDisplay");
 
-- 
2.1.4



More information about the wayland-devel mailing list