Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 1 | /* |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 2 | ** Copyright 2007, The Android Open Source Project |
| 3 | ** |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | ** you may not use this file except in compliance with the License. |
| 6 | ** You may obtain a copy of the License at |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 7 | ** |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 9 | ** |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 10 | ** Unless required by applicable law or agreed to in writing, software |
| 11 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | ** See the License for the specific language governing permissions and |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 18 | |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 19 | #include "egl_display.h" |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 20 | |
Yiwei Zhang | 8af003e | 2020-06-04 14:11:30 -0700 | [diff] [blame] | 21 | #include <SurfaceFlingerProperties.h> |
| 22 | #include <android-base/properties.h> |
| 23 | #include <android/dlext.h> |
| 24 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 25 | #include <configstore/Utils.h> |
| 26 | #include <dlfcn.h> |
| 27 | #include <graphicsenv/GraphicsEnv.h> |
| 28 | |
Mathias Agopian | 39c24a2 | 2013-04-04 23:17:56 -0700 | [diff] [blame] | 29 | #include "../egl_impl.h" |
Yiwei Zhang | 8af003e | 2020-06-04 14:11:30 -0700 | [diff] [blame] | 30 | #include "EGL/eglext_angle.h" |
Tobin Ehlis | 96a184d | 2018-07-18 16:14:07 -0600 | [diff] [blame] | 31 | #include "Loader.h" |
| 32 | #include "egl_angle_platform.h" |
Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 33 | #include "egl_cache.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 34 | #include "egl_object.h" |
| 35 | #include "egl_tls.h" |
Yiwei Zhang | 8af003e | 2020-06-04 14:11:30 -0700 | [diff] [blame] | 36 | #include "private/EGL/display.h" |
Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 37 | |
| 38 | using namespace android::hardware::configstore; |
| 39 | using namespace android::hardware::configstore::V1_0; |
| 40 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 41 | namespace android { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 42 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 43 | static const char* const sVendorString = "Android"; |
| 44 | static const char* const sVersionString14 = "1.4 Android META-EGL"; |
| 45 | static const char* const sVersionString15 = "1.5 Android META-EGL"; |
| 46 | static const char* const sClientApiString = "OpenGL_ES"; |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 47 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 48 | extern const char* const gBuiltinExtensionString; |
| 49 | extern const char* const gExtensionString; |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 50 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 51 | extern void setGLHooksThreadSpecific(gl_hooks_t const* value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 52 | |
Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 53 | bool findExtension(const char* exts, const char* name, size_t nameLen) { |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 54 | if (exts) { |
Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 55 | if (!nameLen) { |
| 56 | nameLen = strlen(name); |
| 57 | } |
Kalle Raita | 7804aa2 | 2016-04-18 16:03:37 -0700 | [diff] [blame] | 58 | for (const char* match = strstr(exts, name); match; match = strstr(match + nameLen, name)) { |
| 59 | if (match[nameLen] == '\0' || match[nameLen] == ' ') { |
| 60 | return true; |
| 61 | } |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | return false; |
| 65 | } |
| 66 | |
Krzysztof Kosiński | dbccd22 | 2019-05-16 14:10:25 -0700 | [diff] [blame] | 67 | bool needsAndroidPEglMitigation() { |
Michael Hoisie | 4e0f56b | 2020-04-30 18:40:55 -0400 | [diff] [blame] | 68 | static const int32_t vndk_version = base::GetIntProperty("ro.vndk.version", -1); |
Krzysztof Kosiński | dbccd22 | 2019-05-16 14:10:25 -0700 | [diff] [blame] | 69 | return vndk_version <= 28; |
| 70 | } |
| 71 | |
Mathias Agopian | b7f9a24 | 2017-03-08 22:29:31 -0800 | [diff] [blame] | 72 | int egl_get_init_count(EGLDisplay dpy) { |
| 73 | egl_display_t* eglDisplay = egl_display_t::get(dpy); |
| 74 | return eglDisplay ? eglDisplay->getRefsCount() : 0; |
| 75 | } |
| 76 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 77 | egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS]; |
| 78 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 79 | egl_display_t::egl_display_t() |
| 80 | : magic('_dpy'), |
| 81 | finishOnSwap(false), |
| 82 | traceGpuCompletion(false), |
| 83 | refs(0), |
| 84 | eglIsInitialized(false) {} |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 85 | |
| 86 | egl_display_t::~egl_display_t() { |
| 87 | magic = 0; |
Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 88 | egl_cache_t::get()->terminate(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | egl_display_t* egl_display_t::get(EGLDisplay dpy) { |
Ivan Lozano | 7025b54 | 2017-12-06 14:19:44 -0800 | [diff] [blame] | 92 | if (uintptr_t(dpy) == 0) { |
| 93 | return nullptr; |
| 94 | } |
| 95 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 96 | uintptr_t index = uintptr_t(dpy) - 1U; |
Jesse Hall | d6e9946 | 2016-09-28 11:26:57 -0700 | [diff] [blame] | 97 | if (index >= NUM_DISPLAYS || !sDisplay[index].isValid()) { |
| 98 | return nullptr; |
| 99 | } |
| 100 | return &sDisplay[index]; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void egl_display_t::addObject(egl_object_t* object) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 104 | std::lock_guard<std::mutex> _l(lock); |
| 105 | objects.insert(object); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 108 | void egl_display_t::removeObject(egl_object_t* object) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 109 | std::lock_guard<std::mutex> _l(lock); |
| 110 | objects.erase(object); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 113 | bool egl_display_t::getObject(egl_object_t* object) const { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 114 | std::lock_guard<std::mutex> _l(lock); |
| 115 | if (objects.find(object) != objects.end()) { |
Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 116 | if (object->getDisplay() == this) { |
| 117 | object->incRef(); |
| 118 | return true; |
| 119 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 120 | } |
| 121 | return false; |
| 122 | } |
| 123 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 124 | EGLDisplay egl_display_t::getFromNativeDisplay(EGLNativeDisplayType disp, |
| 125 | const EGLAttrib* attrib_list) { |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 126 | if (uintptr_t(disp) >= NUM_DISPLAYS) return nullptr; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 127 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 128 | return sDisplay[uintptr_t(disp)].getPlatformDisplay(disp, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 131 | static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_connection_t* const cnx, |
| 132 | const EGLAttrib* attrib_list, EGLint* error) { |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 133 | EGLDisplay dpy = EGL_NO_DISPLAY; |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 134 | *error = EGL_NONE; |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 135 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 136 | if (cnx->egl.eglGetPlatformDisplay) { |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 137 | std::vector<EGLAttrib> attrs; |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 138 | if (attrib_list) { |
| 139 | for (const EGLAttrib* attr = attrib_list; *attr != EGL_NONE; attr += 2) { |
| 140 | attrs.push_back(attr[0]); |
| 141 | attrs.push_back(attr[1]); |
| 142 | } |
| 143 | } |
| 144 | |
Courtney Goeltzenleuchter | c1a1a86 | 2020-04-23 08:19:11 -0600 | [diff] [blame] | 145 | attrs.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE); |
| 146 | attrs.push_back(EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE); |
| 147 | |
Courtney Goeltzenleuchter | c1a1a86 | 2020-04-23 08:19:11 -0600 | [diff] [blame] | 148 | attrs.push_back(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE); |
Michael Hoisie | 4e0f56b | 2020-04-30 18:40:55 -0400 | [diff] [blame] | 149 | attrs.push_back(base::GetBoolProperty("debug.angle.validation", false)); |
Courtney Goeltzenleuchter | c1a1a86 | 2020-04-23 08:19:11 -0600 | [diff] [blame] | 150 | |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 151 | attrs.push_back(EGL_NONE); |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 152 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 153 | dpy = cnx->egl.eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, |
| 154 | reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), |
| 155 | attrs.data()); |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 156 | if (dpy == EGL_NO_DISPLAY) { |
| 157 | ALOGE("eglGetPlatformDisplay failed!"); |
Tobin Ehlis | 96a184d | 2018-07-18 16:14:07 -0600 | [diff] [blame] | 158 | } else { |
Tobin Ehlis | 75ce477 | 2018-11-20 09:48:47 -0700 | [diff] [blame] | 159 | if (!angle::initializeAnglePlatform(dpy)) { |
Tobin Ehlis | 96a184d | 2018-07-18 16:14:07 -0600 | [diff] [blame] | 160 | ALOGE("initializeAnglePlatform failed!"); |
| 161 | } |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 162 | } |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 163 | } else { |
| 164 | ALOGE("eglGetDisplay(%p) failed: Unable to look up eglGetPlatformDisplay from ANGLE", |
| 165 | display); |
| 166 | } |
| 167 | |
| 168 | return dpy; |
| 169 | } |
| 170 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 171 | EGLDisplay egl_display_t::getPlatformDisplay(EGLNativeDisplayType display, |
| 172 | const EGLAttrib* attrib_list) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 173 | std::lock_guard<std::mutex> _l(lock); |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 174 | ATRACE_CALL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 175 | |
| 176 | // get our driver loader |
| 177 | Loader& loader(Loader::getInstance()); |
| 178 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 179 | egl_connection_t* const cnx = &gEGLImpl; |
Yiwei Zhang | 5e21eb3 | 2019-06-05 00:26:03 -0700 | [diff] [blame] | 180 | if (cnx->dso) { |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 181 | EGLDisplay dpy = EGL_NO_DISPLAY; |
| 182 | |
Charlie Lao | 840bd53 | 2020-01-16 17:34:37 -0800 | [diff] [blame] | 183 | if (cnx->useAngle) { |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 184 | EGLint error; |
| 185 | dpy = getPlatformDisplayAngle(display, cnx, attrib_list, &error); |
| 186 | if (error != EGL_NONE) { |
| 187 | return setError(error, dpy); |
| 188 | } |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 189 | } |
| 190 | if (dpy == EGL_NO_DISPLAY) { |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 191 | // NOTE: eglGetPlatformDisplay with a empty attribute list |
| 192 | // behaves the same as eglGetDisplay |
| 193 | if (cnx->egl.eglGetPlatformDisplay) { |
| 194 | dpy = cnx->egl.eglGetPlatformDisplay(EGL_PLATFORM_ANDROID_KHR, display, |
| 195 | attrib_list); |
Ben Lin | e17f69b | 2018-11-05 16:49:28 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | // It is possible that eglGetPlatformDisplay does not have a |
| 199 | // working implementation for Android platform; in that case, |
| 200 | // one last fallback to eglGetDisplay |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 201 | if (dpy == EGL_NO_DISPLAY) { |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 202 | if (attrib_list) { |
| 203 | ALOGW("getPlatformDisplay: unexpected attribute list, attributes ignored"); |
| 204 | } |
| 205 | dpy = cnx->egl.eglGetDisplay(display); |
| 206 | } |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 207 | } |
| 208 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 209 | disp.dpy = dpy; |
| 210 | if (dpy == EGL_NO_DISPLAY) { |
Courtney Goeltzenleuchter | ee768c2 | 2018-10-25 11:43:52 -0600 | [diff] [blame] | 211 | loader.close(cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
| 215 | return EGLDisplay(uintptr_t(display) + 1U); |
| 216 | } |
| 217 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 218 | EGLBoolean egl_display_t::initialize(EGLint* major, EGLint* minor) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 219 | { // scope for refLock |
| 220 | std::unique_lock<std::mutex> _l(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 221 | refs++; |
| 222 | if (refs > 1) { |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 223 | // We don't know what to report until we know what the |
| 224 | // driver supports. Make sure we are initialized before |
| 225 | // returning the version info. |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 226 | while (!eglIsInitialized) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 227 | refCond.wait(_l); |
| 228 | } |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 229 | egl_connection_t* const cnx = &gEGLImpl; |
| 230 | |
| 231 | // TODO: If device doesn't provide 1.4 or 1.5 then we'll be |
| 232 | // changing the behavior from the past where we always advertise |
| 233 | // version 1.4. May need to check that revision is valid |
| 234 | // before using cnx->major & cnx->minor |
| 235 | if (major != nullptr) *major = cnx->major; |
| 236 | if (minor != nullptr) *minor = cnx->minor; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 237 | return EGL_TRUE; |
| 238 | } |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 239 | while (eglIsInitialized) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 240 | refCond.wait(_l); |
| 241 | } |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 244 | { // scope for lock |
| 245 | std::lock_guard<std::mutex> _l(lock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 246 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 247 | setGLHooksThreadSpecific(&gHooksNoContext); |
| 248 | |
| 249 | // initialize each EGL and |
| 250 | // build our own extension string first, based on the extension we know |
| 251 | // and the extension supported by our client implementation |
| 252 | |
| 253 | egl_connection_t* const cnx = &gEGLImpl; |
| 254 | cnx->major = -1; |
| 255 | cnx->minor = -1; |
| 256 | if (cnx->dso) { |
| 257 | EGLDisplay idpy = disp.dpy; |
| 258 | if (cnx->egl.eglInitialize(idpy, &cnx->major, &cnx->minor)) { |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 259 | // ALOGD("initialized dpy=%p, ver=%d.%d, cnx=%p", |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 260 | // idpy, cnx->major, cnx->minor, cnx); |
| 261 | |
| 262 | // display is now initialized |
| 263 | disp.state = egl_display_t::INITIALIZED; |
| 264 | |
| 265 | // get the query-strings for this display for each implementation |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 266 | disp.queryString.vendor = cnx->egl.eglQueryString(idpy, EGL_VENDOR); |
| 267 | disp.queryString.version = cnx->egl.eglQueryString(idpy, EGL_VERSION); |
| 268 | disp.queryString.extensions = cnx->egl.eglQueryString(idpy, EGL_EXTENSIONS); |
| 269 | disp.queryString.clientApi = cnx->egl.eglQueryString(idpy, EGL_CLIENT_APIS); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 270 | |
| 271 | } else { |
| 272 | ALOGW("eglInitialize(%p) failed (%s)", idpy, |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 273 | egl_tls_t::egl_strerror(cnx->egl.eglGetError())); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
Sean Callanan | ad9061c | 2019-03-12 14:07:23 -0700 | [diff] [blame] | 277 | if (cnx->minor == 5) { |
| 278 | // full list in egl_entries.in |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 279 | if (!cnx->egl.eglCreateImage || !cnx->egl.eglDestroyImage || |
| 280 | !cnx->egl.eglGetPlatformDisplay || !cnx->egl.eglCreatePlatformWindowSurface || |
| 281 | !cnx->egl.eglCreatePlatformPixmapSurface || !cnx->egl.eglCreateSync || |
| 282 | !cnx->egl.eglDestroySync || !cnx->egl.eglClientWaitSync || |
| 283 | !cnx->egl.eglGetSyncAttrib || !cnx->egl.eglWaitSync) { |
Sean Callanan | ad9061c | 2019-03-12 14:07:23 -0700 | [diff] [blame] | 284 | ALOGE("Driver indicates EGL 1.5 support, but does not have " |
| 285 | "a critical API"); |
| 286 | cnx->minor = 4; |
| 287 | } |
| 288 | } |
| 289 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 290 | // the query strings are per-display |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 291 | mVendorString = sVendorString; |
Courtney Goeltzenleuchter | 015ed67 | 2018-07-27 13:43:23 -0600 | [diff] [blame] | 292 | mVersionString.clear(); |
| 293 | cnx->driverVersion = EGL_MAKE_VERSION(1, 4, 0); |
Courtney Goeltzenleuchter | f5b5c41 | 2019-04-10 17:36:19 -0600 | [diff] [blame] | 294 | mVersionString = sVersionString14; |
Courtney Goeltzenleuchter | 015ed67 | 2018-07-27 13:43:23 -0600 | [diff] [blame] | 295 | if ((cnx->major == 1) && (cnx->minor == 5)) { |
| 296 | mVersionString = sVersionString15; |
| 297 | cnx->driverVersion = EGL_MAKE_VERSION(1, 5, 0); |
Courtney Goeltzenleuchter | 015ed67 | 2018-07-27 13:43:23 -0600 | [diff] [blame] | 298 | } |
| 299 | if (mVersionString.empty()) { |
| 300 | ALOGW("Unexpected driver version: %d.%d, want 1.4 or 1.5", cnx->major, cnx->minor); |
| 301 | mVersionString = sVersionString14; |
| 302 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 303 | mClientApiString = sClientApiString; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 304 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 305 | mExtensionString = gBuiltinExtensionString; |
Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 306 | |
Krzysztof Kosiński | f2fc4e9 | 2018-04-18 16:29:49 -0700 | [diff] [blame] | 307 | hasColorSpaceSupport = findExtension(disp.queryString.extensions, "EGL_KHR_gl_colorspace"); |
| 308 | |
| 309 | // Note: CDD requires that devices supporting wide color and/or HDR color also support |
| 310 | // the EGL_KHR_gl_colorspace extension. |
Sundong Ahn | 204fb1f | 2020-04-23 21:56:36 +0900 | [diff] [blame] | 311 | bool wideColorBoardConfig = android::sysprop::has_wide_color_display(false); |
Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 312 | |
| 313 | // Add wide-color extensions if device can support wide-color |
Krzysztof Kosiński | f2fc4e9 | 2018-04-18 16:29:49 -0700 | [diff] [blame] | 314 | if (wideColorBoardConfig && hasColorSpaceSupport) { |
Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 315 | mExtensionString.append( |
| 316 | "EGL_EXT_gl_colorspace_scrgb EGL_EXT_gl_colorspace_scrgb_linear " |
Peiyong Lin | e0ff377 | 2018-12-08 22:23:20 -0800 | [diff] [blame] | 317 | "EGL_EXT_gl_colorspace_display_p3_linear EGL_EXT_gl_colorspace_display_p3 " |
| 318 | "EGL_EXT_gl_colorspace_display_p3_passthrough "); |
Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 319 | } |
| 320 | |
Sundong Ahn | 204fb1f | 2020-04-23 21:56:36 +0900 | [diff] [blame] | 321 | bool hasHdrBoardConfig = android::sysprop::has_HDR_display(false); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 322 | |
Krzysztof Kosiński | f2fc4e9 | 2018-04-18 16:29:49 -0700 | [diff] [blame] | 323 | if (hasHdrBoardConfig && hasColorSpaceSupport) { |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 324 | // hasHDRBoardConfig indicates the system is capable of supporting HDR content. |
| 325 | // Typically that means there is an HDR capable display attached, but could be |
| 326 | // support for attaching an HDR display. In either case, advertise support for |
| 327 | // HDR color spaces. |
| 328 | mExtensionString.append( |
| 329 | "EGL_EXT_gl_colorspace_bt2020_linear EGL_EXT_gl_colorspace_bt2020_pq "); |
| 330 | } |
| 331 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 332 | char const* start = gExtensionString; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 333 | do { |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 334 | // length of the extension name |
| 335 | size_t len = strcspn(start, " "); |
| 336 | if (len) { |
| 337 | // NOTE: we could avoid the copy if we had strnstr. |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 338 | const std::string ext(start, len); |
Krzysztof Kosiński | dbccd22 | 2019-05-16 14:10:25 -0700 | [diff] [blame] | 339 | // Mitigation for Android P vendor partitions: Adreno 530 driver shipped on |
| 340 | // some Android P vendor partitions this extension under the draft KHR name, |
| 341 | // but during Khronos review it was decided to demote it to EXT. |
| 342 | if (needsAndroidPEglMitigation() && ext == "EGL_EXT_image_gl_colorspace" && |
| 343 | findExtension(disp.queryString.extensions, "EGL_KHR_image_gl_colorspace")) { |
| 344 | mExtensionString.append("EGL_EXT_image_gl_colorspace "); |
| 345 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 346 | if (findExtension(disp.queryString.extensions, ext.c_str(), len)) { |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 347 | mExtensionString.append(ext + " "); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 348 | } |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 349 | // advance to the next extension name, skipping the space. |
| 350 | start += len; |
| 351 | start += (*start == ' ') ? 1 : 0; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 352 | } |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 353 | } while (*start != '\0'); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 354 | |
| 355 | egl_cache_t::get()->initialize(this); |
| 356 | |
Michael Hoisie | 4e0f56b | 2020-04-30 18:40:55 -0400 | [diff] [blame] | 357 | finishOnSwap = base::GetBoolProperty("debug.egl.finish", false); |
| 358 | traceGpuCompletion = base::GetBoolProperty("debug.egl.traceGpuCompletion", false); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 359 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame] | 360 | // TODO: If device doesn't provide 1.4 or 1.5 then we'll be |
| 361 | // changing the behavior from the past where we always advertise |
| 362 | // version 1.4. May need to check that revision is valid |
| 363 | // before using cnx->major & cnx->minor |
| 364 | if (major != nullptr) *major = cnx->major; |
| 365 | if (minor != nullptr) *minor = cnx->minor; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 368 | { // scope for refLock |
| 369 | std::unique_lock<std::mutex> _l(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 370 | eglIsInitialized = true; |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 371 | refCond.notify_all(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 374 | return EGL_TRUE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | EGLBoolean egl_display_t::terminate() { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 378 | { // scope for refLock |
| 379 | std::unique_lock<std::mutex> _rl(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 380 | if (refs == 0) { |
| 381 | /* |
| 382 | * From the EGL spec (3.2): |
| 383 | * "Termination of a display that has already been terminated, |
| 384 | * (...), is allowed, but the only effect of such a call is |
| 385 | * to return EGL_TRUE (...) |
| 386 | */ |
| 387 | return EGL_TRUE; |
| 388 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 389 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 390 | // this is specific to Android, display termination is ref-counted. |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 391 | refs--; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 392 | if (refs > 0) { |
| 393 | return EGL_TRUE; |
| 394 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | EGLBoolean res = EGL_FALSE; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 398 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 399 | { // scope for lock |
| 400 | std::lock_guard<std::mutex> _l(lock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 401 | |
| 402 | egl_connection_t* const cnx = &gEGLImpl; |
| 403 | if (cnx->dso && disp.state == egl_display_t::INITIALIZED) { |
Tobin Ehlis | 96a184d | 2018-07-18 16:14:07 -0600 | [diff] [blame] | 404 | // If we're using ANGLE reset any custom DisplayPlatform |
Charlie Lao | 840bd53 | 2020-01-16 17:34:37 -0800 | [diff] [blame] | 405 | if (cnx->useAngle) { |
Tobin Ehlis | 75ce477 | 2018-11-20 09:48:47 -0700 | [diff] [blame] | 406 | angle::resetAnglePlatform(disp.dpy); |
Tobin Ehlis | 96a184d | 2018-07-18 16:14:07 -0600 | [diff] [blame] | 407 | } |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 408 | if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) { |
| 409 | ALOGW("eglTerminate(%p) failed (%s)", disp.dpy, |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 410 | egl_tls_t::egl_strerror(cnx->egl.eglGetError())); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 411 | } |
| 412 | // REVISIT: it's unclear what to do if eglTerminate() fails |
| 413 | disp.state = egl_display_t::TERMINATED; |
| 414 | res = EGL_TRUE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 415 | } |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 416 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 417 | // Reset the extension string since it will be regenerated if we get |
| 418 | // reinitialized. |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 419 | mExtensionString.clear(); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 420 | |
| 421 | // Mark all objects remaining in the list as terminated, unless |
| 422 | // there are no reference to them, it which case, we're free to |
| 423 | // delete them. |
| 424 | size_t count = objects.size(); |
Dan Albert | eacd31f | 2016-02-02 15:08:34 -0800 | [diff] [blame] | 425 | ALOGW_IF(count, "eglTerminate() called w/ %zu objects remaining", count); |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 426 | for (auto o : objects) { |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 427 | o->destroy(); |
| 428 | } |
| 429 | |
| 430 | // this marks all object handles are "terminated" |
| 431 | objects.clear(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 434 | { // scope for refLock |
| 435 | std::unique_lock<std::mutex> _rl(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 436 | eglIsInitialized = false; |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 437 | refCond.notify_all(); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 440 | return res; |
| 441 | } |
| 442 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 443 | void egl_display_t::loseCurrent(egl_context_t* cur_c) { |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 444 | if (cur_c) { |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 445 | egl_display_t* display = cur_c->getDisplay(); |
| 446 | if (display) { |
| 447 | display->loseCurrentImpl(cur_c); |
| 448 | } |
| 449 | } |
| 450 | } |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 451 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 452 | void egl_display_t::loseCurrentImpl(egl_context_t* cur_c) { |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 453 | // by construction, these are either 0 or valid (possibly terminated) |
| 454 | // it should be impossible for these to be invalid |
| 455 | ContextRef _cur_c(cur_c); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 456 | SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : nullptr); |
| 457 | SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : nullptr); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 458 | |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 459 | { // scope for the lock |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 460 | std::lock_guard<std::mutex> _l(lock); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 461 | cur_c->onLooseCurrent(); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 462 | } |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 463 | |
| 464 | // This cannot be called with the lock held because it might end-up |
| 465 | // calling back into EGL (in particular when a surface is destroyed |
| 466 | // it calls ANativeWindow::disconnect |
| 467 | _cur_c.release(); |
| 468 | _cur_r.release(); |
| 469 | _cur_d.release(); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 470 | } |
| 471 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 472 | EGLBoolean egl_display_t::makeCurrent(egl_context_t* c, egl_context_t* cur_c, EGLSurface draw, |
| 473 | EGLSurface read, EGLContext /*ctx*/, EGLSurface impl_draw, |
| 474 | EGLSurface impl_read, EGLContext impl_ctx) { |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 475 | EGLBoolean result; |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 476 | |
| 477 | // by construction, these are either 0 or valid (possibly terminated) |
| 478 | // it should be impossible for these to be invalid |
| 479 | ContextRef _cur_c(cur_c); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 480 | SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : nullptr); |
| 481 | SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : nullptr); |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 482 | |
| 483 | { // scope for the lock |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 484 | std::lock_guard<std::mutex> _l(lock); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 485 | if (c) { |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 486 | result = c->cnx->egl.eglMakeCurrent(disp.dpy, impl_draw, impl_read, impl_ctx); |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 487 | if (result == EGL_TRUE) { |
| 488 | c->onMakeCurrent(draw, read); |
| 489 | } |
| 490 | } else { |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 491 | result = cur_c->cnx->egl.eglMakeCurrent(disp.dpy, impl_draw, impl_read, impl_ctx); |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 492 | if (result == EGL_TRUE) { |
| 493 | cur_c->onLooseCurrent(); |
| 494 | } |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 495 | } |
| 496 | } |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 497 | |
| 498 | if (result == EGL_TRUE) { |
| 499 | // This cannot be called with the lock held because it might end-up |
| 500 | // calling back into EGL (in particular when a surface is destroyed |
| 501 | // it calls ANativeWindow::disconnect |
| 502 | _cur_c.release(); |
| 503 | _cur_r.release(); |
| 504 | _cur_d.release(); |
| 505 | } |
| 506 | |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 507 | return result; |
| 508 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 509 | |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 510 | bool egl_display_t::haveExtension(const char* name, size_t nameLen) const { |
| 511 | if (!nameLen) { |
| 512 | nameLen = strlen(name); |
| 513 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 514 | return findExtension(mExtensionString.c_str(), name, nameLen); |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame^] | 517 | egl_display_t* validate_display(EGLDisplay dpy) { |
| 518 | egl_display_t* const dp = get_display(dpy); |
| 519 | if (!dp) return setError(EGL_BAD_DISPLAY, (egl_display_t*)nullptr); |
| 520 | if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, (egl_display_t*)nullptr); |
| 521 | |
| 522 | return dp; |
| 523 | } |
| 524 | |
| 525 | egl_display_t* validate_display_connection(EGLDisplay dpy, egl_connection_t** outCnx) { |
| 526 | *outCnx = nullptr; |
| 527 | egl_display_t* dp = validate_display(dpy); |
| 528 | if (!dp) return dp; |
| 529 | *outCnx = &gEGLImpl; |
| 530 | if ((*outCnx)->dso == nullptr) { |
| 531 | return setError(EGL_BAD_CONFIG, (egl_display_t*)nullptr); |
| 532 | } |
| 533 | return dp; |
| 534 | } |
| 535 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 536 | }; // namespace android |