• 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 "include/core/SkRefCnt.h"
13 #include "include/gpu/graphite/GraphiteTypes.h"
14 #include "tools/graphite/GraphiteTestContext.h"
15 
16 // TODO: This is only included to get access to GrContextFactory::ContextType. We should instead
17 // move all of tools/gpu/ into tools/gpu/ganesh and tools/graphite into tools/gpu/graphite. Then in
18 // tools gpu we can have files for shared things between ganesh and graphite like ContextType.
19 #include "tools/gpu/GrContextFactory.h"
20 
21 using sk_gpu_test::GrContextFactory;
22 
23 namespace skgpu::graphite {
24     class Context;
25 }
26 
27 namespace skiatest::graphite {
28 
29 class ContextFactory {
30 public:
31     class ContextInfo {
32     public:
33         ContextInfo() = default;
34         ContextInfo(ContextInfo&& other);
35         ~ContextInfo() = default;
36 
type()37         GrContextFactory::ContextType type() const { return fType; }
38 
context()39         skgpu::graphite::Context* context() const { return fContext.get(); }
testContext()40         GraphiteTestContext* testContext() const { return fTestContext.get(); }
41 
42     private:
43         friend class ContextFactory; // for ctor
44 
45         ContextInfo(GrContextFactory::ContextType type,
46                     std::unique_ptr<GraphiteTestContext> testContext,
47                     std::unique_ptr<skgpu::graphite::Context> context);
48 
49         GrContextFactory::ContextType             fType = GrContextFactory::kMock_ContextType;
50         std::unique_ptr<GraphiteTestContext>      fTestContext;
51         std::unique_ptr<skgpu::graphite::Context> fContext;
52     };
53 
54     ContextFactory() = default;
55     ContextFactory(const ContextFactory&) = delete;
56     ContextFactory& operator=(const ContextFactory&) = delete;
57 
58     ~ContextFactory() = default;
59 
60     std::tuple<GraphiteTestContext*, skgpu::graphite::Context*> getContextInfo(
61             GrContextFactory::ContextType);
62 
63 private:
64     std::vector<ContextInfo> fContexts;
65 };
66 
67 } // namespace skiatest::graphite
68 
69 #endif // skiatest_graphite_ContextFactory_DEFINED
70