blob: dd55008126ef3ef16af55191b451e8e2b6618c97 [file] [log] [blame]
Jonny Lamb51a7ae52015-03-20 15:26:51 +01001/*
2 * Copyright © 2015 Collabora, Ltd.
3 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -07004 * 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 Lamb51a7ae52015-03-20 15:26:51 +010011 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -070012 * 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 Lamb51a7ae52015-03-20 15:26:51 +010024 */
25
26#ifndef WESTON_PLATFORM_H
27#define WESTON_PLATFORM_H
28
29#include <string.h>
30
Jonny Lamb0e2ab362015-03-24 13:12:07 +010031#ifdef ENABLE_EGL
Ahmet Acar64d78bb2015-11-13 10:25:46 -060032#include <wayland-egl.h>
Jonny Lamb51a7ae52015-03-20 15:26:51 +010033#include <EGL/egl.h>
34#include <EGL/eglext.h>
Jonny Lamb0e2ab362015-03-24 13:12:07 +010035#endif
36
37#ifndef EGL_PLATFORM_WAYLAND_KHR
38#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
39#endif
Jonny Lamb51a7ae52015-03-20 15:26:51 +010040
41#ifdef __cplusplus
42extern "C" {
43#endif
44
Jonny Lamb0e2ab362015-03-24 13:12:07 +010045#ifdef ENABLE_EGL
46
47#ifndef EGL_EXT_platform_base
Manuel Bachmanne8128592015-03-28 07:05:48 +010048typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform,
49 void *native_display,
50 const EGLint *attrib_list);
51typedef EGLSurface (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy,
52 EGLConfig config,
53 void *native_window,
54 const EGLint *attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010055#endif
56
Jonny Lamb759fbf42015-03-24 13:12:08 +010057static inline void *
58weston_platform_get_egl_proc_address(const char *address)
Jonny Lamb51a7ae52015-03-20 15:26:51 +010059{
Jonny Lamb759fbf42015-03-24 13:12:08 +010060 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010061
Manuel Bachmann5d1d2ca2015-03-29 08:17:01 +020062 if (extensions
63 && (strstr(extensions, "EGL_EXT_platform_wayland")
64 || strstr(extensions, "EGL_KHR_platform_wayland"))) {
Jonny Lamb759fbf42015-03-24 13:12:08 +010065 return (void *) eglGetProcAddress(address);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010066 }
Jonny Lamb759fbf42015-03-24 13:12:08 +010067
68 return NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010069}
70
71static inline EGLDisplay
72weston_platform_get_egl_display(EGLenum platform, void *native_display,
73 const EGLint *attrib_list)
74{
Jonny Lamb759fbf42015-03-24 13:12:08 +010075 static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010076
Jonny Lamb759fbf42015-03-24 13:12:08 +010077 if (!get_platform_display) {
Matthias Treydtecd9424e2016-01-29 17:02:15 +010078 get_platform_display = (PFNEGLGETPLATFORMDISPLAYEXTPROC)
79 weston_platform_get_egl_proc_address(
80 "eglGetPlatformDisplayEXT");
Jonny Lamb759fbf42015-03-24 13:12:08 +010081 }
82
83 if (get_platform_display)
84 return get_platform_display(platform,
85 native_display, attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010086
87 return eglGetDisplay((EGLNativeDisplayType) native_display);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010088}
89
Jonny Lamb4bdcb572015-03-20 15:26:53 +010090static inline EGLSurface
Jonny Lambabff8832015-03-24 13:12:09 +010091weston_platform_create_egl_surface(EGLDisplay dpy, EGLConfig config,
92 void *native_window,
93 const EGLint *attrib_list)
Jonny Lamb4bdcb572015-03-20 15:26:53 +010094{
Jonny Lamb759fbf42015-03-24 13:12:08 +010095 static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC
96 create_platform_window = NULL;
Jonny Lamb4bdcb572015-03-20 15:26:53 +010097
Jonny Lamb759fbf42015-03-24 13:12:08 +010098 if (!create_platform_window) {
Matthias Treydtecd9424e2016-01-29 17:02:15 +010099 create_platform_window = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)
100 weston_platform_get_egl_proc_address(
101 "eglCreatePlatformWindowSurfaceEXT");
Jonny Lamb759fbf42015-03-24 13:12:08 +0100102 }
103
104 if (create_platform_window)
105 return create_platform_window(dpy, config,
106 native_window,
107 attrib_list);
Jonny Lamb4bdcb572015-03-20 15:26:53 +0100108
109 return eglCreateWindowSurface(dpy, config,
110 (EGLNativeWindowType) native_window,
111 attrib_list);
112}
113
Jonny Lamb0e2ab362015-03-24 13:12:07 +0100114#else /* ENABLE_EGL */
115
116static inline void *
117weston_platform_get_egl_display(void *platform, void *native_display,
118 const int *attrib_list)
119{
120 return NULL;
121}
122
123static inline void *
Jonny Lambabff8832015-03-24 13:12:09 +0100124weston_platform_create_egl_surface(void *dpy, void *config,
125 void *native_window,
126 const int *attrib_list)
Jonny Lamb0e2ab362015-03-24 13:12:07 +0100127{
128 return NULL;
129}
130#endif /* ENABLE_EGL */
131
Jonny Lamb51a7ae52015-03-20 15:26:51 +0100132#ifdef __cplusplus
133}
134#endif
135
136#endif /* WESTON_PLATFORM_H */