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 | |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 16 | DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, /*factory*/) { |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 17 | // Test that if NVPR is requested, the context always has path rendering |
| 18 | // or the context creation fails. |
| 19 | GrContextFactory testFactory; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 20 | // Test that if NVPR is possible, caps are in sync. |
| 21 | for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
| 22 | GrContextFactory::GLContextType glCtxType = static_cast<GrContextFactory::GLContextType>(i); |
| 23 | GrContext* context = testFactory.get(glCtxType, |
| 24 | GrContextFactory::kEnableNVPR_GLContextOptions); |
| 25 | if (!context) { |
| 26 | continue; |
| 27 | } |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 28 | REPORTER_ASSERT( |
| 29 | reporter, |
| 30 | context->caps()->shaderCaps()->pathRenderingSupport()); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | DEF_GPUTEST(GrContextFactory_NoPathRenderingUnlessNVPRRequested, reporter, /*factory*/) { |
| 35 | // Test that if NVPR is not requested, the context never has path rendering support. |
| 36 | |
| 37 | GrContextFactory testFactory; |
| 38 | for (int i = 0; i <= GrContextFactory::kLastGLContextType; ++i) { |
| 39 | GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType)i; |
kkinnunen | a18a8bc | 2015-12-03 23:04:50 -0800 | [diff] [blame] | 40 | GrContext* context = testFactory.get(glCtxType); |
| 41 | if (context) { |
| 42 | REPORTER_ASSERT( |
| 43 | reporter, |
| 44 | !context->caps()->shaderCaps()->pathRenderingSupport()); |
| 45 | } |
| 46 | } |
| 47 | } |
keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 48 | |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 49 | DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) { |
| 50 | GrContextFactory testFactory; |
| 51 | for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
| 52 | GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i; |
| 53 | GrContextFactory::ContextInfo info1 = |
| 54 | testFactory.getContextInfo(glCtxType); |
| 55 | if (!info1.fGrContext) { |
| 56 | continue; |
| 57 | } |
| 58 | REPORTER_ASSERT(reporter, info1.fGLContext); |
| 59 | // Ref for comparison. The API does not explicitly say that this stays alive. |
| 60 | info1.fGrContext->ref(); |
| 61 | testFactory.abandonContexts(); |
| 62 | |
| 63 | // Test that we get different context after abandon. |
| 64 | GrContextFactory::ContextInfo info2 = |
| 65 | testFactory.getContextInfo(glCtxType); |
| 66 | REPORTER_ASSERT(reporter, info2.fGrContext); |
| 67 | REPORTER_ASSERT(reporter, info2.fGLContext); |
| 68 | REPORTER_ASSERT(reporter, info1.fGrContext != info2.fGrContext); |
| 69 | // fGLContext should also change, but it also could get the same address. |
| 70 | |
| 71 | info1.fGrContext->unref(); |
| 72 | } |
| 73 | } |
| 74 | |
keyar@chromium.org | 5bdef29 | 2012-08-14 22:02:48 +0000 | [diff] [blame] | 75 | #endif |