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