| 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/SkNativeGLContext.h" | 8 #include "gl/SkGLContext.h" | 
| 9 | 9 | 
| 10 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { | 10 #include <GLES2/gl2.h> | 
| 11     fOldEGLContext = eglGetCurrentContext(); | 11 #include <EGL/egl.h> | 
| 12     fOldDisplay = eglGetCurrentDisplay(); |  | 
| 13     fOldSurface = eglGetCurrentSurface(EGL_DRAW); |  | 
| 14 | 12 | 
| 15 } | 13 namespace { | 
| 16 | 14 | 
| 17 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { | 15 class EGLGLContext : public SkGLContext  { | 
| 18     if (fOldDisplay) { | 16 public: | 
| 19         eglMakeCurrent(fOldDisplay, fOldSurface, fOldSurface, fOldEGLContext); | 17     EGLGLContext(); | 
| 20     } |  | 
| 21 } |  | 
| 22 | 18 | 
| 23 /////////////////////////////////////////////////////////////////////////////// | 19     virtual ~EGLGLContext(); | 
| 24 | 20 | 
| 25 SkNativeGLContext::SkNativeGLContext() | 21     virtual void makeCurrent() const SK_OVERRIDE; | 
|  | 22     virtual void swapBuffers() const SK_OVERRIDE; | 
|  | 23 protected: | 
|  | 24     virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_O
     VERRIDE; | 
|  | 25     virtual void destroyGLContext() SK_OVERRIDE; | 
|  | 26 | 
|  | 27 private: | 
|  | 28     EGLContext fContext; | 
|  | 29     EGLDisplay fDisplay; | 
|  | 30     EGLSurface fSurface; | 
|  | 31 }; | 
|  | 32 | 
|  | 33 EGLGLContext::EGLGLContext() | 
| 26     : fContext(EGL_NO_CONTEXT) | 34     : fContext(EGL_NO_CONTEXT) | 
| 27     , fDisplay(EGL_NO_DISPLAY) | 35     , fDisplay(EGL_NO_DISPLAY) | 
| 28     , fSurface(EGL_NO_SURFACE) { | 36     , fSurface(EGL_NO_SURFACE) { | 
| 29 } | 37 } | 
| 30 | 38 | 
| 31 SkNativeGLContext::~SkNativeGLContext() { | 39 EGLGLContext::~EGLGLContext() { | 
| 32     this->destroyGLContext(); | 40     this->destroyGLContext(); | 
| 33 } | 41 } | 
| 34 | 42 | 
| 35 void SkNativeGLContext::destroyGLContext() { | 43 void EGLGLContext::destroyGLContext() { | 
| 36     if (fDisplay) { | 44     if (fDisplay) { | 
| 37         eglMakeCurrent(fDisplay, 0, 0, 0); | 45         eglMakeCurrent(fDisplay, 0, 0, 0); | 
| 38 | 46 | 
| 39         if (fContext) { | 47         if (fContext) { | 
| 40             eglDestroyContext(fDisplay, fContext); | 48             eglDestroyContext(fDisplay, fContext); | 
| 41             fContext = EGL_NO_CONTEXT; | 49             fContext = EGL_NO_CONTEXT; | 
| 42         } | 50         } | 
| 43 | 51 | 
| 44         if (fSurface) { | 52         if (fSurface) { | 
| 45             eglDestroySurface(fDisplay, fSurface); | 53             eglDestroySurface(fDisplay, fSurface); | 
| 46             fSurface = EGL_NO_SURFACE; | 54             fSurface = EGL_NO_SURFACE; | 
| 47         } | 55         } | 
| 48 | 56 | 
| 49         //TODO should we close the display? | 57         //TODO should we close the display? | 
| 50         fDisplay = EGL_NO_DISPLAY; | 58         fDisplay = EGL_NO_DISPLAY; | 
| 51     } | 59     } | 
| 52 } | 60 } | 
| 53 | 61 | 
| 54 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP
     I) { | 62 const GrGLInterface* EGLGLContext::createGLContext(GrGLStandard forcedGpuAPI) { | 
| 55     static const EGLint kEGLContextAttribsForOpenGL[] = { | 63     static const EGLint kEGLContextAttribsForOpenGL[] = { | 
| 56         EGL_NONE | 64         EGL_NONE | 
| 57     }; | 65     }; | 
| 58 | 66 | 
| 59     static const EGLint kEGLContextAttribsForOpenGLES[] = { | 67     static const EGLint kEGLContextAttribsForOpenGLES[] = { | 
| 60         EGL_CONTEXT_CLIENT_VERSION, 2, | 68         EGL_CONTEXT_CLIENT_VERSION, 2, | 
| 61         EGL_NONE | 69         EGL_NONE | 
| 62     }; | 70     }; | 
| 63 | 71 | 
| 64     static const struct { | 72     static const struct { | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 162         if (!interface->validate()) { | 170         if (!interface->validate()) { | 
| 163             interface->unref(); | 171             interface->unref(); | 
| 164             interface = NULL; | 172             interface = NULL; | 
| 165             this->destroyGLContext(); | 173             this->destroyGLContext(); | 
| 166         } | 174         } | 
| 167     } | 175     } | 
| 168 | 176 | 
| 169     return interface; | 177     return interface; | 
| 170 } | 178 } | 
| 171 | 179 | 
| 172 void SkNativeGLContext::makeCurrent() const { | 180 void EGLGLContext::makeCurrent() const { | 
| 173     if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 181     if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 
| 174         SkDebugf("Could not set the context.\n"); | 182         SkDebugf("Could not set the context.\n"); | 
| 175     } | 183     } | 
| 176 } | 184 } | 
| 177 | 185 | 
| 178 void SkNativeGLContext::swapBuffers() const { | 186 void EGLGLContext::swapBuffers() const { | 
| 179     if (!eglSwapBuffers(fDisplay, fSurface)) { | 187     if (!eglSwapBuffers(fDisplay, fSurface)) { | 
| 180         SkDebugf("Could not complete eglSwapBuffers.\n"); | 188         SkDebugf("Could not complete eglSwapBuffers.\n"); | 
| 181     } | 189     } | 
| 182 } | 190 } | 
|  | 191 | 
|  | 192 } // anonymous namespace | 
|  | 193 | 
|  | 194 SkGLContext* SkCreatePlatformGLContext() { | 
|  | 195     return SkNEW(EGLGLContext); | 
|  | 196 } | 
|  | 197 | 
| OLD | NEW | 
|---|