Revert "wegl: add EGL image create/destroy"
[mesa-waffle.git] / src / waffle / egl / wegl_display.c
blobbd7d375de546e946d69251020940fde7b69e438b
1 // Copyright 2012 Intel Corporation
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
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.
26 #include <assert.h>
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"
36 static bool
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");
46 return false;
49 // ... plus working eglQueryString(EGL_CLIENT_APIS).
50 if (!apis) {
51 wegl_emit_error(plat, "eglQueryString(EGL_CLIENT_APIS)");
52 return false;
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
57 // pending emission.
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;
68 return true;
71 static bool
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);
77 if (!extensions) {
78 wegl_emit_error(plat, "eglQueryString(EGL_EXTENSIONS)");
79 return false;
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
84 // pending emission.
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");
90 return true;
93 /// On Linux, according to eglplatform.h, EGLNativeDisplayType and intptr_t
94 /// have the same size regardless of platform.
95 bool
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);
101 bool ok;
103 ok = wcore_display_init(&dpy->wcore, wc_plat);
104 if (!ok)
105 goto fail;
107 dpy->egl = plat->eglGetDisplay((EGLNativeDisplayType) native_display);
108 if (!dpy->egl) {
109 wegl_emit_error(plat, "eglGetDisplay");
110 goto fail;
113 ok = plat->eglInitialize(dpy->egl, &dpy->major_version, &dpy->minor_version);
114 if (!ok) {
115 wegl_emit_error(plat, "eglInitialize");
116 goto fail;
119 ok = get_apis(dpy);
120 if (!ok)
121 goto fail;
123 ok = get_extensions(dpy);
124 if (!ok)
125 goto fail;
127 return true;
129 fail:
130 wegl_display_teardown(dpy);
131 return false;
134 bool
135 wegl_display_teardown(struct wegl_display *dpy)
137 struct wegl_platform *plat = wegl_platform(dpy->wcore.platform);
138 bool ok = true;
140 if (dpy->egl) {
141 ok = plat->eglTerminate(dpy->egl);
142 if (!ok)
143 wegl_emit_error(plat, "eglTerminate");
146 return ok;
149 bool
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;
164 default:
165 assert(false);
166 return false;