| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrContextFactory_DEFINED | 8 #ifndef GrContextFactory_DEFINED |
| 9 #define GrContextFactory_DEFINED | 9 #define GrContextFactory_DEFINED |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 SkFAIL("Unknown GL Context type."); | 87 SkFAIL("Unknown GL Context type."); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 GrContextFactory() { } | 91 GrContextFactory() { } |
| 92 | 92 |
| 93 ~GrContextFactory() { this->destroyContexts(); } | 93 ~GrContextFactory() { this->destroyContexts(); } |
| 94 | 94 |
| 95 void destroyContexts() { | 95 void destroyContexts() { |
| 96 for (int i = 0; i < fContexts.count(); ++i) { | 96 for (int i = 0; i < fContexts.count(); ++i) { |
| 97 fContexts[i].fGLContext->makeCurrent(); | 97 if (NULL != fContexts[i].fGLContext) { // could be abandoned. |
| 98 fContexts[i].fGLContext->makeCurrent(); |
| 99 } |
| 98 fContexts[i].fGrContext->unref(); | 100 fContexts[i].fGrContext->unref(); |
| 99 fContexts[i].fGLContext->unref(); | 101 if (NULL != fContexts[i].fGLContext) { |
| 102 fContexts[i].fGLContext->unref(); |
| 103 } |
| 100 } | 104 } |
| 101 fContexts.reset(); | 105 fContexts.reset(); |
| 102 } | 106 } |
| 103 | 107 |
| 108 void abandonContexts() { |
| 109 for (int i = 0; i < fContexts.count(); ++i) { |
| 110 SkSafeSetNull(fContexts[i].fGLContext); |
| 111 fContexts[i].fGrContext->abandonContext(); |
| 112 } |
| 113 } |
| 114 |
| 104 /** | 115 /** |
| 105 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. | 116 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. |
| 106 */ | 117 */ |
| 107 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta
ndard) { | 118 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta
ndard) { |
| 108 for (int i = 0; i < fContexts.count(); ++i) { | 119 for (int i = 0; i < fContexts.count(); ++i) { |
| 109 if (forcedGpuAPI != kNone_GrGLStandard && | 120 if (forcedGpuAPI != kNone_GrGLStandard && |
| 110 forcedGpuAPI != fContexts[i].fGLContext->gl()->fStandard) | 121 forcedGpuAPI != fContexts[i].fGLContext->gl()->fStandard) |
| 111 continue; | 122 continue; |
| 112 | 123 |
| 113 if (fContexts[i].fType == type) { | 124 if (fContexts[i].fType == type) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 private: | 201 private: |
| 191 struct GPUContext { | 202 struct GPUContext { |
| 192 GLContextType fType; | 203 GLContextType fType; |
| 193 SkGLContextHelper* fGLContext; | 204 SkGLContextHelper* fGLContext; |
| 194 GrContext* fGrContext; | 205 GrContext* fGrContext; |
| 195 }; | 206 }; |
| 196 SkTArray<GPUContext, true> fContexts; | 207 SkTArray<GPUContext, true> fContexts; |
| 197 }; | 208 }; |
| 198 | 209 |
| 199 #endif | 210 #endif |
| OLD | NEW |