blob: ea5980eb7d1feaaccd3297b87a7983d9c8ff278a [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 Lamb51a7ae52015-03-20 15:26:51 +010048static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display_ext = NULL;
Jonny Lamb4bdcb572015-03-20 15:26:53 +010049static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC create_platform_window_surface_ext = NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010050
Jonny Lamb51a7ae52015-03-20 15:26:51 +010051static inline void
52weston_platform_get_egl_proc_addresses(void)
53{
Jonny Lamb51a7ae52015-03-20 15:26:51 +010054 if (!get_platform_display_ext) {
55 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
56
57 if (strstr(extensions, "EGL_EXT_platform_wayland")
58 || strstr(extensions, "EGL_KHR_platform_wayland")) {
59 get_platform_display_ext =
60 (void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
Jonny Lamb4bdcb572015-03-20 15:26:53 +010061 create_platform_window_surface_ext =
62 (void *) eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
Jonny Lamb51a7ae52015-03-20 15:26:51 +010063 }
64 }
Jonny Lamb51a7ae52015-03-20 15:26:51 +010065}
66
67static inline EGLDisplay
68weston_platform_get_egl_display(EGLenum platform, void *native_display,
69 const EGLint *attrib_list)
70{
Jonny Lamb51a7ae52015-03-20 15:26:51 +010071 if (!get_platform_display_ext)
72 weston_platform_get_egl_proc_addresses();
73
74 if (get_platform_display_ext)
75 return get_platform_display_ext(platform,
76 native_display, attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010077
78 return eglGetDisplay((EGLNativeDisplayType) native_display);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010079}
80
Jonny Lamb4bdcb572015-03-20 15:26:53 +010081static inline EGLSurface
82weston_platform_create_egl_window(EGLDisplay dpy, EGLConfig config,
83 void *native_window,
84 const EGLint *attrib_list)
85{
Jonny Lamb4bdcb572015-03-20 15:26:53 +010086 if (!create_platform_window_surface_ext)
87 weston_platform_get_egl_proc_addresses();
88
89 if (create_platform_window_surface_ext)
90 return create_platform_window_surface_ext(dpy, config,
91 native_window,
92 attrib_list);
Jonny Lamb4bdcb572015-03-20 15:26:53 +010093
94 return eglCreateWindowSurface(dpy, config,
95 (EGLNativeWindowType) native_window,
96 attrib_list);
97}
98
Jonny Lamb0e2ab362015-03-24 13:12:07 +010099#else /* ENABLE_EGL */
100
101static inline void *
102weston_platform_get_egl_display(void *platform, void *native_display,
103 const int *attrib_list)
104{
105 return NULL;
106}
107
108static inline void *
109weston_platform_create_egl_window(void *dpy, void *config,
110 void *native_window,
111 const int *attrib_list)
112{
113 return NULL;
114}
115#endif /* ENABLE_EGL */
116
Jonny Lamb51a7ae52015-03-20 15:26:51 +0100117#ifdef __cplusplus
118}
119#endif
120
121#endif /* WESTON_PLATFORM_H */