OLD | NEW |
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/GLContext.h" | 8 #include "gl/GLTestContext.h" |
9 | 9 |
10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
11 #include <GL/glx.h> | 11 #include <GL/glx.h> |
12 #include <GL/glu.h> | 12 #include <GL/glu.h> |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 /* Note: Skia requires glx 1.3 or newer */ | 16 /* Note: Skia requires glx 1.3 or newer */ |
17 | 17 |
18 /* This struct is taken from a mesa demo. Please update as required */ | 18 /* This struct is taken from a mesa demo. Please update as required */ |
(...skipping 18 matching lines...) Expand all Loading... |
37 {0, 0} /* end of list */ | 37 {0, 0} /* end of list */ |
38 }; | 38 }; |
39 #define NUM_GL_VERSIONS SK_ARRAY_COUNT(gl_versions) | 39 #define NUM_GL_VERSIONS SK_ARRAY_COUNT(gl_versions) |
40 | 40 |
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 sk_gpu_test::GLContext { | 47 class GLXGLTestContext : public sk_gpu_test::GLTestContext { |
48 public: | 48 public: |
49 GLXGLContext(GrGLStandard forcedGpuAPI, GLXGLContext* shareList); | 49 GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext* shareList); |
50 ~GLXGLContext() override; | 50 ~GLXGLTestContext() override; |
51 | 51 |
52 private: | 52 private: |
53 void destroyGLContext(); | 53 void destroyGLContext(); |
54 | 54 |
55 void onPlatformMakeCurrent() const override; | 55 void onPlatformMakeCurrent() const override; |
56 void onPlatformSwapBuffers() const override; | 56 void onPlatformSwapBuffers() const override; |
57 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; | 57 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; |
58 | 58 |
59 GLXContext fContext; | 59 GLXContext fContext; |
60 Display* fDisplay; | 60 Display* fDisplay; |
61 Pixmap fPixmap; | 61 Pixmap fPixmap; |
62 GLXPixmap fGlxPixmap; | 62 GLXPixmap fGlxPixmap; |
63 }; | 63 }; |
64 | 64 |
65 GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI, GLXGLContext* shareContext
) | 65 GLXGLTestContext::GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext*
shareContext) |
66 : fContext(nullptr) | 66 : fContext(nullptr) |
67 , fDisplay(nullptr) | 67 , fDisplay(nullptr) |
68 , fPixmap(0) | 68 , fPixmap(0) |
69 , fGlxPixmap(0) { | 69 , fGlxPixmap(0) { |
70 fDisplay = XOpenDisplay(0); | 70 fDisplay = XOpenDisplay(0); |
71 | 71 |
72 GLXContext glxShareContext = shareContext ? shareContext->fContext : nullptr
; | 72 GLXContext glxShareContext = shareContext ? shareContext->fContext : nullptr
; |
73 | 73 |
74 if (!fDisplay) { | 74 if (!fDisplay) { |
75 SkDebugf("Failed to open X display.\n"); | 75 SkDebugf("Failed to open X display.\n"); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 if (!gl->validate()) { | 281 if (!gl->validate()) { |
282 SkDebugf("Failed to validate gl interface"); | 282 SkDebugf("Failed to validate gl interface"); |
283 this->destroyGLContext(); | 283 this->destroyGLContext(); |
284 return; | 284 return; |
285 } | 285 } |
286 | 286 |
287 this->init(gl.release()); | 287 this->init(gl.release()); |
288 } | 288 } |
289 | 289 |
290 | 290 |
291 GLXGLContext::~GLXGLContext() { | 291 GLXGLTestContext::~GLXGLTestContext() { |
292 this->teardown(); | 292 this->teardown(); |
293 this->destroyGLContext(); | 293 this->destroyGLContext(); |
294 } | 294 } |
295 | 295 |
296 void GLXGLContext::destroyGLContext() { | 296 void GLXGLTestContext::destroyGLContext() { |
297 if (fDisplay) { | 297 if (fDisplay) { |
298 glXMakeCurrent(fDisplay, 0, 0); | 298 glXMakeCurrent(fDisplay, 0, 0); |
299 | 299 |
300 if (fContext) { | 300 if (fContext) { |
301 glXDestroyContext(fDisplay, fContext); | 301 glXDestroyContext(fDisplay, fContext); |
302 fContext = nullptr; | 302 fContext = nullptr; |
303 } | 303 } |
304 | 304 |
305 if (fGlxPixmap) { | 305 if (fGlxPixmap) { |
306 glXDestroyGLXPixmap(fDisplay, fGlxPixmap); | 306 glXDestroyGLXPixmap(fDisplay, fGlxPixmap); |
307 fGlxPixmap = 0; | 307 fGlxPixmap = 0; |
308 } | 308 } |
309 | 309 |
310 if (fPixmap) { | 310 if (fPixmap) { |
311 XFreePixmap(fDisplay, fPixmap); | 311 XFreePixmap(fDisplay, fPixmap); |
312 fPixmap = 0; | 312 fPixmap = 0; |
313 } | 313 } |
314 | 314 |
315 XCloseDisplay(fDisplay); | 315 XCloseDisplay(fDisplay); |
316 fDisplay = nullptr; | 316 fDisplay = nullptr; |
317 } | 317 } |
318 } | 318 } |
319 | 319 |
320 void GLXGLContext::onPlatformMakeCurrent() const { | 320 void GLXGLTestContext::onPlatformMakeCurrent() const { |
321 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { | 321 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { |
322 SkDebugf("Could not set the context.\n"); | 322 SkDebugf("Could not set the context.\n"); |
323 } | 323 } |
324 } | 324 } |
325 | 325 |
326 void GLXGLContext::onPlatformSwapBuffers() const { | 326 void GLXGLTestContext::onPlatformSwapBuffers() const { |
327 glXSwapBuffers(fDisplay, fGlxPixmap); | 327 glXSwapBuffers(fDisplay, fGlxPixmap); |
328 } | 328 } |
329 | 329 |
330 GrGLFuncPtr GLXGLContext::onPlatformGetProcAddress(const char* procName) const { | 330 GrGLFuncPtr GLXGLTestContext::onPlatformGetProcAddress(const char* procName) con
st { |
331 return glXGetProcAddress(reinterpret_cast<const GLubyte*>(procName)); | 331 return glXGetProcAddress(reinterpret_cast<const GLubyte*>(procName)); |
332 } | 332 } |
333 | 333 |
334 } // anonymous namespace | 334 } // anonymous namespace |
335 | 335 |
336 namespace sk_gpu_test { | 336 namespace sk_gpu_test { |
337 GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareCo
ntext) { | 337 GLTestContext *CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, |
338 GLXGLContext *glxShareContext = reinterpret_cast<GLXGLContext *>(shareContex
t); | 338 GLTestContext *shareContext) { |
339 GLXGLContext *ctx = new GLXGLContext(forcedGpuAPI, glxShareContext); | 339 GLXGLTestContext *glxShareContext = reinterpret_cast<GLXGLTestContext *>(sha
reContext); |
| 340 GLXGLTestContext *ctx = new GLXGLTestContext(forcedGpuAPI, glxShareContext); |
340 if (!ctx->isValid()) { | 341 if (!ctx->isValid()) { |
341 delete ctx; | 342 delete ctx; |
342 return nullptr; | 343 return nullptr; |
343 } | 344 } |
344 return ctx; | 345 return ctx; |
345 } | 346 } |
346 } // namespace sk_gpu_test | 347 } // namespace sk_gpu_test |
OLD | NEW |