Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Unified Diff: tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp

Issue 1878943008: Only eglTerminate command buffer displays when no displays are in use (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add statics Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp
diff --git a/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp b/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp
index 5985a2e31f564109d3f2e246a1ba74109683e86b..af0abc58539c7add06c86799897dad3730f27b00 100644
--- a/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp
+++ b/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp
@@ -6,6 +6,7 @@
* found in the LICENSE file.
*/
+#include "SkMutex.h"
#include "SkOnce.h"
#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"
@@ -139,6 +140,41 @@ static const GrGLInterface* create_command_buffer_interface() {
return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc);
}
+// We use a poor man's garbage collector of EGLDisplays. They are only
+// terminated when there are no more EGLDisplays in use. See crbug.com/603223
+SK_DECLARE_STATIC_MUTEX(gDisplayMutex);
+static int gActiveDisplayCnt;
+SkTArray<EGLDisplay> gRetiredDisplays;
+
+static EGLDisplay get_and_init_display() {
+ SkAutoMutexAcquire am(gDisplayMutex);
+ EGLDisplay dsp = gfGetDisplay(EGL_DEFAULT_DISPLAY);
+ if (dsp == EGL_NO_DISPLAY) {
+ return EGL_NO_DISPLAY;
+ }
+ EGLint major, minor;
+ if (!gfInitialize(dsp, &major, &minor)) {
+ gRetiredDisplays.push_back(dsp);
+ return EGL_NO_DISPLAY;
+ }
+ ++gActiveDisplayCnt;
+ return dsp;
+}
+
+static void retire_display(EGLDisplay dsp) {
+ if (dsp == EGL_NO_DISPLAY) {
+ return;
+ }
+ SkAutoMutexAcquire am(gDisplayMutex);
+ gRetiredDisplays.push_back(dsp);
+ --gActiveDisplayCnt;
+ if (!gActiveDisplayCnt) {
+ for (EGLDisplay d : gRetiredDisplays) {
+ gfTerminate(d);
+ }
+ gRetiredDisplays.reset();
+ }
+}
} // anonymous namespace
namespace sk_gpu_test {
@@ -196,20 +232,12 @@ void CommandBufferGLTestContext::initializeGLContext(void *nativeWindow, const i
// Make sure CHROMIUM_path_rendering is enabled for NVPR support.
sk_setenv("CHROME_COMMAND_BUFFER_GLES2_ARGS", "--enable-gl-path-rendering");
- fDisplay = gfGetDisplay(EGL_DEFAULT_DISPLAY);
+ fDisplay = get_and_init_display();
if (EGL_NO_DISPLAY == fDisplay) {
SkDebugf("Command Buffer: Could not create EGL display.\n");
return;
}
- EGLint majorVersion;
- EGLint minorVersion;
- if (!gfInitialize(fDisplay, &majorVersion, &minorVersion)) {
- SkDebugf("Command Buffer: Could not initialize EGL display.\n");
- this->destroyGLContext();
- return;
- }
-
EGLint numConfigs;
if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig *>(&fConfig), 1,
&numConfigs) || numConfigs != 1) {
@@ -288,7 +316,7 @@ void CommandBufferGLTestContext::destroyGLContext() {
fSurface = EGL_NO_SURFACE;
}
- gfTerminate(fDisplay);
+ retire_display(fDisplay);
fDisplay = EGL_NO_DISPLAY;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698