blob: b1b91285e1bf5b4a7328c009230803a8bb03c57d [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
Emil Velikov10772db2016-07-04 15:34:16 +010029#include <stdbool.h>
Jonny Lamb51a7ae52015-03-20 15:26:51 +010030#include <string.h>
31
Jonny Lamb0e2ab362015-03-24 13:12:07 +010032#ifdef ENABLE_EGL
Ahmet Acar64d78bb2015-11-13 10:25:46 -060033#include <wayland-egl.h>
Jonny Lamb51a7ae52015-03-20 15:26:51 +010034#include <EGL/egl.h>
35#include <EGL/eglext.h>
Jonny Lamb0e2ab362015-03-24 13:12:07 +010036#endif
37
38#ifndef EGL_PLATFORM_WAYLAND_KHR
39#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
40#endif
Jonny Lamb51a7ae52015-03-20 15:26:51 +010041
42#ifdef __cplusplus
43extern "C" {
44#endif
45
Jonny Lamb0e2ab362015-03-24 13:12:07 +010046#ifdef ENABLE_EGL
47
48#ifndef EGL_EXT_platform_base
Manuel Bachmanne8128592015-03-28 07:05:48 +010049typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform,
50 void *native_display,
51 const EGLint *attrib_list);
52typedef EGLSurface (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy,
53 EGLConfig config,
54 void *native_window,
55 const EGLint *attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010056#endif
57
Jonny Lamb759fbf42015-03-24 13:12:08 +010058static inline void *
59weston_platform_get_egl_proc_address(const char *address)
Jonny Lamb51a7ae52015-03-20 15:26:51 +010060{
Jonny Lamb759fbf42015-03-24 13:12:08 +010061 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010062
Manuel Bachmann5d1d2ca2015-03-29 08:17:01 +020063 if (extensions
64 && (strstr(extensions, "EGL_EXT_platform_wayland")
65 || strstr(extensions, "EGL_KHR_platform_wayland"))) {
Jonny Lamb759fbf42015-03-24 13:12:08 +010066 return (void *) eglGetProcAddress(address);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010067 }
Jonny Lamb759fbf42015-03-24 13:12:08 +010068
69 return NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010070}
71
72static inline EGLDisplay
73weston_platform_get_egl_display(EGLenum platform, void *native_display,
74 const EGLint *attrib_list)
75{
Jonny Lamb759fbf42015-03-24 13:12:08 +010076 static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010077
Jonny Lamb759fbf42015-03-24 13:12:08 +010078 if (!get_platform_display) {
Matthias Treydtecd9424e2016-01-29 17:02:15 +010079 get_platform_display = (PFNEGLGETPLATFORMDISPLAYEXTPROC)
80 weston_platform_get_egl_proc_address(
81 "eglGetPlatformDisplayEXT");
Jonny Lamb759fbf42015-03-24 13:12:08 +010082 }
83
84 if (get_platform_display)
85 return get_platform_display(platform,
86 native_display, attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010087
88 return eglGetDisplay((EGLNativeDisplayType) native_display);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010089}
90
Jonny Lamb4bdcb572015-03-20 15:26:53 +010091static inline EGLSurface
Jonny Lambabff8832015-03-24 13:12:09 +010092weston_platform_create_egl_surface(EGLDisplay dpy, EGLConfig config,
93 void *native_window,
94 const EGLint *attrib_list)
Jonny Lamb4bdcb572015-03-20 15:26:53 +010095{
Jonny Lamb759fbf42015-03-24 13:12:08 +010096 static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC
97 create_platform_window = NULL;
Jonny Lamb4bdcb572015-03-20 15:26:53 +010098
Jonny Lamb759fbf42015-03-24 13:12:08 +010099 if (!create_platform_window) {
Matthias Treydtecd9424e2016-01-29 17:02:15 +0100100 create_platform_window = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)
101 weston_platform_get_egl_proc_address(
102 "eglCreatePlatformWindowSurfaceEXT");
Jonny Lamb759fbf42015-03-24 13:12:08 +0100103 }
104
105 if (create_platform_window)
106 return create_platform_window(dpy, config,
107 native_window,
108 attrib_list);
Jonny Lamb4bdcb572015-03-20 15:26:53 +0100109
110 return eglCreateWindowSurface(dpy, config,
111 (EGLNativeWindowType) native_window,
112 attrib_list);
113}
114
Jonny Lamb0e2ab362015-03-24 13:12:07 +0100115#else /* ENABLE_EGL */
116
117static inline void *
118weston_platform_get_egl_display(void *platform, void *native_display,
119 const int *attrib_list)
120{
121 return NULL;
122}
123
124static inline void *
Jonny Lambabff8832015-03-24 13:12:09 +0100125weston_platform_create_egl_surface(void *dpy, void *config,
126 void *native_window,
127 const int *attrib_list)
Jonny Lamb0e2ab362015-03-24 13:12:07 +0100128{
129 return NULL;
130}
131#endif /* ENABLE_EGL */
132
Jonny Lamb51a7ae52015-03-20 15:26:51 +0100133#ifdef __cplusplus
134}
135#endif
136
137#endif /* WESTON_PLATFORM_H */