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