2 * Copyright © 2015 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #ifndef WESTON_PLATFORM_H
27 #define WESTON_PLATFORM_H
31 #include <wayland-egl.h>
33 #include <EGL/eglext.h>
35 #ifndef EGL_PLATFORM_WAYLAND_KHR
36 #define EGL_PLATFORM_WAYLAND_KHR 0x31D8
44 #ifndef EGL_EXT_platform_base
45 typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform,
47 const EGLint *attrib_list);
48 typedef EGLSurface (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy,
51 const EGLint *attrib_list);
55 weston_platform_get_egl_proc_address(const char *address)
57 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
60 && (strstr(extensions, "EGL_EXT_platform_wayland")
61 || strstr(extensions, "EGL_KHR_platform_wayland"))) {
62 return (void *) eglGetProcAddress(address);
68 static inline EGLDisplay
69 weston_platform_get_egl_display(EGLenum platform, void *native_display,
70 const EGLint *attrib_list)
72 static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
74 if (!get_platform_display) {
75 get_platform_display = (PFNEGLGETPLATFORMDISPLAYEXTPROC)
76 weston_platform_get_egl_proc_address(
77 "eglGetPlatformDisplayEXT");
80 if (get_platform_display)
81 return get_platform_display(platform,
82 native_display, attrib_list);
84 return eglGetDisplay((EGLNativeDisplayType) native_display);
87 static inline EGLSurface
88 weston_platform_create_egl_surface(EGLDisplay dpy, EGLConfig config,
90 const EGLint *attrib_list)
92 static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC
93 create_platform_window = NULL;
95 if (!create_platform_window) {
96 create_platform_window = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)
97 weston_platform_get_egl_proc_address(
98 "eglCreatePlatformWindowSurfaceEXT");
101 if (create_platform_window)
102 return create_platform_window(dpy, config,
106 return eglCreateWindowSurface(dpy, config,
107 (EGLNativeWindowType) native_window,
115 #endif /* WESTON_PLATFORM_H */