Debian Codegraph @

tools/window/GraphiteDisplayParams.h

raw
1 /*
2 * Copyright 2024 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 #ifndef GraphiteDisplayParams_DEFINED
8 #define GraphiteDisplayParams_DEFINED
9
10 #include "include/gpu/graphite/ContextOptions.h"
11 #include "src/gpu/graphite/ContextOptionsPriv.h"
12 #include "tools/graphite/TestOptions.h"
13 #include "tools/window/DisplayParams.h"
14
15 namespace skwindow {
16
17 struct GraphiteTestOptions {
18 GraphiteTestOptions() { fTestOptions.fContextOptions.fOptionsPriv = &fPriv; }
19
20 GraphiteTestOptions(const GraphiteTestOptions& other)
21 : fTestOptions(other.fTestOptions), fPriv(other.fPriv) {
22 fTestOptions.fContextOptions.fOptionsPriv = &fPriv;
23 }
24
25 GraphiteTestOptions& operator=(const GraphiteTestOptions& other) {
26 fTestOptions = other.fTestOptions;
27 fPriv = other.fPriv;
28 fTestOptions.fContextOptions.fOptionsPriv = &fPriv;
29 return *this;
30 }
31
32 skiatest::graphite::TestOptions fTestOptions;
33 skgpu::graphite::ContextOptionsPriv fPriv;
34 };
35
36 class GraphiteDisplayParams : public DisplayParams {
37 public:
38 GraphiteDisplayParams(GraphiteTestOptions opts) : DisplayParams(), fGraphiteTestOptions(opts) {}
39
40 GraphiteDisplayParams(const DisplayParams* other) : DisplayParams(other) {
41 if (auto existing = other->graphiteTestOptions()) {
42 fGraphiteTestOptions = *existing;
43 } else {
44 fGraphiteTestOptions = GraphiteTestOptions();
45 }
46 }
47
48 std::unique_ptr<DisplayParams> clone() const override {
49 return std::make_unique<GraphiteDisplayParams>(*this);
50 }
51
52 const GraphiteTestOptions* graphiteTestOptions() const override {
53 return &fGraphiteTestOptions;
54 }
55
56 private:
57 friend class GraphiteDisplayParamsBuilder;
58
59 GraphiteTestOptions fGraphiteTestOptions;
60 };
61
62 class GraphiteDisplayParamsBuilder : public DisplayParamsBuilder {
63 public:
64 GraphiteDisplayParamsBuilder()
65 : DisplayParamsBuilder(std::make_unique<GraphiteDisplayParams>(GraphiteTestOptions())) {
66 }
67
68 GraphiteDisplayParamsBuilder(const DisplayParams* other)
69 : DisplayParamsBuilder(std::make_unique<GraphiteDisplayParams>(other)) {}
70
71 GraphiteDisplayParamsBuilder& graphiteTestOptions(
72 const GraphiteTestOptions& graphiteTestOptions) {
73 SkASSERT_RELEASE(fDisplayParams);
74 reinterpret_cast<GraphiteDisplayParams*>(fDisplayParams.get())->fGraphiteTestOptions =
75 graphiteTestOptions;
76 return *this;
77 }
78 };
79
80 } // namespace skwindow
81
82 #endif