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