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