Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: tools/gpu/GrContextFactory.cpp

Issue 1872283003: Vulkan config in dm (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: minor Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 SkAutoTUnref<GrContext> grCtx;
99 switch (type) { 108 GrBackendContext backendContext = 0;
100 case kGL_ContextType: 109 SkAutoTUnref<const GrGLInterface> glInterface;
egdaniel 2016/04/11 20:10:01 can the glInterface be a sk_sp as well here?
bsalomon 2016/04/11 20:40:26 Done.
101 glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); 110 sk_sp<const GrVkBackendContext> vkBackend;
111 GrBackend backend = ContextTypeBackend(type);
112 switch (backend) {
113 case kOpenGL_GrBackend:
114 switch (type) {
115 case kGL_ContextType:
116 glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard));
117 break;
118 case kGLES_ContextType:
119 glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)) ;
120 break;
121 #if SK_ANGLE
122 # ifdef SK_BUILD_FOR_WIN
egdaniel 2016/04/11 20:10:01 are indented ifdefs a skia style?
bsalomon 2016/04/11 20:40:26 there are many skia styles for nested preprocessor
123 case kANGLE_ContextType:
124 glCtx.reset(CreateANGLEDirect3DGLTestContext());
125 break;
126 # endif
127 case kANGLE_GL_ContextType:
128 glCtx.reset(CreateANGLEOpenGLGLTestContext());
129 break;
130 #endif
131 #if SK_COMMAND_BUFFER
132 case kCommandBuffer_ContextType:
133 glCtx.reset(CommandBufferGLTestContext::Create());
134 break;
135 #endif
136 #if SK_MESA
137 case kMESA_ContextType:
138 glCtx.reset(CreateMesaGLTestContext());
139 break;
140 #endif
141 case kNullGL_ContextType:
142 glCtx.reset(CreateNullGLTestContext());
143 break;
144 case kDebugGL_ContextType:
145 glCtx.reset(CreateDebugGLTestContext());
146 break;
147 default:
148 return ContextInfo();
149 }
150 if (nullptr == glCtx.get()) {
151 return ContextInfo();
152 }
153 glInterface.reset(SkRef(glCtx->gl()));
154 // Block NVPR from non-NVPR types.
155 if (!(kEnableNVPR_ContextOptions & options)) {
156 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface));
157 if (!glInterface) {
158 return ContextInfo();
159 }
160 }
161 backendContext = reinterpret_cast<GrBackendContext>(glInterface.get( ));
162 glCtx->makeCurrent();
102 break; 163 break;
103 case kGLES_ContextType: 164 #ifdef SK_VULKAN
104 glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); 165 case kVulkan_GrBackend:
105 break; 166 SkASSERT(kVulkan_ContextType == type);
106 #if SK_ANGLE 167 if ((kEnableNVPR_ContextOptions & options) ||
107 #ifdef SK_BUILD_FOR_WIN 168 (kRequireSRGBSupport_ContextOptions & options)) {
108 case kANGLE_ContextType: 169 return ContextInfo();
109 glCtx.reset(CreateANGLEDirect3DGLTestContext()); 170 }
171 vkBackend.reset(GrVkBackendContext::Create());
172 if (!vkBackend) {
173 return ContextInfo();
174 }
175 backendContext = reinterpret_cast<GrBackendContext>(vkBackend.get()) ;
176 // There is some bug (either in Skia or the NV Vulkan driver) where VkDevice
177 // destruction will hang occaisonally. For some reason having an exi sting GL
178 // context fixes this.
179 if (!fSentinelGLContext) {
180 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLSta ndard));
181 if (!fSentinelGLContext) {
182 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_G rGLStandard));
183 }
184 }
110 break; 185 break;
111 #endif 186 #endif
112 case kANGLE_GL_ContextType: 187 default:
113 glCtx.reset(CreateANGLEOpenGLGLTestContext()); 188 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 } 189 }
136 190
137 SkASSERT(glCtx->isValid()); 191 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()) { 192 if (!grCtx.get()) {
161 return ContextInfo(); 193 return ContextInfo();
162 } 194 }
163 if (kEnableNVPR_ContextOptions & options) { 195 if (kEnableNVPR_ContextOptions & options) {
164 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { 196 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) {
165 return ContextInfo(); 197 return ContextInfo();
166 } 198 }
167 } 199 }
168 if (kRequireSRGBSupport_ContextOptions & options) { 200 if (kRequireSRGBSupport_ContextOptions & options) {
169 if (!grCtx->caps()->srgbSupport()) { 201 if (!grCtx->caps()->srgbSupport()) {
170 return ContextInfo(); 202 return ContextInfo();
171 } 203 }
172 } 204 }
173 205
174 Context& context = fContexts.push_back(); 206 Context& context = fContexts.push_back();
175 context.fGLContext = glCtx.release(); 207 context.fGLContext = glCtx.release();
176 context.fGrContext = SkRef(grCtx.get()); 208 context.fGrContext = SkRef(grCtx.get());
177 context.fType = type; 209 context.fType = type;
178 context.fOptions = options; 210 context.fOptions = options;
211 context.fAbandoned = false;
179 return ContextInfo(context.fGrContext, context.fGLContext); 212 return ContextInfo(context.fGrContext, context.fGLContext);
180 } 213 }
181 } // namespace sk_gpu_test 214 } // namespace sk_gpu_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698