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