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