| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 | 8 |
| 9 #include "gl/SkANGLEGLContext.h" | 9 #include "gl/SkANGLEGLContext.h" |
| 10 | 10 |
| 11 SkANGLEGLContext::SkANGLEGLContext() | 11 SkANGLEGLContext::SkANGLEGLContext() |
| 12 : fContext(EGL_NO_CONTEXT) | 12 : fContext(EGL_NO_CONTEXT) |
| 13 , fDisplay(EGL_NO_DISPLAY) | 13 , fDisplay(EGL_NO_DISPLAY) |
| 14 , fSurface(EGL_NO_SURFACE) { | 14 , fSurface(EGL_NO_SURFACE) { |
| 15 } | |
| 16 | |
| 17 SkANGLEGLContext::~SkANGLEGLContext() { | |
| 18 this->destroyGLContext(); | |
| 19 } | |
| 20 | |
| 21 void SkANGLEGLContext::destroyGLContext() { | |
| 22 if (fDisplay) { | |
| 23 eglMakeCurrent(fDisplay, 0, 0, 0); | |
| 24 | |
| 25 if (fContext) { | |
| 26 eglDestroyContext(fDisplay, fContext); | |
| 27 fContext = EGL_NO_CONTEXT; | |
| 28 } | |
| 29 | |
| 30 if (fSurface) { | |
| 31 eglDestroySurface(fDisplay, fSurface); | |
| 32 fSurface = EGL_NO_SURFACE; | |
| 33 } | |
| 34 | |
| 35 //TODO should we close the display? | |
| 36 fDisplay = EGL_NO_DISPLAY; | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 const GrGLInterface* SkANGLEGLContext::createGLContext(GrGLStandard forcedGpuAPI
) { | |
| 41 if (kGL_GrGLStandard == forcedGpuAPI) { | |
| 42 return NULL; | |
| 43 } | |
| 44 | |
| 45 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 15 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 46 | 16 |
| 47 EGLint majorVersion; | 17 EGLint majorVersion; |
| 48 EGLint minorVersion; | 18 EGLint minorVersion; |
| 49 eglInitialize(fDisplay, &majorVersion, &minorVersion); | 19 eglInitialize(fDisplay, &majorVersion, &minorVersion); |
| 50 | 20 |
| 51 EGLint numConfigs; | 21 EGLint numConfigs; |
| 52 static const EGLint configAttribs[] = { | 22 static const EGLint configAttribs[] = { |
| 53 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, | 23 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
| 54 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 24 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 | 41 |
| 72 static const EGLint surfaceAttribs[] = { | 42 static const EGLint surfaceAttribs[] = { |
| 73 EGL_WIDTH, 1, | 43 EGL_WIDTH, 1, |
| 74 EGL_HEIGHT, 1, | 44 EGL_HEIGHT, 1, |
| 75 EGL_NONE | 45 EGL_NONE |
| 76 }; | 46 }; |
| 77 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs); | 47 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs); |
| 78 | 48 |
| 79 eglMakeCurrent(fDisplay, fSurface, fSurface, fContext); | 49 eglMakeCurrent(fDisplay, fSurface, fSurface, fContext); |
| 80 | 50 |
| 81 const GrGLInterface* interface = GrGLCreateANGLEInterface(); | 51 fGL.reset(GrGLCreateANGLEInterface()); |
| 82 if (NULL == interface) { | 52 if (NULL == fGL.get()) { |
| 83 SkDebugf("Could not create ANGLE GL interface!\n"); | 53 SkDebugf("Could not create ANGLE GL interface!\n"); |
| 84 this->destroyGLContext(); | 54 this->destroyGLContext(); |
| 85 return NULL; | 55 return; |
| 86 } | 56 } |
| 57 if (!fGL->validate()) { |
| 58 SkDebugf("Could not validate ANGLE GL interface!\n"); |
| 59 this->destroyGLContext(); |
| 60 return; |
| 61 } |
| 62 } |
| 87 | 63 |
| 88 return interface; | 64 SkANGLEGLContext::~SkANGLEGLContext() { |
| 65 this->destroyGLContext(); |
| 66 } |
| 67 |
| 68 void SkANGLEGLContext::destroyGLContext() { |
| 69 fGL.reset(NULL); |
| 70 if (fDisplay) { |
| 71 eglMakeCurrent(fDisplay, 0, 0, 0); |
| 72 |
| 73 if (fContext) { |
| 74 eglDestroyContext(fDisplay, fContext); |
| 75 fContext = EGL_NO_CONTEXT; |
| 76 } |
| 77 |
| 78 if (fSurface) { |
| 79 eglDestroySurface(fDisplay, fSurface); |
| 80 fSurface = EGL_NO_SURFACE; |
| 81 } |
| 82 |
| 83 //TODO should we close the display? |
| 84 fDisplay = EGL_NO_DISPLAY; |
| 85 } |
| 89 } | 86 } |
| 90 | 87 |
| 91 void SkANGLEGLContext::makeCurrent() const { | 88 void SkANGLEGLContext::makeCurrent() const { |
| 92 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 89 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| 93 SkDebugf("Could not set the context.\n"); | 90 SkDebugf("Could not set the context.\n"); |
| 94 } | 91 } |
| 95 } | 92 } |
| 96 | 93 |
| 97 void SkANGLEGLContext::swapBuffers() const { | 94 void SkANGLEGLContext::swapBuffers() const { |
| 98 if (!eglSwapBuffers(fDisplay, fSurface)) { | 95 if (!eglSwapBuffers(fDisplay, fSurface)) { |
| 99 SkDebugf("Could not complete eglSwapBuffers.\n"); | 96 SkDebugf("Could not complete eglSwapBuffers.\n"); |
| 100 } | 97 } |
| 101 } | 98 } |
| OLD | NEW |