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 | |
Mathias Agopian | b7f9a24 | 2017-03-08 22:29:31 -0800 | [diff] [blame] | 74 | int egl_get_init_count(EGLDisplay dpy) { |
| 75 | egl_display_t* eglDisplay = egl_display_t::get(dpy); |
| 76 | return eglDisplay ? eglDisplay->getRefsCount() : 0; |
| 77 | } |
| 78 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 79 | egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS]; |
| 80 | |
| 81 | egl_display_t::egl_display_t() : |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 82 | magic('_dpy'), finishOnSwap(false), traceGpuCompletion(false), refs(0), eglIsInitialized(false) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | egl_display_t::~egl_display_t() { |
| 86 | magic = 0; |
Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 87 | egl_cache_t::get()->terminate(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | egl_display_t* egl_display_t::get(EGLDisplay dpy) { |
Ivan Lozano | 7025b54 | 2017-12-06 14:19:44 -0800 | [diff] [blame] | 91 | if (uintptr_t(dpy) == 0) { |
| 92 | return nullptr; |
| 93 | } |
| 94 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 95 | uintptr_t index = uintptr_t(dpy)-1U; |
Jesse Hall | d6e9946 | 2016-09-28 11:26:57 -0700 | [diff] [blame] | 96 | if (index >= NUM_DISPLAYS || !sDisplay[index].isValid()) { |
| 97 | return nullptr; |
| 98 | } |
| 99 | return &sDisplay[index]; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void egl_display_t::addObject(egl_object_t* object) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 103 | std::lock_guard<std::mutex> _l(lock); |
| 104 | objects.insert(object); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 107 | void egl_display_t::removeObject(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.erase(object); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 112 | bool egl_display_t::getObject(egl_object_t* object) const { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 113 | std::lock_guard<std::mutex> _l(lock); |
| 114 | if (objects.find(object) != objects.end()) { |
Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 115 | if (object->getDisplay() == this) { |
| 116 | object->incRef(); |
| 117 | return true; |
| 118 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 119 | } |
| 120 | return false; |
| 121 | } |
| 122 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 123 | EGLDisplay egl_display_t::getFromNativeDisplay(EGLNativeDisplayType disp, |
| 124 | const EGLAttrib* attrib_list) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 125 | if (uintptr_t(disp) >= NUM_DISPLAYS) |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 126 | return nullptr; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 127 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 128 | return sDisplay[uintptr_t(disp)].getPlatformDisplay(disp, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 131 | static bool addAnglePlatformAttributes(egl_connection_t* const cnx, const EGLAttrib* attrib_list, |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 132 | std::vector<EGLAttrib>& attrs) { |
| 133 | intptr_t vendorEGL = (intptr_t)cnx->vendorEGL; |
| 134 | |
| 135 | EGLint angleBackendDefault = EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE; |
| 136 | if (attrib_list) { |
| 137 | while (*attrib_list != EGL_NONE) { |
| 138 | EGLAttrib attr = *attrib_list++; |
| 139 | EGLAttrib value = *attrib_list++; |
| 140 | if (attr == EGL_PLATFORM_ANGLE_TYPE_ANGLE) { |
| 141 | switch (value) { |
| 142 | case EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE: |
| 143 | angleBackendDefault = EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE; |
| 144 | break; |
| 145 | case EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE: |
| 146 | case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE: |
| 147 | angleBackendDefault = value; |
| 148 | break; |
| 149 | default: |
| 150 | ALOGW("Invalid EGL_PLATFORM_ANGLE_TYPE_ANGLE attribute: 0x%" PRIxPTR, |
| 151 | value); |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 158 | // Allow debug property to override application's |
| 159 | char prop[PROPERTY_VALUE_MAX]; |
| 160 | property_get("debug.angle.backend", prop, "0"); |
| 161 | switch (atoi(prop)) { |
| 162 | case 1: |
| 163 | ALOGV("addAnglePlatformAttributes: Requesting OpenGLES back-end"); |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 164 | angleBackendDefault = EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE; |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 165 | break; |
| 166 | case 2: |
| 167 | ALOGV("addAnglePlatformAttributes: Requesting Vulkan back-end"); |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 168 | angleBackendDefault = EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE; |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 169 | break; |
| 170 | default: |
| 171 | break; |
| 172 | } |
| 173 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 174 | if (cnx->angleBackend == 0) { |
| 175 | // Haven't been initialized yet, so set it. |
| 176 | cnx->angleBackend = angleBackendDefault; |
| 177 | } else if (cnx->angleBackend != angleBackendDefault) { |
| 178 | return false; |
| 179 | } |
| 180 | |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 181 | attrs.reserve(4 * 2); |
| 182 | |
| 183 | attrs.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE); |
| 184 | attrs.push_back(cnx->angleBackend); |
| 185 | |
| 186 | switch (cnx->angleBackend) { |
| 187 | case EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE: |
| 188 | ALOGV("%s: Requesting Vulkan ANGLE back-end", __FUNCTION__); |
| 189 | property_get("debug.angle.validation", prop, "0"); |
| 190 | attrs.push_back(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE); |
| 191 | attrs.push_back(atoi(prop)); |
| 192 | break; |
| 193 | case EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE: |
| 194 | ALOGV("%s: Requesting Default ANGLE back-end", __FUNCTION__); |
| 195 | break; |
| 196 | case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE: |
| 197 | ALOGV("%s: Requesting OpenGL ES ANGLE back-end", __FUNCTION__); |
| 198 | // NOTE: This is only valid if the backend is OpenGL |
| 199 | attrs.push_back(EGL_PLATFORM_ANGLE_EGL_HANDLE_ANGLE); |
| 200 | attrs.push_back(vendorEGL); |
| 201 | break; |
| 202 | default: |
| 203 | ALOGV("%s: Requesting Unknown (%d) ANGLE back-end", __FUNCTION__, cnx->angleBackend); |
| 204 | break; |
| 205 | } |
| 206 | attrs.push_back(EGL_PLATFORM_ANGLE_CONTEXT_VIRTUALIZATION_ANGLE); |
| 207 | attrs.push_back(EGL_FALSE); |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 208 | |
| 209 | return true; |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 210 | } |
| 211 | |
Tobin Ehlis | 96a184d | 2018-07-18 16:14:07 -0600 | [diff] [blame] | 212 | // Initialize function ptrs for ANGLE PlatformMethods struct, used for systrace |
| 213 | bool initializeAnglePlatform(EGLDisplay dpy) { |
| 214 | // Since we're inside libEGL, use dlsym to lookup fptr for ANGLEGetDisplayPlatform |
| 215 | android_namespace_t* ns = android_getAngleNamespace(); |
| 216 | const android_dlextinfo dlextinfo = { |
| 217 | .flags = ANDROID_DLEXT_USE_NAMESPACE, |
| 218 | .library_namespace = ns, |
| 219 | }; |
| 220 | void* so = android_dlopen_ext("libEGL_angle.so", RTLD_LOCAL | RTLD_NOW, &dlextinfo); |
| 221 | angle::AnglePlatformImpl::angleGetDisplayPlatform = |
| 222 | reinterpret_cast<angle::GetDisplayPlatformFunc>(dlsym(so, "ANGLEGetDisplayPlatform")); |
| 223 | |
| 224 | if (!angle::AnglePlatformImpl::angleGetDisplayPlatform) { |
| 225 | ALOGE("dlsym lookup of ANGLEGetDisplayPlatform in libEGL_angle failed!"); |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | angle::AnglePlatformImpl::angleResetDisplayPlatform = |
| 230 | reinterpret_cast<angle::ResetDisplayPlatformFunc>( |
| 231 | eglGetProcAddress("ANGLEResetDisplayPlatform")); |
| 232 | |
| 233 | angle::PlatformMethods* platformMethods = nullptr; |
| 234 | if (!((angle::AnglePlatformImpl::angleGetDisplayPlatform)(dpy, angle::g_PlatformMethodNames, |
| 235 | angle::g_NumPlatformMethods, nullptr, |
| 236 | &platformMethods))) { |
| 237 | ALOGE("ANGLEGetDisplayPlatform call failed!"); |
| 238 | return false; |
| 239 | } |
| 240 | if (platformMethods) { |
| 241 | angle::AnglePlatformImpl::assignAnglePlatformMethods(platformMethods); |
| 242 | } else { |
| 243 | ALOGE("In initializeAnglePlatform() platformMethods struct ptr is NULL. Not assigning " |
| 244 | "tracing function ptrs!"); |
| 245 | } |
| 246 | return true; |
| 247 | } |
| 248 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 249 | static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_connection_t* const cnx, |
| 250 | const EGLAttrib* attrib_list, EGLint* error) { |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 251 | EGLDisplay dpy = EGL_NO_DISPLAY; |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 252 | *error = EGL_NONE; |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 253 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 254 | if (cnx->egl.eglGetPlatformDisplay) { |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 255 | std::vector<EGLAttrib> attrs; |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 256 | if (attrib_list) { |
| 257 | for (const EGLAttrib* attr = attrib_list; *attr != EGL_NONE; attr += 2) { |
| 258 | attrs.push_back(attr[0]); |
| 259 | attrs.push_back(attr[1]); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | if (!addAnglePlatformAttributes(cnx, attrib_list, attrs)) { |
| 264 | ALOGE("eglGetDisplay(%p) failed: Mismatch display request", display); |
| 265 | *error = EGL_BAD_PARAMETER; |
| 266 | return EGL_NO_DISPLAY; |
| 267 | } |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 268 | attrs.push_back(EGL_NONE); |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 269 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 270 | dpy = cnx->egl.eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, |
| 271 | reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), |
| 272 | attrs.data()); |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 273 | if (dpy == EGL_NO_DISPLAY) { |
| 274 | ALOGE("eglGetPlatformDisplay failed!"); |
Tobin Ehlis | 96a184d | 2018-07-18 16:14:07 -0600 | [diff] [blame] | 275 | } else { |
| 276 | if (!initializeAnglePlatform(dpy)) { |
| 277 | ALOGE("initializeAnglePlatform failed!"); |
| 278 | } |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 279 | } |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 280 | } else { |
| 281 | ALOGE("eglGetDisplay(%p) failed: Unable to look up eglGetPlatformDisplay from ANGLE", |
| 282 | display); |
| 283 | } |
| 284 | |
| 285 | return dpy; |
| 286 | } |
| 287 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 288 | EGLDisplay egl_display_t::getPlatformDisplay(EGLNativeDisplayType display, |
| 289 | const EGLAttrib* attrib_list) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 290 | std::lock_guard<std::mutex> _l(lock); |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 291 | ATRACE_CALL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 292 | |
| 293 | // get our driver loader |
| 294 | Loader& loader(Loader::getInstance()); |
| 295 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 296 | egl_connection_t* const cnx = &gEGLImpl; |
| 297 | if (cnx->dso && disp.dpy == EGL_NO_DISPLAY) { |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 298 | EGLDisplay dpy = EGL_NO_DISPLAY; |
| 299 | |
| 300 | if (cnx->useAngle) { |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 301 | EGLint error; |
| 302 | dpy = getPlatformDisplayAngle(display, cnx, attrib_list, &error); |
| 303 | if (error != EGL_NONE) { |
| 304 | return setError(error, dpy); |
| 305 | } |
Courtney Goeltzenleuchter | 555f1df | 2018-09-25 14:34:29 -0600 | [diff] [blame] | 306 | } |
| 307 | if (dpy == EGL_NO_DISPLAY) { |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 308 | // NOTE: eglGetPlatformDisplay with a empty attribute list |
| 309 | // behaves the same as eglGetDisplay |
| 310 | if (cnx->egl.eglGetPlatformDisplay) { |
| 311 | dpy = cnx->egl.eglGetPlatformDisplay(EGL_PLATFORM_ANDROID_KHR, display, |
| 312 | attrib_list); |
| 313 | } else { |
| 314 | if (attrib_list) { |
| 315 | ALOGW("getPlatformDisplay: unexpected attribute list, attributes ignored"); |
| 316 | } |
| 317 | dpy = cnx->egl.eglGetDisplay(display); |
| 318 | } |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 319 | } |
| 320 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 321 | disp.dpy = dpy; |
| 322 | if (dpy == EGL_NO_DISPLAY) { |
| 323 | loader.close(cnx->dso); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 324 | cnx->dso = nullptr; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
| 328 | return EGLDisplay(uintptr_t(display) + 1U); |
| 329 | } |
| 330 | |
| 331 | EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) { |
| 332 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 333 | { // scope for refLock |
| 334 | std::unique_lock<std::mutex> _l(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 335 | refs++; |
| 336 | if (refs > 1) { |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 337 | // We don't know what to report until we know what the |
| 338 | // driver supports. Make sure we are initialized before |
| 339 | // returning the version info. |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 340 | while(!eglIsInitialized) { |
| 341 | refCond.wait(_l); |
| 342 | } |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 343 | egl_connection_t* const cnx = &gEGLImpl; |
| 344 | |
| 345 | // TODO: If device doesn't provide 1.4 or 1.5 then we'll be |
| 346 | // changing the behavior from the past where we always advertise |
| 347 | // version 1.4. May need to check that revision is valid |
| 348 | // before using cnx->major & cnx->minor |
| 349 | if (major != nullptr) *major = cnx->major; |
| 350 | if (minor != nullptr) *minor = cnx->minor; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 351 | return EGL_TRUE; |
| 352 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 353 | while(eglIsInitialized) { |
| 354 | refCond.wait(_l); |
| 355 | } |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 358 | { // scope for lock |
| 359 | std::lock_guard<std::mutex> _l(lock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 360 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 361 | setGLHooksThreadSpecific(&gHooksNoContext); |
| 362 | |
| 363 | // initialize each EGL and |
| 364 | // build our own extension string first, based on the extension we know |
| 365 | // and the extension supported by our client implementation |
| 366 | |
| 367 | egl_connection_t* const cnx = &gEGLImpl; |
| 368 | cnx->major = -1; |
| 369 | cnx->minor = -1; |
| 370 | if (cnx->dso) { |
| 371 | EGLDisplay idpy = disp.dpy; |
| 372 | if (cnx->egl.eglInitialize(idpy, &cnx->major, &cnx->minor)) { |
| 373 | //ALOGD("initialized dpy=%p, ver=%d.%d, cnx=%p", |
| 374 | // idpy, cnx->major, cnx->minor, cnx); |
| 375 | |
| 376 | // display is now initialized |
| 377 | disp.state = egl_display_t::INITIALIZED; |
| 378 | |
| 379 | // get the query-strings for this display for each implementation |
| 380 | disp.queryString.vendor = cnx->egl.eglQueryString(idpy, |
| 381 | EGL_VENDOR); |
| 382 | disp.queryString.version = cnx->egl.eglQueryString(idpy, |
| 383 | EGL_VERSION); |
| 384 | disp.queryString.extensions = cnx->egl.eglQueryString(idpy, |
| 385 | EGL_EXTENSIONS); |
| 386 | disp.queryString.clientApi = cnx->egl.eglQueryString(idpy, |
| 387 | EGL_CLIENT_APIS); |
| 388 | |
| 389 | } else { |
| 390 | ALOGW("eglInitialize(%p) failed (%s)", idpy, |
| 391 | egl_tls_t::egl_strerror(cnx->egl.eglGetError())); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | // the query strings are per-display |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 396 | mVendorString = sVendorString; |
Courtney Goeltzenleuchter | 015ed67 | 2018-07-27 13:43:23 -0600 | [diff] [blame] | 397 | mVersionString.clear(); |
| 398 | cnx->driverVersion = EGL_MAKE_VERSION(1, 4, 0); |
| 399 | if ((cnx->major == 1) && (cnx->minor == 5)) { |
| 400 | mVersionString = sVersionString15; |
| 401 | cnx->driverVersion = EGL_MAKE_VERSION(1, 5, 0); |
| 402 | } else if ((cnx->major == 1) && (cnx->minor == 4)) { |
| 403 | mVersionString = sVersionString14; |
| 404 | // Extensions needed for an EGL 1.4 implementation to be |
| 405 | // able to support EGL 1.5 functionality |
| 406 | std::vector<const char*> egl15extensions = { |
| 407 | "EGL_EXT_client_extensions", |
| 408 | // "EGL_EXT_platform_base", // implemented by EGL runtime |
| 409 | "EGL_KHR_image_base", |
| 410 | "EGL_KHR_fence_sync", |
| 411 | "EGL_KHR_wait_sync", |
| 412 | "EGL_KHR_create_context", |
| 413 | "EGL_EXT_create_context_robustness", |
| 414 | "EGL_KHR_gl_colorspace", |
| 415 | "EGL_ANDROID_native_fence_sync", |
| 416 | }; |
| 417 | bool extensionsFound = true; |
| 418 | for (const auto& name : egl15extensions) { |
| 419 | extensionsFound &= findExtension(disp.queryString.extensions, name); |
| 420 | ALOGV("Extension %s: %s", name, |
| 421 | findExtension(disp.queryString.extensions, name) ? "Found" : "Missing"); |
| 422 | } |
| 423 | // NOTE: From the spec: |
| 424 | // Creation of fence sync objects requires support from the bound |
| 425 | // client API, and will not succeed unless the client API satisfies: |
| 426 | // client API is OpenGL ES, and either the OpenGL ES version is 3.0 |
| 427 | // or greater, or the GL_OES_EGL_sync extension is supported. |
| 428 | // We don't have a way to check the GL_EXTENSIONS string at this |
| 429 | // point in the code, assume that GL_OES_EGL_sync is supported |
| 430 | // because EGL_KHR_fence_sync is supported (as verified above). |
| 431 | if (extensionsFound) { |
| 432 | // Have everything needed to emulate EGL 1.5 so report EGL 1.5 |
| 433 | // to the application. |
| 434 | mVersionString = sVersionString15; |
| 435 | cnx->major = 1; |
| 436 | cnx->minor = 5; |
| 437 | } |
| 438 | } |
| 439 | if (mVersionString.empty()) { |
| 440 | ALOGW("Unexpected driver version: %d.%d, want 1.4 or 1.5", cnx->major, cnx->minor); |
| 441 | mVersionString = sVersionString14; |
| 442 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 443 | mClientApiString = sClientApiString; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 444 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 445 | mExtensionString = gBuiltinExtensionString; |
Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 446 | |
Krzysztof Kosiński | f2fc4e9 | 2018-04-18 16:29:49 -0700 | [diff] [blame] | 447 | hasColorSpaceSupport = findExtension(disp.queryString.extensions, "EGL_KHR_gl_colorspace"); |
| 448 | |
| 449 | // Note: CDD requires that devices supporting wide color and/or HDR color also support |
| 450 | // the EGL_KHR_gl_colorspace extension. |
Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 451 | bool wideColorBoardConfig = |
| 452 | getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>( |
| 453 | false); |
| 454 | |
| 455 | // Add wide-color extensions if device can support wide-color |
Krzysztof Kosiński | f2fc4e9 | 2018-04-18 16:29:49 -0700 | [diff] [blame] | 456 | if (wideColorBoardConfig && hasColorSpaceSupport) { |
Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 457 | mExtensionString.append( |
| 458 | "EGL_EXT_gl_colorspace_scrgb EGL_EXT_gl_colorspace_scrgb_linear " |
| 459 | "EGL_EXT_gl_colorspace_display_p3_linear EGL_EXT_gl_colorspace_display_p3 "); |
| 460 | } |
| 461 | |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 462 | bool hasHdrBoardConfig = |
| 463 | getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(false); |
| 464 | |
Krzysztof Kosiński | f2fc4e9 | 2018-04-18 16:29:49 -0700 | [diff] [blame] | 465 | if (hasHdrBoardConfig && hasColorSpaceSupport) { |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 466 | // hasHDRBoardConfig indicates the system is capable of supporting HDR content. |
| 467 | // Typically that means there is an HDR capable display attached, but could be |
| 468 | // support for attaching an HDR display. In either case, advertise support for |
| 469 | // HDR color spaces. |
| 470 | mExtensionString.append( |
| 471 | "EGL_EXT_gl_colorspace_bt2020_linear EGL_EXT_gl_colorspace_bt2020_pq "); |
| 472 | } |
| 473 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 474 | char const* start = gExtensionString; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 475 | do { |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 476 | // length of the extension name |
| 477 | size_t len = strcspn(start, " "); |
| 478 | if (len) { |
| 479 | // NOTE: we could avoid the copy if we had strnstr. |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 480 | const std::string ext(start, len); |
| 481 | if (findExtension(disp.queryString.extensions, ext.c_str(), len)) { |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 482 | mExtensionString.append(ext + " "); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 483 | } |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 484 | // advance to the next extension name, skipping the space. |
| 485 | start += len; |
| 486 | start += (*start == ' ') ? 1 : 0; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 487 | } |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 488 | } while (*start != '\0'); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 489 | |
| 490 | egl_cache_t::get()->initialize(this); |
| 491 | |
| 492 | char value[PROPERTY_VALUE_MAX]; |
| 493 | property_get("debug.egl.finish", value, "0"); |
| 494 | if (atoi(value)) { |
| 495 | finishOnSwap = true; |
| 496 | } |
| 497 | |
| 498 | property_get("debug.egl.traceGpuCompletion", value, "0"); |
| 499 | if (atoi(value)) { |
| 500 | traceGpuCompletion = true; |
| 501 | } |
| 502 | |
Courtney Goeltzenleuchter | 4adf75b | 2018-10-11 13:09:40 -0600 | [diff] [blame^] | 503 | // TODO: If device doesn't provide 1.4 or 1.5 then we'll be |
| 504 | // changing the behavior from the past where we always advertise |
| 505 | // version 1.4. May need to check that revision is valid |
| 506 | // before using cnx->major & cnx->minor |
| 507 | if (major != nullptr) *major = cnx->major; |
| 508 | if (minor != nullptr) *minor = cnx->minor; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 511 | { // scope for refLock |
| 512 | std::unique_lock<std::mutex> _l(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 513 | eglIsInitialized = true; |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 514 | refCond.notify_all(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 517 | return EGL_TRUE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | EGLBoolean egl_display_t::terminate() { |
| 521 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 522 | { // scope for refLock |
| 523 | std::unique_lock<std::mutex> _rl(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 524 | if (refs == 0) { |
| 525 | /* |
| 526 | * From the EGL spec (3.2): |
| 527 | * "Termination of a display that has already been terminated, |
| 528 | * (...), is allowed, but the only effect of such a call is |
| 529 | * to return EGL_TRUE (...) |
| 530 | */ |
| 531 | return EGL_TRUE; |
| 532 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 533 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 534 | // this is specific to Android, display termination is ref-counted. |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 535 | refs--; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 536 | if (refs > 0) { |
| 537 | return EGL_TRUE; |
| 538 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | EGLBoolean res = EGL_FALSE; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 542 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 543 | { // scope for lock |
| 544 | std::lock_guard<std::mutex> _l(lock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 545 | |
| 546 | egl_connection_t* const cnx = &gEGLImpl; |
| 547 | if (cnx->dso && disp.state == egl_display_t::INITIALIZED) { |
Tobin Ehlis | 96a184d | 2018-07-18 16:14:07 -0600 | [diff] [blame] | 548 | // If we're using ANGLE reset any custom DisplayPlatform |
| 549 | if (cnx->useAngle && angle::AnglePlatformImpl::angleResetDisplayPlatform) { |
| 550 | (angle::AnglePlatformImpl::angleResetDisplayPlatform)(disp.dpy); |
| 551 | } |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 552 | if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) { |
| 553 | ALOGW("eglTerminate(%p) failed (%s)", disp.dpy, |
| 554 | egl_tls_t::egl_strerror(cnx->egl.eglGetError())); |
| 555 | } |
| 556 | // REVISIT: it's unclear what to do if eglTerminate() fails |
| 557 | disp.state = egl_display_t::TERMINATED; |
| 558 | res = EGL_TRUE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 559 | } |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 560 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 561 | // Reset the extension string since it will be regenerated if we get |
| 562 | // reinitialized. |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 563 | mExtensionString.clear(); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 564 | |
| 565 | // Mark all objects remaining in the list as terminated, unless |
| 566 | // there are no reference to them, it which case, we're free to |
| 567 | // delete them. |
| 568 | size_t count = objects.size(); |
Dan Albert | eacd31f | 2016-02-02 15:08:34 -0800 | [diff] [blame] | 569 | ALOGW_IF(count, "eglTerminate() called w/ %zu objects remaining", count); |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 570 | for (auto o : objects) { |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 571 | o->destroy(); |
| 572 | } |
| 573 | |
| 574 | // this marks all object handles are "terminated" |
| 575 | objects.clear(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 578 | { // scope for refLock |
| 579 | std::unique_lock<std::mutex> _rl(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 580 | eglIsInitialized = false; |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 581 | refCond.notify_all(); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 584 | return res; |
| 585 | } |
| 586 | |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 587 | void egl_display_t::loseCurrent(egl_context_t * cur_c) |
| 588 | { |
| 589 | if (cur_c) { |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 590 | egl_display_t* display = cur_c->getDisplay(); |
| 591 | if (display) { |
| 592 | display->loseCurrentImpl(cur_c); |
| 593 | } |
| 594 | } |
| 595 | } |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 596 | |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 597 | void egl_display_t::loseCurrentImpl(egl_context_t * cur_c) |
| 598 | { |
| 599 | // by construction, these are either 0 or valid (possibly terminated) |
| 600 | // it should be impossible for these to be invalid |
| 601 | ContextRef _cur_c(cur_c); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 602 | SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : nullptr); |
| 603 | SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : nullptr); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 604 | |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 605 | { // scope for the lock |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 606 | std::lock_guard<std::mutex> _l(lock); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 607 | cur_c->onLooseCurrent(); |
| 608 | |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 609 | } |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 610 | |
| 611 | // This cannot be called with the lock held because it might end-up |
| 612 | // calling back into EGL (in particular when a surface is destroyed |
| 613 | // it calls ANativeWindow::disconnect |
| 614 | _cur_c.release(); |
| 615 | _cur_r.release(); |
| 616 | _cur_d.release(); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | 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] | 620 | EGLSurface draw, EGLSurface read, EGLContext /*ctx*/, |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 621 | EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx) |
| 622 | { |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 623 | EGLBoolean result; |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 624 | |
| 625 | // by construction, these are either 0 or valid (possibly terminated) |
| 626 | // it should be impossible for these to be invalid |
| 627 | ContextRef _cur_c(cur_c); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 628 | SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : nullptr); |
| 629 | SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : nullptr); |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 630 | |
| 631 | { // scope for the lock |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 632 | std::lock_guard<std::mutex> _l(lock); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 633 | if (c) { |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 634 | result = c->cnx->egl.eglMakeCurrent( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 635 | disp.dpy, impl_draw, impl_read, impl_ctx); |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 636 | if (result == EGL_TRUE) { |
| 637 | c->onMakeCurrent(draw, read); |
| 638 | } |
| 639 | } else { |
| 640 | result = cur_c->cnx->egl.eglMakeCurrent( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 641 | disp.dpy, impl_draw, impl_read, impl_ctx); |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 642 | if (result == EGL_TRUE) { |
| 643 | cur_c->onLooseCurrent(); |
| 644 | } |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 645 | } |
| 646 | } |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 647 | |
| 648 | if (result == EGL_TRUE) { |
| 649 | // This cannot be called with the lock held because it might end-up |
| 650 | // calling back into EGL (in particular when a surface is destroyed |
| 651 | // it calls ANativeWindow::disconnect |
| 652 | _cur_c.release(); |
| 653 | _cur_r.release(); |
| 654 | _cur_d.release(); |
| 655 | } |
| 656 | |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 657 | return result; |
| 658 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 659 | |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 660 | bool egl_display_t::haveExtension(const char* name, size_t nameLen) const { |
| 661 | if (!nameLen) { |
| 662 | nameLen = strlen(name); |
| 663 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 664 | return findExtension(mExtensionString.c_str(), name, nameLen); |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Jesse Hall | a0fef1c | 2012-04-17 12:02:26 -0700 | [diff] [blame] | 667 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 668 | }; // namespace android |
| 669 | // ---------------------------------------------------------------------------- |