blob: 9b600fa8a407b2045e7eb9430cf9a66c4931563a [file] [log] [blame]
keyar@chromium.org5bdef292012-08-14 22:02:48 +00001/*
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
halcanary96fcdcc2015-08-27 07:41:13 -07008#include "SkTypes.h"
9
keyar@chromium.org5bdef292012-08-14 22:02:48 +000010#if SK_SUPPORT_GPU
keyar@chromium.org5bdef292012-08-14 22:02:48 +000011
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000012#include "GrContextFactory.h"
kkinnunena18a8bc2015-12-03 23:04:50 -080013#include "GrCaps.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000014#include "Test.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000015
bsalomonf2f1c172016-04-05 12:59:06 -070016using namespace sk_gpu_test;
bsalomon3724e572016-03-30 18:56:19 -070017
kkinnunen5219fd92015-12-10 06:28:13 -080018DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, /*factory*/) {
kkinnunena18a8bc2015-12-03 23:04:50 -080019 // Test that if NVPR is requested, the context always has path rendering
20 // or the context creation fails.
21 GrContextFactory testFactory;
kkinnunen3e980c32015-12-23 01:33:00 -080022 // Test that if NVPR is possible, caps are in sync.
bsalomon85b4b532016-04-05 11:06:27 -070023 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
24 GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
25 GrContext* context = testFactory.get(ctxType,
csmartdalton6270e552016-09-13 10:41:49 -070026 GrContextFactory::ContextOptions::kEnableNVPR);
kkinnunen3e980c32015-12-23 01:33:00 -080027 if (!context) {
28 continue;
29 }
kkinnunena18a8bc2015-12-03 23:04:50 -080030 REPORTER_ASSERT(
31 reporter,
32 context->caps()->shaderCaps()->pathRenderingSupport());
33 }
34}
35
36DEF_GPUTEST(GrContextFactory_NoPathRenderingUnlessNVPRRequested, reporter, /*factory*/) {
37 // Test that if NVPR is not requested, the context never has path rendering support.
38
39 GrContextFactory testFactory;
bsalomon85b4b532016-04-05 11:06:27 -070040 for (int i = 0; i <= GrContextFactory::kLastContextType; ++i) {
41 GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)i;
42 GrContext* context = testFactory.get(ctxType);
kkinnunena18a8bc2015-12-03 23:04:50 -080043 if (context) {
44 REPORTER_ASSERT(
45 reporter,
46 !context->caps()->shaderCaps()->pathRenderingSupport());
47 }
48 }
49}
keyar@chromium.org5bdef292012-08-14 22:02:48 +000050
brianosman61d3b082016-03-30 11:19:36 -070051DEF_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.
bsalomon85b4b532016-04-05 11:06:27 -070057 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
58 GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
brianosman61d3b082016-03-30 11:19:36 -070059 GrContext* context =
csmartdalton6270e552016-09-13 10:41:49 -070060 testFactory.get(ctxType, GrContextFactory::ContextOptions::kRequireSRGBSupport);
brianosman61d3b082016-03-30 11:19:36 -070061
62 if (context) {
63 REPORTER_ASSERT(reporter, context->caps()->srgbSupport());
64 } else {
bsalomon85b4b532016-04-05 11:06:27 -070065 context = testFactory.get(ctxType);
brianosman61d3b082016-03-30 11:19:36 -070066 if (context) {
67 REPORTER_ASSERT(reporter, !context->caps()->srgbSupport());
68 }
69 }
70 }
71}
72
kkinnunen34058002016-01-06 23:49:30 -080073DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) {
74 GrContextFactory testFactory;
bsalomon85b4b532016-04-05 11:06:27 -070075 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
76 GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i;
bsalomonf2f1c172016-04-05 12:59:06 -070077 ContextInfo info1 = testFactory.getContextInfo(ctxType);
bsalomon8b7451a2016-05-11 06:33:06 -070078 if (!info1.grContext()) {
kkinnunen34058002016-01-06 23:49:30 -080079 continue;
80 }
bsalomon0fd3c812016-05-11 10:38:05 -070081 REPORTER_ASSERT(reporter, info1.testContext());
kkinnunen34058002016-01-06 23:49:30 -080082 // Ref for comparison. The API does not explicitly say that this stays alive.
bsalomon8b7451a2016-05-11 06:33:06 -070083 info1.grContext()->ref();
kkinnunen34058002016-01-06 23:49:30 -080084 testFactory.abandonContexts();
85
86 // Test that we get different context after abandon.
bsalomonf2f1c172016-04-05 12:59:06 -070087 ContextInfo info2 = testFactory.getContextInfo(ctxType);
bsalomon8b7451a2016-05-11 06:33:06 -070088 REPORTER_ASSERT(reporter, info2.grContext());
bsalomon0fd3c812016-05-11 10:38:05 -070089 REPORTER_ASSERT(reporter, info2.testContext());
90
bsalomon8b7451a2016-05-11 06:33:06 -070091 REPORTER_ASSERT(reporter, info1.grContext() != info2.grContext());
92 // The GL context should also change, but it also could get the same address.
kkinnunen34058002016-01-06 23:49:30 -080093
bsalomon8b7451a2016-05-11 06:33:06 -070094 info1.grContext()->unref();
kkinnunen34058002016-01-06 23:49:30 -080095 }
96}
97
keyar@chromium.org5bdef292012-08-14 22:02:48 +000098#endif