blob: 64e1fbf271ba9891ba27cf84267c70f5fedf8fd8 [file] [log] [blame]
Jonny Lamb51a7ae52015-03-20 15:26:51 +01001/*
2 * Copyright © 2015 Collabora, Ltd.
3 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Jonny Lamb51a7ae52015-03-20 15:26:51 +010011 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Jonny Lamb51a7ae52015-03-20 15:26:51 +010024 */
25
26#ifndef WESTON_PLATFORM_H
27#define WESTON_PLATFORM_H
28
29#include <string.h>
30
Jonny Lamb0e2ab362015-03-24 13:12:07 +010031#ifdef ENABLE_EGL
Jonny Lamb51a7ae52015-03-20 15:26:51 +010032#include <EGL/egl.h>
33#include <EGL/eglext.h>
Jonny Lamb0e2ab362015-03-24 13:12:07 +010034#endif
35
36#ifndef EGL_PLATFORM_WAYLAND_KHR
37#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
38#endif
Jonny Lamb51a7ae52015-03-20 15:26:51 +010039
40#ifdef __cplusplus
41extern "C" {
42#endif
43
Jonny Lamb0e2ab362015-03-24 13:12:07 +010044#ifdef ENABLE_EGL
45
46#ifndef EGL_EXT_platform_base
Manuel Bachmanne8128592015-03-28 07:05:48 +010047typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform,
48 void *native_display,
49 const EGLint *attrib_list);
50typedef EGLSurface (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy,
51 EGLConfig config,
52 void *native_window,
53 const EGLint *attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010054#endif
55
Jonny Lamb759fbf42015-03-24 13:12:08 +010056static inline void *
57weston_platform_get_egl_proc_address(const char *address)
Jonny Lamb51a7ae52015-03-20 15:26:51 +010058{
Jonny Lamb759fbf42015-03-24 13:12:08 +010059 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010060
Manuel Bachmann5d1d2ca2015-03-29 08:17:01 +020061 if (extensions
62 && (strstr(extensions, "EGL_EXT_platform_wayland")
63 || strstr(extensions, "EGL_KHR_platform_wayland"))) {
Jonny Lamb759fbf42015-03-24 13:12:08 +010064 return (void *) eglGetProcAddress(address);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010065 }
Jonny Lamb759fbf42015-03-24 13:12:08 +010066
67 return NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010068}
69
70static inline EGLDisplay
71weston_platform_get_egl_display(EGLenum platform, void *native_display,
72 const EGLint *attrib_list)
73{
Jonny Lamb759fbf42015-03-24 13:12:08 +010074 static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
Jonny Lamb51a7ae52015-03-20 15:26:51 +010075
Jonny Lamb759fbf42015-03-24 13:12:08 +010076 if (!get_platform_display) {
77 get_platform_display = weston_platform_get_egl_proc_address(
78 "eglGetPlatformDisplayEXT");
79 }
80
81 if (get_platform_display)
82 return get_platform_display(platform,
83 native_display, attrib_list);
Jonny Lamb0e2ab362015-03-24 13:12:07 +010084
85 return eglGetDisplay((EGLNativeDisplayType) native_display);
Jonny Lamb51a7ae52015-03-20 15:26:51 +010086}
87
Jonny Lamb4bdcb572015-03-20 15:26:53 +010088static inline EGLSurface
Jonny Lambabff8832015-03-24 13:12:09 +010089weston_platform_create_egl_surface(EGLDisplay dpy, EGLConfig config,
90 void *native_window,
91 const EGLint *attrib_list)
Jonny Lamb4bdcb572015-03-20 15:26:53 +010092{
Jonny Lamb759fbf42015-03-24 13:12:08 +010093 static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC
94 create_platform_window = NULL;
Jonny Lamb4bdcb572015-03-20 15:26:53 +010095
Jonny Lamb759fbf42015-03-24 13:12:08 +010096 if (!create_platform_window) {
97 create_platform_window = weston_platform_get_egl_proc_address(
98 "eglCreatePlatformWindowSurfaceEXT");
99 }
100
101 if (create_platform_window)
102 return create_platform_window(dpy, config,
103 native_window,
104 attrib_list);
Jonny Lamb4bdcb572015-03-20 15:26:53 +0100105
106 return eglCreateWindowSurface(dpy, config,
107 (EGLNativeWindowType) native_window,
108 attrib_list);
109}
110
Jonny Lamb0e2ab362015-03-24 13:12:07 +0100111#else /* ENABLE_EGL */
112
113static inline void *
114weston_platform_get_egl_display(void *platform, void *native_display,
115 const int *attrib_list)
116{
117 return NULL;
118}
119
120static inline void *
Jonny Lambabff8832015-03-24 13:12:09 +0100121weston_platform_create_egl_surface(void *dpy, void *config,
122 void *native_window,
123 const int *attrib_list)
Jonny Lamb0e2ab362015-03-24 13:12:07 +0100124{
125 return NULL;
126}
127#endif /* ENABLE_EGL */
128
Jonny Lamb51a7ae52015-03-20 15:26:51 +0100129#ifdef __cplusplus
130}
131#endif
132
133#endif /* WESTON_PLATFORM_H */