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

Side by Side Diff: src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp

Issue 1194783003: Implement SkGLContext swapBuffers with fence syncs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: windows build Created 5 years, 6 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "gl/SkGLContext.h" 8 #include "gl/SkGLContext.h"
9 9
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
(...skipping 30 matching lines...) Expand all
41 static bool ctxErrorOccurred = false; 41 static bool ctxErrorOccurred = false;
42 static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) { 42 static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
43 ctxErrorOccurred = true; 43 ctxErrorOccurred = true;
44 return 0; 44 return 0;
45 } 45 }
46 46
47 class GLXGLContext : public SkGLContext { 47 class GLXGLContext : public SkGLContext {
48 public: 48 public:
49 GLXGLContext(GrGLStandard forcedGpuAPI); 49 GLXGLContext(GrGLStandard forcedGpuAPI);
50 ~GLXGLContext() override; 50 ~GLXGLContext() override;
51 void makeCurrent() const override;
52 void swapBuffers() const override;
53 51
54 private: 52 private:
55 void destroyGLContext(); 53 void destroyGLContext();
56 54
55 void onPlatformMakeCurrent() const override;
56 void onPlatformSwapBuffers() const override;
57 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
58
57 GLXContext fContext; 59 GLXContext fContext;
58 Display* fDisplay; 60 Display* fDisplay;
59 Pixmap fPixmap; 61 Pixmap fPixmap;
60 GLXPixmap fGlxPixmap; 62 GLXPixmap fGlxPixmap;
61 }; 63 };
62 64
63 GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI) 65 GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI)
64 : fContext(NULL) 66 : fContext(NULL)
65 , fDisplay(NULL) 67 , fDisplay(NULL)
66 , fPixmap(0) 68 , fPixmap(0)
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 //SkDebugf("Direct GLX rendering context obtained.\n"); 262 //SkDebugf("Direct GLX rendering context obtained.\n");
261 } 263 }
262 264
263 //SkDebugf("Making context current.\n"); 265 //SkDebugf("Making context current.\n");
264 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { 266 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) {
265 SkDebugf("Could not set the context.\n"); 267 SkDebugf("Could not set the context.\n");
266 this->destroyGLContext(); 268 this->destroyGLContext();
267 return; 269 return;
268 } 270 }
269 271
270 fGL.reset(GrGLCreateNativeInterface()); 272 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface());
271 if (NULL == fGL.get()) { 273 if (NULL == gl.get()) {
272 SkDebugf("Failed to create gl interface"); 274 SkDebugf("Failed to create gl interface");
273 this->destroyGLContext(); 275 this->destroyGLContext();
274 return; 276 return;
275 } 277 }
276 278
277 if (!fGL->validate()) { 279 if (!gl->validate()) {
278 SkDebugf("Failed to validate gl interface"); 280 SkDebugf("Failed to validate gl interface");
279 this->destroyGLContext(); 281 this->destroyGLContext();
280 return; 282 return;
281 } 283 }
284
285 this->init(gl.detach());
282 } 286 }
283 287
284 288
285 GLXGLContext::~GLXGLContext() { 289 GLXGLContext::~GLXGLContext() {
290 this->teardown();
286 this->destroyGLContext(); 291 this->destroyGLContext();
287 } 292 }
288 293
289 void GLXGLContext::destroyGLContext() { 294 void GLXGLContext::destroyGLContext() {
290 fGL.reset(NULL);
291 if (fDisplay) { 295 if (fDisplay) {
292 glXMakeCurrent(fDisplay, 0, 0); 296 glXMakeCurrent(fDisplay, 0, 0);
293 297
294 if (fContext) { 298 if (fContext) {
295 glXDestroyContext(fDisplay, fContext); 299 glXDestroyContext(fDisplay, fContext);
296 fContext = NULL; 300 fContext = NULL;
297 } 301 }
298 302
299 if (fGlxPixmap) { 303 if (fGlxPixmap) {
300 glXDestroyGLXPixmap(fDisplay, fGlxPixmap); 304 glXDestroyGLXPixmap(fDisplay, fGlxPixmap);
301 fGlxPixmap = 0; 305 fGlxPixmap = 0;
302 } 306 }
303 307
304 if (fPixmap) { 308 if (fPixmap) {
305 XFreePixmap(fDisplay, fPixmap); 309 XFreePixmap(fDisplay, fPixmap);
306 fPixmap = 0; 310 fPixmap = 0;
307 } 311 }
308 312
309 XCloseDisplay(fDisplay); 313 XCloseDisplay(fDisplay);
310 fDisplay = NULL; 314 fDisplay = NULL;
311 } 315 }
312 } 316 }
313 317
314 void GLXGLContext::makeCurrent() const { 318 void GLXGLContext::onPlatformMakeCurrent() const {
315 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { 319 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) {
316 SkDebugf("Could not set the context.\n"); 320 SkDebugf("Could not set the context.\n");
317 } 321 }
318 } 322 }
319 323
320 void GLXGLContext::swapBuffers() const { 324 void GLXGLContext::onPlatformSwapBuffers() const {
321 glXSwapBuffers(fDisplay, fGlxPixmap); 325 glXSwapBuffers(fDisplay, fGlxPixmap);
322 } 326 }
323 327
328 GrGLFuncPtr GLXGLContext::onPlatformGetProcAddress(const char* procName) const {
329 return glXGetProcAddress(reinterpret_cast<const GLubyte*>(procName));
330 }
331
324 } // anonymous namespace 332 } // anonymous namespace
325 333
326 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { 334 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) {
327 GLXGLContext* ctx = SkNEW_ARGS(GLXGLContext, (forcedGpuAPI)); 335 GLXGLContext* ctx = SkNEW_ARGS(GLXGLContext, (forcedGpuAPI));
328 if (!ctx->isValid()) { 336 if (!ctx->isValid()) {
329 SkDELETE(ctx); 337 SkDELETE(ctx);
330 return NULL; 338 return NULL;
331 } 339 }
332 return ctx; 340 return ctx;
333 } 341 }
OLDNEW
« no previous file with comments | « src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp ('k') | src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698