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