blob: b05f2e29ce4b2589f7678bf9f2bdb788c3773e75 [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
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000010#include "GrContextFactory.h"
Brian Osman51279982017-08-23 10:12:00 -040011#include "GrContextPriv.h"
kkinnunena18a8bc2015-12-03 23:04:50 -080012#include "GrCaps.h"
Brian Osman51279982017-08-23 10:12:00 -040013#include "SkExecutor.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
Brian Salomondcfca432017-11-15 15:48:03 -050018DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, options) {
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.
bsalomon85b4b532016-04-05 11:06:27 -070021 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
Brian Salomondcfca432017-11-15 15:48:03 -050022 GrContextFactory testFactory(options);
23 // Test that if NVPR is possible, caps are in sync.
bsalomon85b4b532016-04-05 11:06:27 -070024 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 }
Brian Salomonc7fe0f72018-05-11 10:14:21 -040030 REPORTER_ASSERT(reporter,
31 context->contextPriv().caps()->shaderCaps()->pathRenderingSupport());
kkinnunena18a8bc2015-12-03 23:04:50 -080032 }
33}
34
Brian Salomondcfca432017-11-15 15:48:03 -050035DEF_GPUTEST(GrContextFactory_NoPathRenderingIfNVPRDisabled, reporter, options) {
csmartdaltone812d492017-02-21 12:36:05 -070036 // Test that if NVPR is explicitly disabled, the context has no path rendering support.
kkinnunena18a8bc2015-12-03 23:04:50 -080037
bsalomon85b4b532016-04-05 11:06:27 -070038 for (int i = 0; i <= GrContextFactory::kLastContextType; ++i) {
Brian Salomondcfca432017-11-15 15:48:03 -050039 GrContextFactory testFactory(options);
bsalomon85b4b532016-04-05 11:06:27 -070040 GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)i;
csmartdaltone812d492017-02-21 12:36:05 -070041 GrContext* context =
42 testFactory.get(ctxType, GrContextFactory::ContextOverrides::kDisableNVPR);
kkinnunena18a8bc2015-12-03 23:04:50 -080043 if (context) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -040044 REPORTER_ASSERT(reporter,
45 !context->contextPriv().caps()->shaderCaps()->pathRenderingSupport());
kkinnunena18a8bc2015-12-03 23:04:50 -080046 }
47 }
48}
keyar@chromium.org5bdef292012-08-14 22:02:48 +000049
Brian Salomondcfca432017-11-15 15:48:03 -050050DEF_GPUTEST(GrContextFactory_abandon, reporter, options) {
bsalomon85b4b532016-04-05 11:06:27 -070051 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
Brian Salomondcfca432017-11-15 15:48:03 -050052 GrContextFactory testFactory(options);
bsalomon85b4b532016-04-05 11:06:27 -070053 GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i;
bsalomonf2f1c172016-04-05 12:59:06 -070054 ContextInfo info1 = testFactory.getContextInfo(ctxType);
bsalomon8b7451a2016-05-11 06:33:06 -070055 if (!info1.grContext()) {
kkinnunen34058002016-01-06 23:49:30 -080056 continue;
57 }
bsalomon0fd3c812016-05-11 10:38:05 -070058 REPORTER_ASSERT(reporter, info1.testContext());
kkinnunen34058002016-01-06 23:49:30 -080059 // Ref for comparison. The API does not explicitly say that this stays alive.
bsalomon8b7451a2016-05-11 06:33:06 -070060 info1.grContext()->ref();
kkinnunen34058002016-01-06 23:49:30 -080061 testFactory.abandonContexts();
62
63 // Test that we get different context after abandon.
bsalomonf2f1c172016-04-05 12:59:06 -070064 ContextInfo info2 = testFactory.getContextInfo(ctxType);
bsalomon8b7451a2016-05-11 06:33:06 -070065 REPORTER_ASSERT(reporter, info2.grContext());
bsalomon0fd3c812016-05-11 10:38:05 -070066 REPORTER_ASSERT(reporter, info2.testContext());
67
bsalomon8b7451a2016-05-11 06:33:06 -070068 REPORTER_ASSERT(reporter, info1.grContext() != info2.grContext());
69 // The GL context should also change, but it also could get the same address.
kkinnunen34058002016-01-06 23:49:30 -080070
bsalomon8b7451a2016-05-11 06:33:06 -070071 info1.grContext()->unref();
kkinnunen34058002016-01-06 23:49:30 -080072 }
73}
74
Brian Salomondcfca432017-11-15 15:48:03 -050075DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, options) {
Brian Osman60c774d2017-02-21 16:58:08 -050076 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
Brian Salomondcfca432017-11-15 15:48:03 -050077 GrContextFactory testFactory(options);
Brian Osman60c774d2017-02-21 16:58:08 -050078 GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
79 ContextInfo info1 = testFactory.getContextInfo(ctxType);
80 if (!info1.grContext()) {
81 continue;
82 }
83
84 // Ref for passing in. The API does not explicitly say that this stays alive.
85 info1.grContext()->ref();
86 testFactory.abandonContexts();
87
88 // Test that creating a context in a share group with an abandoned context fails.
Brian Osman9eac2ea2017-02-24 14:51:44 -050089 ContextInfo info2 = testFactory.getSharedContextInfo(info1.grContext());
Brian Osman60c774d2017-02-21 16:58:08 -050090 REPORTER_ASSERT(reporter, !info2.grContext());
91 info1.grContext()->unref();
92
93 // Create a new base context
94 ContextInfo info3 = testFactory.getContextInfo(ctxType);
Brian Osmanc746bc12017-02-28 10:05:43 -050095 if (!info3.grContext()) {
96 // Vulkan NexusPlayer bot fails here. Sigh.
97 continue;
98 }
Brian Osman60c774d2017-02-21 16:58:08 -050099
100 // Creating a context in a share group may fail, but should never crash.
Brian Osman9eac2ea2017-02-24 14:51:44 -0500101 ContextInfo info4 = testFactory.getSharedContextInfo(info3.grContext());
Brian Osman60c774d2017-02-21 16:58:08 -0500102 if (!info4.grContext()) {
103 continue;
104 }
105 REPORTER_ASSERT(reporter, info3.grContext() != info4.grContext());
106 REPORTER_ASSERT(reporter, info3.testContext() != info4.testContext());
107
108 // Passing a different index should create a new (unique) context.
Brian Osman9eac2ea2017-02-24 14:51:44 -0500109 ContextInfo info5 = testFactory.getSharedContextInfo(info3.grContext(), 1);
Brian Osman60c774d2017-02-21 16:58:08 -0500110 REPORTER_ASSERT(reporter, info5.grContext());
111 REPORTER_ASSERT(reporter, info5.testContext());
112 REPORTER_ASSERT(reporter, info5.grContext() != info4.grContext());
113 REPORTER_ASSERT(reporter, info5.testContext() != info4.testContext());
Brian Osman60c774d2017-02-21 16:58:08 -0500114 }
115}
116
Brian Salomondcfca432017-11-15 15:48:03 -0500117DEF_GPUTEST(GrContextFactory_executorAndTaskGroup, reporter, options) {
Brian Osman51279982017-08-23 10:12:00 -0400118 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
Brian Salomondcfca432017-11-15 15:48:03 -0500119 // Verify that contexts have a task group iff we supply an executor with context options
120 GrContextOptions contextOptions = options;
121 contextOptions.fExecutor = nullptr;
122 GrContextFactory serialFactory(contextOptions);
123
124 std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeFIFOThreadPool(1);
125 contextOptions.fExecutor = threadPool.get();
126 GrContextFactory threadedFactory(contextOptions);
127
Brian Osman51279982017-08-23 10:12:00 -0400128 GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
129 ContextInfo serialInfo = serialFactory.getContextInfo(ctxType);
130 if (GrContext* serialContext = serialInfo.grContext()) {
131 REPORTER_ASSERT(reporter, nullptr == serialContext->contextPriv().getTaskGroup());
132 }
133
134 ContextInfo threadedInfo = threadedFactory.getContextInfo(ctxType);
135 if (GrContext* threadedContext = threadedInfo.grContext()) {
136 REPORTER_ASSERT(reporter, nullptr != threadedContext->contextPriv().getTaskGroup());
137 }
138 }
139}
140
Brian Osman71a18892017-08-10 10:23:25 -0400141DEF_GPUTEST_FOR_ALL_CONTEXTS(GrContextDump, reporter, ctxInfo) {
142 // Ensure that GrContext::dump doesn't assert (which is possible, if the JSON code is wrong)
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500143 SkString result = ctxInfo.grContext()->contextPriv().dump();
Brian Osman71a18892017-08-10 10:23:25 -0400144 REPORTER_ASSERT(reporter, !result.isEmpty());
145}