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/GLTestContext.h" | 14 #include "gl/GLTestContext.h" |
| 15 #include "vk/VkTestContext.h" |
15 #include "SkTArray.h" | 16 #include "SkTArray.h" |
16 | 17 |
17 struct GrVkBackendContext; | 18 struct GrVkBackendContext; |
18 | 19 |
19 namespace sk_gpu_test { | 20 namespace sk_gpu_test { |
20 | 21 |
21 class ContextInfo { | 22 class ContextInfo { |
22 public: | 23 public: |
| 24 ContextInfo() = default; |
| 25 ContextInfo& operator=(const ContextInfo&) = default; |
| 26 |
| 27 GrBackend backend() const { return fBackend; }; |
| 28 |
23 GrContext* grContext() const { return fGrContext; } | 29 GrContext* grContext() const { return fGrContext; } |
24 GLTestContext* glContext() const { return fGLContext; } | 30 |
| 31 GLTestContext* glContext() const { |
| 32 SkASSERT(kOpenGL_GrBackend == fBackend); |
| 33 return static_cast<GLTestContext*>(fTestContext); |
| 34 } |
| 35 |
| 36 #ifdef SK_VULKAN |
| 37 VkTestContext* vkContext() const { |
| 38 SkASSERT(kVulkan_GrBackend == fBackend); |
| 39 return static_cast<VkTestContext*>(fTestContext); |
| 40 } |
| 41 #endif |
25 | 42 |
26 private: | 43 private: |
27 ContextInfo() | 44 ContextInfo(GrBackend backend, TestContext* testContext, GrContext* grContex
t) |
28 : fGrContext(nullptr), fGLContext(nullptr) { } | 45 : fBackend(backend) |
29 ContextInfo(GrContext* grContext, GLTestContext* glContext) | 46 , fTestContext(testContext) |
30 : fGrContext(grContext), fGLContext(glContext) { } | 47 , fGrContext(grContext) {} |
31 GrContext* fGrContext; | 48 |
32 GLTestContext* fGLContext; //! Valid until the factory destroys it via aband
onContexts() or | 49 GrBackend fBackend = kOpenGL_GrBackend; |
33 //! destroyContexts(). Null if context is not bas
ed on OpenGL. | 50 // Valid until the factory destroys it via abandonContexts() or destroyConte
xts(). |
| 51 TestContext* fTestContext = nullptr; |
| 52 GrContext* fGrContext = nullptr; |
34 | 53 |
35 friend class GrContextFactory; | 54 friend class GrContextFactory; |
36 }; | 55 }; |
37 | 56 |
38 /** | 57 /** |
39 * This is a simple class that is useful in test apps that use different | 58 * This is a simple class that is useful in test apps that use different |
40 * GrContexts backed by different types of GL contexts. It manages creating the | 59 * GrContexts backed by different types of GL contexts. It manages creating the |
41 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the | 60 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the |
42 * factory is destroyed (though the caller can always grab a ref on the returned | 61 * factory is destroyed (though the caller can always grab a ref on the returned |
43 * Gr and GL contexts to make them outlive the factory). | 62 * Gr and GL contexts to make them outlive the factory). |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 146 |
128 /** | 147 /** |
129 * Get a context initialized with a type of GL context. It also makes the GL
context current. | 148 * Get a context initialized with a type of GL context. It also makes the GL
context current. |
130 */ | 149 */ |
131 ContextInfo getContextInfo(ContextType type, | 150 ContextInfo getContextInfo(ContextType type, |
132 ContextOptions options = kNone_ContextOptions); | 151 ContextOptions options = kNone_ContextOptions); |
133 /** | 152 /** |
134 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. | 153 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. |
135 */ | 154 */ |
136 GrContext* get(ContextType type, ContextOptions options = kNone_ContextOptio
ns) { | 155 GrContext* get(ContextType type, ContextOptions options = kNone_ContextOptio
ns) { |
137 return this->getContextInfo(type, options).fGrContext; | 156 return this->getContextInfo(type, options).grContext(); |
138 } | 157 } |
139 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } | 158 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } |
140 | 159 |
141 private: | 160 private: |
142 struct Context { | 161 struct Context { |
143 ContextType fType; | 162 ContextType fType; |
144 ContextOptions fOptions; | 163 ContextOptions fOptions; |
145 GLTestContext* fGLContext; // null if non-GL | 164 GrBackend fBackend; |
| 165 TestContext* fTestContext; |
146 GrContext* fGrContext; | 166 GrContext* fGrContext; |
147 bool fAbandoned; | 167 bool fAbandoned; |
148 }; | 168 }; |
149 SkTArray<Context, true> fContexts; | 169 SkTArray<Context, true> fContexts; |
150 SkAutoTDelete<GLTestContext> fSentinelGLContext; | 170 SkAutoTDelete<GLTestContext> fSentinelGLContext; |
151 const GrContextOptions fGlobalOptions; | 171 const GrContextOptions fGlobalOptions; |
152 }; | 172 }; |
153 } // namespace sk_gpu_test | 173 } // namespace sk_gpu_test |
154 #endif | 174 #endif |
OLD | NEW |