blob: 7f847fa2b6138cbfc6ef2f95fea0d40f5a61dc87 [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;
37
38#ifndef EGL_PLATFORM_WAYLAND_KHR
39#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
40#endif
41#endif /* EGL_EXT_platform_base */
42
43static inline void
44weston_platform_get_egl_proc_addresses(void)
45{
46#ifdef EGL_EXT_platform_base
47 if (!get_platform_display_ext) {
48 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
49
50 if (strstr(extensions, "EGL_EXT_platform_wayland")
51 || strstr(extensions, "EGL_KHR_platform_wayland")) {
52 get_platform_display_ext =
53 (void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
54 }
55 }
56#endif
57}
58
59static inline EGLDisplay
60weston_platform_get_egl_display(EGLenum platform, void *native_display,
61 const EGLint *attrib_list)
62{
63#ifdef EGL_EXT_platform_base
64 if (!get_platform_display_ext)
65 weston_platform_get_egl_proc_addresses();
66
67 if (get_platform_display_ext)
68 return get_platform_display_ext(platform,
69 native_display, attrib_list);
70 else
71#endif
72 return eglGetDisplay((EGLNativeDisplayType) native_display);
73}
74
75#ifdef __cplusplus
76}
77#endif
78
79#endif /* WESTON_PLATFORM_H */