OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrContextFactory.h" | 9 #include "GrContextFactory.h" |
10 #include "gl/GLTestContext.h" | 10 #include "gl/GLTestContext.h" |
11 | 11 |
12 #if SK_ANGLE | 12 #if SK_ANGLE |
13 #include "gl/angle/GLTestContext_angle.h" | 13 #include "gl/angle/GLTestContext_angle.h" |
14 #endif | 14 #endif |
15 #if SK_COMMAND_BUFFER | 15 #if SK_COMMAND_BUFFER |
16 #include "gl/command_buffer/GLTestContext_command_buffer.h" | 16 #include "gl/command_buffer/GLTestContext_command_buffer.h" |
17 #endif | 17 #endif |
18 #include "gl/debug/DebugGLTestContext.h" | 18 #include "gl/debug/DebugGLTestContext.h" |
19 #if SK_MESA | 19 #if SK_MESA |
20 #include "gl/mesa/GLTestContext_mesa.h" | 20 #include "gl/mesa/GLTestContext_mesa.h" |
21 #endif | 21 #endif |
22 #if SK_VULKAN | 22 #if SK_VULKAN |
23 #include "vk/GrVkBackendContext.h" | 23 #include "vk/VkTestContext.h" |
24 #endif | 24 #endif |
25 #include "gl/null/NullGLTestContext.h" | 25 #include "gl/null/NullGLTestContext.h" |
26 #include "gl/GrGLGpu.h" | 26 #include "gl/GrGLGpu.h" |
27 #include "GrCaps.h" | 27 #include "GrCaps.h" |
28 | 28 |
29 namespace sk_gpu_test { | 29 namespace sk_gpu_test { |
30 GrContextFactory::GrContextFactory() { } | 30 GrContextFactory::GrContextFactory() { } |
31 | 31 |
32 GrContextFactory::GrContextFactory(const GrContextOptions& opts) | 32 GrContextFactory::GrContextFactory(const GrContextOptions& opts) |
33 : fGlobalOptions(opts) { | 33 : fGlobalOptions(opts) { |
34 } | 34 } |
35 | 35 |
36 GrContextFactory::~GrContextFactory() { | 36 GrContextFactory::~GrContextFactory() { |
37 this->destroyContexts(); | 37 this->destroyContexts(); |
38 } | 38 } |
39 | 39 |
40 void GrContextFactory::destroyContexts() { | 40 void GrContextFactory::destroyContexts() { |
41 for (Context& context : fContexts) { | 41 for (Context& context : fContexts) { |
42 if (context.fGLContext) { | 42 if (context.fTestContext) { |
43 context.fGLContext->makeCurrent(); | 43 context.fTestContext->makeCurrent(); |
44 } | 44 } |
45 if (!context.fGrContext->unique()) { | 45 if (!context.fGrContext->unique()) { |
46 context.fGrContext->releaseResourcesAndAbandonContext(); | 46 context.fGrContext->releaseResourcesAndAbandonContext(); |
47 context.fAbandoned = true; | 47 context.fAbandoned = true; |
48 } | 48 } |
49 context.fGrContext->unref(); | 49 context.fGrContext->unref(); |
50 delete context.fGLContext; | 50 delete context.fTestContext; |
51 } | 51 } |
52 fContexts.reset(); | 52 fContexts.reset(); |
53 } | 53 } |
54 | 54 |
55 void GrContextFactory::abandonContexts() { | 55 void GrContextFactory::abandonContexts() { |
56 for (Context& context : fContexts) { | 56 for (Context& context : fContexts) { |
57 if (!context.fAbandoned) { | 57 if (!context.fAbandoned) { |
58 if (context.fGLContext) { | 58 if (context.fTestContext) { |
59 context.fGLContext->makeCurrent(); | 59 context.fTestContext->makeCurrent(); |
60 context.fGLContext->testAbandon(); | 60 context.fTestContext->testAbandon(); |
61 delete(context.fGLContext); | 61 delete(context.fTestContext); |
62 context.fGLContext = nullptr; | 62 context.fTestContext = nullptr; |
63 } | 63 } |
64 context.fGrContext->abandonContext(); | 64 context.fGrContext->abandonContext(); |
65 context.fAbandoned = true; | 65 context.fAbandoned = true; |
66 } | 66 } |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 void GrContextFactory::releaseResourcesAndAbandonContexts() { | 70 void GrContextFactory::releaseResourcesAndAbandonContexts() { |
71 for (Context& context : fContexts) { | 71 for (Context& context : fContexts) { |
72 if (!context.fAbandoned) { | 72 if (!context.fAbandoned) { |
73 if (context.fGLContext) { | 73 if (context.fTestContext) { |
74 context.fGLContext->makeCurrent(); | 74 context.fTestContext->makeCurrent(); |
75 } | 75 } |
76 context.fGrContext->releaseResourcesAndAbandonContext(); | 76 context.fGrContext->releaseResourcesAndAbandonContext(); |
77 context.fAbandoned = true; | 77 context.fAbandoned = true; |
78 if (context.fGLContext) { | 78 if (context.fTestContext) { |
79 delete context.fGLContext; | 79 delete context.fTestContext; |
80 context.fGLContext = nullptr; | 80 context.fTestContext = nullptr; |
81 } | 81 } |
82 } | 82 } |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_
FOR_MAC) | 86 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_
FOR_MAC) |
87 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = | 87 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = |
88 GrContextFactory::kGL_ContextType; | 88 GrContextFactory::kGL_ContextType; |
89 #else | 89 #else |
90 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = | 90 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = |
91 GrContextFactory::kGLES_ContextType; | 91 GrContextFactory::kGLES_ContextType; |
92 #endif | 92 #endif |
93 | 93 |
94 ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
tions) { | 94 ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
tions) { |
95 for (int i = 0; i < fContexts.count(); ++i) { | 95 for (int i = 0; i < fContexts.count(); ++i) { |
96 Context& context = fContexts[i]; | 96 Context& context = fContexts[i]; |
97 if (context.fType == type && | 97 if (context.fType == type && |
98 context.fOptions == options && | 98 context.fOptions == options && |
99 !context.fAbandoned) { | 99 !context.fAbandoned) { |
100 if (context.fGLContext) { | 100 context.fTestContext->makeCurrent(); |
101 context.fGLContext->makeCurrent(); | 101 return ContextInfo(context.fBackend, context.fTestContext, context.f
GrContext); |
102 } | |
103 return ContextInfo(context.fGrContext, context.fGLContext); | |
104 } | 102 } |
105 } | 103 } |
106 SkAutoTDelete<GLTestContext> glCtx; | 104 SkAutoTDelete<TestContext> testCtx; |
107 sk_sp<GrContext> grCtx; | 105 sk_sp<GrContext> grCtx; |
108 GrBackendContext backendContext = 0; | 106 GrBackendContext backendContext = 0; |
109 sk_sp<const GrGLInterface> glInterface; | 107 sk_sp<const GrGLInterface> glInterface; |
110 #ifdef SK_VULKAN | |
111 sk_sp<const GrVkBackendContext> vkBackend; | |
112 #endif | |
113 GrBackend backend = ContextTypeBackend(type); | 108 GrBackend backend = ContextTypeBackend(type); |
114 switch (backend) { | 109 switch (backend) { |
115 case kOpenGL_GrBackend: | 110 case kOpenGL_GrBackend: { |
| 111 GLTestContext* glCtx; |
116 switch (type) { | 112 switch (type) { |
117 case kGL_ContextType: | 113 case kGL_ContextType: |
118 glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); | 114 glCtx = CreatePlatformGLTestContext(kGL_GrGLStandard); |
119 break; | 115 break; |
120 case kGLES_ContextType: | 116 case kGLES_ContextType: |
121 glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard))
; | 117 glCtx = CreatePlatformGLTestContext(kGLES_GrGLStandard); |
122 break; | 118 break; |
123 #if SK_ANGLE | 119 #if SK_ANGLE |
124 # ifdef SK_BUILD_FOR_WIN | 120 # ifdef SK_BUILD_FOR_WIN |
125 case kANGLE_ContextType: | 121 case kANGLE_ContextType: |
126 glCtx.reset(CreateANGLEDirect3DGLTestContext()); | 122 glCtx = CreateANGLEDirect3DGLTestContext(); |
127 break; | 123 break; |
128 # endif | 124 # endif |
129 case kANGLE_GL_ContextType: | 125 case kANGLE_GL_ContextType: |
130 glCtx.reset(CreateANGLEOpenGLGLTestContext()); | 126 glCtx = CreateANGLEOpenGLGLTestContext(); |
131 break; | 127 break; |
132 #endif | 128 #endif |
133 #if SK_COMMAND_BUFFER | 129 #if SK_COMMAND_BUFFER |
134 case kCommandBuffer_ContextType: | 130 case kCommandBuffer_ContextType: |
135 glCtx.reset(CommandBufferGLTestContext::Create()); | 131 glCtx = CommandBufferGLTestContext::Create(); |
136 break; | 132 break; |
137 #endif | 133 #endif |
138 #if SK_MESA | 134 #if SK_MESA |
139 case kMESA_ContextType: | 135 case kMESA_ContextType: |
140 glCtx.reset(CreateMesaGLTestContext()); | 136 glCtx = CreateMesaGLTestContext(); |
141 break; | 137 break; |
142 #endif | 138 #endif |
143 case kNullGL_ContextType: | 139 case kNullGL_ContextType: |
144 glCtx.reset(CreateNullGLTestContext(kEnableNVPR_ContextOptio
ns & options)); | 140 glCtx = CreateNullGLTestContext(kEnableNVPR_ContextOptions &
options); |
145 break; | 141 break; |
146 case kDebugGL_ContextType: | 142 case kDebugGL_ContextType: |
147 glCtx.reset(CreateDebugGLTestContext()); | 143 glCtx = CreateDebugGLTestContext(); |
148 break; | 144 break; |
149 default: | 145 default: |
150 return ContextInfo(); | 146 return ContextInfo(); |
151 } | 147 } |
152 if (nullptr == glCtx.get()) { | 148 if (!glCtx) { |
153 return ContextInfo(); | 149 return ContextInfo(); |
154 } | 150 } |
| 151 testCtx.reset(glCtx); |
155 glInterface.reset(SkRef(glCtx->gl())); | 152 glInterface.reset(SkRef(glCtx->gl())); |
156 // Block NVPR from non-NVPR types. | 153 // Block NVPR from non-NVPR types. |
157 if (!(kEnableNVPR_ContextOptions & options)) { | 154 if (!(kEnableNVPR_ContextOptions & options)) { |
158 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface.get())); | 155 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface.get())); |
159 if (!glInterface) { | 156 if (!glInterface) { |
160 return ContextInfo(); | 157 return ContextInfo(); |
161 } | 158 } |
162 } | 159 } |
163 backendContext = reinterpret_cast<GrBackendContext>(glInterface.get(
)); | 160 backendContext = reinterpret_cast<GrBackendContext>(glInterface.get(
)); |
164 glCtx->makeCurrent(); | |
165 break; | 161 break; |
| 162 } |
166 #ifdef SK_VULKAN | 163 #ifdef SK_VULKAN |
167 case kVulkan_GrBackend: | 164 case kVulkan_GrBackend: |
168 SkASSERT(kVulkan_ContextType == type); | 165 SkASSERT(kVulkan_ContextType == type); |
169 if ((kEnableNVPR_ContextOptions & options) || | 166 if ((kEnableNVPR_ContextOptions & options) || |
170 (kRequireSRGBSupport_ContextOptions & options)) { | 167 (kRequireSRGBSupport_ContextOptions & options)) { |
171 return ContextInfo(); | 168 return ContextInfo(); |
172 } | 169 } |
173 vkBackend.reset(GrVkBackendContext::Create()); | 170 testCtx.reset(CreatePlatformVkTestContext()); |
174 if (!vkBackend) { | 171 if (!testCtx) { |
175 return ContextInfo(); | 172 return ContextInfo(); |
176 } | 173 } |
177 backendContext = reinterpret_cast<GrBackendContext>(vkBackend.get())
; | 174 |
178 // There is some bug (either in Skia or the NV Vulkan driver) where
VkDevice | 175 // There is some bug (either in Skia or the NV Vulkan driver) where
VkDevice |
179 // destruction will hang occaisonally. For some reason having an exi
sting GL | 176 // destruction will hang occaisonally. For some reason having an exi
sting GL |
180 // context fixes this. | 177 // context fixes this. |
181 if (!fSentinelGLContext) { | 178 if (!fSentinelGLContext) { |
182 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLSta
ndard)); | 179 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLSta
ndard)); |
183 if (!fSentinelGLContext) { | 180 if (!fSentinelGLContext) { |
184 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_G
rGLStandard)); | 181 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_G
rGLStandard)); |
185 } | 182 } |
186 } | 183 } |
| 184 backendContext = testCtx->backendContext(); |
187 break; | 185 break; |
188 #endif | 186 #endif |
189 default: | 187 default: |
190 return ContextInfo(); | 188 return ContextInfo(); |
191 } | 189 } |
192 | 190 testCtx->makeCurrent(); |
| 191 SkASSERT(testCtx && testCtx->backend() == backend); |
193 grCtx.reset(GrContext::Create(backend, backendContext, fGlobalOptions)); | 192 grCtx.reset(GrContext::Create(backend, backendContext, fGlobalOptions)); |
194 if (!grCtx.get()) { | 193 if (!grCtx.get()) { |
195 return ContextInfo(); | 194 return ContextInfo(); |
196 } | 195 } |
197 if (kEnableNVPR_ContextOptions & options) { | 196 if (kEnableNVPR_ContextOptions & options) { |
198 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { | 197 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { |
199 return ContextInfo(); | 198 return ContextInfo(); |
200 } | 199 } |
201 } | 200 } |
202 if (kRequireSRGBSupport_ContextOptions & options) { | 201 if (kRequireSRGBSupport_ContextOptions & options) { |
203 if (!grCtx->caps()->srgbSupport()) { | 202 if (!grCtx->caps()->srgbSupport()) { |
204 return ContextInfo(); | 203 return ContextInfo(); |
205 } | 204 } |
206 } | 205 } |
207 | 206 |
208 Context& context = fContexts.push_back(); | 207 Context& context = fContexts.push_back(); |
209 context.fGLContext = glCtx.release(); | 208 context.fBackend = backend; |
| 209 context.fTestContext = testCtx.release(); |
210 context.fGrContext = SkRef(grCtx.get()); | 210 context.fGrContext = SkRef(grCtx.get()); |
211 context.fType = type; | 211 context.fType = type; |
212 context.fOptions = options; | 212 context.fOptions = options; |
213 context.fAbandoned = false; | 213 context.fAbandoned = false; |
214 return ContextInfo(context.fGrContext, context.fGLContext); | 214 return ContextInfo(context.fBackend, context.fTestContext, context.fGrContex
t); |
215 } | 215 } |
216 } // namespace sk_gpu_test | 216 } // namespace sk_gpu_test |
OLD | NEW |