keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 8 | #include "SkTypes.h" |
| 9 | |
keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 10 | #if SK_SUPPORT_GPU |
keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 11 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 12 | #include "GrContextFactory.h" |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 13 | #include "GrContextPriv.h" |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 14 | #include "GrCaps.h" |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 15 | #include "SkExecutor.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 16 | #include "Test.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 17 | |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 18 | using namespace sk_gpu_test; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 19 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 20 | DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, options) { |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 21 | // Test that if NVPR is requested, the context always has path rendering |
| 22 | // or the context creation fails. |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 23 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 24 | GrContextFactory testFactory(options); |
| 25 | // Test that if NVPR is possible, caps are in sync. |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 26 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
| 27 | GrContext* context = testFactory.get(ctxType, |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 28 | GrContextFactory::ContextOverrides::kRequireNVPRSupport); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 29 | if (!context) { |
| 30 | continue; |
| 31 | } |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 32 | REPORTER_ASSERT(reporter, |
| 33 | context->contextPriv().caps()->shaderCaps()->pathRenderingSupport()); |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 37 | DEF_GPUTEST(GrContextFactory_NoPathRenderingIfNVPRDisabled, reporter, options) { |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 38 | // Test that if NVPR is explicitly disabled, the context has no path rendering support. |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 39 | |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 40 | for (int i = 0; i <= GrContextFactory::kLastContextType; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 41 | GrContextFactory testFactory(options); |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 42 | GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)i; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 43 | GrContext* context = |
| 44 | testFactory.get(ctxType, GrContextFactory::ContextOverrides::kDisableNVPR); |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 45 | if (context) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, |
| 47 | !context->contextPriv().caps()->shaderCaps()->pathRenderingSupport()); |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | } |
keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 51 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 52 | DEF_GPUTEST(GrContextFactory_RequiredSRGBSupport, reporter, options) { |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 53 | // Test that if sRGB support is requested, the context always has that capability |
| 54 | // or the context creation fails. Also test that if the creation fails, a context |
| 55 | // created without that flag would not have had sRGB support. |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 56 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 57 | GrContextFactory testFactory(options); |
| 58 | // Test that if sRGB is requested, caps are in sync. |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 59 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 60 | GrContext* context = |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 61 | testFactory.get(ctxType, GrContextFactory::ContextOverrides::kRequireSRGBSupport); |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 62 | |
| 63 | if (context) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, context->contextPriv().caps()->srgbSupport()); |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 65 | } else { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 66 | context = testFactory.get(ctxType); |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 67 | if (context) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 68 | REPORTER_ASSERT(reporter, !context->contextPriv().caps()->srgbSupport()); |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 74 | DEF_GPUTEST(GrContextFactory_abandon, reporter, options) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 75 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 76 | GrContextFactory testFactory(options); |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 77 | GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i; |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 78 | ContextInfo info1 = testFactory.getContextInfo(ctxType); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 79 | if (!info1.grContext()) { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 80 | continue; |
| 81 | } |
bsalomon | 0fd3c81 | 2016-05-11 10:38:05 -0700 | [diff] [blame] | 82 | REPORTER_ASSERT(reporter, info1.testContext()); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 83 | // Ref for comparison. The API does not explicitly say that this stays alive. |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 84 | info1.grContext()->ref(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 85 | testFactory.abandonContexts(); |
| 86 | |
| 87 | // Test that we get different context after abandon. |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 88 | ContextInfo info2 = testFactory.getContextInfo(ctxType); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 89 | REPORTER_ASSERT(reporter, info2.grContext()); |
bsalomon | 0fd3c81 | 2016-05-11 10:38:05 -0700 | [diff] [blame] | 90 | REPORTER_ASSERT(reporter, info2.testContext()); |
| 91 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 92 | REPORTER_ASSERT(reporter, info1.grContext() != info2.grContext()); |
| 93 | // The GL context should also change, but it also could get the same address. |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 94 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 95 | info1.grContext()->unref(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 99 | DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, options) { |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 100 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 101 | GrContextFactory testFactory(options); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 102 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
| 103 | ContextInfo info1 = testFactory.getContextInfo(ctxType); |
| 104 | if (!info1.grContext()) { |
| 105 | continue; |
| 106 | } |
| 107 | |
| 108 | // Ref for passing in. The API does not explicitly say that this stays alive. |
| 109 | info1.grContext()->ref(); |
| 110 | testFactory.abandonContexts(); |
| 111 | |
| 112 | // Test that creating a context in a share group with an abandoned context fails. |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 113 | ContextInfo info2 = testFactory.getSharedContextInfo(info1.grContext()); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 114 | REPORTER_ASSERT(reporter, !info2.grContext()); |
| 115 | info1.grContext()->unref(); |
| 116 | |
| 117 | // Create a new base context |
| 118 | ContextInfo info3 = testFactory.getContextInfo(ctxType); |
Brian Osman | c746bc1 | 2017-02-28 10:05:43 -0500 | [diff] [blame] | 119 | if (!info3.grContext()) { |
| 120 | // Vulkan NexusPlayer bot fails here. Sigh. |
| 121 | continue; |
| 122 | } |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 123 | |
| 124 | // Creating a context in a share group may fail, but should never crash. |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 125 | ContextInfo info4 = testFactory.getSharedContextInfo(info3.grContext()); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 126 | if (!info4.grContext()) { |
| 127 | continue; |
| 128 | } |
| 129 | REPORTER_ASSERT(reporter, info3.grContext() != info4.grContext()); |
| 130 | REPORTER_ASSERT(reporter, info3.testContext() != info4.testContext()); |
| 131 | |
| 132 | // Passing a different index should create a new (unique) context. |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 133 | ContextInfo info5 = testFactory.getSharedContextInfo(info3.grContext(), 1); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 134 | REPORTER_ASSERT(reporter, info5.grContext()); |
| 135 | REPORTER_ASSERT(reporter, info5.testContext()); |
| 136 | REPORTER_ASSERT(reporter, info5.grContext() != info4.grContext()); |
| 137 | REPORTER_ASSERT(reporter, info5.testContext() != info4.testContext()); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 141 | DEF_GPUTEST(GrContextFactory_executorAndTaskGroup, reporter, options) { |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 142 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 143 | // Verify that contexts have a task group iff we supply an executor with context options |
| 144 | GrContextOptions contextOptions = options; |
| 145 | contextOptions.fExecutor = nullptr; |
| 146 | GrContextFactory serialFactory(contextOptions); |
| 147 | |
| 148 | std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeFIFOThreadPool(1); |
| 149 | contextOptions.fExecutor = threadPool.get(); |
| 150 | GrContextFactory threadedFactory(contextOptions); |
| 151 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 152 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
| 153 | ContextInfo serialInfo = serialFactory.getContextInfo(ctxType); |
| 154 | if (GrContext* serialContext = serialInfo.grContext()) { |
| 155 | REPORTER_ASSERT(reporter, nullptr == serialContext->contextPriv().getTaskGroup()); |
| 156 | } |
| 157 | |
| 158 | ContextInfo threadedInfo = threadedFactory.getContextInfo(ctxType); |
| 159 | if (GrContext* threadedContext = threadedInfo.grContext()) { |
| 160 | REPORTER_ASSERT(reporter, nullptr != threadedContext->contextPriv().getTaskGroup()); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 165 | DEF_GPUTEST_FOR_ALL_CONTEXTS(GrContextDump, reporter, ctxInfo) { |
| 166 | // Ensure that GrContext::dump doesn't assert (which is possible, if the JSON code is wrong) |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 167 | SkString result = ctxInfo.grContext()->contextPriv().dump(); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, !result.isEmpty()); |
| 169 | } |
| 170 | |
keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 171 | #endif |