Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Collabora, Ltd. |
| 3 | * |
Bryce Harrington | 6c6164c | 2015-06-11 14:20:17 -0700 | [diff] [blame] | 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: |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 11 | * |
Bryce Harrington | 6c6164c | 2015-06-11 14:20:17 -0700 | [diff] [blame] | 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. |
| 15 | * |
| 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 |
| 23 | * SOFTWARE. |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #ifndef WESTON_PLATFORM_H |
| 27 | #define WESTON_PLATFORM_H |
| 28 | |
| 29 | #include <string.h> |
| 30 | |
Jonny Lamb | 0e2ab36 | 2015-03-24 13:12:07 +0100 | [diff] [blame] | 31 | #ifdef ENABLE_EGL |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 32 | #include <EGL/egl.h> |
| 33 | #include <EGL/eglext.h> |
Jonny Lamb | 0e2ab36 | 2015-03-24 13:12:07 +0100 | [diff] [blame] | 34 | #endif |
| 35 | |
| 36 | #ifndef EGL_PLATFORM_WAYLAND_KHR |
| 37 | #define EGL_PLATFORM_WAYLAND_KHR 0x31D8 |
| 38 | #endif |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
Jonny Lamb | 0e2ab36 | 2015-03-24 13:12:07 +0100 | [diff] [blame] | 44 | #ifdef ENABLE_EGL |
| 45 | |
| 46 | #ifndef EGL_EXT_platform_base |
Manuel Bachmann | e812859 | 2015-03-28 07:05:48 +0100 | [diff] [blame] | 47 | typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform, |
| 48 | void *native_display, |
| 49 | const EGLint *attrib_list); |
| 50 | typedef EGLSurface (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy, |
| 51 | EGLConfig config, |
| 52 | void *native_window, |
| 53 | const EGLint *attrib_list); |
Jonny Lamb | 0e2ab36 | 2015-03-24 13:12:07 +0100 | [diff] [blame] | 54 | #endif |
| 55 | |
Jonny Lamb | 759fbf4 | 2015-03-24 13:12:08 +0100 | [diff] [blame] | 56 | static inline void * |
| 57 | weston_platform_get_egl_proc_address(const char *address) |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 58 | { |
Jonny Lamb | 759fbf4 | 2015-03-24 13:12:08 +0100 | [diff] [blame] | 59 | const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 60 | |
Manuel Bachmann | 5d1d2ca | 2015-03-29 08:17:01 +0200 | [diff] [blame] | 61 | if (extensions |
| 62 | && (strstr(extensions, "EGL_EXT_platform_wayland") |
| 63 | || strstr(extensions, "EGL_KHR_platform_wayland"))) { |
Jonny Lamb | 759fbf4 | 2015-03-24 13:12:08 +0100 | [diff] [blame] | 64 | return (void *) eglGetProcAddress(address); |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 65 | } |
Jonny Lamb | 759fbf4 | 2015-03-24 13:12:08 +0100 | [diff] [blame] | 66 | |
| 67 | return NULL; |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static inline EGLDisplay |
| 71 | weston_platform_get_egl_display(EGLenum platform, void *native_display, |
| 72 | const EGLint *attrib_list) |
| 73 | { |
Jonny Lamb | 759fbf4 | 2015-03-24 13:12:08 +0100 | [diff] [blame] | 74 | static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL; |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 75 | |
Jonny Lamb | 759fbf4 | 2015-03-24 13:12:08 +0100 | [diff] [blame] | 76 | if (!get_platform_display) { |
| 77 | get_platform_display = weston_platform_get_egl_proc_address( |
| 78 | "eglGetPlatformDisplayEXT"); |
| 79 | } |
| 80 | |
| 81 | if (get_platform_display) |
| 82 | return get_platform_display(platform, |
| 83 | native_display, attrib_list); |
Jonny Lamb | 0e2ab36 | 2015-03-24 13:12:07 +0100 | [diff] [blame] | 84 | |
| 85 | return eglGetDisplay((EGLNativeDisplayType) native_display); |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Jonny Lamb | 4bdcb57 | 2015-03-20 15:26:53 +0100 | [diff] [blame] | 88 | static inline EGLSurface |
Jonny Lamb | abff883 | 2015-03-24 13:12:09 +0100 | [diff] [blame] | 89 | weston_platform_create_egl_surface(EGLDisplay dpy, EGLConfig config, |
| 90 | void *native_window, |
| 91 | const EGLint *attrib_list) |
Jonny Lamb | 4bdcb57 | 2015-03-20 15:26:53 +0100 | [diff] [blame] | 92 | { |
Jonny Lamb | 759fbf4 | 2015-03-24 13:12:08 +0100 | [diff] [blame] | 93 | static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC |
| 94 | create_platform_window = NULL; |
Jonny Lamb | 4bdcb57 | 2015-03-20 15:26:53 +0100 | [diff] [blame] | 95 | |
Jonny Lamb | 759fbf4 | 2015-03-24 13:12:08 +0100 | [diff] [blame] | 96 | if (!create_platform_window) { |
| 97 | create_platform_window = weston_platform_get_egl_proc_address( |
| 98 | "eglCreatePlatformWindowSurfaceEXT"); |
| 99 | } |
| 100 | |
| 101 | if (create_platform_window) |
| 102 | return create_platform_window(dpy, config, |
| 103 | native_window, |
| 104 | attrib_list); |
Jonny Lamb | 4bdcb57 | 2015-03-20 15:26:53 +0100 | [diff] [blame] | 105 | |
| 106 | return eglCreateWindowSurface(dpy, config, |
| 107 | (EGLNativeWindowType) native_window, |
| 108 | attrib_list); |
| 109 | } |
| 110 | |
Jonny Lamb | 0e2ab36 | 2015-03-24 13:12:07 +0100 | [diff] [blame] | 111 | #else /* ENABLE_EGL */ |
| 112 | |
| 113 | static inline void * |
| 114 | weston_platform_get_egl_display(void *platform, void *native_display, |
| 115 | const int *attrib_list) |
| 116 | { |
| 117 | return NULL; |
| 118 | } |
| 119 | |
| 120 | static inline void * |
Jonny Lamb | abff883 | 2015-03-24 13:12:09 +0100 | [diff] [blame] | 121 | weston_platform_create_egl_surface(void *dpy, void *config, |
| 122 | void *native_window, |
| 123 | const int *attrib_list) |
Jonny Lamb | 0e2ab36 | 2015-03-24 13:12:07 +0100 | [diff] [blame] | 124 | { |
| 125 | return NULL; |
| 126 | } |
| 127 | #endif /* ENABLE_EGL */ |
| 128 | |
Jonny Lamb | 51a7ae5 | 2015-03-20 15:26:51 +0100 | [diff] [blame] | 129 | #ifdef __cplusplus |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | #endif /* WESTON_PLATFORM_H */ |