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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkTypes.h" |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkExecutor.h" |
| 11 | #include "src/gpu/GrCaps.h" |
| 12 | #include "src/gpu/GrContextPriv.h" |
| 13 | #include "tests/Test.h" |
| 14 | #include "tools/gpu/GrContextFactory.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_abandon, reporter, options) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 19 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 20 | GrContextFactory testFactory(options); |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 21 | GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i; |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 22 | ContextInfo info1 = testFactory.getContextInfo(ctxType); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 23 | if (!info1.grContext()) { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 24 | continue; |
| 25 | } |
bsalomon | 0fd3c81 | 2016-05-11 10:38:05 -0700 | [diff] [blame] | 26 | REPORTER_ASSERT(reporter, info1.testContext()); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 27 | // Ref for comparison. The API does not explicitly say that this stays alive. |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 28 | info1.grContext()->ref(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 29 | testFactory.abandonContexts(); |
| 30 | |
| 31 | // Test that we get different context after abandon. |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 32 | ContextInfo info2 = testFactory.getContextInfo(ctxType); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 33 | REPORTER_ASSERT(reporter, info2.grContext()); |
bsalomon | 0fd3c81 | 2016-05-11 10:38:05 -0700 | [diff] [blame] | 34 | REPORTER_ASSERT(reporter, info2.testContext()); |
| 35 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 36 | REPORTER_ASSERT(reporter, info1.grContext() != info2.grContext()); |
| 37 | // 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] | 38 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 39 | info1.grContext()->unref(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 43 | DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, options) { |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 44 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 45 | GrContextFactory testFactory(options); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 46 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
| 47 | ContextInfo info1 = testFactory.getContextInfo(ctxType); |
| 48 | if (!info1.grContext()) { |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | // Ref for passing in. The API does not explicitly say that this stays alive. |
| 53 | info1.grContext()->ref(); |
| 54 | testFactory.abandonContexts(); |
| 55 | |
| 56 | // 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] | 57 | ContextInfo info2 = testFactory.getSharedContextInfo(info1.grContext()); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 58 | REPORTER_ASSERT(reporter, !info2.grContext()); |
| 59 | info1.grContext()->unref(); |
| 60 | |
| 61 | // Create a new base context |
| 62 | ContextInfo info3 = testFactory.getContextInfo(ctxType); |
| 63 | |
| 64 | // 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] | 65 | ContextInfo info4 = testFactory.getSharedContextInfo(info3.grContext()); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 66 | if (!info4.grContext()) { |
| 67 | continue; |
| 68 | } |
| 69 | REPORTER_ASSERT(reporter, info3.grContext() != info4.grContext()); |
| 70 | REPORTER_ASSERT(reporter, info3.testContext() != info4.testContext()); |
| 71 | |
| 72 | // Passing a different index should create a new (unique) context. |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 73 | ContextInfo info5 = testFactory.getSharedContextInfo(info3.grContext(), 1); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 74 | REPORTER_ASSERT(reporter, info5.grContext()); |
| 75 | REPORTER_ASSERT(reporter, info5.testContext()); |
| 76 | REPORTER_ASSERT(reporter, info5.grContext() != info4.grContext()); |
| 77 | REPORTER_ASSERT(reporter, info5.testContext() != info4.testContext()); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 81 | DEF_GPUTEST(GrContextFactory_executorAndTaskGroup, reporter, options) { |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 82 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 83 | // Verify that contexts have a task group iff we supply an executor with context options |
| 84 | GrContextOptions contextOptions = options; |
| 85 | contextOptions.fExecutor = nullptr; |
| 86 | GrContextFactory serialFactory(contextOptions); |
| 87 | |
| 88 | std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeFIFOThreadPool(1); |
| 89 | contextOptions.fExecutor = threadPool.get(); |
| 90 | GrContextFactory threadedFactory(contextOptions); |
| 91 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 92 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
| 93 | ContextInfo serialInfo = serialFactory.getContextInfo(ctxType); |
| 94 | if (GrContext* serialContext = serialInfo.grContext()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 95 | REPORTER_ASSERT(reporter, nullptr == serialContext->priv().getTaskGroup()); |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | ContextInfo threadedInfo = threadedFactory.getContextInfo(ctxType); |
| 99 | if (GrContext* threadedContext = threadedInfo.grContext()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 100 | REPORTER_ASSERT(reporter, nullptr != threadedContext->priv().getTaskGroup()); |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 105 | #ifdef SK_ENABLE_DUMP_GPU |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 106 | DEF_GPUTEST_FOR_ALL_CONTEXTS(GrContextDump, reporter, ctxInfo) { |
| 107 | // Ensure that GrContext::dump doesn't assert (which is possible, if the JSON code is wrong) |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 108 | SkString result = ctxInfo.grContext()->priv().dump(); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 109 | REPORTER_ASSERT(reporter, !result.isEmpty()); |
| 110 | } |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 111 | #endif |