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

Derek Foreman derekf at osg.samsung.com
Mon Feb 23 09:57:18 PST 2015


On 17/02/15 09:48 AM, Jonny Lamb wrote:
> ---
>  clients/nested-client.c   | 29 ++++++++++++++++++++++++++++-
>  clients/simple-egl.c      | 23 ++++++++++++++++++++++-
>  clients/subsurfaces.c     | 26 +++++++++++++++++++++++++-
>  clients/window.c          | 27 ++++++++++++++++++++++++++-
>  tests/buffer-count-test.c | 30 ++++++++++++++++++++++++++++--
>  5 files changed, 129 insertions(+), 6 deletions(-)
> 
> diff --git a/clients/nested-client.c b/clients/nested-client.c
> index 7f237e6..fbf5350 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,10 @@ static const struct wl_registry_listener registry_listener = {
>  	registry_handle_global_remove
>  };
>  
> +#ifdef EGL_EXT_platform_base
> +static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
> +#endif
> +
>  static struct nested_client *
>  nested_client_create(void)
>  {
> @@ -261,6 +266,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 +286,25 @@ 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")) {
> +		get_platform_display =
> +			(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
> +	} else {
> +		fprintf(stderr, "error: no wayland egl support\n");
> +		return NULL;
> +	}
> +#endif
> +
> +	if (get_platform_display) {
> +		client->egl_display = get_platform_display(EGL_PLATFORM_WAYLAND_EXT,
> +							   client->display, NULL);
> +	} else {
> +		client->egl_display = eglGetDisplay(client->display);
> +	}
> +
>  	if (client->egl_display == NULL)
>  		return NULL;
>  
> diff --git a/clients/simple-egl.c b/clients/simple-egl.c
> index d3c205f..1162eb4 100644
> --- a/clients/simple-egl.c
> +++ b/clients/simple-egl.c
> @@ -125,6 +125,10 @@ static const char *frag_shader_text =
>  
>  static int running = 1;
>  
> +#ifdef EGL_EXT_platform_base
> +static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
> +#endif
> +
>  static void
>  init_egl(struct display *display, struct window *window)
>  {
> @@ -151,7 +155,24 @@ 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")) {
> +		get_platform_display =
> +			(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
> +	} else {
> +		fprintf(stderr, "error: no wayland egl support\n");
> +		exit(1);
> +	}
> +#endif
> +
> +	if (get_platform_display) {
> +		display->egl.dpy = get_platform_display(EGL_PLATFORM_WAYLAND_EXT,
> +							display->display, NULL);
> +	} else {
> +		display->egl.dpy = eglGetDisplay(display->display);
> +	}
>  	assert(display->egl.dpy);
>  
>  	ret = eglInitialize(display->egl.dpy, &major, &minor);
> diff --git a/clients/subsurfaces.c b/clients/subsurfaces.c
> index fcbe496..d15d5a5 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,10 @@ egl_print_config_info(struct egl_state *egl)
>  		printf(" unknown\n");
>  }
>  
> +#ifdef EGL_EXT_platform_base
> +static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
> +#endif
> +
>  static struct egl_state *
>  egl_state_create(struct wl_display *display)
>  {
> @@ -212,10 +217,29 @@ 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")) {
> +		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);
> +	if (get_platform_display) {
> +		egl->dpy = get_platform_display(EGL_PLATFORM_WAYLAND_EXT,
> +						display, NULL);
> +	} else {
> +		egl->dpy = eglGetDisplay(display);
> +	}
>  	assert(egl->dpy);
>  
>  	ret = eglInitialize(egl->dpy, &major, &minor);
> diff --git a/clients/window.c b/clients/window.c
> index c5082ba..dc08f59 100644
> --- a/clients/window.c
> +++ b/clients/window.c
> @@ -5348,6 +5348,11 @@ static const struct wl_registry_listener registry_listener = {
>  };
>  
>  #ifdef HAVE_CAIRO_EGL
> +
> +#ifdef EGL_EXT_platform_base
> +static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
> +#endif
> +
>  static int
>  init_egl(struct display *d)
>  {
> @@ -5382,7 +5387,27 @@ 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")) {
> +		get_platform_display =
> +			(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
> +	} else {
> +		fprintf(stderr, "error: no wayland egl support\n");
> +		return -1;
> +	}
> +#endif
> +
> +	if (get_platform_display) {

I don't think get_platform_display will be defined here if
EGL_EXT_platform_base wasn't defined?

> +		d->dpy = get_platform_display(EGL_PLATFORM_WAYLAND_EXT,
> +					      d->display, NULL);

What about EGL_PLATFORM_WAYLAND_KHR?  I think it's possible that
EGL_PLATFORM_WAYLAND_KHR is defined but EGL_PLATFORM_WAYLAND_EXT is not?

> +	} else {
> +		d->dpy = eglGetDisplay(d->display);
> +	}
> +
>  	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..1912b62 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,29 @@ 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")) {
> +		get_platform_display =
> +			(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
> +	} else {
> +		fprintf(stderr, "error: no wayland egl support\n");
> +		return -1;
> +	}
> +#endif
> +
> +	if (get_platform_display) {
> +		test_data->egl_dpy = get_platform_display(EGL_PLATFORM_WAYLAND_EXT,
> +							  test_data->client->wl_display,
> +							  NULL);
> +	} else {
> +		test_data->egl_dpy = eglGetDisplay((EGLNativeDisplayType)
> +						   test_data->client->wl_display);
> +	}
> +
>  	if (!test_data->egl_dpy)
>  		fail("eglGetDisplay");
>  
> 


More information about the wayland-devel mailing list