blob: 10a097a66f680e875c3e55f05ebef83995d61bba [file] [log] [blame]
Jesse Hall21558da2013-08-06 15:31:22 -07001/*
Mathias Agopian518ec112011-05-13 16:21:08 -07002 ** Copyright 2007, The Android Open Source Project
3 **
Jesse Hall21558da2013-08-06 15:31:22 -07004 ** 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 Agopian518ec112011-05-13 16:21:08 -07007 **
Jesse Hall21558da2013-08-06 15:31:22 -07008 ** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopian518ec112011-05-13 16:21:08 -07009 **
Jesse Hall21558da2013-08-06 15:31:22 -070010 ** 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 Agopian518ec112011-05-13 16:21:08 -070014 ** limitations under the License.
15 */
16
Jesse Hallb29e5e82012-04-04 16:53:42 -070017#define __STDC_LIMIT_MACROS 1
Jesse Hall1508ae62017-01-19 17:43:26 -080018#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Jesse Hallb29e5e82012-04-04 16:53:42 -070019
Mathias Agopian311b4792017-02-28 15:00:49 -080020#include "egl_display.h"
Mathias Agopian4b9511c2011-11-13 23:52:47 -080021
Mathias Agopian39c24a22013-04-04 23:17:56 -070022#include "../egl_impl.h"
23
Cody Northrop1f00e172018-04-02 11:23:31 -060024#include <EGL/eglext_angle.h>
Mathias Agopianb7f9a242017-03-08 22:29:31 -080025#include <private/EGL/display.h>
26
Jamie Gennisaca51c02011-11-03 17:42:43 -070027#include "egl_cache.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070028#include "egl_object.h"
29#include "egl_tls.h"
Mathias Agopian65421432017-03-08 11:49:05 -080030#include "egl_trace.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070031#include "Loader.h"
Mathias Agopian7db993a2012-03-25 00:49:46 -070032#include <cutils/properties.h>
Mathias Agopian311b4792017-02-28 15:00:49 -080033
Courtney Goeltzenleuchtere5d6f992017-07-07 14:55:40 -060034#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
35#include <configstore/Utils.h>
36
37using namespace android::hardware::configstore;
38using namespace android::hardware::configstore::V1_0;
39
Mathias Agopian518ec112011-05-13 16:21:08 -070040// ----------------------------------------------------------------------------
41namespace android {
42// ----------------------------------------------------------------------------
43
Mathias Agopian4b9511c2011-11-13 23:52:47 -080044static char const * const sVendorString = "Android";
45static char const * const sVersionString = "1.4 Android META-EGL";
Mathias Agopiancc2b1562012-05-21 14:01:37 -070046static char const * const sClientApiString = "OpenGL_ES";
Mathias Agopian4b9511c2011-11-13 23:52:47 -080047
Jesse Hall21558da2013-08-06 15:31:22 -070048extern char const * const gBuiltinExtensionString;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070049extern char const * const gExtensionString;
Mathias Agopian4b9511c2011-11-13 23:52:47 -080050
Mathias Agopian518ec112011-05-13 16:21:08 -070051extern void setGLHooksThreadSpecific(gl_hooks_t const *value);
52
Mathias Agopian518ec112011-05-13 16:21:08 -070053// ----------------------------------------------------------------------------
54
Courtney Goeltzenleuchtera1e59f12018-03-05 08:19:25 -070055bool findExtension(const char* exts, const char* name, size_t nameLen) {
Jesse Hallc2e41222013-08-08 13:40:22 -070056 if (exts) {
Courtney Goeltzenleuchtera1e59f12018-03-05 08:19:25 -070057 if (!nameLen) {
58 nameLen = strlen(name);
59 }
Kalle Raita7804aa22016-04-18 16:03:37 -070060 for (const char* match = strstr(exts, name); match; match = strstr(match + nameLen, name)) {
61 if (match[nameLen] == '\0' || match[nameLen] == ' ') {
62 return true;
63 }
Jesse Hallc2e41222013-08-08 13:40:22 -070064 }
65 }
66 return false;
67}
68
Mathias Agopianb7f9a242017-03-08 22:29:31 -080069int egl_get_init_count(EGLDisplay dpy) {
70 egl_display_t* eglDisplay = egl_display_t::get(dpy);
71 return eglDisplay ? eglDisplay->getRefsCount() : 0;
72}
73
Mathias Agopian518ec112011-05-13 16:21:08 -070074egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS];
75
76egl_display_t::egl_display_t() :
Michael Lentine54466bc2015-01-27 09:01:03 -080077 magic('_dpy'), finishOnSwap(false), traceGpuCompletion(false), refs(0), eglIsInitialized(false) {
Mathias Agopian518ec112011-05-13 16:21:08 -070078}
79
80egl_display_t::~egl_display_t() {
81 magic = 0;
Jamie Gennis76601082011-11-06 14:14:33 -080082 egl_cache_t::get()->terminate();
Mathias Agopian518ec112011-05-13 16:21:08 -070083}
84
85egl_display_t* egl_display_t::get(EGLDisplay dpy) {
Ivan Lozano7025b542017-12-06 14:19:44 -080086 if (uintptr_t(dpy) == 0) {
87 return nullptr;
88 }
89
Mathias Agopian518ec112011-05-13 16:21:08 -070090 uintptr_t index = uintptr_t(dpy)-1U;
Jesse Halld6e99462016-09-28 11:26:57 -070091 if (index >= NUM_DISPLAYS || !sDisplay[index].isValid()) {
92 return nullptr;
93 }
94 return &sDisplay[index];
Mathias Agopian518ec112011-05-13 16:21:08 -070095}
96
97void egl_display_t::addObject(egl_object_t* object) {
Mathias Agopian65421432017-03-08 11:49:05 -080098 std::lock_guard<std::mutex> _l(lock);
99 objects.insert(object);
Mathias Agopian518ec112011-05-13 16:21:08 -0700100}
101
Mathias Agopian5b287a62011-05-16 18:58:55 -0700102void egl_display_t::removeObject(egl_object_t* object) {
Mathias Agopian65421432017-03-08 11:49:05 -0800103 std::lock_guard<std::mutex> _l(lock);
104 objects.erase(object);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700105}
106
Mathias Agopianf0480de2011-11-13 20:50:07 -0800107bool egl_display_t::getObject(egl_object_t* object) const {
Mathias Agopian65421432017-03-08 11:49:05 -0800108 std::lock_guard<std::mutex> _l(lock);
109 if (objects.find(object) != objects.end()) {
Mathias Agopianf0480de2011-11-13 20:50:07 -0800110 if (object->getDisplay() == this) {
111 object->incRef();
112 return true;
113 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700114 }
115 return false;
116}
117
Mathias Agopian518ec112011-05-13 16:21:08 -0700118EGLDisplay egl_display_t::getFromNativeDisplay(EGLNativeDisplayType disp) {
119 if (uintptr_t(disp) >= NUM_DISPLAYS)
Yi Kong48a6cd22018-07-18 10:07:09 -0700120 return nullptr;
Mathias Agopian518ec112011-05-13 16:21:08 -0700121
122 return sDisplay[uintptr_t(disp)].getDisplay(disp);
123}
124
Cody Northrop1f00e172018-04-02 11:23:31 -0600125EGLDisplay getDisplayAngle(EGLNativeDisplayType display, egl_connection_t* const cnx) {
126 EGLDisplay dpy = EGL_NO_DISPLAY;
127
128 // Locally define this until EGL 1.5 is supported
129 typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYPROC)(EGLenum platform, void* native_display,
130 const EGLAttrib* attrib_list);
131
132 PFNEGLGETPLATFORMDISPLAYPROC eglGetPlatformDisplay =
133 reinterpret_cast<PFNEGLGETPLATFORMDISPLAYPROC>(
134 cnx->egl.eglGetProcAddress("eglGetPlatformDisplay"));
135
136 if (eglGetPlatformDisplay) {
137 intptr_t vendorEGL = (intptr_t)cnx->vendorEGL;
138
139 EGLAttrib attrs[] = {
140 EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE,
141 EGL_PLATFORM_ANGLE_EGL_HANDLE_ANGLE, vendorEGL,
142 EGL_NONE // list terminator
143 };
144
145 // Initially, request the default display type
146 dpy = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
147 reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), attrs);
148
149 } else {
150 ALOGE("eglGetDisplay(%p) failed: Unable to look up eglGetPlatformDisplay from ANGLE",
151 display);
152 }
153
154 return dpy;
155}
156
Mathias Agopian518ec112011-05-13 16:21:08 -0700157EGLDisplay egl_display_t::getDisplay(EGLNativeDisplayType display) {
158
Mathias Agopian65421432017-03-08 11:49:05 -0800159 std::lock_guard<std::mutex> _l(lock);
Jesse Hall1508ae62017-01-19 17:43:26 -0800160 ATRACE_CALL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700161
162 // get our driver loader
163 Loader& loader(Loader::getInstance());
164
Mathias Agopianada798b2012-02-13 17:09:30 -0800165 egl_connection_t* const cnx = &gEGLImpl;
166 if (cnx->dso && disp.dpy == EGL_NO_DISPLAY) {
Cody Northrop1f00e172018-04-02 11:23:31 -0600167 EGLDisplay dpy = EGL_NO_DISPLAY;
168
169 if (cnx->useAngle) {
170 dpy = getDisplayAngle(display, cnx);
171 } else {
172 dpy = cnx->egl.eglGetDisplay(display);
173 }
174
Mathias Agopianada798b2012-02-13 17:09:30 -0800175 disp.dpy = dpy;
176 if (dpy == EGL_NO_DISPLAY) {
177 loader.close(cnx->dso);
Yi Kong48a6cd22018-07-18 10:07:09 -0700178 cnx->dso = nullptr;
Mathias Agopian518ec112011-05-13 16:21:08 -0700179 }
180 }
181
182 return EGLDisplay(uintptr_t(display) + 1U);
183}
184
185EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {
186
Mathias Agopian65421432017-03-08 11:49:05 -0800187 { // scope for refLock
188 std::unique_lock<std::mutex> _l(refLock);
Michael Lentine54466bc2015-01-27 09:01:03 -0800189 refs++;
190 if (refs > 1) {
Yi Kong48a6cd22018-07-18 10:07:09 -0700191 if (major != nullptr)
Michael Lentine54466bc2015-01-27 09:01:03 -0800192 *major = VERSION_MAJOR;
Yi Kong48a6cd22018-07-18 10:07:09 -0700193 if (minor != nullptr)
Michael Lentine54466bc2015-01-27 09:01:03 -0800194 *minor = VERSION_MINOR;
Mathias Agopian65421432017-03-08 11:49:05 -0800195 while(!eglIsInitialized) {
196 refCond.wait(_l);
197 }
Michael Lentine54466bc2015-01-27 09:01:03 -0800198 return EGL_TRUE;
199 }
Mathias Agopian65421432017-03-08 11:49:05 -0800200 while(eglIsInitialized) {
201 refCond.wait(_l);
202 }
Michael Lentine54466bc2015-01-27 09:01:03 -0800203 }
204
Mathias Agopian65421432017-03-08 11:49:05 -0800205 { // scope for lock
206 std::lock_guard<std::mutex> _l(lock);
Michael Lentine54466bc2015-01-27 09:01:03 -0800207
Michael Lentine54466bc2015-01-27 09:01:03 -0800208 setGLHooksThreadSpecific(&gHooksNoContext);
209
210 // initialize each EGL and
211 // build our own extension string first, based on the extension we know
212 // and the extension supported by our client implementation
213
214 egl_connection_t* const cnx = &gEGLImpl;
215 cnx->major = -1;
216 cnx->minor = -1;
217 if (cnx->dso) {
218 EGLDisplay idpy = disp.dpy;
219 if (cnx->egl.eglInitialize(idpy, &cnx->major, &cnx->minor)) {
220 //ALOGD("initialized dpy=%p, ver=%d.%d, cnx=%p",
221 // idpy, cnx->major, cnx->minor, cnx);
222
223 // display is now initialized
224 disp.state = egl_display_t::INITIALIZED;
225
226 // get the query-strings for this display for each implementation
227 disp.queryString.vendor = cnx->egl.eglQueryString(idpy,
228 EGL_VENDOR);
229 disp.queryString.version = cnx->egl.eglQueryString(idpy,
230 EGL_VERSION);
231 disp.queryString.extensions = cnx->egl.eglQueryString(idpy,
232 EGL_EXTENSIONS);
233 disp.queryString.clientApi = cnx->egl.eglQueryString(idpy,
234 EGL_CLIENT_APIS);
235
236 } else {
237 ALOGW("eglInitialize(%p) failed (%s)", idpy,
238 egl_tls_t::egl_strerror(cnx->egl.eglGetError()));
239 }
240 }
241
242 // the query strings are per-display
Mathias Agopian65421432017-03-08 11:49:05 -0800243 mVendorString = sVendorString;
244 mVersionString = sVersionString;
245 mClientApiString = sClientApiString;
Michael Lentine54466bc2015-01-27 09:01:03 -0800246
Mathias Agopian65421432017-03-08 11:49:05 -0800247 mExtensionString = gBuiltinExtensionString;
Courtney Goeltzenleuchtere5d6f992017-07-07 14:55:40 -0600248
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700249 hasColorSpaceSupport = findExtension(disp.queryString.extensions, "EGL_KHR_gl_colorspace");
250
251 // Note: CDD requires that devices supporting wide color and/or HDR color also support
252 // the EGL_KHR_gl_colorspace extension.
Courtney Goeltzenleuchtere5d6f992017-07-07 14:55:40 -0600253 bool wideColorBoardConfig =
254 getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(
255 false);
256
257 // Add wide-color extensions if device can support wide-color
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700258 if (wideColorBoardConfig && hasColorSpaceSupport) {
Courtney Goeltzenleuchtere5d6f992017-07-07 14:55:40 -0600259 mExtensionString.append(
260 "EGL_EXT_gl_colorspace_scrgb EGL_EXT_gl_colorspace_scrgb_linear "
261 "EGL_EXT_gl_colorspace_display_p3_linear EGL_EXT_gl_colorspace_display_p3 ");
262 }
263
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700264 bool hasHdrBoardConfig =
265 getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(false);
266
Krzysztof Kosińskif2fc4e92018-04-18 16:29:49 -0700267 if (hasHdrBoardConfig && hasColorSpaceSupport) {
Courtney Goeltzenleuchter12ffe092017-11-16 14:27:48 -0700268 // hasHDRBoardConfig indicates the system is capable of supporting HDR content.
269 // Typically that means there is an HDR capable display attached, but could be
270 // support for attaching an HDR display. In either case, advertise support for
271 // HDR color spaces.
272 mExtensionString.append(
273 "EGL_EXT_gl_colorspace_bt2020_linear EGL_EXT_gl_colorspace_bt2020_pq ");
274 }
275
Michael Lentine54466bc2015-01-27 09:01:03 -0800276 char const* start = gExtensionString;
Michael Lentine54466bc2015-01-27 09:01:03 -0800277 do {
Nicolas Capensecc0c9a2015-10-30 12:55:21 -0400278 // length of the extension name
279 size_t len = strcspn(start, " ");
280 if (len) {
281 // NOTE: we could avoid the copy if we had strnstr.
Mathias Agopian65421432017-03-08 11:49:05 -0800282 const std::string ext(start, len);
283 if (findExtension(disp.queryString.extensions, ext.c_str(), len)) {
Nicolas Capensecc0c9a2015-10-30 12:55:21 -0400284 mExtensionString.append(ext + " ");
Michael Lentine54466bc2015-01-27 09:01:03 -0800285 }
Nicolas Capensecc0c9a2015-10-30 12:55:21 -0400286 // advance to the next extension name, skipping the space.
287 start += len;
288 start += (*start == ' ') ? 1 : 0;
Michael Lentine54466bc2015-01-27 09:01:03 -0800289 }
Nicolas Capensecc0c9a2015-10-30 12:55:21 -0400290 } while (*start != '\0');
Michael Lentine54466bc2015-01-27 09:01:03 -0800291
292 egl_cache_t::get()->initialize(this);
293
294 char value[PROPERTY_VALUE_MAX];
295 property_get("debug.egl.finish", value, "0");
296 if (atoi(value)) {
297 finishOnSwap = true;
298 }
299
300 property_get("debug.egl.traceGpuCompletion", value, "0");
301 if (atoi(value)) {
302 traceGpuCompletion = true;
303 }
304
Yi Kong48a6cd22018-07-18 10:07:09 -0700305 if (major != nullptr)
Mathias Agopian518ec112011-05-13 16:21:08 -0700306 *major = VERSION_MAJOR;
Yi Kong48a6cd22018-07-18 10:07:09 -0700307 if (minor != nullptr)
Mathias Agopian518ec112011-05-13 16:21:08 -0700308 *minor = VERSION_MINOR;
Mathias Agopian518ec112011-05-13 16:21:08 -0700309 }
310
Mathias Agopian65421432017-03-08 11:49:05 -0800311 { // scope for refLock
312 std::unique_lock<std::mutex> _l(refLock);
Michael Lentine54466bc2015-01-27 09:01:03 -0800313 eglIsInitialized = true;
Mathias Agopian65421432017-03-08 11:49:05 -0800314 refCond.notify_all();
Mathias Agopian518ec112011-05-13 16:21:08 -0700315 }
316
Mathias Agopian7773c432012-02-13 20:06:08 -0800317 return EGL_TRUE;
Mathias Agopian518ec112011-05-13 16:21:08 -0700318}
319
320EGLBoolean egl_display_t::terminate() {
321
Mathias Agopian65421432017-03-08 11:49:05 -0800322 { // scope for refLock
323 std::unique_lock<std::mutex> _rl(refLock);
Michael Lentine54466bc2015-01-27 09:01:03 -0800324 if (refs == 0) {
325 /*
326 * From the EGL spec (3.2):
327 * "Termination of a display that has already been terminated,
328 * (...), is allowed, but the only effect of such a call is
329 * to return EGL_TRUE (...)
330 */
331 return EGL_TRUE;
332 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700333
Michael Lentine54466bc2015-01-27 09:01:03 -0800334 // this is specific to Android, display termination is ref-counted.
Mathias Agopian518ec112011-05-13 16:21:08 -0700335 refs--;
Michael Lentine54466bc2015-01-27 09:01:03 -0800336 if (refs > 0) {
337 return EGL_TRUE;
338 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700339 }
340
341 EGLBoolean res = EGL_FALSE;
Michael Lentine54466bc2015-01-27 09:01:03 -0800342
Mathias Agopian65421432017-03-08 11:49:05 -0800343 { // scope for lock
344 std::lock_guard<std::mutex> _l(lock);
Michael Lentine54466bc2015-01-27 09:01:03 -0800345
346 egl_connection_t* const cnx = &gEGLImpl;
347 if (cnx->dso && disp.state == egl_display_t::INITIALIZED) {
348 if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) {
349 ALOGW("eglTerminate(%p) failed (%s)", disp.dpy,
350 egl_tls_t::egl_strerror(cnx->egl.eglGetError()));
351 }
352 // REVISIT: it's unclear what to do if eglTerminate() fails
353 disp.state = egl_display_t::TERMINATED;
354 res = EGL_TRUE;
Mathias Agopian518ec112011-05-13 16:21:08 -0700355 }
Michael Lentine54466bc2015-01-27 09:01:03 -0800356
Michael Lentine54466bc2015-01-27 09:01:03 -0800357 // Reset the extension string since it will be regenerated if we get
358 // reinitialized.
Mathias Agopian65421432017-03-08 11:49:05 -0800359 mExtensionString.clear();
Michael Lentine54466bc2015-01-27 09:01:03 -0800360
361 // Mark all objects remaining in the list as terminated, unless
362 // there are no reference to them, it which case, we're free to
363 // delete them.
364 size_t count = objects.size();
Dan Alberteacd31f2016-02-02 15:08:34 -0800365 ALOGW_IF(count, "eglTerminate() called w/ %zu objects remaining", count);
Mathias Agopian65421432017-03-08 11:49:05 -0800366 for (auto o : objects) {
Michael Lentine54466bc2015-01-27 09:01:03 -0800367 o->destroy();
368 }
369
370 // this marks all object handles are "terminated"
371 objects.clear();
Mathias Agopian518ec112011-05-13 16:21:08 -0700372 }
373
Mathias Agopian65421432017-03-08 11:49:05 -0800374 { // scope for refLock
375 std::unique_lock<std::mutex> _rl(refLock);
Michael Lentine54466bc2015-01-27 09:01:03 -0800376 eglIsInitialized = false;
Mathias Agopian65421432017-03-08 11:49:05 -0800377 refCond.notify_all();
Mathias Agopian5b287a62011-05-16 18:58:55 -0700378 }
379
Mathias Agopian518ec112011-05-13 16:21:08 -0700380 return res;
381}
382
Mathias Agopianfb87e542012-01-30 18:20:52 -0800383void egl_display_t::loseCurrent(egl_context_t * cur_c)
384{
385 if (cur_c) {
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800386 egl_display_t* display = cur_c->getDisplay();
387 if (display) {
388 display->loseCurrentImpl(cur_c);
389 }
390 }
391}
Mathias Agopianfb87e542012-01-30 18:20:52 -0800392
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800393void egl_display_t::loseCurrentImpl(egl_context_t * cur_c)
394{
395 // by construction, these are either 0 or valid (possibly terminated)
396 // it should be impossible for these to be invalid
397 ContextRef _cur_c(cur_c);
Yi Kong48a6cd22018-07-18 10:07:09 -0700398 SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : nullptr);
399 SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : nullptr);
Mathias Agopianfb87e542012-01-30 18:20:52 -0800400
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800401 { // scope for the lock
Mathias Agopian65421432017-03-08 11:49:05 -0800402 std::lock_guard<std::mutex> _l(lock);
Mathias Agopianfb87e542012-01-30 18:20:52 -0800403 cur_c->onLooseCurrent();
404
Mathias Agopianfb87e542012-01-30 18:20:52 -0800405 }
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800406
407 // This cannot be called with the lock held because it might end-up
408 // calling back into EGL (in particular when a surface is destroyed
409 // it calls ANativeWindow::disconnect
410 _cur_c.release();
411 _cur_r.release();
412 _cur_d.release();
Mathias Agopianfb87e542012-01-30 18:20:52 -0800413}
414
415EGLBoolean egl_display_t::makeCurrent(egl_context_t* c, egl_context_t* cur_c,
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -0700416 EGLSurface draw, EGLSurface read, EGLContext /*ctx*/,
Mathias Agopianfb87e542012-01-30 18:20:52 -0800417 EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx)
418{
Mathias Agopianfb87e542012-01-30 18:20:52 -0800419 EGLBoolean result;
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800420
421 // by construction, these are either 0 or valid (possibly terminated)
422 // it should be impossible for these to be invalid
423 ContextRef _cur_c(cur_c);
Yi Kong48a6cd22018-07-18 10:07:09 -0700424 SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : nullptr);
425 SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : nullptr);
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800426
427 { // scope for the lock
Mathias Agopian65421432017-03-08 11:49:05 -0800428 std::lock_guard<std::mutex> _l(lock);
Mathias Agopianfb87e542012-01-30 18:20:52 -0800429 if (c) {
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800430 result = c->cnx->egl.eglMakeCurrent(
Mathias Agopianada798b2012-02-13 17:09:30 -0800431 disp.dpy, impl_draw, impl_read, impl_ctx);
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800432 if (result == EGL_TRUE) {
433 c->onMakeCurrent(draw, read);
434 }
435 } else {
436 result = cur_c->cnx->egl.eglMakeCurrent(
Mathias Agopianada798b2012-02-13 17:09:30 -0800437 disp.dpy, impl_draw, impl_read, impl_ctx);
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800438 if (result == EGL_TRUE) {
439 cur_c->onLooseCurrent();
440 }
Mathias Agopianfb87e542012-01-30 18:20:52 -0800441 }
442 }
Mathias Agopiana4b2c042012-02-03 15:24:51 -0800443
444 if (result == EGL_TRUE) {
445 // This cannot be called with the lock held because it might end-up
446 // calling back into EGL (in particular when a surface is destroyed
447 // it calls ANativeWindow::disconnect
448 _cur_c.release();
449 _cur_r.release();
450 _cur_d.release();
451 }
452
Mathias Agopianfb87e542012-01-30 18:20:52 -0800453 return result;
454}
Mathias Agopian518ec112011-05-13 16:21:08 -0700455
Jesse Hallc2e41222013-08-08 13:40:22 -0700456bool egl_display_t::haveExtension(const char* name, size_t nameLen) const {
457 if (!nameLen) {
458 nameLen = strlen(name);
459 }
Mathias Agopian65421432017-03-08 11:49:05 -0800460 return findExtension(mExtensionString.c_str(), name, nameLen);
Jesse Hallc2e41222013-08-08 13:40:22 -0700461}
462
Jesse Halla0fef1c2012-04-17 12:02:26 -0700463// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -0700464}; // namespace android
465// ----------------------------------------------------------------------------