diff options
author | Woody Chow <woodychow@google.com> | 2020-08-31 14:34:12 +0900 |
---|---|---|
committer | Woody Chow <woodychow@google.com> | 2020-09-10 13:37:55 +0900 |
commit | a9550f3fe9097e0934e9b44c5aac6b914fb46aec (patch) | |
tree | a7e0a779b3ac16485a07d6046b23bdbf44b913e2 /opengl | |
parent | 27d8f4662870a6bd252a8e29f05d9bf3a8ed7dd2 (diff) |
Fix support of different attrib_list in eglGetPlatformDisplay
Regression was introduced by ag/5161774, where different
EGLDisplay(s) with the same display type but different
attrib_list(s) would share the same egl_display_t object.
Only the first EGLDisplay associated with the egl_display_t
would be initialized.
Bug: 162381841
Test: Run android.graphics.cts.EGL15Test in CtsGraphicsTestCases
Change-Id: I4419e0f9f0d0f6491e7fae397b6c8926405ca836
Diffstat (limited to 'opengl')
-rw-r--r-- | opengl/libs/EGL/egl_display.cpp | 24 | ||||
-rw-r--r-- | opengl/libs/EGL/egl_display.h | 8 |
2 files changed, 22 insertions, 10 deletions
diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp index 07ec327ab3..a288c21f31 100644 --- a/opengl/libs/EGL/egl_display.cpp +++ b/opengl/libs/EGL/egl_display.cpp @@ -74,7 +74,8 @@ int egl_get_init_count(EGLDisplay dpy) { return eglDisplay ? eglDisplay->getRefsCount() : 0; } -egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS]; +std::map<EGLDisplay, std::unique_ptr<egl_display_t>> egl_display_t::displayMap; +std::mutex egl_display_t::displayMapLock; egl_display_t::egl_display_t() : magic('_dpy'), @@ -93,11 +94,12 @@ egl_display_t* egl_display_t::get(EGLDisplay dpy) { return nullptr; } - uintptr_t index = uintptr_t(dpy) - 1U; - if (index >= NUM_DISPLAYS || !sDisplay[index].isValid()) { + const std::lock_guard<std::mutex> lock(displayMapLock); + auto search = displayMap.find(dpy); + if (search == displayMap.end() || !search->second->isValid()) { return nullptr; } - return &sDisplay[index]; + return search->second.get(); } void egl_display_t::addObject(egl_object_t* object) { @@ -125,7 +127,7 @@ EGLDisplay egl_display_t::getFromNativeDisplay(EGLNativeDisplayType disp, const EGLAttrib* attrib_list) { if (uintptr_t(disp) >= NUM_DISPLAYS) return nullptr; - return sDisplay[uintptr_t(disp)].getPlatformDisplay(disp, attrib_list); + return getPlatformDisplay(disp, attrib_list); } static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_connection_t* const cnx, @@ -170,7 +172,6 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn EGLDisplay egl_display_t::getPlatformDisplay(EGLNativeDisplayType display, const EGLAttrib* attrib_list) { - std::lock_guard<std::mutex> _l(lock); ATRACE_CALL(); // get our driver loader @@ -206,13 +207,20 @@ EGLDisplay egl_display_t::getPlatformDisplay(EGLNativeDisplayType display, } } - disp.dpy = dpy; if (dpy == EGL_NO_DISPLAY) { loader.close(cnx); + } else { + const std::lock_guard<std::mutex> lock(displayMapLock); + if (displayMap.find(dpy) == displayMap.end()) { + auto d = std::make_unique<egl_display_t>(); + d->disp.dpy = dpy; + displayMap[dpy] = std::move(d); + } + return dpy; } } - return EGLDisplay(uintptr_t(display) + 1U); + return nullptr; } EGLBoolean egl_display_t::initialize(EGLint* major, EGLint* minor) { diff --git a/opengl/libs/EGL/egl_display.h b/opengl/libs/EGL/egl_display.h index 01551330a2..87c2176045 100644 --- a/opengl/libs/EGL/egl_display.h +++ b/opengl/libs/EGL/egl_display.h @@ -23,6 +23,8 @@ #include <stdint.h> #include <condition_variable> +#include <map> +#include <memory> #include <mutex> #include <string> #include <unordered_set> @@ -40,9 +42,11 @@ bool findExtension(const char* exts, const char* name, size_t nameLen = 0); bool needsAndroidPEglMitigation(); class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes - static egl_display_t sDisplay[NUM_DISPLAYS]; + static std::map<EGLDisplay, std::unique_ptr<egl_display_t>> displayMap; + static std::mutex displayMapLock; EGLDisplay getDisplay(EGLNativeDisplayType display); - EGLDisplay getPlatformDisplay(EGLNativeDisplayType display, const EGLAttrib* attrib_list); + static EGLDisplay getPlatformDisplay(EGLNativeDisplayType display, + const EGLAttrib* attrib_list); void loseCurrentImpl(egl_context_t* cur_c); public: |