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 #include "GrContextOptions.h" |
13 | 13 |
14 #include "gl/SkGLContext.h" | 14 #include "gl/SkGLContext.h" |
15 #include "SkTArray.h" | 15 #include "SkTArray.h" |
16 | 16 |
17 /** | 17 /** |
18 * 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 |
19 * 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 |
20 * 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 |
21 * 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 |
22 * Gr and GL contexts to make them outlive the factory). | 22 * Gr and GL contexts to make them outlive the factory). |
23 */ | 23 */ |
24 class GrContextFactory : SkNoncopyable { | 24 class GrContextFactory : SkNoncopyable { |
25 public: | 25 public: |
26 enum GLContextType { | 26 enum GLContextType { |
27 kNative_GLContextType, | 27 kNative_GLContextType, //! OpenGL or OpenGL ES context. |
| 28 kGL_GLContextType, //! OpenGL context. |
| 29 kGLES_GLContextType, //! OpenGL ES context. |
28 #if SK_ANGLE | 30 #if SK_ANGLE |
29 kANGLE_GLContextType, | 31 kANGLE_GLContextType, //! ANGLE on DirectX OpenGL ES context. |
30 kANGLE_GL_GLContextType, | 32 kANGLE_GL_GLContextType, //! ANGLE on OpenGL OpenGL ES context. |
31 #endif | 33 #endif |
32 #if SK_COMMAND_BUFFER | 34 #if SK_COMMAND_BUFFER |
33 kCommandBuffer_GLContextType, | 35 kCommandBuffer_GLContextType, //! Chromium command buffer OpenGL ES cont
ext. |
34 #endif | 36 #endif |
35 #if SK_MESA | 37 #if SK_MESA |
36 kMESA_GLContextType, | 38 kMESA_GLContextType, //! MESA OpenGL context |
37 #endif | 39 #endif |
38 kNull_GLContextType, | 40 kNull_GLContextType, //! Non-rendering OpenGL mock context. |
39 kDebug_GLContextType, | 41 kDebug_GLContextType, //! Non-rendering, state verifying OpenGL context. |
40 kLastGLContextType = kDebug_GLContextType | 42 kLastGLContextType = kDebug_GLContextType |
41 }; | 43 }; |
42 | 44 |
43 static const int kGLContextTypeCnt = kLastGLContextType + 1; | 45 static const int kGLContextTypeCnt = kLastGLContextType + 1; |
44 | 46 |
45 /** | 47 /** |
46 * Options for GL context creation. For historical and testing reasons the o
ptions will default | 48 * Options for GL context creation. For historical and testing reasons the o
ptions will default |
47 * to not using GL_NV_path_rendering extension even when the driver support
s it. | 49 * to not using GL_NV_path_rendering extension even when the driver support
s it. |
48 */ | 50 */ |
49 enum GLContextOptions { | 51 enum GLContextOptions { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 struct ContextInfo { | 119 struct ContextInfo { |
118 GLContextType fType; | 120 GLContextType fType; |
119 GLContextOptions fOptions; | 121 GLContextOptions fOptions; |
120 SkGLContext* fGLContext; | 122 SkGLContext* fGLContext; |
121 GrContext* fGrContext; | 123 GrContext* fGrContext; |
122 }; | 124 }; |
123 /** | 125 /** |
124 * Get a context initialized with a type of GL context. It also makes the GL
context current. | 126 * Get a context initialized with a type of GL context. It also makes the GL
context current. |
125 * Pointer is valid until destroyContexts() is called. | 127 * Pointer is valid until destroyContexts() is called. |
126 */ | 128 */ |
127 ContextInfo* getContextInfo(GLContextType type, GrGLStandard forcedGpuAPI =
kNone_GrGLStandard, GLContextOptions options = kNone_GLContextOptions); | 129 ContextInfo* getContextInfo(GLContextType type, GLContextOptions options = k
None_GLContextOptions); |
128 | 130 |
129 /** | 131 /** |
130 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. | 132 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. |
131 */ | 133 */ |
132 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta
ndard, | 134 GrContext* get(GLContextType type, GLContextOptions options = kNone_GLContex
tOptions) { |
133 GLContextOptions options = kNone_GLContextOptions) { | 135 if (ContextInfo* info = this->getContextInfo(type, options)) { |
134 if (ContextInfo* info = this->getContextInfo(type, forcedGpuAPI, options
)) { | |
135 return info->fGrContext; | 136 return info->fGrContext; |
136 } | 137 } |
137 return nullptr; | 138 return nullptr; |
138 } | 139 } |
139 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } | 140 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } |
140 | 141 |
141 private: | 142 private: |
142 SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts; | 143 SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts; |
143 const GrContextOptions fGlobalOptions; | 144 const GrContextOptions fGlobalOptions; |
144 }; | 145 }; |
145 | 146 |
146 #endif | 147 #endif |
OLD | NEW |