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