blob: 098b2d61a9d8e2aa8a8904d491358989a77ec5a1 [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,
csmartdaltone812d492017-02-21 12:36:05 -070026 GrContextFactory::ContextOverrides::kRequireNVPRSupport);
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
csmartdaltone812d492017-02-21 12:36:05 -070036DEF_GPUTEST(GrContextFactory_NoPathRenderingIfNVPRDisabled, reporter, /*factory*/) {
37 // Test that if NVPR is explicitly disabled, the context has no path rendering support.
kkinnunena18a8bc2015-12-03 23:04:50 -080038
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;
csmartdaltone812d492017-02-21 12:36:05 -070042 GrContext* context =
43 testFactory.get(ctxType, GrContextFactory::ContextOverrides::kDisableNVPR);
kkinnunena18a8bc2015-12-03 23:04:50 -080044 if (context) {
45 REPORTER_ASSERT(
46 reporter,
47 !context->caps()->shaderCaps()->pathRenderingSupport());
48 }
49 }
50}
keyar@chromium.org5bdef292012-08-14 22:02:48 +000051
brianosman61d3b082016-03-30 11:19:36 -070052DEF_GPUTEST(GrContextFactory_RequiredSRGBSupport, reporter, /*factory*/) {
53 // Test that if sRGB support is requested, the context always has that capability
54 // or the context creation fails. Also test that if the creation fails, a context
55 // created without that flag would not have had sRGB support.
56 GrContextFactory testFactory;
57 // Test that if sRGB is requested, caps are in sync.
bsalomon85b4b532016-04-05 11:06:27 -070058 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
59 GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
brianosman61d3b082016-03-30 11:19:36 -070060 GrContext* context =
csmartdaltone812d492017-02-21 12:36:05 -070061 testFactory.get(ctxType, GrContextFactory::ContextOverrides::kRequireSRGBSupport);
brianosman61d3b082016-03-30 11:19:36 -070062
63 if (context) {
64 REPORTER_ASSERT(reporter, context->caps()->srgbSupport());
65 } else {
bsalomon85b4b532016-04-05 11:06:27 -070066 context = testFactory.get(ctxType);
brianosman61d3b082016-03-30 11:19:36 -070067 if (context) {
68 REPORTER_ASSERT(reporter, !context->caps()->srgbSupport());
69 }
70 }
71 }
72}
73
kkinnunen34058002016-01-06 23:49:30 -080074DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) {
75 GrContextFactory testFactory;
bsalomon85b4b532016-04-05 11:06:27 -070076 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
77 GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i;
bsalomonf2f1c172016-04-05 12:59:06 -070078 ContextInfo info1 = testFactory.getContextInfo(ctxType);
bsalomon8b7451a2016-05-11 06:33:06 -070079 if (!info1.grContext()) {
kkinnunen34058002016-01-06 23:49:30 -080080 continue;
81 }
bsalomon0fd3c812016-05-11 10:38:05 -070082 REPORTER_ASSERT(reporter, info1.testContext());
kkinnunen34058002016-01-06 23:49:30 -080083 // Ref for comparison. The API does not explicitly say that this stays alive.
bsalomon8b7451a2016-05-11 06:33:06 -070084 info1.grContext()->ref();
kkinnunen34058002016-01-06 23:49:30 -080085 testFactory.abandonContexts();
86
87 // Test that we get different context after abandon.
bsalomonf2f1c172016-04-05 12:59:06 -070088 ContextInfo info2 = testFactory.getContextInfo(ctxType);
bsalomon8b7451a2016-05-11 06:33:06 -070089 REPORTER_ASSERT(reporter, info2.grContext());
bsalomon0fd3c812016-05-11 10:38:05 -070090 REPORTER_ASSERT(reporter, info2.testContext());
91
bsalomon8b7451a2016-05-11 06:33:06 -070092 REPORTER_ASSERT(reporter, info1.grContext() != info2.grContext());
93 // The GL context should also change, but it also could get the same address.
kkinnunen34058002016-01-06 23:49:30 -080094
bsalomon8b7451a2016-05-11 06:33:06 -070095 info1.grContext()->unref();
kkinnunen34058002016-01-06 23:49:30 -080096 }
97}
98
Brian Osman60c774d2017-02-21 16:58:08 -050099DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, /*factory*/) {
100 GrContextFactory testFactory;
Brian Osman60c774d2017-02-21 16:58:08 -0500101
102 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
103 GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
104 ContextInfo info1 = testFactory.getContextInfo(ctxType);
105 if (!info1.grContext()) {
106 continue;
107 }
108
109 // Ref for passing in. The API does not explicitly say that this stays alive.
110 info1.grContext()->ref();
111 testFactory.abandonContexts();
112
113 // Test that creating a context in a share group with an abandoned context fails.
Brian Osman9eac2ea2017-02-24 14:51:44 -0500114 ContextInfo info2 = testFactory.getSharedContextInfo(info1.grContext());
Brian Osman60c774d2017-02-21 16:58:08 -0500115 REPORTER_ASSERT(reporter, !info2.grContext());
116 info1.grContext()->unref();
117
118 // Create a new base context
119 ContextInfo info3 = testFactory.getContextInfo(ctxType);
Brian Osmanc746bc12017-02-28 10:05:43 -0500120 if (!info3.grContext()) {
121 // Vulkan NexusPlayer bot fails here. Sigh.
122 continue;
123 }
Brian Osman60c774d2017-02-21 16:58:08 -0500124
125 // Creating a context in a share group may fail, but should never crash.
Brian Osman9eac2ea2017-02-24 14:51:44 -0500126 ContextInfo info4 = testFactory.getSharedContextInfo(info3.grContext());
Brian Osman60c774d2017-02-21 16:58:08 -0500127 if (!info4.grContext()) {
128 continue;
129 }
130 REPORTER_ASSERT(reporter, info3.grContext() != info4.grContext());
131 REPORTER_ASSERT(reporter, info3.testContext() != info4.testContext());
132
133 // Passing a different index should create a new (unique) context.
Brian Osman9eac2ea2017-02-24 14:51:44 -0500134 ContextInfo info5 = testFactory.getSharedContextInfo(info3.grContext(), 1);
Brian Osman60c774d2017-02-21 16:58:08 -0500135 REPORTER_ASSERT(reporter, info5.grContext());
136 REPORTER_ASSERT(reporter, info5.testContext());
137 REPORTER_ASSERT(reporter, info5.grContext() != info4.grContext());
138 REPORTER_ASSERT(reporter, info5.testContext() != info4.testContext());
Brian Osman60c774d2017-02-21 16:58:08 -0500139 }
140}
141
Brian Osman71a18892017-08-10 10:23:25 -0400142DEF_GPUTEST_FOR_ALL_CONTEXTS(GrContextDump, reporter, ctxInfo) {
143 // Ensure that GrContext::dump doesn't assert (which is possible, if the JSON code is wrong)
144 SkString result = ctxInfo.grContext()->dump();
145 REPORTER_ASSERT(reporter, !result.isEmpty());
146}
147
keyar@chromium.org5bdef292012-08-14 22:02:48 +0000148#endif