Debian Codegraph @

tools/graphite/ContextFactory.h

raw
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 "include/core/SkRefCnt.h"
12 #include "include/gpu/graphite/ContextOptions.h"
13 #include "include/gpu/graphite/GraphiteTypes.h"
14 #include "include/private/base/SkTArray.h"
15 #include "tools/gpu/ContextType.h"
16 #include "tools/graphite/GraphiteTestContext.h"
17 #include "tools/graphite/TestOptions.h"
18
19 namespace skgpu::graphite {
20 class Context;
21 }
22
23 namespace skiatest::graphite {
24
25 struct ContextInfo {
26 GraphiteTestContext* fTestContext = nullptr;
27 skgpu::graphite::Context* fContext = nullptr;
28 };
29
30 class ContextFactory {
31 public:
32 explicit ContextFactory(const TestOptions&);
33 ContextFactory() = default;
34 ContextFactory(const ContextFactory&) = delete;
35 ContextFactory& operator=(const ContextFactory&) = delete;
36
37 ~ContextFactory() = default;
38
39 ContextInfo getContextInfo(skgpu::ContextType);
40
41 private:
42 struct OwnedContextInfo {
43 OwnedContextInfo();
44 OwnedContextInfo(skgpu::ContextType,
45 std::unique_ptr<GraphiteTestContext>,
46 std::unique_ptr<skgpu::graphite::Context>);
47
48 ~OwnedContextInfo();
49 OwnedContextInfo(OwnedContextInfo&&);
50 OwnedContextInfo& operator=(OwnedContextInfo&&);
51
52 // This holds the same data as ContextInfo, but uses unique_ptr to maintain ownership.
53 skgpu::ContextType fType = skgpu::ContextType::kMock;
54 std::unique_ptr<GraphiteTestContext> fTestContext;
55 std::unique_ptr<skgpu::graphite::Context> fContext;
56 };
57
58 static ContextInfo AsContextInfo(const OwnedContextInfo& ctx);
59
60 skia_private::TArray<OwnedContextInfo> fContexts;
61 const TestOptions fOptions = {};
62 };
63
64 } // namespace skiatest::graphite
65
66 #endif // skiatest_graphite_ContextFactory_DEFINED