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