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 |
11 #if SK_ANGLE | 11 #if SK_ANGLE |
12 #include "gl/SkANGLEGLContext.h" | 12 #include "gl/SkANGLEGLContext.h" |
13 #endif | 13 #endif |
14 #include "gl/SkDebugGLContext.h" | 14 #include "gl/SkDebugGLContext.h" |
15 #if SK_MESA | 15 #if SK_MESA |
16 #include "gl/SkMesaGLContext.h" | 16 #include "gl/SkMesaGLContext.h" |
17 #endif | 17 #endif |
18 #include "gl/SkGLContext.h" | 18 #include "gl/SkNativeGLContext.h" |
19 #include "gl/SkNullGLContext.h" | 19 #include "gl/SkNullGLContext.h" |
20 | 20 |
21 #include "GrContext.h" | 21 #include "GrContext.h" |
22 #include "SkTArray.h" | 22 #include "SkTArray.h" |
23 | 23 |
24 /** | 24 /** |
25 * This is a simple class that is useful in test apps that use different | 25 * This is a simple class that is useful in test apps that use different |
26 * GrContexts backed by different types of GL contexts. It manages creating the | 26 * GrContexts backed by different types of GL contexts. It manages creating the |
27 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the | 27 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the |
28 * factory is destroyed (though the caller can always grab a ref on the returned | 28 * factory is destroyed (though the caller can always grab a ref on the returned |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 for (int i = 0; i < fContexts.count(); ++i) { | 123 for (int i = 0; i < fContexts.count(); ++i) { |
124 if (forcedGpuAPI != kNone_GrGLStandard && | 124 if (forcedGpuAPI != kNone_GrGLStandard && |
125 forcedGpuAPI != fContexts[i].fGLContext->gl()->fStandard) | 125 forcedGpuAPI != fContexts[i].fGLContext->gl()->fStandard) |
126 continue; | 126 continue; |
127 | 127 |
128 if (fContexts[i].fType == type) { | 128 if (fContexts[i].fType == type) { |
129 fContexts[i].fGLContext->makeCurrent(); | 129 fContexts[i].fGLContext->makeCurrent(); |
130 return fContexts[i].fGrContext; | 130 return fContexts[i].fGrContext; |
131 } | 131 } |
132 } | 132 } |
133 SkAutoTUnref<SkGLContext> glCtx; | 133 SkAutoTUnref<SkGLContextHelper> glCtx; |
134 SkAutoTUnref<GrContext> grCtx; | 134 SkAutoTUnref<GrContext> grCtx; |
135 switch (type) { | 135 switch (type) { |
136 case kNVPR_GLContextType: // fallthru | 136 case kNVPR_GLContextType: // fallthru |
137 case kNative_GLContextType: | 137 case kNative_GLContextType: |
138 glCtx.reset(SkCreatePlatformGLContext()); | 138 glCtx.reset(SkNEW(SkNativeGLContext)); |
139 break; | 139 break; |
140 #ifdef SK_ANGLE | 140 #ifdef SK_ANGLE |
141 case kANGLE_GLContextType: | 141 case kANGLE_GLContextType: |
142 glCtx.reset(SkNEW(SkANGLEGLContext)); | 142 glCtx.reset(SkNEW(SkANGLEGLContext)); |
143 break; | 143 break; |
144 #endif | 144 #endif |
145 #ifdef SK_MESA | 145 #ifdef SK_MESA |
146 case kMESA_GLContextType: | 146 case kMESA_GLContextType: |
147 glCtx.reset(SkNEW(SkMesaGLContext)); | 147 glCtx.reset(SkNEW(SkMesaGLContext)); |
148 break; | 148 break; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 ctx.fGLContext = glCtx.get(); | 185 ctx.fGLContext = glCtx.get(); |
186 ctx.fGLContext->ref(); | 186 ctx.fGLContext->ref(); |
187 ctx.fGrContext = grCtx.get(); | 187 ctx.fGrContext = grCtx.get(); |
188 ctx.fGrContext->ref(); | 188 ctx.fGrContext->ref(); |
189 ctx.fType = type; | 189 ctx.fType = type; |
190 return ctx.fGrContext; | 190 return ctx.fGrContext; |
191 } | 191 } |
192 | 192 |
193 // Returns the GLContext of the given type. If it has not been created yet, | 193 // Returns the GLContext of the given type. If it has not been created yet, |
194 // NULL is returned instead. | 194 // NULL is returned instead. |
195 SkGLContext* getGLContext(GLContextType type) { | 195 SkGLContextHelper* getGLContext(GLContextType type) { |
196 for (int i = 0; i < fContexts.count(); ++i) { | 196 for (int i = 0; i < fContexts.count(); ++i) { |
197 if (fContexts[i].fType == type) { | 197 if (fContexts[i].fType == type) { |
198 return fContexts[i].fGLContext; | 198 return fContexts[i].fGLContext; |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 return NULL; | 202 return NULL; |
203 } | 203 } |
204 | 204 |
205 const GrContext::Options& getGlobalOptions() const { return fGlobalOptions;
} | 205 const GrContext::Options& getGlobalOptions() const { return fGlobalOptions;
} |
206 | 206 |
207 private: | 207 private: |
208 struct GPUContext { | 208 struct GPUContext { |
209 GLContextType fType; | 209 GLContextType fType; |
210 SkGLContext* fGLContext; | 210 SkGLContextHelper* fGLContext; |
211 GrContext* fGrContext; | 211 GrContext* fGrContext; |
212 }; | 212 }; |
213 SkTArray<GPUContext, true> fContexts; | 213 SkTArray<GPUContext, true> fContexts; |
214 const GrContext::Options fGlobalOptions; | 214 const GrContext::Options fGlobalOptions; |
215 }; | 215 }; |
216 | 216 |
217 #endif | 217 #endif |
OLD | NEW |