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/SkNativeGLContext.h" | 9 #include "gl/SkNativeGLContext.h" |
10 #import <OpenGLES/EAGL.h> | 10 #import <OpenGLES/EAGL.h> |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 SkNativeGLContext::SkNativeGLContext() | 30 SkNativeGLContext::SkNativeGLContext() |
31 : fEAGLContext(NULL) { | 31 : fEAGLContext(NULL) { |
32 } | 32 } |
33 | 33 |
34 SkNativeGLContext::~SkNativeGLContext() { | 34 SkNativeGLContext::~SkNativeGLContext() { |
35 this->destroyGLContext(); | 35 this->destroyGLContext(); |
36 } | 36 } |
37 | 37 |
38 void SkNativeGLContext::destroyGLContext() { | 38 void SkNativeGLContext::destroyGLContext() { |
39 if ([EAGLContext currentContext] == EAGLCTX) { | 39 if (NULL != fEAGLContext) { |
40 [EAGLContext setCurrentContext:nil]; | 40 if ([EAGLContext currentContext] == EAGLCTX) { |
| 41 [EAGLContext setCurrentContext:nil]; |
| 42 } |
| 43 [EAGLCTX release]; |
| 44 fEAGLContext = NULL; |
41 } | 45 } |
42 [EAGLCTX release]; | |
43 } | 46 } |
44 | 47 |
45 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP
I) { | 48 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP
I) { |
46 if (kGL_GrGLStandard == forcedGpuAPI) { | 49 if (kGL_GrGLStandard == forcedGpuAPI) { |
47 return NULL; | 50 return NULL; |
48 } | 51 } |
49 | 52 |
50 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; | 53 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; |
51 [EAGLContext setCurrentContext:EAGLCTX]; | 54 [EAGLContext setCurrentContext:EAGLCTX]; |
52 | 55 |
53 const GrGLInterface* interface = GrGLCreateNativeInterface(); | 56 const GrGLInterface* interface = GrGLCreateNativeInterface(); |
54 if (!interface) { | 57 if (!interface) { |
55 SkDebugf("Failed to create gl interface"); | 58 SkDebugf("Failed to create gl interface"); |
56 this->destroyGLContext(); | 59 this->destroyGLContext(); |
57 return NULL; | 60 return NULL; |
58 } | 61 } |
59 return interface; | 62 return interface; |
60 } | 63 } |
61 | 64 |
62 void SkNativeGLContext::makeCurrent() const { | 65 void SkNativeGLContext::makeCurrent() const { |
63 if (![EAGLContext setCurrentContext:EAGLCTX]) { | 66 if (![EAGLContext setCurrentContext:EAGLCTX]) { |
64 SkDebugf("Could not set the context.\n"); | 67 SkDebugf("Could not set the context.\n"); |
65 } | 68 } |
66 } | 69 } |
67 | 70 |
68 void SkNativeGLContext::swapBuffers() const { } | 71 void SkNativeGLContext::swapBuffers() const { } |
OLD | NEW |