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" |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 13 | #include "GrCaps.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 | |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 18 | DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, /*factory*/) { |
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. |
| 21 | GrContextFactory testFactory; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 22 | // Test that if NVPR is possible, caps are in sync. |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 23 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
| 24 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
| 25 | GrContext* context = testFactory.get(ctxType, |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 26 | GrContextFactory::ContextOptions::kEnableNVPR); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 27 | if (!context) { |
| 28 | continue; |
| 29 | } |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 30 | REPORTER_ASSERT( |
| 31 | reporter, |
| 32 | context->caps()->shaderCaps()->pathRenderingSupport()); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | DEF_GPUTEST(GrContextFactory_NoPathRenderingUnlessNVPRRequested, reporter, /*factory*/) { |
| 37 | // Test that if NVPR is not requested, the context never has path rendering support. |
| 38 | |
| 39 | GrContextFactory testFactory; |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 40 | for (int i = 0; i <= GrContextFactory::kLastContextType; ++i) { |
| 41 | GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)i; |
| 42 | GrContext* context = testFactory.get(ctxType); |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 43 | if (context) { |
| 44 | REPORTER_ASSERT( |
| 45 | reporter, |
| 46 | !context->caps()->shaderCaps()->pathRenderingSupport()); |
| 47 | } |
| 48 | } |
| 49 | } |
keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 50 | |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 51 | DEF_GPUTEST(GrContextFactory_RequiredSRGBSupport, reporter, /*factory*/) { |
| 52 | // Test that if sRGB support is requested, the context always has that capability |
| 53 | // or the context creation fails. Also test that if the creation fails, a context |
| 54 | // created without that flag would not have had sRGB support. |
| 55 | GrContextFactory testFactory; |
| 56 | // Test that if sRGB is requested, caps are in sync. |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 57 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
| 58 | GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 59 | GrContext* context = |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 60 | testFactory.get(ctxType, GrContextFactory::ContextOptions::kRequireSRGBSupport); |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 61 | |
| 62 | if (context) { |
| 63 | REPORTER_ASSERT(reporter, context->caps()->srgbSupport()); |
| 64 | } else { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 65 | context = testFactory.get(ctxType); |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 66 | if (context) { |
| 67 | REPORTER_ASSERT(reporter, !context->caps()->srgbSupport()); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 73 | DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) { |
| 74 | GrContextFactory testFactory; |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 75 | for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { |
| 76 | GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i; |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 77 | ContextInfo info1 = testFactory.getContextInfo(ctxType); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 78 | if (!info1.grContext()) { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 79 | continue; |
| 80 | } |
bsalomon | 0fd3c81 | 2016-05-11 10:38:05 -0700 | [diff] [blame] | 81 | REPORTER_ASSERT(reporter, info1.testContext()); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 82 | // Ref for comparison. The API does not explicitly say that this stays alive. |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 83 | info1.grContext()->ref(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 84 | testFactory.abandonContexts(); |
| 85 | |
| 86 | // Test that we get different context after abandon. |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 87 | ContextInfo info2 = testFactory.getContextInfo(ctxType); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 88 | REPORTER_ASSERT(reporter, info2.grContext()); |
bsalomon | 0fd3c81 | 2016-05-11 10:38:05 -0700 | [diff] [blame] | 89 | REPORTER_ASSERT(reporter, info2.testContext()); |
| 90 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 91 | REPORTER_ASSERT(reporter, info1.grContext() != info2.grContext()); |
| 92 | // 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] | 93 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 94 | info1.grContext()->unref(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 98 | #endif |