clients & tests: use eglCreatePlatformWindowSurfaceEXT when supported

Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
diff --git a/clients/nested-client.c b/clients/nested-client.c
index 96cf1c8..5195831 100644
--- a/clients/nested-client.c
+++ b/clients/nested-client.c
@@ -307,10 +307,9 @@
 	client->native = wl_egl_window_create(client->surface,
 					      client->width, client->height);
 
-	client->egl_surface =
-		eglCreateWindowSurface(client->egl_display,
-				       client->egl_config,
-				       client->native, NULL);
+	client->egl_surface = weston_platform_create_egl_window (client->egl_display,
+								 client->egl_config,
+								 client->native, NULL);
 
 	eglMakeCurrent(client->egl_display, client->egl_surface,
 		       client->egl_surface, client->egl_context);
diff --git a/clients/simple-egl.c b/clients/simple-egl.c
index 33e02e7..1a0724d 100644
--- a/clients/simple-egl.c
+++ b/clients/simple-egl.c
@@ -386,9 +386,10 @@
 				     window->geometry.width,
 				     window->geometry.height);
 	window->egl_surface =
-		eglCreateWindowSurface(display->egl.dpy,
-				       display->egl.conf,
-				       window->native, NULL);
+		weston_platform_create_egl_window(display->egl.dpy,
+						  display->egl.conf,
+						  window->native, NULL);
+
 
 	if (display->shell) {
 		create_xdg_surface(window, display);
diff --git a/clients/subsurfaces.c b/clients/subsurfaces.c
index 5b8fd8d..130fe4c 100644
--- a/clients/subsurfaces.c
+++ b/clients/subsurfaces.c
@@ -422,9 +422,9 @@
 
 	tri->wl_surface = widget_get_wl_surface(tri->widget);
 	tri->egl_window = wl_egl_window_create(tri->wl_surface, width, height);
-	tri->egl_surface = eglCreateWindowSurface(tri->egl->dpy,
-						  tri->egl->conf,
-						  tri->egl_window, NULL);
+	tri->egl_surface = weston_platform_create_egl_window(tri->egl->dpy,
+							     tri->egl->conf,
+							     tri->egl_window, NULL);
 
 	ret = eglMakeCurrent(tri->egl->dpy, tri->egl_surface,
 			     tri->egl_surface, tri->egl->ctx);
diff --git a/clients/window.c b/clients/window.c
index 2858281..62b5185 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -640,10 +640,10 @@
 						   rectangle->width,
 						   rectangle->height);
 
-	surface->egl_surface = eglCreateWindowSurface(display->dpy,
-						      display->argb_config,
-						      surface->egl_window,
-						      NULL);
+	surface->egl_surface =
+		weston_platform_create_egl_window(display->dpy,
+						  display->argb_config,
+						  surface->egl_window, NULL);
 
 	surface->cairo_surface =
 		cairo_gl_surface_create_for_egl(display->argb_device,
diff --git a/shared/platform.h b/shared/platform.h
index 7f847fa..fd06046 100644
--- a/shared/platform.h
+++ b/shared/platform.h
@@ -34,6 +34,7 @@
 
 #ifdef EGL_EXT_platform_base
 static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display_ext = NULL;
+static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC create_platform_window_surface_ext = NULL;
 
 #ifndef EGL_PLATFORM_WAYLAND_KHR
 #define EGL_PLATFORM_WAYLAND_KHR 0x31D8
@@ -51,6 +52,8 @@
 		    || strstr(extensions, "EGL_KHR_platform_wayland")) {
 			get_platform_display_ext =
 				(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
+			create_platform_window_surface_ext =
+				(void *) eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
 		}
 	}
 #endif
@@ -72,6 +75,26 @@
 		return eglGetDisplay((EGLNativeDisplayType) native_display);
 }
 
+static inline EGLSurface
+weston_platform_create_egl_window(EGLDisplay dpy, EGLConfig config,
+				  void *native_window,
+				  const EGLint *attrib_list)
+{
+#ifdef EGL_EXT_platform_base
+	if (!create_platform_window_surface_ext)
+		weston_platform_get_egl_proc_addresses();
+
+	if (create_platform_window_surface_ext)
+		return create_platform_window_surface_ext(dpy, config,
+							  native_window,
+							  attrib_list);
+#endif
+
+	return eglCreateWindowSurface(dpy, config,
+				      (EGLNativeWindowType) native_window,
+				      attrib_list);
+}
+
 #ifdef  __cplusplus
 }
 #endif
diff --git a/tests/buffer-count-test.c b/tests/buffer-count-test.c
index 815e1cc..23cbc6e 100644
--- a/tests/buffer-count-test.c
+++ b/tests/buffer-count-test.c
@@ -95,10 +95,9 @@
 				     surface->width,
 				     surface->height);
 	test_data->egl_surface =
-		eglCreateWindowSurface(test_data->egl_dpy,
-				       test_data->egl_conf,
-				       (EGLNativeWindowType) native_window,
-				       NULL);
+		weston_platform_create_egl_window(test_data->egl_dpy,
+						  test_data->egl_conf,
+						  native_window, NULL);
 
 	ret = eglMakeCurrent(test_data->egl_dpy, test_data->egl_surface,
 			     test_data->egl_surface, test_data->egl_ctx);