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 | |
Mathias Agopian | b7f9a24 | 2017-03-08 22:29:31 -0800 | [diff] [blame] | 24 | #include <private/EGL/display.h> |
| 25 | |
Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 26 | #include "egl_cache.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 27 | #include "egl_object.h" |
| 28 | #include "egl_tls.h" |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 29 | #include "egl_trace.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 30 | #include "Loader.h" |
Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 31 | #include <cutils/properties.h> |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 32 | |
Courtney Goeltzenleuchter | 1b71702 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 33 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 34 | #include <configstore/Utils.h> |
| 35 | |
| 36 | using namespace android::hardware::configstore; |
| 37 | using namespace android::hardware::configstore::V1_0; |
| 38 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 39 | // ---------------------------------------------------------------------------- |
| 40 | namespace android { |
| 41 | // ---------------------------------------------------------------------------- |
| 42 | |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 43 | static char const * const sVendorString = "Android"; |
| 44 | static char const * const sVersionString = "1.4 Android META-EGL"; |
Mathias Agopian | cc2b156 | 2012-05-21 14:01:37 -0700 | [diff] [blame] | 45 | static char const * const sClientApiString = "OpenGL_ES"; |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 46 | |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 47 | extern char const * const gBuiltinExtensionString; |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 48 | extern char const * const gExtensionString; |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 49 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 50 | extern void setGLHooksThreadSpecific(gl_hooks_t const *value); |
| 51 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 52 | // ---------------------------------------------------------------------------- |
| 53 | |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 54 | static bool findExtension(const char* exts, const char* name, size_t nameLen) { |
| 55 | if (exts) { |
Kalle Raita | 7804aa2 | 2016-04-18 16:03:37 -0700 | [diff] [blame] | 56 | for (const char* match = strstr(exts, name); match; match = strstr(match + nameLen, name)) { |
| 57 | if (match[nameLen] == '\0' || match[nameLen] == ' ') { |
| 58 | return true; |
| 59 | } |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
Mathias Agopian | b7f9a24 | 2017-03-08 22:29:31 -0800 | [diff] [blame] | 65 | int egl_get_init_count(EGLDisplay dpy) { |
| 66 | egl_display_t* eglDisplay = egl_display_t::get(dpy); |
| 67 | return eglDisplay ? eglDisplay->getRefsCount() : 0; |
| 68 | } |
| 69 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 70 | egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS]; |
| 71 | |
| 72 | egl_display_t::egl_display_t() : |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 73 | magic('_dpy'), finishOnSwap(false), traceGpuCompletion(false), refs(0), eglIsInitialized(false) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | egl_display_t::~egl_display_t() { |
| 77 | magic = 0; |
Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 78 | egl_cache_t::get()->terminate(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | egl_display_t* egl_display_t::get(EGLDisplay dpy) { |
Ivan Lozano | 13f2c07 | 2017-12-06 14:19:44 -0800 | [diff] [blame] | 82 | if (uintptr_t(dpy) == 0) { |
| 83 | return nullptr; |
| 84 | } |
| 85 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 86 | uintptr_t index = uintptr_t(dpy)-1U; |
Jesse Hall | d6e9946 | 2016-09-28 11:26:57 -0700 | [diff] [blame] | 87 | if (index >= NUM_DISPLAYS || !sDisplay[index].isValid()) { |
| 88 | return nullptr; |
| 89 | } |
| 90 | return &sDisplay[index]; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void egl_display_t::addObject(egl_object_t* object) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 94 | std::lock_guard<std::mutex> _l(lock); |
| 95 | objects.insert(object); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 98 | void egl_display_t::removeObject(egl_object_t* object) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 99 | std::lock_guard<std::mutex> _l(lock); |
| 100 | objects.erase(object); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 103 | bool egl_display_t::getObject(egl_object_t* object) const { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 104 | std::lock_guard<std::mutex> _l(lock); |
| 105 | if (objects.find(object) != objects.end()) { |
Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 106 | if (object->getDisplay() == this) { |
| 107 | object->incRef(); |
| 108 | return true; |
| 109 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 110 | } |
| 111 | return false; |
| 112 | } |
| 113 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 114 | EGLDisplay egl_display_t::getFromNativeDisplay(EGLNativeDisplayType disp) { |
| 115 | if (uintptr_t(disp) >= NUM_DISPLAYS) |
| 116 | return NULL; |
| 117 | |
| 118 | return sDisplay[uintptr_t(disp)].getDisplay(disp); |
| 119 | } |
| 120 | |
| 121 | EGLDisplay egl_display_t::getDisplay(EGLNativeDisplayType display) { |
| 122 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 123 | std::lock_guard<std::mutex> _l(lock); |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 124 | ATRACE_CALL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 125 | |
| 126 | // get our driver loader |
| 127 | Loader& loader(Loader::getInstance()); |
| 128 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 129 | egl_connection_t* const cnx = &gEGLImpl; |
| 130 | if (cnx->dso && disp.dpy == EGL_NO_DISPLAY) { |
| 131 | EGLDisplay dpy = cnx->egl.eglGetDisplay(display); |
| 132 | disp.dpy = dpy; |
| 133 | if (dpy == EGL_NO_DISPLAY) { |
| 134 | loader.close(cnx->dso); |
| 135 | cnx->dso = NULL; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | return EGLDisplay(uintptr_t(display) + 1U); |
| 140 | } |
| 141 | |
| 142 | EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) { |
| 143 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 144 | { // scope for refLock |
| 145 | std::unique_lock<std::mutex> _l(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 146 | refs++; |
| 147 | if (refs > 1) { |
| 148 | if (major != NULL) |
| 149 | *major = VERSION_MAJOR; |
| 150 | if (minor != NULL) |
| 151 | *minor = VERSION_MINOR; |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 152 | while(!eglIsInitialized) { |
| 153 | refCond.wait(_l); |
| 154 | } |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 155 | return EGL_TRUE; |
| 156 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 157 | while(eglIsInitialized) { |
| 158 | refCond.wait(_l); |
| 159 | } |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 162 | { // scope for lock |
| 163 | std::lock_guard<std::mutex> _l(lock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 164 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 165 | setGLHooksThreadSpecific(&gHooksNoContext); |
| 166 | |
| 167 | // initialize each EGL and |
| 168 | // build our own extension string first, based on the extension we know |
| 169 | // and the extension supported by our client implementation |
| 170 | |
| 171 | egl_connection_t* const cnx = &gEGLImpl; |
| 172 | cnx->major = -1; |
| 173 | cnx->minor = -1; |
| 174 | if (cnx->dso) { |
| 175 | EGLDisplay idpy = disp.dpy; |
| 176 | if (cnx->egl.eglInitialize(idpy, &cnx->major, &cnx->minor)) { |
| 177 | //ALOGD("initialized dpy=%p, ver=%d.%d, cnx=%p", |
| 178 | // idpy, cnx->major, cnx->minor, cnx); |
| 179 | |
| 180 | // display is now initialized |
| 181 | disp.state = egl_display_t::INITIALIZED; |
| 182 | |
| 183 | // get the query-strings for this display for each implementation |
| 184 | disp.queryString.vendor = cnx->egl.eglQueryString(idpy, |
| 185 | EGL_VENDOR); |
| 186 | disp.queryString.version = cnx->egl.eglQueryString(idpy, |
| 187 | EGL_VERSION); |
| 188 | disp.queryString.extensions = cnx->egl.eglQueryString(idpy, |
| 189 | EGL_EXTENSIONS); |
| 190 | disp.queryString.clientApi = cnx->egl.eglQueryString(idpy, |
| 191 | EGL_CLIENT_APIS); |
| 192 | |
| 193 | } else { |
| 194 | ALOGW("eglInitialize(%p) failed (%s)", idpy, |
| 195 | egl_tls_t::egl_strerror(cnx->egl.eglGetError())); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // the query strings are per-display |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 200 | mVendorString = sVendorString; |
| 201 | mVersionString = sVersionString; |
| 202 | mClientApiString = sClientApiString; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 203 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 204 | mExtensionString = gBuiltinExtensionString; |
Courtney Goeltzenleuchter | 1b71702 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 205 | |
| 206 | bool wideColorBoardConfig = |
| 207 | getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>( |
| 208 | false); |
| 209 | |
| 210 | // Add wide-color extensions if device can support wide-color |
| 211 | if (wideColorBoardConfig) { |
| 212 | mExtensionString.append( |
| 213 | "EGL_EXT_gl_colorspace_scrgb EGL_EXT_gl_colorspace_scrgb_linear " |
| 214 | "EGL_EXT_gl_colorspace_display_p3_linear EGL_EXT_gl_colorspace_display_p3 "); |
| 215 | } |
| 216 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 217 | char const* start = gExtensionString; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 218 | do { |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 219 | // length of the extension name |
| 220 | size_t len = strcspn(start, " "); |
| 221 | if (len) { |
| 222 | // NOTE: we could avoid the copy if we had strnstr. |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 223 | const std::string ext(start, len); |
| 224 | if (findExtension(disp.queryString.extensions, ext.c_str(), len)) { |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 225 | mExtensionString.append(ext + " "); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 226 | } |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 227 | // advance to the next extension name, skipping the space. |
| 228 | start += len; |
| 229 | start += (*start == ' ') ? 1 : 0; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 230 | } |
Nicolas Capens | ecc0c9a | 2015-10-30 12:55:21 -0400 | [diff] [blame] | 231 | } while (*start != '\0'); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 232 | |
| 233 | egl_cache_t::get()->initialize(this); |
| 234 | |
| 235 | char value[PROPERTY_VALUE_MAX]; |
| 236 | property_get("debug.egl.finish", value, "0"); |
| 237 | if (atoi(value)) { |
| 238 | finishOnSwap = true; |
| 239 | } |
| 240 | |
| 241 | property_get("debug.egl.traceGpuCompletion", value, "0"); |
| 242 | if (atoi(value)) { |
| 243 | traceGpuCompletion = true; |
| 244 | } |
| 245 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 246 | if (major != NULL) |
| 247 | *major = VERSION_MAJOR; |
| 248 | if (minor != NULL) |
| 249 | *minor = VERSION_MINOR; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 252 | { // scope for refLock |
| 253 | std::unique_lock<std::mutex> _l(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 254 | eglIsInitialized = true; |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 255 | refCond.notify_all(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 258 | return EGL_TRUE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | EGLBoolean egl_display_t::terminate() { |
| 262 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 263 | { // scope for refLock |
| 264 | std::unique_lock<std::mutex> _rl(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 265 | if (refs == 0) { |
| 266 | /* |
| 267 | * From the EGL spec (3.2): |
| 268 | * "Termination of a display that has already been terminated, |
| 269 | * (...), is allowed, but the only effect of such a call is |
| 270 | * to return EGL_TRUE (...) |
| 271 | */ |
| 272 | return EGL_TRUE; |
| 273 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 274 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 275 | // this is specific to Android, display termination is ref-counted. |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 276 | refs--; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 277 | if (refs > 0) { |
| 278 | return EGL_TRUE; |
| 279 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | EGLBoolean res = EGL_FALSE; |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 283 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 284 | { // scope for lock |
| 285 | std::lock_guard<std::mutex> _l(lock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 286 | |
| 287 | egl_connection_t* const cnx = &gEGLImpl; |
| 288 | if (cnx->dso && disp.state == egl_display_t::INITIALIZED) { |
| 289 | if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) { |
| 290 | ALOGW("eglTerminate(%p) failed (%s)", disp.dpy, |
| 291 | egl_tls_t::egl_strerror(cnx->egl.eglGetError())); |
| 292 | } |
| 293 | // REVISIT: it's unclear what to do if eglTerminate() fails |
| 294 | disp.state = egl_display_t::TERMINATED; |
| 295 | res = EGL_TRUE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 296 | } |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 297 | |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 298 | // Reset the extension string since it will be regenerated if we get |
| 299 | // reinitialized. |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 300 | mExtensionString.clear(); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 301 | |
| 302 | // Mark all objects remaining in the list as terminated, unless |
| 303 | // there are no reference to them, it which case, we're free to |
| 304 | // delete them. |
| 305 | size_t count = objects.size(); |
Dan Albert | eacd31f | 2016-02-02 15:08:34 -0800 | [diff] [blame] | 306 | ALOGW_IF(count, "eglTerminate() called w/ %zu objects remaining", count); |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 307 | for (auto o : objects) { |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 308 | o->destroy(); |
| 309 | } |
| 310 | |
| 311 | // this marks all object handles are "terminated" |
| 312 | objects.clear(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 315 | { // scope for refLock |
| 316 | std::unique_lock<std::mutex> _rl(refLock); |
Michael Lentine | 54466bc | 2015-01-27 09:01:03 -0800 | [diff] [blame] | 317 | eglIsInitialized = false; |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 318 | refCond.notify_all(); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 321 | return res; |
| 322 | } |
| 323 | |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 324 | void egl_display_t::loseCurrent(egl_context_t * cur_c) |
| 325 | { |
| 326 | if (cur_c) { |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 327 | egl_display_t* display = cur_c->getDisplay(); |
| 328 | if (display) { |
| 329 | display->loseCurrentImpl(cur_c); |
| 330 | } |
| 331 | } |
| 332 | } |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 333 | |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 334 | void egl_display_t::loseCurrentImpl(egl_context_t * cur_c) |
| 335 | { |
| 336 | // by construction, these are either 0 or valid (possibly terminated) |
| 337 | // it should be impossible for these to be invalid |
| 338 | ContextRef _cur_c(cur_c); |
| 339 | SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL); |
| 340 | SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 341 | |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 342 | { // scope for the lock |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 343 | std::lock_guard<std::mutex> _l(lock); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 344 | cur_c->onLooseCurrent(); |
| 345 | |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 346 | } |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 347 | |
| 348 | // This cannot be called with the lock held because it might end-up |
| 349 | // calling back into EGL (in particular when a surface is destroyed |
| 350 | // it calls ANativeWindow::disconnect |
| 351 | _cur_c.release(); |
| 352 | _cur_r.release(); |
| 353 | _cur_d.release(); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | 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] | 357 | EGLSurface draw, EGLSurface read, EGLContext /*ctx*/, |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 358 | EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx) |
| 359 | { |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 360 | EGLBoolean result; |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 361 | |
| 362 | // by construction, these are either 0 or valid (possibly terminated) |
| 363 | // it should be impossible for these to be invalid |
| 364 | ContextRef _cur_c(cur_c); |
| 365 | SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL); |
| 366 | SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL); |
| 367 | |
| 368 | { // scope for the lock |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 369 | std::lock_guard<std::mutex> _l(lock); |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 370 | if (c) { |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 371 | result = c->cnx->egl.eglMakeCurrent( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 372 | disp.dpy, impl_draw, impl_read, impl_ctx); |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 373 | if (result == EGL_TRUE) { |
| 374 | c->onMakeCurrent(draw, read); |
| 375 | } |
| 376 | } else { |
| 377 | result = cur_c->cnx->egl.eglMakeCurrent( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 378 | disp.dpy, impl_draw, impl_read, impl_ctx); |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 379 | if (result == EGL_TRUE) { |
| 380 | cur_c->onLooseCurrent(); |
| 381 | } |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 382 | } |
| 383 | } |
Mathias Agopian | a4b2c04 | 2012-02-03 15:24:51 -0800 | [diff] [blame] | 384 | |
| 385 | if (result == EGL_TRUE) { |
| 386 | // This cannot be called with the lock held because it might end-up |
| 387 | // calling back into EGL (in particular when a surface is destroyed |
| 388 | // it calls ANativeWindow::disconnect |
| 389 | _cur_c.release(); |
| 390 | _cur_r.release(); |
| 391 | _cur_d.release(); |
| 392 | } |
| 393 | |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 394 | return result; |
| 395 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 396 | |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 397 | bool egl_display_t::haveExtension(const char* name, size_t nameLen) const { |
| 398 | if (!nameLen) { |
| 399 | nameLen = strlen(name); |
| 400 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 401 | return findExtension(mExtensionString.c_str(), name, nameLen); |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Jesse Hall | a0fef1c | 2012-04-17 12:02:26 -0700 | [diff] [blame] | 404 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 405 | }; // namespace android |
| 406 | // ---------------------------------------------------------------------------- |