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