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" |
(...skipping 25 matching lines...) Expand all Loading... |
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.fGLContext) { |
43 context.fGLContext->makeCurrent(); | 43 context.fGLContext->makeCurrent(); |
44 } | 44 } |
45 if (!context.fGrContext->unique()) { | 45 if (!context.fGrContext->unique()) { |
46 context.fGrContext->abandonContext(); | 46 context.fGrContext->releaseResourcesAndAbandonContext(); |
| 47 context.fAbandoned = true; |
47 } | 48 } |
48 context.fGrContext->unref(); | 49 context.fGrContext->unref(); |
49 delete(context.fGLContext); | 50 delete context.fGLContext; |
50 } | 51 } |
51 fContexts.reset(); | 52 fContexts.reset(); |
52 } | 53 } |
53 | 54 |
54 void GrContextFactory::abandonContexts() { | 55 void GrContextFactory::abandonContexts() { |
55 for (Context& context : fContexts) { | 56 for (Context& context : fContexts) { |
56 if (context.fGLContext) { | 57 if (!context.fAbandoned) { |
57 context.fGLContext->makeCurrent(); | 58 if (context.fGLContext) { |
58 context.fGLContext->testAbandon(); | 59 context.fGLContext->makeCurrent(); |
59 delete(context.fGLContext); | 60 context.fGLContext->testAbandon(); |
60 context.fGLContext = nullptr; | 61 delete(context.fGLContext); |
| 62 context.fGLContext = nullptr; |
| 63 } |
| 64 context.fGrContext->abandonContext(); |
| 65 context.fAbandoned = true; |
61 } | 66 } |
62 context.fGrContext->abandonContext(); | |
63 } | 67 } |
64 } | 68 } |
65 | 69 |
66 void GrContextFactory::releaseResourcesAndAbandonContexts() { | 70 void GrContextFactory::releaseResourcesAndAbandonContexts() { |
67 for (Context& context : fContexts) { | 71 for (Context& context : fContexts) { |
68 if (context.fGLContext) { | 72 if (!context.fAbandoned) { |
69 context.fGLContext->makeCurrent(); | 73 if (context.fGLContext) { |
| 74 context.fGLContext->makeCurrent(); |
| 75 } |
70 context.fGrContext->releaseResourcesAndAbandonContext(); | 76 context.fGrContext->releaseResourcesAndAbandonContext(); |
71 delete(context.fGLContext); | 77 context.fAbandoned = true; |
72 context.fGLContext = nullptr; | 78 if (context.fGLContext) { |
| 79 delete context.fGLContext; |
| 80 context.fGLContext = nullptr; |
| 81 } |
73 } | 82 } |
74 } | 83 } |
75 } | 84 } |
76 | 85 |
77 #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) |
78 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = | 87 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = |
79 GrContextFactory::kGL_ContextType; | 88 GrContextFactory::kGL_ContextType; |
80 #else | 89 #else |
81 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = | 90 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = |
82 GrContextFactory::kGLES_ContextType; | 91 GrContextFactory::kGLES_ContextType; |
83 #endif | 92 #endif |
84 | 93 |
85 ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
tions) { | 94 ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
tions) { |
86 for (int i = 0; i < fContexts.count(); ++i) { | 95 for (int i = 0; i < fContexts.count(); ++i) { |
87 Context& context = fContexts[i]; | 96 Context& context = fContexts[i]; |
88 if (!context.fGLContext) { | |
89 continue; | |
90 } | |
91 if (context.fType == type && | 97 if (context.fType == type && |
92 context.fOptions == options) { | 98 context.fOptions == options && |
93 context.fGLContext->makeCurrent(); | 99 !context.fAbandoned) { |
| 100 if (context.fGLContext) { |
| 101 context.fGLContext->makeCurrent(); |
| 102 } |
94 return ContextInfo(context.fGrContext, context.fGLContext); | 103 return ContextInfo(context.fGrContext, context.fGLContext); |
95 } | 104 } |
96 } | 105 } |
97 SkAutoTDelete<GLTestContext> glCtx; | 106 SkAutoTDelete<GLTestContext> glCtx; |
98 SkAutoTUnref<GrContext> grCtx; | 107 sk_sp<GrContext> grCtx; |
99 switch (type) { | 108 GrBackendContext backendContext = 0; |
100 case kGL_ContextType: | 109 sk_sp<const GrGLInterface> glInterface; |
101 glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); | 110 #ifdef SK_VULKAN |
| 111 sk_sp<const GrVkBackendContext> vkBackend; |
| 112 #endif |
| 113 GrBackend backend = ContextTypeBackend(type); |
| 114 switch (backend) { |
| 115 case kOpenGL_GrBackend: |
| 116 switch (type) { |
| 117 case kGL_ContextType: |
| 118 glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); |
| 119 break; |
| 120 case kGLES_ContextType: |
| 121 glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard))
; |
| 122 break; |
| 123 #if SK_ANGLE |
| 124 # ifdef SK_BUILD_FOR_WIN |
| 125 case kANGLE_ContextType: |
| 126 glCtx.reset(CreateANGLEDirect3DGLTestContext()); |
| 127 break; |
| 128 # endif |
| 129 case kANGLE_GL_ContextType: |
| 130 glCtx.reset(CreateANGLEOpenGLGLTestContext()); |
| 131 break; |
| 132 #endif |
| 133 #if SK_COMMAND_BUFFER |
| 134 case kCommandBuffer_ContextType: |
| 135 glCtx.reset(CommandBufferGLTestContext::Create()); |
| 136 break; |
| 137 #endif |
| 138 #if SK_MESA |
| 139 case kMESA_ContextType: |
| 140 glCtx.reset(CreateMesaGLTestContext()); |
| 141 break; |
| 142 #endif |
| 143 case kNullGL_ContextType: |
| 144 glCtx.reset(CreateNullGLTestContext()); |
| 145 break; |
| 146 case kDebugGL_ContextType: |
| 147 glCtx.reset(CreateDebugGLTestContext()); |
| 148 break; |
| 149 default: |
| 150 return ContextInfo(); |
| 151 } |
| 152 if (nullptr == glCtx.get()) { |
| 153 return ContextInfo(); |
| 154 } |
| 155 glInterface.reset(SkRef(glCtx->gl())); |
| 156 // Block NVPR from non-NVPR types. |
| 157 if (!(kEnableNVPR_ContextOptions & options)) { |
| 158 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface.get())); |
| 159 if (!glInterface) { |
| 160 return ContextInfo(); |
| 161 } |
| 162 } |
| 163 backendContext = reinterpret_cast<GrBackendContext>(glInterface.get(
)); |
| 164 glCtx->makeCurrent(); |
102 break; | 165 break; |
103 case kGLES_ContextType: | 166 #ifdef SK_VULKAN |
104 glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); | 167 case kVulkan_GrBackend: |
105 break; | 168 SkASSERT(kVulkan_ContextType == type); |
106 #if SK_ANGLE | 169 if ((kEnableNVPR_ContextOptions & options) || |
107 #ifdef SK_BUILD_FOR_WIN | 170 (kRequireSRGBSupport_ContextOptions & options)) { |
108 case kANGLE_ContextType: | 171 return ContextInfo(); |
109 glCtx.reset(CreateANGLEDirect3DGLTestContext()); | 172 } |
| 173 vkBackend.reset(GrVkBackendContext::Create()); |
| 174 if (!vkBackend) { |
| 175 return ContextInfo(); |
| 176 } |
| 177 backendContext = reinterpret_cast<GrBackendContext>(vkBackend.get())
; |
| 178 // 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 |
| 180 // context fixes this. |
| 181 if (!fSentinelGLContext) { |
| 182 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLSta
ndard)); |
| 183 if (!fSentinelGLContext) { |
| 184 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_G
rGLStandard)); |
| 185 } |
| 186 } |
110 break; | 187 break; |
111 #endif | 188 #endif |
112 case kANGLE_GL_ContextType: | 189 default: |
113 glCtx.reset(CreateANGLEOpenGLGLTestContext()); | 190 return ContextInfo(); |
114 break; | |
115 #endif | |
116 #if SK_COMMAND_BUFFER | |
117 case kCommandBuffer_ContextType: | |
118 glCtx.reset(CommandBufferGLTestContext::Create()); | |
119 break; | |
120 #endif | |
121 #if SK_MESA | |
122 case kMESA_ContextType: | |
123 glCtx.reset(CreateMesaGLTestContext()); | |
124 break; | |
125 #endif | |
126 case kNullGL_ContextType: | |
127 glCtx.reset(CreateNullGLTestContext()); | |
128 break; | |
129 case kDebugGL_ContextType: | |
130 glCtx.reset(CreateDebugGLTestContext()); | |
131 break; | |
132 } | |
133 if (nullptr == glCtx.get()) { | |
134 return ContextInfo(); | |
135 } | 191 } |
136 | 192 |
137 SkASSERT(glCtx->isValid()); | 193 grCtx.reset(GrContext::Create(backend, backendContext, fGlobalOptions)); |
138 | |
139 // Block NVPR from non-NVPR types. | |
140 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); | |
141 if (!(kEnableNVPR_ContextOptions & options)) { | |
142 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); | |
143 if (!glInterface) { | |
144 return ContextInfo(); | |
145 } | |
146 } | |
147 | |
148 glCtx->makeCurrent(); | |
149 #ifdef SK_VULKAN | |
150 if (kEnableNVPR_ContextOptions & options) { | |
151 return ContextInfo(); | |
152 } else { | |
153 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackend
Context::Create()); | |
154 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)
); | |
155 } | |
156 #else | |
157 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); | |
158 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); | |
159 #endif | |
160 if (!grCtx.get()) { | 194 if (!grCtx.get()) { |
161 return ContextInfo(); | 195 return ContextInfo(); |
162 } | 196 } |
163 if (kEnableNVPR_ContextOptions & options) { | 197 if (kEnableNVPR_ContextOptions & options) { |
164 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { | 198 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { |
165 return ContextInfo(); | 199 return ContextInfo(); |
166 } | 200 } |
167 } | 201 } |
168 if (kRequireSRGBSupport_ContextOptions & options) { | 202 if (kRequireSRGBSupport_ContextOptions & options) { |
169 if (!grCtx->caps()->srgbSupport()) { | 203 if (!grCtx->caps()->srgbSupport()) { |
170 return ContextInfo(); | 204 return ContextInfo(); |
171 } | 205 } |
172 } | 206 } |
173 | 207 |
174 Context& context = fContexts.push_back(); | 208 Context& context = fContexts.push_back(); |
175 context.fGLContext = glCtx.release(); | 209 context.fGLContext = glCtx.release(); |
176 context.fGrContext = SkRef(grCtx.get()); | 210 context.fGrContext = SkRef(grCtx.get()); |
177 context.fType = type; | 211 context.fType = type; |
178 context.fOptions = options; | 212 context.fOptions = options; |
| 213 context.fAbandoned = false; |
179 return ContextInfo(context.fGrContext, context.fGLContext); | 214 return ContextInfo(context.fGrContext, context.fGLContext); |
180 } | 215 } |
181 } // namespace sk_gpu_test | 216 } // namespace sk_gpu_test |
OLD | NEW |