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 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 10 | #include "GrContextFactory.h" |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 11 | #include "GrContextPriv.h" |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 12 | #include "GrCaps.h" |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 13 | #include "SkExecutor.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 14 | #include "Test.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 15 | |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 16 | using namespace sk_gpu_test; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 17 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 18 | DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, options) { |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 19 | // Test that if NVPR is requested, the context always has path rendering |
| 20 | // or the context creation fails. |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 21 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 22 | GrContextFactory testFactory(options); |
| 23 | // Test that if NVPR is possible, caps are in sync. |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 24 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
| 25 | GrContext* context = testFactory.get(ctxType, |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 26 | GrContextFactory::ContextOverrides::kRequireNVPRSupport); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 27 | if (!context) { |
| 28 | continue; |
| 29 | } |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 30 | REPORTER_ASSERT(reporter, |
| 31 | context->contextPriv().caps()->shaderCaps()->pathRenderingSupport()); |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 32 | } |
| 33 | } |
| 34 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 35 | DEF_GPUTEST(GrContextFactory_NoPathRenderingIfNVPRDisabled, reporter, options) { |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 36 | // 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] | 37 | |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 38 | for (int i = 0; i <= GrContextFactory::kLastContextType; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 39 | GrContextFactory testFactory(options); |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 40 | GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)i; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 41 | GrContext* context = |
| 42 | testFactory.get(ctxType, GrContextFactory::ContextOverrides::kDisableNVPR); |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 43 | if (context) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, |
| 45 | !context->contextPriv().caps()->shaderCaps()->pathRenderingSupport()); |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |
keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 49 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 50 | DEF_GPUTEST(GrContextFactory_abandon, reporter, options) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 51 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 52 | GrContextFactory testFactory(options); |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 53 | GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i; |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 54 | ContextInfo info1 = testFactory.getContextInfo(ctxType); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 55 | if (!info1.grContext()) { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 56 | continue; |
| 57 | } |
bsalomon | 0fd3c81 | 2016-05-11 10:38:05 -0700 | [diff] [blame] | 58 | REPORTER_ASSERT(reporter, info1.testContext()); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 59 | // Ref for comparison. The API does not explicitly say that this stays alive. |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 60 | info1.grContext()->ref(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 61 | testFactory.abandonContexts(); |
| 62 | |
| 63 | // Test that we get different context after abandon. |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 64 | ContextInfo info2 = testFactory.getContextInfo(ctxType); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 65 | REPORTER_ASSERT(reporter, info2.grContext()); |
bsalomon | 0fd3c81 | 2016-05-11 10:38:05 -0700 | [diff] [blame] | 66 | REPORTER_ASSERT(reporter, info2.testContext()); |
| 67 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 68 | REPORTER_ASSERT(reporter, info1.grContext() != info2.grContext()); |
| 69 | // 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] | 70 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 71 | info1.grContext()->unref(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 75 | DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, options) { |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 76 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 77 | GrContextFactory testFactory(options); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 78 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
| 79 | ContextInfo info1 = testFactory.getContextInfo(ctxType); |
| 80 | if (!info1.grContext()) { |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | // Ref for passing in. The API does not explicitly say that this stays alive. |
| 85 | info1.grContext()->ref(); |
| 86 | testFactory.abandonContexts(); |
| 87 | |
| 88 | // 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] | 89 | ContextInfo info2 = testFactory.getSharedContextInfo(info1.grContext()); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 90 | REPORTER_ASSERT(reporter, !info2.grContext()); |
| 91 | info1.grContext()->unref(); |
| 92 | |
| 93 | // Create a new base context |
| 94 | ContextInfo info3 = testFactory.getContextInfo(ctxType); |
Brian Osman | c746bc1 | 2017-02-28 10:05:43 -0500 | [diff] [blame] | 95 | if (!info3.grContext()) { |
| 96 | // Vulkan NexusPlayer bot fails here. Sigh. |
| 97 | continue; |
| 98 | } |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 99 | |
| 100 | // 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] | 101 | ContextInfo info4 = testFactory.getSharedContextInfo(info3.grContext()); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 102 | if (!info4.grContext()) { |
| 103 | continue; |
| 104 | } |
| 105 | REPORTER_ASSERT(reporter, info3.grContext() != info4.grContext()); |
| 106 | REPORTER_ASSERT(reporter, info3.testContext() != info4.testContext()); |
| 107 | |
| 108 | // Passing a different index should create a new (unique) context. |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 109 | ContextInfo info5 = testFactory.getSharedContextInfo(info3.grContext(), 1); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 110 | REPORTER_ASSERT(reporter, info5.grContext()); |
| 111 | REPORTER_ASSERT(reporter, info5.testContext()); |
| 112 | REPORTER_ASSERT(reporter, info5.grContext() != info4.grContext()); |
| 113 | REPORTER_ASSERT(reporter, info5.testContext() != info4.testContext()); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 117 | DEF_GPUTEST(GrContextFactory_executorAndTaskGroup, reporter, options) { |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 118 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 119 | // Verify that contexts have a task group iff we supply an executor with context options |
| 120 | GrContextOptions contextOptions = options; |
| 121 | contextOptions.fExecutor = nullptr; |
| 122 | GrContextFactory serialFactory(contextOptions); |
| 123 | |
| 124 | std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeFIFOThreadPool(1); |
| 125 | contextOptions.fExecutor = threadPool.get(); |
| 126 | GrContextFactory threadedFactory(contextOptions); |
| 127 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 128 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
| 129 | ContextInfo serialInfo = serialFactory.getContextInfo(ctxType); |
| 130 | if (GrContext* serialContext = serialInfo.grContext()) { |
| 131 | REPORTER_ASSERT(reporter, nullptr == serialContext->contextPriv().getTaskGroup()); |
| 132 | } |
| 133 | |
| 134 | ContextInfo threadedInfo = threadedFactory.getContextInfo(ctxType); |
| 135 | if (GrContext* threadedContext = threadedInfo.grContext()) { |
| 136 | REPORTER_ASSERT(reporter, nullptr != threadedContext->contextPriv().getTaskGroup()); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 141 | DEF_GPUTEST_FOR_ALL_CONTEXTS(GrContextDump, reporter, ctxInfo) { |
| 142 | // 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] | 143 | SkString result = ctxInfo.grContext()->contextPriv().dump(); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, !result.isEmpty()); |
| 145 | } |