bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 1 | |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 2 | /* |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/GrContextPriv.h" |
| 10 | #include "tools/gpu/GrContextFactory.h" |
| 11 | #include "tools/gpu/gl/GLTestContext.h" |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 12 | |
Mike Klein | c168a3a | 2016-11-14 14:53:13 +0000 | [diff] [blame] | 13 | #if SK_ANGLE |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "tools/gpu/gl/angle/GLTestContext_angle.h" |
Mike Klein | c168a3a | 2016-11-14 14:53:13 +0000 | [diff] [blame] | 15 | #endif |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "tools/gpu/gl/command_buffer/GLTestContext_command_buffer.h" |
djsollen | 7e73108 | 2016-06-09 13:07:13 -0700 | [diff] [blame] | 17 | #ifdef SK_VULKAN |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "tools/gpu/vk/VkTestContext.h" |
bsalomon | 7c62b47 | 2016-04-01 07:42:05 -0700 | [diff] [blame] | 19 | #endif |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 20 | #ifdef SK_METAL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "tools/gpu/mtl/MtlTestContext.h" |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 22 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame^] | 23 | #ifdef SK_DAWN |
| 24 | #include "tools/gpu/dawn/DawnTestContext.h" |
| 25 | #endif |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 26 | #include "src/gpu/GrCaps.h" |
Robert Phillips | 08ba085 | 2019-05-22 20:23:43 +0000 | [diff] [blame] | 27 | #include "src/gpu/gl/GrGLGpu.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #include "tools/gpu/mock/MockTestContext.h" |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 29 | |
Mike Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 30 | #if defined(SK_BUILD_FOR_WIN) && defined(SK_ENABLE_DISCRETE_GPU) |
Brian Osman | 3f375d0 | 2016-12-28 11:19:22 -0500 | [diff] [blame] | 31 | extern "C" { |
| 32 | // NVIDIA documents that the presence and value of this symbol programmatically enable the high |
| 33 | // performance GPU in laptops with switchable graphics. |
| 34 | // https://docs.nvidia.com/gameworks/content/technologies/desktop/optimus.htm |
| 35 | // From testing, including this symbol, even if it is set to 0, we still get the NVIDIA GPU. |
| 36 | _declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; |
| 37 | |
| 38 | // AMD has a similar mechanism, although I don't have an AMD laptop, so this is untested. |
| 39 | // https://community.amd.com/thread/169965 |
| 40 | __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; |
| 41 | } |
| 42 | #endif |
| 43 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 44 | namespace sk_gpu_test { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 45 | GrContextFactory::GrContextFactory() { } |
| 46 | |
| 47 | GrContextFactory::GrContextFactory(const GrContextOptions& opts) |
| 48 | : fGlobalOptions(opts) { |
| 49 | } |
| 50 | |
| 51 | GrContextFactory::~GrContextFactory() { |
| 52 | this->destroyContexts(); |
| 53 | } |
| 54 | |
| 55 | void GrContextFactory::destroyContexts() { |
Greg Daniel | f0fe02f | 2018-01-16 11:20:41 -0500 | [diff] [blame] | 56 | // We must delete the test contexts in reverse order so that any child context is finished and |
| 57 | // deleted before a parent context. This relies on the fact that when we make a new context we |
| 58 | // append it to the end of fContexts array. |
| 59 | // TODO: Look into keeping a dependency dag for contexts and deletion order |
| 60 | for (int i = fContexts.count() - 1; i >= 0; --i) { |
| 61 | Context& context = fContexts[i]; |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 62 | SkScopeExit restore(nullptr); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 63 | if (context.fTestContext) { |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 64 | restore = context.fTestContext->makeCurrentAndAutoRestore(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 65 | } |
| 66 | if (!context.fGrContext->unique()) { |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 67 | context.fGrContext->releaseResourcesAndAbandonContext(); |
| 68 | context.fAbandoned = true; |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 69 | } |
| 70 | context.fGrContext->unref(); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 71 | delete context.fTestContext; |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 72 | } |
| 73 | fContexts.reset(); |
| 74 | } |
| 75 | |
| 76 | void GrContextFactory::abandonContexts() { |
Greg Daniel | f0fe02f | 2018-01-16 11:20:41 -0500 | [diff] [blame] | 77 | // We must abandon the test contexts in reverse order so that any child context is finished and |
| 78 | // abandoned before a parent context. This relies on the fact that when we make a new context we |
| 79 | // append it to the end of fContexts array. |
| 80 | // TODO: Look into keeping a dependency dag for contexts and deletion order |
| 81 | for (int i = fContexts.count() - 1; i >= 0; --i) { |
| 82 | Context& context = fContexts[i]; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 83 | if (!context.fAbandoned) { |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 84 | if (context.fTestContext) { |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 85 | auto restore = context.fTestContext->makeCurrentAndAutoRestore(); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 86 | context.fTestContext->testAbandon(); |
| 87 | delete(context.fTestContext); |
| 88 | context.fTestContext = nullptr; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 89 | } |
| 90 | context.fGrContext->abandonContext(); |
| 91 | context.fAbandoned = true; |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 92 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 96 | void GrContextFactory::releaseResourcesAndAbandonContexts() { |
Greg Daniel | f0fe02f | 2018-01-16 11:20:41 -0500 | [diff] [blame] | 97 | // We must abandon the test contexts in reverse order so that any child context is finished and |
| 98 | // abandoned before a parent context. This relies on the fact that when we make a new context we |
| 99 | // append it to the end of fContexts array. |
| 100 | // TODO: Look into keeping a dependency dag for contexts and deletion order |
| 101 | for (int i = fContexts.count() - 1; i >= 0; --i) { |
| 102 | Context& context = fContexts[i]; |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 103 | SkScopeExit restore(nullptr); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 104 | if (!context.fAbandoned) { |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 105 | if (context.fTestContext) { |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 106 | restore = context.fTestContext->makeCurrentAndAutoRestore(); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 107 | } |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 108 | context.fGrContext->releaseResourcesAndAbandonContext(); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 109 | context.fAbandoned = true; |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 110 | if (context.fTestContext) { |
| 111 | delete context.fTestContext; |
| 112 | context.fTestContext = nullptr; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 113 | } |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
Robert Phillips | cdabbcc | 2017-06-08 16:03:17 -0400 | [diff] [blame] | 118 | GrContext* GrContextFactory::get(ContextType type, ContextOverrides overrides) { |
| 119 | return this->getContextInfo(type, overrides).grContext(); |
| 120 | } |
| 121 | |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 122 | ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOverrides overrides, |
| 123 | GrContext* shareContext, uint32_t shareIndex) { |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 124 | // (shareIndex != 0) -> (shareContext != nullptr) |
| 125 | SkASSERT((shareIndex == 0) || (shareContext != nullptr)); |
| 126 | |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 127 | for (int i = 0; i < fContexts.count(); ++i) { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 128 | Context& context = fContexts[i]; |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 129 | if (context.fType == type && |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 130 | context.fOverrides == overrides && |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 131 | context.fShareContext == shareContext && |
| 132 | context.fShareIndex == shareIndex && |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 133 | !context.fAbandoned) { |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 134 | context.fTestContext->makeCurrent(); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 135 | return ContextInfo(context.fType, context.fTestContext, context.fGrContext, |
| 136 | context.fOptions); |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 137 | } |
| 138 | } |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 139 | |
| 140 | // If we're trying to create a context in a share group, find the master context |
| 141 | Context* masterContext = nullptr; |
| 142 | if (shareContext) { |
| 143 | for (int i = 0; i < fContexts.count(); ++i) { |
| 144 | if (!fContexts[i].fAbandoned && fContexts[i].fGrContext == shareContext) { |
| 145 | masterContext = &fContexts[i]; |
| 146 | break; |
| 147 | } |
| 148 | } |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 149 | SkASSERT(masterContext && masterContext->fType == type); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 152 | std::unique_ptr<TestContext> testCtx; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 153 | GrBackendApi backend = ContextTypeBackend(type); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 154 | switch (backend) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 155 | case GrBackendApi::kOpenGL: { |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 156 | GLTestContext* glShareContext = masterContext |
| 157 | ? static_cast<GLTestContext*>(masterContext->fTestContext) : nullptr; |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 158 | GLTestContext* glCtx; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 159 | switch (type) { |
| 160 | case kGL_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 161 | glCtx = CreatePlatformGLTestContext(kGL_GrGLStandard, glShareContext); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 162 | break; |
| 163 | case kGLES_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 164 | glCtx = CreatePlatformGLTestContext(kGLES_GrGLStandard, glShareContext); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 165 | break; |
Mike Klein | c168a3a | 2016-11-14 14:53:13 +0000 | [diff] [blame] | 166 | #if SK_ANGLE |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 167 | case kANGLE_D3D9_ES2_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 168 | glCtx = MakeANGLETestContext(ANGLEBackend::kD3D9, ANGLEContextVersion::kES2, |
| 169 | glShareContext).release(); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 170 | break; |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 171 | case kANGLE_D3D11_ES2_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 172 | glCtx = MakeANGLETestContext(ANGLEBackend::kD3D11, ANGLEContextVersion::kES2, |
| 173 | glShareContext).release(); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 174 | break; |
| 175 | case kANGLE_D3D11_ES3_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 176 | glCtx = MakeANGLETestContext(ANGLEBackend::kD3D11, ANGLEContextVersion::kES3, |
| 177 | glShareContext).release(); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 178 | break; |
| 179 | case kANGLE_GL_ES2_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 180 | glCtx = MakeANGLETestContext(ANGLEBackend::kOpenGL, ANGLEContextVersion::kES2, |
| 181 | glShareContext).release(); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 182 | break; |
| 183 | case kANGLE_GL_ES3_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 184 | glCtx = MakeANGLETestContext(ANGLEBackend::kOpenGL, ANGLEContextVersion::kES3, |
| 185 | glShareContext).release(); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 186 | break; |
Mike Klein | c168a3a | 2016-11-14 14:53:13 +0000 | [diff] [blame] | 187 | #endif |
Kevin Lubick | ffce079 | 2017-05-24 15:30:35 -0400 | [diff] [blame] | 188 | #ifndef SK_NO_COMMAND_BUFFER |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 189 | case kCommandBuffer_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 190 | glCtx = CommandBufferGLTestContext::Create(glShareContext); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 191 | break; |
Kevin Lubick | ffce079 | 2017-05-24 15:30:35 -0400 | [diff] [blame] | 192 | #endif |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 193 | default: |
| 194 | return ContextInfo(); |
| 195 | } |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 196 | if (!glCtx) { |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 197 | return ContextInfo(); |
| 198 | } |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 199 | testCtx.reset(glCtx); |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 200 | break; |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 201 | } |
jvanverth | a50e17a | 2015-08-12 12:19:36 -0700 | [diff] [blame] | 202 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 203 | case GrBackendApi::kVulkan: { |
Greg Daniel | 604b197 | 2017-05-15 13:50:35 -0400 | [diff] [blame] | 204 | VkTestContext* vkSharedContext = masterContext |
| 205 | ? static_cast<VkTestContext*>(masterContext->fTestContext) : nullptr; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 206 | SkASSERT(kVulkan_ContextType == type); |
Greg Daniel | 604b197 | 2017-05-15 13:50:35 -0400 | [diff] [blame] | 207 | testCtx.reset(CreatePlatformVkTestContext(vkSharedContext)); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 208 | if (!testCtx) { |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 209 | return ContextInfo(); |
| 210 | } |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 211 | |
Brian Salomon | 7f9c29a | 2017-01-24 22:22:05 +0000 | [diff] [blame] | 212 | // There is some bug (either in Skia or the NV Vulkan driver) where VkDevice |
| 213 | // destruction will hang occaisonally. For some reason having an existing GL |
| 214 | // context fixes this. |
| 215 | if (!fSentinelGLContext) { |
| 216 | fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); |
| 217 | if (!fSentinelGLContext) { |
| 218 | fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); |
| 219 | } |
| 220 | } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 221 | break; |
Greg Daniel | 604b197 | 2017-05-15 13:50:35 -0400 | [diff] [blame] | 222 | } |
jvanverth | a50e17a | 2015-08-12 12:19:36 -0700 | [diff] [blame] | 223 | #endif |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 224 | #ifdef SK_METAL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 225 | case GrBackendApi::kMetal: { |
Jim Van Verth | a3407ab | 2019-03-15 15:22:39 -0400 | [diff] [blame] | 226 | MtlTestContext* mtlSharedContext = masterContext |
| 227 | ? static_cast<MtlTestContext*>(masterContext->fTestContext) : nullptr; |
| 228 | SkASSERT(kMetal_ContextType == type); |
| 229 | testCtx.reset(CreatePlatformMtlTestContext(mtlSharedContext)); |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 230 | if (!testCtx) { |
| 231 | return ContextInfo(); |
| 232 | } |
| 233 | break; |
| 234 | } |
| 235 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame^] | 236 | #ifdef SK_DAWN |
| 237 | case GrBackendApi::kDawn: { |
| 238 | DawnTestContext* dawnSharedContext = masterContext |
| 239 | ? static_cast<DawnTestContext*>(masterContext->fTestContext) : nullptr; |
| 240 | testCtx.reset(CreatePlatformDawnTestContext(dawnSharedContext)); |
| 241 | if (!testCtx) { |
| 242 | return ContextInfo(); |
| 243 | } |
| 244 | break; |
| 245 | } |
| 246 | #endif |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 247 | case GrBackendApi::kMock: { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 248 | TestContext* sharedContext = masterContext ? masterContext->fTestContext : nullptr; |
| 249 | SkASSERT(kMock_ContextType == type); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 250 | testCtx.reset(CreateMockTestContext(sharedContext)); |
| 251 | if (!testCtx) { |
| 252 | return ContextInfo(); |
| 253 | } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 254 | break; |
| 255 | } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 256 | default: |
| 257 | return ContextInfo(); |
| 258 | } |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 259 | |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 260 | SkASSERT(testCtx && testCtx->backend() == backend); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 261 | GrContextOptions grOptions = fGlobalOptions; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 262 | if (ContextOverrides::kAvoidStencilBuffers & overrides) { |
| 263 | grOptions.fAvoidStencilBuffers = true; |
| 264 | } |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 265 | sk_sp<GrContext> grCtx; |
| 266 | { |
| 267 | auto restore = testCtx->makeCurrentAndAutoRestore(); |
| 268 | grCtx = testCtx->makeGrContext(grOptions); |
| 269 | } |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 270 | if (!grCtx.get()) { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 271 | return ContextInfo(); |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 272 | } |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 273 | |
Greg Daniel | f0fe02f | 2018-01-16 11:20:41 -0500 | [diff] [blame] | 274 | // We must always add new contexts by pushing to the back so that when we delete them we delete |
| 275 | // them in reverse order in which they were made. |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 276 | Context& context = fContexts.push_back(); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 277 | context.fBackend = backend; |
| 278 | context.fTestContext = testCtx.release(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 279 | context.fGrContext = SkRef(grCtx.get()); |
| 280 | context.fType = type; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 281 | context.fOverrides = overrides; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 282 | context.fAbandoned = false; |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 283 | context.fShareContext = shareContext; |
| 284 | context.fShareIndex = shareIndex; |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 285 | context.fOptions = grOptions; |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 286 | context.fTestContext->makeCurrent(); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 287 | return ContextInfo(context.fType, context.fTestContext, context.fGrContext, context.fOptions); |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 288 | } |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 289 | |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 290 | ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides overrides) { |
| 291 | return this->getContextInfoInternal(type, overrides, nullptr, 0); |
| 292 | } |
| 293 | |
| 294 | ContextInfo GrContextFactory::getSharedContextInfo(GrContext* shareContext, uint32_t shareIndex) { |
| 295 | SkASSERT(shareContext); |
| 296 | for (int i = 0; i < fContexts.count(); ++i) { |
| 297 | if (!fContexts[i].fAbandoned && fContexts[i].fGrContext == shareContext) { |
| 298 | return this->getContextInfoInternal(fContexts[i].fType, fContexts[i].fOverrides, |
| 299 | shareContext, shareIndex); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | return ContextInfo(); |
| 304 | } |
| 305 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 306 | } // namespace sk_gpu_test |