blob: fd06046b2d9981cda1c1028a7109680d57f6bdae [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
28#include <EGL/egl.h>
29#include <EGL/eglext.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#ifdef EGL_EXT_platform_base
36static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display_ext = NULL;
Jonny Lamb4bdcb572015-03-20 15:26:53 +010037static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC create_platform_window_surface_ext = NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010038
39#ifndef EGL_PLATFORM_WAYLAND_KHR
40#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
41#endif
42#endif /* EGL_EXT_platform_base */
43
44static inline void
45weston_platform_get_egl_proc_addresses(void)
46{
47#ifdef EGL_EXT_platform_base
48 if (!get_platform_display_ext) {
49 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
50
51 if (strstr(extensions, "EGL_EXT_platform_wayland")
52 || strstr(extensions, "EGL_KHR_platform_wayland")) {
53 get_platform_display_ext =
54 (void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
Jonny Lamb4bdcb572015-03-20 15:26:53 +010055 create_platform_window_surface_ext =
56 (void *) eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
Jonny Lamb51a7ae52015-03-20 15:26:51 +010057 }
58 }
59#endif
60}
61
62static inline EGLDisplay
63weston_platform_get_egl_display(EGLenum platform, void *native_display,
64 const EGLint *attrib_list)
65{
66#ifdef EGL_EXT_platform_base
67 if (!get_platform_display_ext)
68 weston_platform_get_egl_proc_addresses();
69
70 if (get_platform_display_ext)
71 return get_platform_display_ext(platform,
72 native_display, attrib_list);
73 else
74#endif
75 return eglGetDisplay((EGLNativeDisplayType) native_display);
76}
77
Jonny Lamb4bdcb572015-03-20 15:26:53 +010078static inline EGLSurface
79weston_platform_create_egl_window(EGLDisplay dpy, EGLConfig config,
80 void *native_window,
81 const EGLint *attrib_list)
82{
83#ifdef EGL_EXT_platform_base
84 if (!create_platform_window_surface_ext)
85 weston_platform_get_egl_proc_addresses();
86
87 if (create_platform_window_surface_ext)
88 return create_platform_window_surface_ext(dpy, config,
89 native_window,
90 attrib_list);
91#endif
92
93 return eglCreateWindowSurface(dpy, config,
94 (EGLNativeWindowType) native_window,
95 attrib_list);
96}
97
Jonny Lamb51a7ae52015-03-20 15:26:51 +010098#ifdef __cplusplus
99}
100#endif
101
102#endif /* WESTON_PLATFORM_H */