blob: 46f0121d39004d7d1fd880fd153b51f8e7737fce [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#ifndef sk_graphite_test_ContextFactory_DEFINED
9#define sk_graphite_test_ContextFactory_DEFINED
10
11#include <vector>
12#include "experimental/graphite/include/GraphiteTypes.h"
13#include "include/core/SkRefCnt.h"
14#include "tools/graphite/GraphiteTestContext.h"
15
16namespace skgpu {
17 class Context;
18};
19
20namespace sk_graphite_test {
21
22class ContextFactory {
23public:
24 enum class ContextType {
25 kMetal,
26 kMock,
27 };
28
29 class ContextInfo {
30 public:
31 ContextInfo() = default;
32 ContextInfo(ContextInfo&& other)
33 : fType(other.fType)
34 , fTestContext(std::move(other.fTestContext))
35 , fContext(std::move(other.fContext)) {
36 }
37
38 ~ContextInfo() = default;
39
40 ContextFactory::ContextType type() const { return fType; }
41
42 skgpu::Context* context() const { return fContext.get(); }
43 sk_sp<skgpu::Context> refContext() const { return fContext; }
44 GraphiteTestContext* testContext() const { return fTestContext.get(); }
45
46 private:
47 friend class ContextFactory; // for ctor
48
49 ContextInfo(ContextFactory::ContextType type,
50 std::unique_ptr<GraphiteTestContext> testContext,
51 sk_sp<skgpu::Context> context)
52 : fType(type)
53 , fTestContext(std::move(testContext))
54 , fContext(std::move(context)) {
55 }
56
57 ContextType fType = ContextType::kMock;
58 std::unique_ptr<GraphiteTestContext> fTestContext;
59 sk_sp<skgpu::Context> fContext;
60 };
61
62 ContextFactory() = default;
63 ContextFactory(const ContextFactory&) = delete;
64 ContextFactory& operator=(const ContextFactory&) = delete;
65
66 ~ContextFactory() = default;
67
68 std::tuple<GraphiteTestContext*, sk_sp<skgpu::Context>> getContextInfo(ContextType);
69
70private:
71 std::vector<ContextInfo> fContexts;
72};
73
74} // namespace sk_graphite_test
75
76#endif // sk_graphite_test_ContextFactory_DEFINED