blob: 364ce5aaaf9a5b5e6ec69ecfd548d470265fe519 [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
Manuel Bachmanne8128592015-03-28 07:05:48 +010044typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform,
45 void *native_display,
46 const EGLint *attrib_list);
47typedef EGLSurface (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy,
48 EGLConfig config,
49 void *native_window,
50 const EGLint *attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010051#endif
52
Jonny Lamb759fbf42015-03-24 13:12:08 +010053static inline void *
54weston_platform_get_egl_proc_address(const char *address)
Jonny Lamb51a7ae52015-03-20 15:26:51 +010055{
Jonny Lamb759fbf42015-03-24 13:12:08 +010056 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010057
Manuel Bachmann5d1d2ca2015-03-29 08:17:01 +020058 if (extensions
59 && (strstr(extensions, "EGL_EXT_platform_wayland")
60 || strstr(extensions, "EGL_KHR_platform_wayland"))) {
Jonny Lamb759fbf42015-03-24 13:12:08 +010061 return (void *) eglGetProcAddress(address);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010062 }
Jonny Lamb759fbf42015-03-24 13:12:08 +010063
64 return NULL;
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 Lamb759fbf42015-03-24 13:12:08 +010071 static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010072
Jonny Lamb759fbf42015-03-24 13:12:08 +010073 if (!get_platform_display) {
74 get_platform_display = weston_platform_get_egl_proc_address(
75 "eglGetPlatformDisplayEXT");
76 }
77
78 if (get_platform_display)
79 return get_platform_display(platform,
80 native_display, attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010081
82 return eglGetDisplay((EGLNativeDisplayType) native_display);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010083}
84
Jonny Lamb4bdcb572015-03-20 15:26:53 +010085static inline EGLSurface
Jonny Lambabff8832015-03-24 13:12:09 +010086weston_platform_create_egl_surface(EGLDisplay dpy, EGLConfig config,
87 void *native_window,
88 const EGLint *attrib_list)
Jonny Lamb4bdcb572015-03-20 15:26:53 +010089{
Jonny Lamb759fbf42015-03-24 13:12:08 +010090 static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC
91 create_platform_window = NULL;
Jonny Lamb4bdcb572015-03-20 15:26:53 +010092
Jonny Lamb759fbf42015-03-24 13:12:08 +010093 if (!create_platform_window) {
94 create_platform_window = weston_platform_get_egl_proc_address(
95 "eglCreatePlatformWindowSurfaceEXT");
96 }
97
98 if (create_platform_window)
99 return create_platform_window(dpy, config,
100 native_window,
101 attrib_list);
Jonny Lamb4bdcb572015-03-20 15:26:53 +0100102
103 return eglCreateWindowSurface(dpy, config,
104 (EGLNativeWindowType) native_window,
105 attrib_list);
106}
107
Jonny Lamb0e2ab362015-03-24 13:12:07 +0100108#else /* ENABLE_EGL */
109
110static inline void *
111weston_platform_get_egl_display(void *platform, void *native_display,
112 const int *attrib_list)
113{
114 return NULL;
115}
116
117static inline void *
Jonny Lambabff8832015-03-24 13:12:09 +0100118weston_platform_create_egl_surface(void *dpy, void *config,
119 void *native_window,
120 const int *attrib_list)
Jonny Lamb0e2ab362015-03-24 13:12:07 +0100121{
122 return NULL;
123}
124#endif /* ENABLE_EGL */
125
Jonny Lamb51a7ae52015-03-20 15:26:51 +0100126#ifdef __cplusplus
127}
128#endif
129
130#endif /* WESTON_PLATFORM_H */