Debian Codegraph @

src/core/SkRasterPipelineVizualizer.h

raw
1 /*
2 * Copyright 2025 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 SkRasterPipelineVizualizer_DEFINED
8 #define SkRasterPipelineVizualizer_DEFINED
9
10 #include "include/core/SkBitmap.h"
11 #include "include/core/SkRefCnt.h" // IWYU pragma: keep
12
13 #include <vector>
14
15 class SkArenaAlloc;
16 class SkBlitter;
17 class SkMatrix;
18 class SkPaint;
19 class SkPixmap;
20 class SkShader;
21 class SkSurfaceProps;
22 enum class SkRasterPipelineOp;
23
24 namespace SkRasterPipelineVisualizer {
25
26 // After each stage, visualize 0 or more (probably 1-4) lanes into the provided panels.
27 // The vectors are parallel data structures with the op chosen by the user of what
28 // and how to be visualized. The number of panels per stage can differ (the pipeline
29 // frequently can be thought of as a ragged 2 dimensional array of images).
30 struct DebugStage {
31 std::vector<SkBitmap> panels;
32 // Should be only ops that start with debug_
33 std::vector<SkRasterPipelineOp> ops;
34 };
35
36 // The same as SkCreateRasterPipelineBlitter but takes in some stages to
37 // visualize the output of each of the main stages. This will inject some
38 // stages into the shader on the provided paint and then return a blitter
39 // which can be used to draw the final output and the intermediate represenations.
40 // If stages is not the same size as the actual number of pipeline stages, this
41 // will abort. The first time this function is called, the original pipeline will be
42 // displayed via standard out to make it easier to get the number of stages right.
43 //
44 // Note that different methods on the provided Blitter may add stages after creation
45 // (e.g. for blending with the destination) so this won't visualize those, but the main
46 // ones from the shader should be visualized via this code path.
47 SkBlitter* CreateBlitter(const SkPixmap& output,
48 const std::vector<DebugStage>& stages,
49 const SkPaint&,
50 const SkMatrix& ctm,
51 SkArenaAlloc*,
52 sk_sp<SkShader> clipShader,
53 const SkSurfaceProps& props);
54
55 // A convinence class for making many debug stages. The user chooses which lanes are
56 // useful to be visualized for each lane.
57 // SkBitmap* panels = ...; // make a bunch of bitmaps somehow
58 //
59 // DebugStageBuilder stageBuilder;
60 // stageBuilder.add(panels[0], SkRasterPipelineOp::debug_x,
61 // panels[1], SkRasterPipelineOp::debug_y)
62 // .add(panels[2], SkRasterPipelineOp::debug_b)
63 // .add(panels[3], SkRasterPipelineOp::debug_r_255,
64 // panels[4], SkRasterPipelineOp::debug_g_255,
65 // panels[5], SkRasterPipelineOp::debug_b_255,
66 // panels[6], SkRasterPipelineOp::debug_a_255);
67 // auto stages = stageBuilder.build()
68 class DebugStageBuilder {
69 public:
70 DebugStageBuilder() = default;
71 DebugStageBuilder(const DebugStageBuilder&) = delete;
72 DebugStageBuilder(DebugStageBuilder&&) = delete;
73 DebugStageBuilder& operator=(const DebugStageBuilder&) = delete;
74 DebugStageBuilder& operator=(DebugStageBuilder&&) = delete;
75
76 template <typename... Args>
77 DebugStageBuilder& add(const SkBitmap& panel, SkRasterPipelineOp op, Args... args) {
78 std::vector<SkBitmap> panels;
79 std::vector<SkRasterPipelineOp> ops;
80
81 add_next(panels, ops, panel, op, args...);
82 fDebugStages.push_back({panels, ops});
83 return *this;
84 }
85
86 DebugStageBuilder& add() {
87 std::vector<SkBitmap> panels;
88 std::vector<SkRasterPipelineOp> ops;
89 fDebugStages.push_back({panels, ops});
90 return *this;
91 }
92
93 std::vector<DebugStage> build() { return fDebugStages; }
94
95 private:
96 std::vector<DebugStage> fDebugStages;
97
98 static void add_next(std::vector<SkBitmap>& v, std::vector<SkRasterPipelineOp>& ops) {}
99
100 template <typename... Args>
101 static void add_next(std::vector<SkBitmap>& panels,
102 std::vector<SkRasterPipelineOp>& ops,
103 const SkBitmap& panel,
104 SkRasterPipelineOp op,
105 Args... args) {
106 panels.emplace_back(panel);
107 ops.emplace_back(op);
108 add_next(panels, ops, args...);
109 }
110 };
111
112 } // namespace SkRasterPipelineVisualizer
113
114 #endif