• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 skiatest_graphite_ContextFactory_DEFINED
9 #define skiatest_graphite_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 
16 namespace skgpu {
17     class Context;
18 };
19 
20 namespace skiatest::graphite {
21 
22 class ContextFactory {
23 public:
24     enum class ContextType {
25         kDirect3D,
26         kMetal,
27         kVulkan,
28         kMock,
29     };
30 
31     class ContextInfo {
32     public:
33         ContextInfo() = default;
34         ContextInfo(ContextInfo&& other);
35         ~ContextInfo() = default;
36 
type()37         ContextFactory::ContextType type() const { return fType; }
38 
context()39         skgpu::Context* context() const { return fContext.get(); }
40         sk_sp<skgpu::Context> refContext() const;
testContext()41         GraphiteTestContext* testContext() const { return fTestContext.get(); }
42 
43     private:
44         friend class ContextFactory; // for ctor
45 
46         ContextInfo(ContextFactory::ContextType type,
47                     std::unique_ptr<GraphiteTestContext> testContext,
48                     sk_sp<skgpu::Context> context);
49 
50         ContextType                          fType = ContextType::kMock;
51         std::unique_ptr<GraphiteTestContext> fTestContext;
52         sk_sp<skgpu::Context>                fContext;
53     };
54 
55     ContextFactory() = default;
56     ContextFactory(const ContextFactory&) = delete;
57     ContextFactory& operator=(const ContextFactory&) = delete;
58 
59     ~ContextFactory() = default;
60 
61     std::tuple<GraphiteTestContext*, sk_sp<skgpu::Context>> getContextInfo(ContextType);
62 
63 private:
64     std::vector<ContextInfo> fContexts;
65 };
66 
67 } // namespace skiatest::graphite
68 
69 #endif // skiatest_graphite_ContextFactory_DEFINED
70