aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/gpu/gl
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-08-11 14:58:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-11 14:58:34 -0700
commit300178b1c83e7a9b8d3bee7aeb09e0d4fb096d6b (patch)
tree4ec605aca0e923f1c934de3e7ad8fcd367e74c82 /tools/gpu/gl
parentd22a817ff57986407facd16af36320fc86ce02da (diff)
Only open X Display once for all test GLX contexts
Saves about 4 seconds of runtime for 'dm --src gm --config gpu' on my system. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2240673002 Review-Url: https://codereview.chromium.org/2240673002
Diffstat (limited to 'tools/gpu/gl')
-rw-r--r--tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp b/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
index c483fecabe..1da245d87c 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);
+ }
+ }
+ 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;
}
}