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

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

Issue 630843002: Make the Sk GL context class an abstract base class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix android link problem and ios compile problem Created 6 years, 2 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 | « src/gpu/gl/egl/SkNativeGLContext_egl.cpp ('k') | src/gpu/gl/glx/SkNativeGLContext_glx.cpp » ('j') | 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 /* 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/SkNativeGLContext.h" 8 #include "gl/SkGLContext.h"
9 9
10 #include <X11/Xlib.h>
11 #include <GL/glx.h>
10 #include <GL/glu.h> 12 #include <GL/glu.h>
11 13
14 namespace {
15
12 /* Note: Skia requires glx 1.3 or newer */ 16 /* Note: Skia requires glx 1.3 or newer */
13 17
14 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { 18 /* This struct is taken from a mesa demo. Please update as required */
15 fOldGLXContext = glXGetCurrentContext(); 19 static const struct { int major, minor; } gl_versions[] = {
16 fOldDisplay = glXGetCurrentDisplay(); 20 {1, 0},
17 fOldDrawable = glXGetCurrentDrawable(); 21 {1, 1},
18 } 22 {1, 2},
19 23 {1, 3},
20 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { 24 {1, 4},
21 if (fOldDisplay) { 25 {1, 5},
22 glXMakeCurrent(fOldDisplay, fOldDrawable, fOldGLXContext); 26 {2, 0},
23 } 27 {2, 1},
24 } 28 {3, 0},
25 29 {3, 1},
26 /////////////////////////////////////////////////////////////////////////////// 30 {3, 2},
31 {3, 3},
32 {4, 0},
33 {4, 1},
34 {4, 2},
35 {4, 3},
36 {4, 4},
37 {0, 0} /* end of list */
38 };
39 #define NUM_GL_VERSIONS SK_ARRAY_COUNT(gl_versions)
27 40
28 static bool ctxErrorOccurred = false; 41 static bool ctxErrorOccurred = false;
29 static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) { 42 static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
30 ctxErrorOccurred = true; 43 ctxErrorOccurred = true;
31 return 0; 44 return 0;
32 } 45 }
33 46
34 SkNativeGLContext::SkNativeGLContext() 47 class GLXGLContext : public SkGLContext {
48 public:
49 GLXGLContext();
50
51 virtual ~GLXGLContext();
52
53 virtual void makeCurrent() const SK_OVERRIDE;
54 virtual void swapBuffers() const SK_OVERRIDE;
55 protected:
56 virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_O VERRIDE;
57 virtual void destroyGLContext() SK_OVERRIDE;
58
59 private:
60 GLXContext fContext;
61 Display* fDisplay;
62 Pixmap fPixmap;
63 GLXPixmap fGlxPixmap;
64 };
65
66 GLXGLContext::GLXGLContext()
35 : fContext(NULL) 67 : fContext(NULL)
36 , fDisplay(NULL) 68 , fDisplay(NULL)
37 , fPixmap(0) 69 , fPixmap(0)
38 , fGlxPixmap(0) { 70 , fGlxPixmap(0) {
39 } 71 }
40 72
41 SkNativeGLContext::~SkNativeGLContext() { 73 GLXGLContext::~GLXGLContext() {
42 this->destroyGLContext(); 74 this->destroyGLContext();
43 } 75 }
44 76
45 void SkNativeGLContext::destroyGLContext() { 77 void GLXGLContext::destroyGLContext() {
46 if (fDisplay) { 78 if (fDisplay) {
47 glXMakeCurrent(fDisplay, 0, 0); 79 glXMakeCurrent(fDisplay, 0, 0);
48 80
49 if (fContext) { 81 if (fContext) {
50 glXDestroyContext(fDisplay, fContext); 82 glXDestroyContext(fDisplay, fContext);
51 fContext = NULL; 83 fContext = NULL;
52 } 84 }
53 85
54 if (fGlxPixmap) { 86 if (fGlxPixmap) {
55 glXDestroyGLXPixmap(fDisplay, fGlxPixmap); 87 glXDestroyGLXPixmap(fDisplay, fGlxPixmap);
56 fGlxPixmap = 0; 88 fGlxPixmap = 0;
57 } 89 }
58 90
59 if (fPixmap) { 91 if (fPixmap) {
60 XFreePixmap(fDisplay, fPixmap); 92 XFreePixmap(fDisplay, fPixmap);
61 fPixmap = 0; 93 fPixmap = 0;
62 } 94 }
63 95
64 XCloseDisplay(fDisplay); 96 XCloseDisplay(fDisplay);
65 fDisplay = NULL; 97 fDisplay = NULL;
66 } 98 }
67 } 99 }
68 100
69 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP I) { 101 const GrGLInterface* GLXGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
70 fDisplay = XOpenDisplay(0); 102 fDisplay = XOpenDisplay(0);
71 103
72 if (!fDisplay) { 104 if (!fDisplay) {
73 SkDebugf("Failed to open X display.\n"); 105 SkDebugf("Failed to open X display.\n");
74 this->destroyGLContext(); 106 this->destroyGLContext();
75 return NULL; 107 return NULL;
76 } 108 }
77 109
78 // Get a matching FB config 110 // Get a matching FB config
79 static int visual_attribs[] = { 111 static int visual_attribs[] = {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 302
271 const GrGLInterface* interface = GrGLCreateNativeInterface(); 303 const GrGLInterface* interface = GrGLCreateNativeInterface();
272 if (!interface) { 304 if (!interface) {
273 SkDebugf("Failed to create gl interface"); 305 SkDebugf("Failed to create gl interface");
274 this->destroyGLContext(); 306 this->destroyGLContext();
275 return NULL; 307 return NULL;
276 } 308 }
277 return interface; 309 return interface;
278 } 310 }
279 311
280 void SkNativeGLContext::makeCurrent() const { 312 void GLXGLContext::makeCurrent() const {
281 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { 313 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) {
282 SkDebugf("Could not set the context.\n"); 314 SkDebugf("Could not set the context.\n");
283 } 315 }
284 } 316 }
285 317
286 void SkNativeGLContext::swapBuffers() const { 318 void GLXGLContext::swapBuffers() const {
287 glXSwapBuffers(fDisplay, fGlxPixmap); 319 glXSwapBuffers(fDisplay, fGlxPixmap);
288 } 320 }
321
322 } // anonymous namespace
323
324 SkGLContext* SkCreatePlatformGLContext() {
325 return SkNEW(GLXGLContext);
326 }
OLDNEW
« no previous file with comments | « src/gpu/gl/egl/SkNativeGLContext_egl.cpp ('k') | src/gpu/gl/glx/SkNativeGLContext_glx.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698