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