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 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrContextOptions.h" |
12 | 13 |
13 #include "gl/SkGLContext.h" | 14 #include "gl/SkGLContext.h" |
14 #include "SkTArray.h" | 15 #include "SkTArray.h" |
15 | 16 |
16 /** | 17 /** |
17 * This is a simple class that is useful in test apps that use different | 18 * This is a simple class that is useful in test apps that use different |
18 * GrContexts backed by different types of GL contexts. It manages creating the | 19 * GrContexts backed by different types of GL contexts. It manages creating the |
19 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the | 20 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the |
20 * factory is destroyed (though the caller can always grab a ref on the returned | 21 * factory is destroyed (though the caller can always grab a ref on the returned |
21 * Gr and GL contexts to make them outlive the factory). | 22 * Gr and GL contexts to make them outlive the factory). |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 #endif | 74 #endif |
74 case kNVPR_GLContextType: | 75 case kNVPR_GLContextType: |
75 return "nvpr"; | 76 return "nvpr"; |
76 case kDebug_GLContextType: | 77 case kDebug_GLContextType: |
77 return "debug"; | 78 return "debug"; |
78 default: | 79 default: |
79 SkFAIL("Unknown GL Context type."); | 80 SkFAIL("Unknown GL Context type."); |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 explicit GrContextFactory(const GrContext::Options& opts) : fGlobalOptions(o
pts) { } | 84 explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt
s) { } |
84 GrContextFactory() { } | 85 GrContextFactory() { } |
85 | 86 |
86 ~GrContextFactory() { this->destroyContexts(); } | 87 ~GrContextFactory() { this->destroyContexts(); } |
87 | 88 |
88 void destroyContexts() { | 89 void destroyContexts() { |
89 for (int i = 0; i < fContexts.count(); ++i) { | 90 for (int i = 0; i < fContexts.count(); ++i) { |
90 if (fContexts[i].fGLContext) { // could be abandoned. | 91 if (fContexts[i].fGLContext) { // could be abandoned. |
91 fContexts[i].fGLContext->makeCurrent(); | 92 fContexts[i].fGLContext->makeCurrent(); |
92 } | 93 } |
93 fContexts[i].fGrContext->unref(); | 94 fContexts[i].fGrContext->unref(); |
(...skipping 25 matching lines...) Expand all Loading... |
119 SkGLContext* getGLContext(GLContextType type) { | 120 SkGLContext* getGLContext(GLContextType type) { |
120 for (int i = 0; i < fContexts.count(); ++i) { | 121 for (int i = 0; i < fContexts.count(); ++i) { |
121 if (fContexts[i].fType == type) { | 122 if (fContexts[i].fType == type) { |
122 return fContexts[i].fGLContext; | 123 return fContexts[i].fGLContext; |
123 } | 124 } |
124 } | 125 } |
125 | 126 |
126 return NULL; | 127 return NULL; |
127 } | 128 } |
128 | 129 |
129 const GrContext::Options& getGlobalOptions() const { return fGlobalOptions;
} | 130 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } |
130 | 131 |
131 private: | 132 private: |
132 struct GPUContext { | 133 struct GPUContext { |
133 GLContextType fType; | 134 GLContextType fType; |
134 SkGLContext* fGLContext; | 135 SkGLContext* fGLContext; |
135 GrContext* fGrContext; | 136 GrContext* fGrContext; |
136 }; | 137 }; |
137 SkTArray<GPUContext, true> fContexts; | 138 SkTArray<GPUContext, true> fContexts; |
138 const GrContext::Options fGlobalOptions; | 139 const GrContextOptions fGlobalOptions; |
139 }; | 140 }; |
140 | 141 |
141 #endif | 142 #endif |
OLD | NEW |