1 // Copyright 2012 Intel Corporation
3 // All rights reserved.
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
8 // - Redistributions of source code must retain the above copyright notice, this
9 // list of conditions and the following disclaimer.
11 // - Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "wcore_error.h"
29 #include "wcore_platform.h"
31 #include "wegl_display.h"
32 #include "wegl_imports.h"
33 #include "wegl_util.h"
34 #include "wegl_platform.h"
37 get_apis(struct wegl_display
*dpy
)
39 struct wegl_platform
*plat
= wegl_platform(dpy
->wcore
.platform
);
40 const char *apis
= plat
->eglQueryString(dpy
->egl
, EGL_CLIENT_APIS
);
42 // Our minimum requirement - EGL 1.2 ...
43 if (dpy
->major_version
!= 1 || dpy
->minor_version
< 2) {
44 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM
,
45 "EGL 1.2 or later is required");
49 // ... plus working eglQueryString(EGL_CLIENT_APIS).
51 wegl_emit_error(plat
, "eglQueryString(EGL_CLIENT_APIS)");
55 // waffle_is_extension_in_string() resets the error state. That's ok,
56 // however, because if we've reached this point then no error should be
58 assert(wcore_error_get_code() == 0);
60 if (waffle_is_extension_in_string(apis
, "OpenGL_ES"))
61 dpy
->api_mask
|= WEGL_OPENGL_ES_API
;
63 // Check for "OpenGL" if we're running EGL 1.4 or later.
64 if (dpy
->major_version
== 1 && dpy
->minor_version
>= 4)
65 if (waffle_is_extension_in_string(apis
, "OpenGL"))
66 dpy
->api_mask
|= WEGL_OPENGL_API
;
72 get_extensions(struct wegl_display
*dpy
)
74 struct wegl_platform
*plat
= wegl_platform(dpy
->wcore
.platform
);
75 const char *extensions
= plat
->eglQueryString(dpy
->egl
, EGL_EXTENSIONS
);
78 wegl_emit_error(plat
, "eglQueryString(EGL_EXTENSIONS)");
82 // waffle_is_extension_in_string() resets the error state. That's ok,
83 // however, because if we've reached this point then no error should be
85 assert(wcore_error_get_code() == 0);
87 dpy
->EXT_create_context_robustness
= waffle_is_extension_in_string(extensions
, "EGL_EXT_create_context_robustness");
88 dpy
->KHR_create_context
= waffle_is_extension_in_string(extensions
, "EGL_KHR_create_context");
93 /// On Linux, according to eglplatform.h, EGLNativeDisplayType and intptr_t
94 /// have the same size regardless of platform.
96 wegl_display_init(struct wegl_display
*dpy
,
97 struct wcore_platform
*wc_plat
,
98 intptr_t native_display
)
100 struct wegl_platform
*plat
= wegl_platform(wc_plat
);
103 ok
= wcore_display_init(&dpy
->wcore
, wc_plat
);
107 dpy
->egl
= plat
->eglGetDisplay((EGLNativeDisplayType
) native_display
);
109 wegl_emit_error(plat
, "eglGetDisplay");
113 ok
= plat
->eglInitialize(dpy
->egl
, &dpy
->major_version
, &dpy
->minor_version
);
115 wegl_emit_error(plat
, "eglInitialize");
123 ok
= get_extensions(dpy
);
130 wegl_display_teardown(dpy
);
135 wegl_display_teardown(struct wegl_display
*dpy
)
137 struct wegl_platform
*plat
= wegl_platform(dpy
->wcore
.platform
);
141 ok
= plat
->eglTerminate(dpy
->egl
);
143 wegl_emit_error(plat
, "eglTerminate");
150 wegl_display_supports_context_api(struct wcore_display
*wc_dpy
,
151 int32_t waffle_context_api
)
153 struct wegl_display
*dpy
= wegl_display(wc_dpy
);
155 switch (waffle_context_api
) {
156 case WAFFLE_CONTEXT_OPENGL
:
157 return !!(dpy
->api_mask
& WEGL_OPENGL_API
);
158 case WAFFLE_CONTEXT_OPENGL_ES1
:
159 case WAFFLE_CONTEXT_OPENGL_ES2
:
160 return !!(dpy
->api_mask
& WEGL_OPENGL_ES_API
);
161 case WAFFLE_CONTEXT_OPENGL_ES3
:
162 return !!(dpy
->api_mask
& WEGL_OPENGL_ES_API
) &&
163 dpy
->KHR_create_context
;