Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Collabora, Ltd. |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef WESTON_PLATFORM_H |
| 24 | #define WESTON_PLATFORM_H |
| 25 | |
| 26 | #include <string.h> |
| 27 | |
| 28 | #include <EGL/egl.h> |
| 29 | #include <EGL/eglext.h> |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | #ifdef EGL_EXT_platform_base |
| 36 | static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display_ext = NULL; |
Jonny Lamb | 4bdcb57 | 2015-03-20 15:26:53 +0100 | [diff] [blame] | 37 | static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC create_platform_window_surface_ext = NULL; |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 38 | |
| 39 | #ifndef EGL_PLATFORM_WAYLAND_KHR |
| 40 | #define EGL_PLATFORM_WAYLAND_KHR 0x31D8 |
| 41 | #endif |
| 42 | #endif /* EGL_EXT_platform_base */ |
| 43 | |
| 44 | static inline void |
| 45 | weston_platform_get_egl_proc_addresses(void) |
| 46 | { |
| 47 | #ifdef EGL_EXT_platform_base |
| 48 | if (!get_platform_display_ext) { |
| 49 | const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); |
| 50 | |
| 51 | if (strstr(extensions, "EGL_EXT_platform_wayland") |
| 52 | || strstr(extensions, "EGL_KHR_platform_wayland")) { |
| 53 | get_platform_display_ext = |
| 54 | (void *) eglGetProcAddress("eglGetPlatformDisplayEXT"); |
Jonny Lamb | 4bdcb57 | 2015-03-20 15:26:53 +0100 | [diff] [blame] | 55 | create_platform_window_surface_ext = |
| 56 | (void *) eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT"); |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | #endif |
| 60 | } |
| 61 | |
| 62 | static inline EGLDisplay |
| 63 | weston_platform_get_egl_display(EGLenum platform, void *native_display, |
| 64 | const EGLint *attrib_list) |
| 65 | { |
| 66 | #ifdef EGL_EXT_platform_base |
| 67 | if (!get_platform_display_ext) |
| 68 | weston_platform_get_egl_proc_addresses(); |
| 69 | |
| 70 | if (get_platform_display_ext) |
| 71 | return get_platform_display_ext(platform, |
| 72 | native_display, attrib_list); |
| 73 | else |
| 74 | #endif |
| 75 | return eglGetDisplay((EGLNativeDisplayType) native_display); |
| 76 | } |
| 77 | |
Jonny Lamb | 4bdcb57 | 2015-03-20 15:26:53 +0100 | [diff] [blame] | 78 | static inline EGLSurface |
| 79 | weston_platform_create_egl_window(EGLDisplay dpy, EGLConfig config, |
| 80 | void *native_window, |
| 81 | const EGLint *attrib_list) |
| 82 | { |
| 83 | #ifdef EGL_EXT_platform_base |
| 84 | if (!create_platform_window_surface_ext) |
| 85 | weston_platform_get_egl_proc_addresses(); |
| 86 | |
| 87 | if (create_platform_window_surface_ext) |
| 88 | return create_platform_window_surface_ext(dpy, config, |
| 89 | native_window, |
| 90 | attrib_list); |
| 91 | #endif |
| 92 | |
| 93 | return eglCreateWindowSurface(dpy, config, |
| 94 | (EGLNativeWindowType) native_window, |
| 95 | attrib_list); |
| 96 | } |
| 97 | |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 98 | #ifdef __cplusplus |
| 99 | } |
| 100 | #endif |
| 101 | |
| 102 | #endif /* WESTON_PLATFORM_H */ |