2012-08-14 22:02:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2015-08-27 14:41:13 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkExecutor.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrCaps.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2012-08-14 22:02:48 +00:00
|
|
|
|
2016-04-05 19:59:06 +00:00
|
|
|
using namespace sk_gpu_test;
|
2016-03-31 01:56:19 +00:00
|
|
|
|
2017-11-15 20:48:03 +00:00
|
|
|
DEF_GPUTEST(GrContextFactory_abandon, reporter, options) {
|
2016-04-05 18:06:27 +00:00
|
|
|
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
|
2017-11-15 20:48:03 +00:00
|
|
|
GrContextFactory testFactory(options);
|
2016-04-05 18:06:27 +00:00
|
|
|
GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i;
|
2016-04-05 19:59:06 +00:00
|
|
|
ContextInfo info1 = testFactory.getContextInfo(ctxType);
|
2020-07-06 14:56:46 +00:00
|
|
|
if (!info1.directContext()) {
|
2016-01-07 07:49:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-05-11 17:38:05 +00:00
|
|
|
REPORTER_ASSERT(reporter, info1.testContext());
|
2016-01-07 07:49:30 +00:00
|
|
|
// Ref for comparison. The API does not explicitly say that this stays alive.
|
2020-07-06 14:56:46 +00:00
|
|
|
info1.directContext()->ref();
|
2016-01-07 07:49:30 +00:00
|
|
|
testFactory.abandonContexts();
|
|
|
|
|
|
|
|
// Test that we get different context after abandon.
|
2016-04-05 19:59:06 +00:00
|
|
|
ContextInfo info2 = testFactory.getContextInfo(ctxType);
|
2020-07-06 14:56:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, info2.directContext());
|
2016-05-11 17:38:05 +00:00
|
|
|
REPORTER_ASSERT(reporter, info2.testContext());
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, info1.directContext() != info2.directContext());
|
2016-05-11 13:33:06 +00:00
|
|
|
// The GL context should also change, but it also could get the same address.
|
2016-01-07 07:49:30 +00:00
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
info1.directContext()->unref();
|
2016-01-07 07:49:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 20:48:03 +00:00
|
|
|
DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, options) {
|
2017-02-21 21:58:08 +00:00
|
|
|
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
|
2017-11-15 20:48:03 +00:00
|
|
|
GrContextFactory testFactory(options);
|
2017-02-21 21:58:08 +00:00
|
|
|
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
|
|
|
|
ContextInfo info1 = testFactory.getContextInfo(ctxType);
|
2020-07-06 14:56:46 +00:00
|
|
|
if (!info1.directContext()) {
|
2017-02-21 21:58:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ref for passing in. The API does not explicitly say that this stays alive.
|
2020-07-06 14:56:46 +00:00
|
|
|
info1.directContext()->ref();
|
2017-02-21 21:58:08 +00:00
|
|
|
testFactory.abandonContexts();
|
|
|
|
|
|
|
|
// Test that creating a context in a share group with an abandoned context fails.
|
2020-07-01 20:09:43 +00:00
|
|
|
ContextInfo info2 = testFactory.getSharedContextInfo(info1.directContext());
|
2020-07-06 14:56:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, !info2.directContext());
|
|
|
|
info1.directContext()->unref();
|
2017-02-21 21:58:08 +00:00
|
|
|
|
|
|
|
// Create a new base context
|
|
|
|
ContextInfo info3 = testFactory.getContextInfo(ctxType);
|
|
|
|
|
|
|
|
// Creating a context in a share group may fail, but should never crash.
|
2020-07-01 20:09:43 +00:00
|
|
|
ContextInfo info4 = testFactory.getSharedContextInfo(info3.directContext());
|
2020-07-06 14:56:46 +00:00
|
|
|
if (!info4.directContext()) {
|
2017-02-21 21:58:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-07-06 14:56:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, info3.directContext() != info4.directContext());
|
2017-02-21 21:58:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, info3.testContext() != info4.testContext());
|
|
|
|
|
|
|
|
// Passing a different index should create a new (unique) context.
|
2020-07-01 20:09:43 +00:00
|
|
|
ContextInfo info5 = testFactory.getSharedContextInfo(info3.directContext(), 1);
|
2020-07-06 14:56:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, info5.directContext());
|
2017-02-21 21:58:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, info5.testContext());
|
2020-07-06 14:56:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, info5.directContext() != info4.directContext());
|
2017-02-21 21:58:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, info5.testContext() != info4.testContext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 20:48:03 +00:00
|
|
|
DEF_GPUTEST(GrContextFactory_executorAndTaskGroup, reporter, options) {
|
|
|
|
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
|
|
|
|
// Verify that contexts have a task group iff we supply an executor with context options
|
|
|
|
GrContextOptions contextOptions = options;
|
|
|
|
contextOptions.fExecutor = nullptr;
|
|
|
|
GrContextFactory serialFactory(contextOptions);
|
2017-08-23 14:12:00 +00:00
|
|
|
|
2017-11-15 20:48:03 +00:00
|
|
|
std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeFIFOThreadPool(1);
|
|
|
|
contextOptions.fExecutor = threadPool.get();
|
|
|
|
GrContextFactory threadedFactory(contextOptions);
|
2017-08-23 14:12:00 +00:00
|
|
|
|
|
|
|
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
|
|
|
|
ContextInfo serialInfo = serialFactory.getContextInfo(ctxType);
|
2020-07-06 14:56:46 +00:00
|
|
|
if (auto serialContext = serialInfo.directContext()) {
|
2019-02-04 18:26:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == serialContext->priv().getTaskGroup());
|
2017-08-23 14:12:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ContextInfo threadedInfo = threadedFactory.getContextInfo(ctxType);
|
2020-07-06 14:56:46 +00:00
|
|
|
if (auto threadedContext = threadedInfo.directContext()) {
|
2019-02-04 18:26:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr != threadedContext->priv().getTaskGroup());
|
2017-08-23 14:12:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 16:52:50 +00:00
|
|
|
#ifdef SK_ENABLE_DUMP_GPU
|
2017-08-10 14:23:25 +00:00
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(GrContextDump, reporter, ctxInfo) {
|
2020-07-23 17:54:35 +00:00
|
|
|
// Ensure that GrDirectContext::dump doesn't assert (which is possible, if the JSON code
|
|
|
|
// is wrong)
|
2020-07-06 14:56:46 +00:00
|
|
|
SkString result = ctxInfo.directContext()->dump();
|
2017-08-10 14:23:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !result.isEmpty());
|
|
|
|
}
|
2018-10-04 16:52:50 +00:00
|
|
|
#endif
|