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