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