| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 #endif | 81 #endif |
| 82 case kNVPR_GLContextType: | 82 case kNVPR_GLContextType: |
| 83 return "nvpr"; | 83 return "nvpr"; |
| 84 case kDebug_GLContextType: | 84 case kDebug_GLContextType: |
| 85 return "debug"; | 85 return "debug"; |
| 86 default: | 86 default: |
| 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 |
| 93 ~GrContextFactory() { this->destroyContexts(); } | 94 ~GrContextFactory() { this->destroyContexts(); } |
| 94 | 95 |
| 95 void destroyContexts() { | 96 void destroyContexts() { |
| 96 for (int i = 0; i < fContexts.count(); ++i) { | 97 for (int i = 0; i < fContexts.count(); ++i) { |
| 97 fContexts[i].fGLContext->makeCurrent(); | 98 fContexts[i].fGLContext->makeCurrent(); |
| 98 fContexts[i].fGrContext->unref(); | 99 fContexts[i].fGrContext->unref(); |
| 99 fContexts[i].fGLContext->unref(); | 100 fContexts[i].fGLContext->unref(); |
| 100 } | 101 } |
| 101 fContexts.reset(); | 102 fContexts.reset(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 /** | 105 /** |
| 105 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. | 106 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. |
| 106 */ | 107 */ |
| 107 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta
ndard) { | 108 GrContext* get(GLContextType type) { |
| 109 |
| 108 for (int i = 0; i < fContexts.count(); ++i) { | 110 for (int i = 0; i < fContexts.count(); ++i) { |
| 109 if (forcedGpuAPI != kNone_GrGLStandard && | |
| 110 forcedGpuAPI != fContexts[i].fGLContext->gl()->fStandard) | |
| 111 continue; | |
| 112 | |
| 113 if (fContexts[i].fType == type) { | 111 if (fContexts[i].fType == type) { |
| 114 fContexts[i].fGLContext->makeCurrent(); | 112 fContexts[i].fGLContext->makeCurrent(); |
| 115 return fContexts[i].fGrContext; | 113 return fContexts[i].fGrContext; |
| 116 } | 114 } |
| 117 } | 115 } |
| 118 SkAutoTUnref<SkGLContextHelper> glCtx; | 116 SkAutoTUnref<SkGLContextHelper> glCtx; |
| 119 SkAutoTUnref<GrContext> grCtx; | 117 SkAutoTUnref<GrContext> grCtx; |
| 120 switch (type) { | 118 switch (type) { |
| 121 case kNVPR_GLContextType: // fallthru | 119 case kNVPR_GLContextType: // fallthru |
| 122 case kNative_GLContextType: | 120 case kNative_GLContextType: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 136 glCtx.reset(SkNEW(SkNullGLContext)); | 134 glCtx.reset(SkNEW(SkNullGLContext)); |
| 137 break; | 135 break; |
| 138 case kDebug_GLContextType: | 136 case kDebug_GLContextType: |
| 139 glCtx.reset(SkNEW(SkDebugGLContext)); | 137 glCtx.reset(SkNEW(SkDebugGLContext)); |
| 140 break; | 138 break; |
| 141 } | 139 } |
| 142 static const int kBogusSize = 1; | 140 static const int kBogusSize = 1; |
| 143 if (!glCtx.get()) { | 141 if (!glCtx.get()) { |
| 144 return NULL; | 142 return NULL; |
| 145 } | 143 } |
| 146 if (!glCtx.get()->init(forcedGpuAPI, kBogusSize, kBogusSize)) { | 144 if (!glCtx.get()->init(kBogusSize, kBogusSize)) { |
| 147 return NULL; | 145 return NULL; |
| 148 } | 146 } |
| 149 | 147 |
| 150 // Ensure NVPR is available for the NVPR type and block it from other ty
pes. | 148 // Ensure NVPR is available for the NVPR type and block it from other ty
pes. |
| 151 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx.get()->gl())); | 149 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx.get()->gl())); |
| 152 if (kNVPR_GLContextType == type) { | 150 if (kNVPR_GLContextType == type) { |
| 153 if (!glInterface->hasExtension("GL_NV_path_rendering")) { | 151 if (!glInterface->hasExtension("GL_NV_path_rendering")) { |
| 154 return NULL; | 152 return NULL; |
| 155 } | 153 } |
| 156 } else { | 154 } else { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 private: | 188 private: |
| 191 struct GPUContext { | 189 struct GPUContext { |
| 192 GLContextType fType; | 190 GLContextType fType; |
| 193 SkGLContextHelper* fGLContext; | 191 SkGLContextHelper* fGLContext; |
| 194 GrContext* fGrContext; | 192 GrContext* fGrContext; |
| 195 }; | 193 }; |
| 196 SkTArray<GPUContext, true> fContexts; | 194 SkTArray<GPUContext, true> fContexts; |
| 197 }; | 195 }; |
| 198 | 196 |
| 199 #endif | 197 #endif |
| OLD | NEW |