blob: be6d8e6e8d7e01ff9e205f1687e9b6cabdc251af [file] [log] [blame]
Jonny Lamb51a7ae52015-03-20 15:26:51 +01001/*
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
Jonny Lamb0e2ab362015-03-24 13:12:07 +010028#ifdef ENABLE_EGL
Jonny Lamb51a7ae52015-03-20 15:26:51 +010029#include <EGL/egl.h>
30#include <EGL/eglext.h>
Jonny Lamb0e2ab362015-03-24 13:12:07 +010031#endif
32
33#ifndef EGL_PLATFORM_WAYLAND_KHR
34#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
35#endif
Jonny Lamb51a7ae52015-03-20 15:26:51 +010036
37#ifdef __cplusplus
38extern "C" {
39#endif
40
Jonny Lamb0e2ab362015-03-24 13:12:07 +010041#ifdef ENABLE_EGL
42
43#ifndef EGL_EXT_platform_base
44typedef void (*PFNEGLGETPLATFORMDISPLAYEXTPROC) (void);
45typedef void (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (void);
46#endif
47
Jonny Lamb759fbf42015-03-24 13:12:08 +010048static inline void *
49weston_platform_get_egl_proc_address(const char *address)
Jonny Lamb51a7ae52015-03-20 15:26:51 +010050{
Jonny Lamb759fbf42015-03-24 13:12:08 +010051 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010052
Jonny Lamb759fbf42015-03-24 13:12:08 +010053 if (strstr(extensions, "EGL_EXT_platform_wayland")
54 || strstr(extensions, "EGL_KHR_platform_wayland")) {
55 return (void *) eglGetProcAddress(address);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010056 }
Jonny Lamb759fbf42015-03-24 13:12:08 +010057
58 return NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010059}
60
61static inline EGLDisplay
62weston_platform_get_egl_display(EGLenum platform, void *native_display,
63 const EGLint *attrib_list)
64{
Jonny Lamb759fbf42015-03-24 13:12:08 +010065 static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010066
Jonny Lamb759fbf42015-03-24 13:12:08 +010067 if (!get_platform_display) {
68 get_platform_display = weston_platform_get_egl_proc_address(
69 "eglGetPlatformDisplayEXT");
70 }
71
72 if (get_platform_display)
73 return get_platform_display(platform,
74 native_display, attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010075
76 return eglGetDisplay((EGLNativeDisplayType) native_display);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010077}
78
Jonny Lamb4bdcb572015-03-20 15:26:53 +010079static inline EGLSurface
80weston_platform_create_egl_window(EGLDisplay dpy, EGLConfig config,
81 void *native_window,
82 const EGLint *attrib_list)
83{
Jonny Lamb759fbf42015-03-24 13:12:08 +010084 static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC
85 create_platform_window = NULL;
Jonny Lamb4bdcb572015-03-20 15:26:53 +010086
Jonny Lamb759fbf42015-03-24 13:12:08 +010087 if (!create_platform_window) {
88 create_platform_window = weston_platform_get_egl_proc_address(
89 "eglCreatePlatformWindowSurfaceEXT");
90 }
91
92 if (create_platform_window)
93 return create_platform_window(dpy, config,
94 native_window,
95 attrib_list);
Jonny Lamb4bdcb572015-03-20 15:26:53 +010096
97 return eglCreateWindowSurface(dpy, config,
98 (EGLNativeWindowType) native_window,
99 attrib_list);
100}
101
Jonny Lamb0e2ab362015-03-24 13:12:07 +0100102#else /* ENABLE_EGL */
103
104static inline void *
105weston_platform_get_egl_display(void *platform, void *native_display,
106 const int *attrib_list)
107{
108 return NULL;
109}
110
111static inline void *
112weston_platform_create_egl_window(void *dpy, void *config,
113 void *native_window,
114 const int *attrib_list)
115{
116 return NULL;
117}
118#endif /* ENABLE_EGL */
119
Jonny Lamb51a7ae52015-03-20 15:26:51 +0100120#ifdef __cplusplus
121}
122#endif
123
124#endif /* WESTON_PLATFORM_H */