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