2021-09-30 15:41:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tools/graphite/ContextFactory.h"
|
|
|
|
|
2022-04-11 15:48:46 +00:00
|
|
|
#include "include/gpu/graphite/Context.h"
|
2021-09-30 15:41:16 +00:00
|
|
|
|
|
|
|
#ifdef SK_METAL
|
|
|
|
#include "tools/graphite/mtl/GraphiteMtlTestContext.h"
|
|
|
|
#endif
|
|
|
|
|
2021-10-11 15:28:21 +00:00
|
|
|
namespace skiatest::graphite {
|
2021-09-30 15:41:16 +00:00
|
|
|
|
2021-10-13 14:37:36 +00:00
|
|
|
ContextFactory::ContextInfo::ContextInfo(ContextInfo&& other)
|
|
|
|
: fType(other.fType)
|
|
|
|
, fTestContext(std::move(other.fTestContext))
|
|
|
|
, fContext(std::move(other.fContext)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ContextFactory::ContextInfo::ContextInfo(ContextFactory::ContextType type,
|
|
|
|
std::unique_ptr<GraphiteTestContext> testContext,
|
2022-04-07 20:08:04 +00:00
|
|
|
std::unique_ptr<skgpu::graphite::Context> context)
|
2021-10-13 14:37:36 +00:00
|
|
|
: fType(type)
|
|
|
|
, fTestContext(std::move(testContext))
|
|
|
|
, fContext(std::move(context)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2022-04-07 20:08:04 +00:00
|
|
|
std::tuple<GraphiteTestContext*, skgpu::graphite::Context*> ContextFactory::getContextInfo(
|
2021-09-30 15:41:16 +00:00
|
|
|
ContextType type) {
|
|
|
|
|
|
|
|
for (ContextInfo& c : fContexts) {
|
|
|
|
if (c.type() == type) {
|
2022-02-03 16:12:45 +00:00
|
|
|
return { c.testContext(), c.context() };
|
2021-09-30 15:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<GraphiteTestContext> testCtx;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ContextType::kMetal: {
|
|
|
|
#ifdef SK_METAL
|
2022-04-06 21:16:56 +00:00
|
|
|
testCtx = graphite::MtlTestContext::Make();
|
2021-09-30 15:41:16 +00:00
|
|
|
#endif
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!testCtx) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-04-07 20:08:04 +00:00
|
|
|
std::unique_ptr<skgpu::graphite::Context> context = testCtx->makeContext();
|
2021-09-30 15:41:16 +00:00
|
|
|
if (!context) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
fContexts.push_back({ type, std::move(testCtx), std::move(context) });
|
|
|
|
|
2022-02-03 16:12:45 +00:00
|
|
|
return { fContexts.back().testContext(), fContexts.back().context() };
|
2021-09-30 15:41:16 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 15:28:21 +00:00
|
|
|
} // namespace skiatest::graphite
|