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

Unified Diff: tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp

Issue 2240673002: Only open X Display once for all test GLX contexts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 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/glx/CreatePlatformGLTestContext_glx.cpp
diff --git a/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp b/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
index c483fecabec5f751fef470cd2f3cce4d92f308a3..1da245d87c3264c0ea59c159de2f1b14f8557eaa 100644
--- a/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
+++ b/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
@@ -4,7 +4,9 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "gl/GLTestContext.h"
+#include "SkOnce.h"
#include <X11/Xlib.h>
#include <GL/glx.h>
@@ -69,12 +71,31 @@ private:
GLXPixmap fGlxPixmap;
};
+static Display* get_display() {
+ class AutoDisplay {
+ public:
+ AutoDisplay() { fDisplay = XOpenDisplay(nullptr); };
+ ~AutoDisplay() {
+ if (fDisplay) {
+ XCloseDisplay(fDisplay);
csmartdalton 2016/08/11 21:29:05 This might not be necessary, I'd imagine it would
+ }
+ }
+ Display* display() const { return fDisplay; }
+ private:
+ Display* fDisplay;
+ };
+ static std::unique_ptr<AutoDisplay> ad;
+ static SkOnce once;
+ once([] { ad.reset(new AutoDisplay{}); });
+ return ad->display();
+}
+
GLXGLTestContext::GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext* shareContext)
: fContext(nullptr)
, fDisplay(nullptr)
, fPixmap(0)
, fGlxPixmap(0) {
- fDisplay = XOpenDisplay(0);
+ fDisplay = get_display();
GLXContext glxShareContext = shareContext ? shareContext->fContext : nullptr;
@@ -239,7 +260,6 @@ void GLXGLTestContext::destroyGLContext() {
fPixmap = 0;
}
- XCloseDisplay(fDisplay);
fDisplay = nullptr;
}
}
« 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