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