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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7
7 #include "gl/GLTestContext.h" 8 #include "gl/GLTestContext.h"
9 #include "SkOnce.h"
8 10
9 #include <X11/Xlib.h> 11 #include <X11/Xlib.h>
10 #include <GL/glx.h> 12 #include <GL/glx.h>
11 #include <GL/glu.h> 13 #include <GL/glu.h>
12 14
13 #include <vector> 15 #include <vector>
14 #include <utility> 16 #include <utility>
15 17
16 namespace { 18 namespace {
17 19
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 void onPlatformMakeCurrent() const override; 64 void onPlatformMakeCurrent() const override;
63 void onPlatformSwapBuffers() const override; 65 void onPlatformSwapBuffers() const override;
64 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; 66 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
65 67
66 GLXContext fContext; 68 GLXContext fContext;
67 Display* fDisplay; 69 Display* fDisplay;
68 Pixmap fPixmap; 70 Pixmap fPixmap;
69 GLXPixmap fGlxPixmap; 71 GLXPixmap fGlxPixmap;
70 }; 72 };
71 73
74 static Display* get_display() {
75 class AutoDisplay {
76 public:
77 AutoDisplay() { fDisplay = XOpenDisplay(nullptr); };
78 ~AutoDisplay() {
79 if (fDisplay) {
80 XCloseDisplay(fDisplay);
csmartdalton 2016/08/11 21:29:05 This might not be necessary, I'd imagine it would
81 }
82 }
83 Display* display() const { return fDisplay; }
84 private:
85 Display* fDisplay;
86 };
87 static std::unique_ptr<AutoDisplay> ad;
88 static SkOnce once;
89 once([] { ad.reset(new AutoDisplay{}); });
90 return ad->display();
91 }
92
72 GLXGLTestContext::GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext* shareContext) 93 GLXGLTestContext::GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext* shareContext)
73 : fContext(nullptr) 94 : fContext(nullptr)
74 , fDisplay(nullptr) 95 , fDisplay(nullptr)
75 , fPixmap(0) 96 , fPixmap(0)
76 , fGlxPixmap(0) { 97 , fGlxPixmap(0) {
77 fDisplay = XOpenDisplay(0); 98 fDisplay = get_display();
78 99
79 GLXContext glxShareContext = shareContext ? shareContext->fContext : nullptr ; 100 GLXContext glxShareContext = shareContext ? shareContext->fContext : nullptr ;
80 101
81 if (!fDisplay) { 102 if (!fDisplay) {
82 SkDebugf("Failed to open X display.\n"); 103 SkDebugf("Failed to open X display.\n");
83 this->destroyGLContext(); 104 this->destroyGLContext();
84 return; 105 return;
85 } 106 }
86 107
87 // Get a matching FB config 108 // Get a matching FB config
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (fGlxPixmap) { 253 if (fGlxPixmap) {
233 glXDestroyGLXPixmap(fDisplay, fGlxPixmap); 254 glXDestroyGLXPixmap(fDisplay, fGlxPixmap);
234 fGlxPixmap = 0; 255 fGlxPixmap = 0;
235 } 256 }
236 257
237 if (fPixmap) { 258 if (fPixmap) {
238 XFreePixmap(fDisplay, fPixmap); 259 XFreePixmap(fDisplay, fPixmap);
239 fPixmap = 0; 260 fPixmap = 0;
240 } 261 }
241 262
242 XCloseDisplay(fDisplay);
243 fDisplay = nullptr; 263 fDisplay = nullptr;
244 } 264 }
245 } 265 }
246 266
247 /* Create a context with the highest possible version. 267 /* Create a context with the highest possible version.
248 * 268 *
249 * Disable Xlib errors for the duration of this function (by default they abort 269 * Disable Xlib errors for the duration of this function (by default they abort
250 * the program) and try to get a context starting from the highest version 270 * the program) and try to get a context starting from the highest version
251 * number - there is no way to just directly ask what the highest supported 271 * number - there is no way to just directly ask what the highest supported
252 * version is. 272 * version is.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 GLTestContext *shareContext) { 347 GLTestContext *shareContext) {
328 GLXGLTestContext *glxShareContext = reinterpret_cast<GLXGLTestContext *>(sha reContext); 348 GLXGLTestContext *glxShareContext = reinterpret_cast<GLXGLTestContext *>(sha reContext);
329 GLXGLTestContext *ctx = new GLXGLTestContext(forcedGpuAPI, glxShareContext); 349 GLXGLTestContext *ctx = new GLXGLTestContext(forcedGpuAPI, glxShareContext);
330 if (!ctx->isValid()) { 350 if (!ctx->isValid()) {
331 delete ctx; 351 delete ctx;
332 return nullptr; 352 return nullptr;
333 } 353 }
334 return ctx; 354 return ctx;
335 } 355 }
336 } // namespace sk_gpu_test 356 } // namespace sk_gpu_test
OLDNEW
« 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