blob: 485d278dd2bdb914ce782a298bb4fdc16c684a15 [file] [log] [blame]
bsalomon3724e572016-03-30 18:56:19 -07001
djsollene4545212014-11-13 11:12:41 -08002/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
Robert Phillips00f78de2020-07-01 16:09:43 -04009#include "include/gpu/GrDirectContext.h"
Adlai Hollera0693042020-10-14 11:23:11 -040010#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "tools/gpu/GrContextFactory.h"
John Rosascoa9b348f2019-11-08 13:18:15 -080012#ifdef SK_GL
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "tools/gpu/gl/GLTestContext.h"
John Rosascoa9b348f2019-11-08 13:18:15 -080014#endif
djsollene4545212014-11-13 11:12:41 -080015
Mike Kleinc168a3a2016-11-14 14:53:13 +000016#if SK_ANGLE
Jim Van Verthb01e12b2020-02-18 14:34:38 -050017#include "tools/gpu/gl/angle/GLTestContext_angle.h"
Mike Kleinc168a3a2016-11-14 14:53:13 +000018#endif
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "tools/gpu/gl/command_buffer/GLTestContext_command_buffer.h"
djsollen7e731082016-06-09 13:07:13 -070020#ifdef SK_VULKAN
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "tools/gpu/vk/VkTestContext.h"
bsalomon7c62b472016-04-01 07:42:05 -070022#endif
Greg Danielb76a72a2017-07-13 15:07:54 -040023#ifdef SK_METAL
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "tools/gpu/mtl/MtlTestContext.h"
Greg Danielb76a72a2017-07-13 15:07:54 -040025#endif
Jim Van Verthb01e12b2020-02-18 14:34:38 -050026#ifdef SK_DIRECT3D
27#include "tools/gpu/d3d/D3DTestContext.h"
28#endif
Stephen White985741a2019-07-18 11:43:45 -040029#ifdef SK_DAWN
30#include "tools/gpu/dawn/DawnTestContext.h"
31#endif
Mike Kleinc0bd9f92019-04-23 12:05:21 -050032#include "src/gpu/GrCaps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050033#include "tools/gpu/mock/MockTestContext.h"
djsollene4545212014-11-13 11:12:41 -080034
Mike Klein8f11d4d2018-01-24 12:42:55 -050035#if defined(SK_BUILD_FOR_WIN) && defined(SK_ENABLE_DISCRETE_GPU)
Brian Osman3f375d02016-12-28 11:19:22 -050036extern "C" {
37 // NVIDIA documents that the presence and value of this symbol programmatically enable the high
38 // performance GPU in laptops with switchable graphics.
39 // https://docs.nvidia.com/gameworks/content/technologies/desktop/optimus.htm
40 // From testing, including this symbol, even if it is set to 0, we still get the NVIDIA GPU.
41 _declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
42
43 // AMD has a similar mechanism, although I don't have an AMD laptop, so this is untested.
44 // https://community.amd.com/thread/169965
45 __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
46}
47#endif
48
bsalomon3724e572016-03-30 18:56:19 -070049namespace sk_gpu_test {
kkinnunen34058002016-01-06 23:49:30 -080050GrContextFactory::GrContextFactory() { }
51
52GrContextFactory::GrContextFactory(const GrContextOptions& opts)
53 : fGlobalOptions(opts) {
54}
55
56GrContextFactory::~GrContextFactory() {
57 this->destroyContexts();
58}
59
60void GrContextFactory::destroyContexts() {
Greg Danielf0fe02f2018-01-16 11:20:41 -050061 // We must delete the test contexts in reverse order so that any child context is finished and
62 // deleted before a parent context. This relies on the fact that when we make a new context we
63 // append it to the end of fContexts array.
64 // TODO: Look into keeping a dependency dag for contexts and deletion order
65 for (int i = fContexts.count() - 1; i >= 0; --i) {
66 Context& context = fContexts[i];
Brian Salomon55ad7742017-11-17 09:25:23 -050067 SkScopeExit restore(nullptr);
bsalomon18a2f9d2016-05-11 10:09:18 -070068 if (context.fTestContext) {
Brian Salomon55ad7742017-11-17 09:25:23 -050069 restore = context.fTestContext->makeCurrentAndAutoRestore();
kkinnunen34058002016-01-06 23:49:30 -080070 }
71 if (!context.fGrContext->unique()) {
bsalomondc0fcd42016-04-11 14:21:33 -070072 context.fGrContext->releaseResourcesAndAbandonContext();
73 context.fAbandoned = true;
kkinnunen34058002016-01-06 23:49:30 -080074 }
75 context.fGrContext->unref();
bsalomon18a2f9d2016-05-11 10:09:18 -070076 delete context.fTestContext;
kkinnunen34058002016-01-06 23:49:30 -080077 }
78 fContexts.reset();
79}
80
81void GrContextFactory::abandonContexts() {
Greg Danielf0fe02f2018-01-16 11:20:41 -050082 // We must abandon the test contexts in reverse order so that any child context is finished and
83 // abandoned before a parent context. This relies on the fact that when we make a new context we
84 // append it to the end of fContexts array.
85 // TODO: Look into keeping a dependency dag for contexts and deletion order
86 for (int i = fContexts.count() - 1; i >= 0; --i) {
87 Context& context = fContexts[i];
bsalomondc0fcd42016-04-11 14:21:33 -070088 if (!context.fAbandoned) {
bsalomon18a2f9d2016-05-11 10:09:18 -070089 if (context.fTestContext) {
Brian Salomon55ad7742017-11-17 09:25:23 -050090 auto restore = context.fTestContext->makeCurrentAndAutoRestore();
bsalomon18a2f9d2016-05-11 10:09:18 -070091 context.fTestContext->testAbandon();
Greg Danielf0e04f02019-12-04 15:17:54 -050092 }
Stephen White37a46d22020-06-05 11:42:39 -040093 GrBackendApi api = context.fGrContext->backend();
94 bool requiresEarlyAbandon = api == GrBackendApi::kVulkan || api == GrBackendApi::kDawn;
Greg Danielf0e04f02019-12-04 15:17:54 -050095 if (requiresEarlyAbandon) {
96 context.fGrContext->abandonContext();
97 }
98 if (context.fTestContext) {
bsalomon18a2f9d2016-05-11 10:09:18 -070099 delete(context.fTestContext);
100 context.fTestContext = nullptr;
bsalomondc0fcd42016-04-11 14:21:33 -0700101 }
Greg Danielf0e04f02019-12-04 15:17:54 -0500102 if (!requiresEarlyAbandon) {
103 context.fGrContext->abandonContext();
104 }
bsalomondc0fcd42016-04-11 14:21:33 -0700105 context.fAbandoned = true;
kkinnunen34058002016-01-06 23:49:30 -0800106 }
kkinnunen34058002016-01-06 23:49:30 -0800107 }
108}
109
bsalomon6e2aad42016-04-01 11:54:31 -0700110void GrContextFactory::releaseResourcesAndAbandonContexts() {
Greg Danielf0fe02f2018-01-16 11:20:41 -0500111 // We must abandon the test contexts in reverse order so that any child context is finished and
112 // abandoned before a parent context. This relies on the fact that when we make a new context we
113 // append it to the end of fContexts array.
114 // TODO: Look into keeping a dependency dag for contexts and deletion order
115 for (int i = fContexts.count() - 1; i >= 0; --i) {
116 Context& context = fContexts[i];
Brian Salomon55ad7742017-11-17 09:25:23 -0500117 SkScopeExit restore(nullptr);
bsalomondc0fcd42016-04-11 14:21:33 -0700118 if (!context.fAbandoned) {
bsalomon18a2f9d2016-05-11 10:09:18 -0700119 if (context.fTestContext) {
Brian Salomon55ad7742017-11-17 09:25:23 -0500120 restore = context.fTestContext->makeCurrentAndAutoRestore();
bsalomondc0fcd42016-04-11 14:21:33 -0700121 }
bsalomon6e2aad42016-04-01 11:54:31 -0700122 context.fGrContext->releaseResourcesAndAbandonContext();
bsalomon18a2f9d2016-05-11 10:09:18 -0700123 if (context.fTestContext) {
124 delete context.fTestContext;
125 context.fTestContext = nullptr;
bsalomondc0fcd42016-04-11 14:21:33 -0700126 }
Greg Danielf0e04f02019-12-04 15:17:54 -0500127 context.fAbandoned = true;
bsalomon6e2aad42016-04-01 11:54:31 -0700128 }
129 }
130}
131
Robert Phillips00f78de2020-07-01 16:09:43 -0400132GrDirectContext* GrContextFactory::get(ContextType type, ContextOverrides overrides) {
133 return this->getContextInfo(type, overrides).directContext();
Robert Phillipscdabbcc2017-06-08 16:03:17 -0400134}
135
Brian Osman9eac2ea2017-02-24 14:51:44 -0500136ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOverrides overrides,
Robert Phillips00f78de2020-07-01 16:09:43 -0400137 GrDirectContext* shareContext,
138 uint32_t shareIndex) {
Brian Osman60c774d2017-02-21 16:58:08 -0500139 // (shareIndex != 0) -> (shareContext != nullptr)
140 SkASSERT((shareIndex == 0) || (shareContext != nullptr));
141
djsollene4545212014-11-13 11:12:41 -0800142 for (int i = 0; i < fContexts.count(); ++i) {
kkinnunen34058002016-01-06 23:49:30 -0800143 Context& context = fContexts[i];
kkinnunen34058002016-01-06 23:49:30 -0800144 if (context.fType == type &&
csmartdaltone812d492017-02-21 12:36:05 -0700145 context.fOverrides == overrides &&
Brian Osman60c774d2017-02-21 16:58:08 -0500146 context.fShareContext == shareContext &&
147 context.fShareIndex == shareIndex &&
bsalomondc0fcd42016-04-11 14:21:33 -0700148 !context.fAbandoned) {
bsalomon18a2f9d2016-05-11 10:09:18 -0700149 context.fTestContext->makeCurrent();
Brian Salomon43f8bf02017-10-18 08:33:29 -0400150 return ContextInfo(context.fType, context.fTestContext, context.fGrContext,
151 context.fOptions);
djsollene4545212014-11-13 11:12:41 -0800152 }
153 }
Brian Osman60c774d2017-02-21 16:58:08 -0500154
Leon Scroggins III75306392020-07-30 16:07:01 -0400155 // If we're trying to create a context in a share group, find the primary context
156 Context* primaryContext = nullptr;
Brian Osman60c774d2017-02-21 16:58:08 -0500157 if (shareContext) {
158 for (int i = 0; i < fContexts.count(); ++i) {
159 if (!fContexts[i].fAbandoned && fContexts[i].fGrContext == shareContext) {
Leon Scroggins III75306392020-07-30 16:07:01 -0400160 primaryContext = &fContexts[i];
Brian Osman60c774d2017-02-21 16:58:08 -0500161 break;
162 }
163 }
Leon Scroggins III75306392020-07-30 16:07:01 -0400164 SkASSERT(primaryContext && primaryContext->fType == type);
Brian Osman60c774d2017-02-21 16:58:08 -0500165 }
166
Ben Wagner145dbcd2016-11-03 14:40:50 -0400167 std::unique_ptr<TestContext> testCtx;
Greg Danielbdf12ad2018-10-12 09:31:11 -0400168 GrBackendApi backend = ContextTypeBackend(type);
bsalomondc0fcd42016-04-11 14:21:33 -0700169 switch (backend) {
John Rosascoa9b348f2019-11-08 13:18:15 -0800170#ifdef SK_GL
Greg Danielbdf12ad2018-10-12 09:31:11 -0400171 case GrBackendApi::kOpenGL: {
Leon Scroggins III75306392020-07-30 16:07:01 -0400172 GLTestContext* glShareContext = primaryContext
173 ? static_cast<GLTestContext*>(primaryContext->fTestContext) : nullptr;
bsalomon18a2f9d2016-05-11 10:09:18 -0700174 GLTestContext* glCtx;
bsalomondc0fcd42016-04-11 14:21:33 -0700175 switch (type) {
176 case kGL_ContextType:
Brian Osman60c774d2017-02-21 16:58:08 -0500177 glCtx = CreatePlatformGLTestContext(kGL_GrGLStandard, glShareContext);
bsalomondc0fcd42016-04-11 14:21:33 -0700178 break;
179 case kGLES_ContextType:
Brian Osman60c774d2017-02-21 16:58:08 -0500180 glCtx = CreatePlatformGLTestContext(kGLES_GrGLStandard, glShareContext);
bsalomondc0fcd42016-04-11 14:21:33 -0700181 break;
Mike Kleinc168a3a2016-11-14 14:53:13 +0000182#if SK_ANGLE
bsalomon11abd8d2016-10-14 08:13:48 -0700183 case kANGLE_D3D9_ES2_ContextType:
Brian Osman60c774d2017-02-21 16:58:08 -0500184 glCtx = MakeANGLETestContext(ANGLEBackend::kD3D9, ANGLEContextVersion::kES2,
185 glShareContext).release();
Brian Salomon414782d2020-04-17 09:34:17 -0400186 // Chrome will only run on D3D9 with NVIDIA for 2012 and earlier drivers.
187 // (<= 269.73). We get shader link failures when testing on recent drivers
188 // using this backend.
189 if (glCtx) {
Brian Salomon19893422021-05-06 15:11:43 -0400190 GrGLDriverInfo info = GrGLGetDriverInfo(glCtx->gl());
Brian Salomon96263aa2021-05-07 13:42:17 -0400191 if (info.fANGLEVendor == GrGLVendor::kNVIDIA) {
Brian Salomon414782d2020-04-17 09:34:17 -0400192 delete glCtx;
193 return ContextInfo();
194 }
195 }
bsalomondc0fcd42016-04-11 14:21:33 -0700196 break;
bsalomon11abd8d2016-10-14 08:13:48 -0700197 case kANGLE_D3D11_ES2_ContextType:
Brian Osman60c774d2017-02-21 16:58:08 -0500198 glCtx = MakeANGLETestContext(ANGLEBackend::kD3D11, ANGLEContextVersion::kES2,
199 glShareContext).release();
bsalomon11abd8d2016-10-14 08:13:48 -0700200 break;
201 case kANGLE_D3D11_ES3_ContextType:
Brian Osman60c774d2017-02-21 16:58:08 -0500202 glCtx = MakeANGLETestContext(ANGLEBackend::kD3D11, ANGLEContextVersion::kES3,
203 glShareContext).release();
bsalomon11abd8d2016-10-14 08:13:48 -0700204 break;
205 case kANGLE_GL_ES2_ContextType:
Brian Osman60c774d2017-02-21 16:58:08 -0500206 glCtx = MakeANGLETestContext(ANGLEBackend::kOpenGL, ANGLEContextVersion::kES2,
207 glShareContext).release();
bsalomon11abd8d2016-10-14 08:13:48 -0700208 break;
209 case kANGLE_GL_ES3_ContextType:
Brian Osman60c774d2017-02-21 16:58:08 -0500210 glCtx = MakeANGLETestContext(ANGLEBackend::kOpenGL, ANGLEContextVersion::kES3,
211 glShareContext).release();
bsalomondc0fcd42016-04-11 14:21:33 -0700212 break;
Mike Kleinc168a3a2016-11-14 14:53:13 +0000213#endif
Kevin Lubickffce0792017-05-24 15:30:35 -0400214#ifndef SK_NO_COMMAND_BUFFER
Chris Daltone0f4de62021-06-28 08:43:08 -0600215 case kCommandBuffer_ES2_ContextType:
216 glCtx = CommandBufferGLTestContext::Create(2, glShareContext);
217 break;
218 case kCommandBuffer_ES3_ContextType:
219 glCtx = CommandBufferGLTestContext::Create(3, glShareContext);
bsalomondc0fcd42016-04-11 14:21:33 -0700220 break;
Kevin Lubickffce0792017-05-24 15:30:35 -0400221#endif
bsalomondc0fcd42016-04-11 14:21:33 -0700222 default:
223 return ContextInfo();
224 }
bsalomon18a2f9d2016-05-11 10:09:18 -0700225 if (!glCtx) {
bsalomondc0fcd42016-04-11 14:21:33 -0700226 return ContextInfo();
227 }
Brian Salomonb2b7f802020-08-26 15:27:03 -0400228 if (glCtx->gl()->fStandard == kGLES_GrGLStandard &&
229 (overrides & ContextOverrides::kFakeGLESVersionAs2)) {
230 glCtx->overrideVersion("OpenGL ES 2.0", "OpenGL ES GLSL ES 1.00");
231 }
bsalomon18a2f9d2016-05-11 10:09:18 -0700232 testCtx.reset(glCtx);
djsollene4545212014-11-13 11:12:41 -0800233 break;
bsalomon18a2f9d2016-05-11 10:09:18 -0700234 }
John Rosascoa9b348f2019-11-08 13:18:15 -0800235#endif // SK_GL
jvanvertha50e17a2015-08-12 12:19:36 -0700236#ifdef SK_VULKAN
Greg Danielbdf12ad2018-10-12 09:31:11 -0400237 case GrBackendApi::kVulkan: {
Leon Scroggins III75306392020-07-30 16:07:01 -0400238 VkTestContext* vkSharedContext = primaryContext
239 ? static_cast<VkTestContext*>(primaryContext->fTestContext) : nullptr;
bsalomondc0fcd42016-04-11 14:21:33 -0700240 SkASSERT(kVulkan_ContextType == type);
Greg Daniel604b1972017-05-15 13:50:35 -0400241 testCtx.reset(CreatePlatformVkTestContext(vkSharedContext));
bsalomon18a2f9d2016-05-11 10:09:18 -0700242 if (!testCtx) {
bsalomondc0fcd42016-04-11 14:21:33 -0700243 return ContextInfo();
244 }
bsalomon18a2f9d2016-05-11 10:09:18 -0700245
Brian Salomonf4ba4ec2020-03-19 15:54:28 -0400246 // We previously had an issue where the VkDevice destruction would occasionally hang
247 // on systems with NVIDIA GPUs and having an existing GL context fixed it. Now (March
248 // 2020) we still need the GL context to keep Vulkan/TSAN bots from running incredibly
249 // slow. Perhaps this prevents repeated driver loading/unloading? Note that keeping
250 // a persistent VkTestContext around instead was tried and did not work.
Brian Salomon7f9c29a2017-01-24 22:22:05 +0000251 if (!fSentinelGLContext) {
252 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLStandard));
253 if (!fSentinelGLContext) {
254 fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard));
255 }
256 }
bsalomondc0fcd42016-04-11 14:21:33 -0700257 break;
Greg Daniel604b1972017-05-15 13:50:35 -0400258 }
jvanvertha50e17a2015-08-12 12:19:36 -0700259#endif
Greg Danielb76a72a2017-07-13 15:07:54 -0400260#ifdef SK_METAL
Greg Danielbdf12ad2018-10-12 09:31:11 -0400261 case GrBackendApi::kMetal: {
Leon Scroggins III75306392020-07-30 16:07:01 -0400262 MtlTestContext* mtlSharedContext = primaryContext
263 ? static_cast<MtlTestContext*>(primaryContext->fTestContext) : nullptr;
Jim Van Vertha3407ab2019-03-15 15:22:39 -0400264 SkASSERT(kMetal_ContextType == type);
265 testCtx.reset(CreatePlatformMtlTestContext(mtlSharedContext));
Greg Danielb76a72a2017-07-13 15:07:54 -0400266 if (!testCtx) {
267 return ContextInfo();
268 }
269 break;
270 }
271#endif
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500272#ifdef SK_DIRECT3D
273 case GrBackendApi::kDirect3D: {
Leon Scroggins III75306392020-07-30 16:07:01 -0400274 D3DTestContext* d3dSharedContext = primaryContext
275 ? static_cast<D3DTestContext*>(primaryContext->fTestContext) : nullptr;
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500276 SkASSERT(kDirect3D_ContextType == type);
277 testCtx.reset(CreatePlatformD3DTestContext(d3dSharedContext));
278 if (!testCtx) {
279 return ContextInfo();
280 }
281 break;
282 }
283#endif
Stephen White985741a2019-07-18 11:43:45 -0400284#ifdef SK_DAWN
285 case GrBackendApi::kDawn: {
Leon Scroggins III75306392020-07-30 16:07:01 -0400286 DawnTestContext* dawnSharedContext = primaryContext
287 ? static_cast<DawnTestContext*>(primaryContext->fTestContext) : nullptr;
Stephen White985741a2019-07-18 11:43:45 -0400288 testCtx.reset(CreatePlatformDawnTestContext(dawnSharedContext));
289 if (!testCtx) {
290 return ContextInfo();
291 }
292 break;
293 }
294#endif
Greg Danielbdf12ad2018-10-12 09:31:11 -0400295 case GrBackendApi::kMock: {
Leon Scroggins III75306392020-07-30 16:07:01 -0400296 TestContext* sharedContext = primaryContext ? primaryContext->fTestContext : nullptr;
Brian Salomoncfe910d2017-07-06 16:40:18 -0400297 SkASSERT(kMock_ContextType == type);
Brian Salomoncfe910d2017-07-06 16:40:18 -0400298 testCtx.reset(CreateMockTestContext(sharedContext));
299 if (!testCtx) {
300 return ContextInfo();
301 }
Brian Salomoncfe910d2017-07-06 16:40:18 -0400302 break;
303 }
bsalomondc0fcd42016-04-11 14:21:33 -0700304 default:
305 return ContextInfo();
306 }
Brian Salomon55ad7742017-11-17 09:25:23 -0500307
bsalomon18a2f9d2016-05-11 10:09:18 -0700308 SkASSERT(testCtx && testCtx->backend() == backend);
csmartdaltone0d36292016-07-29 08:14:20 -0700309 GrContextOptions grOptions = fGlobalOptions;
Eric Karl5c779752017-05-08 12:02:07 -0700310 if (ContextOverrides::kAvoidStencilBuffers & overrides) {
311 grOptions.fAvoidStencilBuffers = true;
312 }
Brian Salomon91216d52021-04-09 11:57:59 -0400313 if (ContextOverrides::kReducedShaders & overrides) {
314 grOptions.fReducedShaderVariations = true;
315 }
Robert Phillips00f78de2020-07-01 16:09:43 -0400316 sk_sp<GrDirectContext> grCtx;
Brian Salomon55ad7742017-11-17 09:25:23 -0500317 {
318 auto restore = testCtx->makeCurrentAndAutoRestore();
Robert Phillipsf4f80112020-07-13 16:13:31 -0400319 grCtx = testCtx->makeContext(grOptions);
Brian Salomon55ad7742017-11-17 09:25:23 -0500320 }
John Stilesa008b0f2020-08-16 08:48:02 -0400321 if (!grCtx) {
kkinnunen34058002016-01-06 23:49:30 -0800322 return ContextInfo();
djsollene4545212014-11-13 11:12:41 -0800323 }
kkinnunencfe62e32015-07-01 02:58:50 -0700324
Robert Phillipsedff4672021-03-11 09:16:25 -0500325 if (shareContext) {
326 SkASSERT(grCtx->directContextID() != shareContext->directContextID());
327 }
328
Greg Danielf0fe02f2018-01-16 11:20:41 -0500329 // We must always add new contexts by pushing to the back so that when we delete them we delete
330 // them in reverse order in which they were made.
kkinnunen34058002016-01-06 23:49:30 -0800331 Context& context = fContexts.push_back();
bsalomon18a2f9d2016-05-11 10:09:18 -0700332 context.fBackend = backend;
333 context.fTestContext = testCtx.release();
kkinnunen34058002016-01-06 23:49:30 -0800334 context.fGrContext = SkRef(grCtx.get());
335 context.fType = type;
csmartdaltone812d492017-02-21 12:36:05 -0700336 context.fOverrides = overrides;
bsalomondc0fcd42016-04-11 14:21:33 -0700337 context.fAbandoned = false;
Brian Osman60c774d2017-02-21 16:58:08 -0500338 context.fShareContext = shareContext;
339 context.fShareIndex = shareIndex;
Brian Salomon43f8bf02017-10-18 08:33:29 -0400340 context.fOptions = grOptions;
Brian Salomon55ad7742017-11-17 09:25:23 -0500341 context.fTestContext->makeCurrent();
Brian Salomon43f8bf02017-10-18 08:33:29 -0400342 return ContextInfo(context.fType, context.fTestContext, context.fGrContext, context.fOptions);
djsollene4545212014-11-13 11:12:41 -0800343}
Brian Osman60c774d2017-02-21 16:58:08 -0500344
Brian Osman9eac2ea2017-02-24 14:51:44 -0500345ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides overrides) {
346 return this->getContextInfoInternal(type, overrides, nullptr, 0);
347}
348
Robert Phillips00f78de2020-07-01 16:09:43 -0400349ContextInfo GrContextFactory::getSharedContextInfo(GrDirectContext* shareContext,
350 uint32_t shareIndex) {
Brian Osman9eac2ea2017-02-24 14:51:44 -0500351 SkASSERT(shareContext);
352 for (int i = 0; i < fContexts.count(); ++i) {
353 if (!fContexts[i].fAbandoned && fContexts[i].fGrContext == shareContext) {
354 return this->getContextInfoInternal(fContexts[i].fType, fContexts[i].fOverrides,
355 shareContext, shareIndex);
356 }
357 }
358
359 return ContextInfo();
360}
361
bsalomon3724e572016-03-30 18:56:19 -0700362} // namespace sk_gpu_test