blob: 0bc2c541e03fdb6f027b85435a8dca12991f31b5 [file] [log] [blame]
Robert Phillips091694f2021-09-30 11:41:16 -04001/*
2 * Copyright 2021 Google LLC
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
8#include "tools/graphite/ContextFactory.h"
9
10#include "experimental/graphite/include/Context.h"
11
12#ifdef SK_METAL
13#include "tools/graphite/mtl/GraphiteMtlTestContext.h"
14#endif
15
16namespace sk_graphite_test {
17
18 std::tuple<GraphiteTestContext*, sk_sp<skgpu::Context>> ContextFactory::getContextInfo(
19 ContextType type) {
20
21 for (ContextInfo& c : fContexts) {
22 if (c.type() == type) {
23 return { c.testContext(), c.refContext() };
24 }
25 }
26
27 std::unique_ptr<GraphiteTestContext> testCtx;
28
29 switch (type) {
30 case ContextType::kMetal: {
31#ifdef SK_METAL
32 testCtx = mtl::TestContext::Make();
33#endif
34 } break;
35
36 default:
37 break;
38 }
39
40 if (!testCtx) {
41 return {};
42 }
43
44 sk_sp<skgpu::Context> context = testCtx->makeContext();
45 if (!context) {
46 return {};
47 }
48
49 fContexts.push_back({ type, std::move(testCtx), std::move(context) });
50
51 return { fContexts.back().testContext(), fContexts.back().refContext() };
52}
53
54} // namespace sk_graphite_test