Flutter Engine
The Flutter Engine
SkRasterPipeline.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
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 SkRasterPipeline_DEFINED
9#define SkRasterPipeline_DEFINED
10
18
19#include <cstddef>
20#include <cstdint>
21#include <functional>
22
23class SkMatrix;
24enum class SkRasterPipelineOp;
25enum SkColorType : int;
26struct SkImageInfo;
28
29#if __has_cpp_attribute(clang::musttail) && !defined(__EMSCRIPTEN__) && !defined(SK_CPU_ARM32) && \
30 !defined(SK_CPU_LOONGARCH)
31 #define SK_HAS_MUSTTAIL 1
32#else
33 #define SK_HAS_MUSTTAIL 0
34#endif
35
36/**
37 * SkRasterPipeline provides a cheap way to chain together a pixel processing pipeline.
38 *
39 * It's particularly designed for situations where the potential pipeline is extremely
40 * combinatoric: {N dst formats} x {M source formats} x {K mask formats} x {C transfer modes} ...
41 * No one wants to write specialized routines for all those combinations, and if we did, we'd
42 * end up bloating our code size dramatically. SkRasterPipeline stages can be chained together
43 * at runtime, so we can scale this problem linearly rather than combinatorically.
44 *
45 * Each stage is represented by a function conforming to a common interface and by an
46 * arbitrary context pointer. The stage function arguments and calling convention are
47 * designed to maximize the amount of data we can pass along the pipeline cheaply, and
48 * vary depending on CPU feature detection.
49 */
50
51// Raster pipeline programs are stored as a contiguous array of SkRasterPipelineStages.
54 // `fn` holds a function pointer from `ops_lowp` or `ops_highp` in SkOpts.cpp. These functions
55 // correspond to operations from the SkRasterPipelineOp enum in SkRasterPipelineOpList.h. The
56 // exact function pointer type varies depending on architecture (specifically, look for `using
57 // Stage =` in SkRasterPipeline_opts.h).
58 void (*fn)();
59
60 // `ctx` holds data used by the stage function.
61 // Most context structures are declared in SkRasterPipelineOpContexts.h, and have names ending
62 // in Ctx (e.g. "SkRasterPipeline_SamplerCtx"). Some Raster Pipeline stages pack non-pointer
63 // data into this field using `SkRPCtxUtils::Pack`.
64 void* ctx;
65};
67
69public:
71
74
77
78 void reset();
79
80 void append(SkRasterPipelineOp, void* = nullptr);
81 void append(SkRasterPipelineOp op, const void* ctx) { this->append(op,const_cast<void*>(ctx)); }
82 void append(SkRasterPipelineOp, uintptr_t ctx);
83
84 // Append all stages to this pipeline.
85 void extend(const SkRasterPipeline&);
86
87 // Runs the pipeline in 2d from (x,y) inclusive to (x+w,y+h) exclusive.
88 void run(size_t x, size_t y, size_t w, size_t h) const;
89
90 // Allocates a thunk which amortizes run() setup cost in alloc.
91 std::function<void(size_t, size_t, size_t, size_t)> compile() const;
92
93 // Callers can inspect the stage list for debugging purposes.
94 struct StageList {
97 void* ctx;
98 };
99
100 static const char* GetOpName(SkRasterPipelineOp op);
101 const StageList* getStageList() const { return fStages; }
102 int getNumStages() const { return fNumStages; }
103
104 // Prints the entire StageList using SkDebugf.
105 void dump() const;
106
107 // Appends a stage for the specified matrix.
108 // Tries to optimize the stage by analyzing the type of matrix.
109 void appendMatrix(SkArenaAlloc*, const SkMatrix&);
110
111 // Appends a stage for a constant uniform color.
112 // Tries to optimize the stage based on the color.
113 void appendConstantColor(SkArenaAlloc*, const float rgba[4]);
114
116 this->appendConstantColor(alloc, color.vec());
117 }
118
119 // Like appendConstantColor() but only affecting r,g,b, ignoring the alpha channel.
120 void appendSetRGB(SkArenaAlloc*, const float rgb[3]);
121
123 this->appendSetRGB(alloc, color.vec());
124 }
125
129
131
133
134 void appendStackRewind();
135
136 bool empty() const { return fStages == nullptr; }
137
138private:
139 bool buildLowpPipeline(SkRasterPipelineStage* ip) const;
140 void buildHighpPipeline(SkRasterPipelineStage* ip) const;
141
142 using StartPipelineFn = void (*)(size_t, size_t, size_t, size_t,
143 SkRasterPipelineStage* program,
145 uint8_t*);
146 StartPipelineFn buildPipeline(SkRasterPipelineStage*) const;
147
148 void uncheckedAppend(SkRasterPipelineOp, void*);
149 int stagesNeeded() const;
150
151 void addMemoryContext(SkRasterPipeline_MemoryCtx*, int bytesPerPixel, bool load, bool store);
152 uint8_t* tailPointer();
153
154 SkArenaAlloc* fAlloc;
155 SkRasterPipeline_RewindCtx* fRewindCtx;
156 StageList* fStages;
157 uint8_t* fTailPointer;
158 int fNumStages;
159
160 // Only 1 in 2 million CPU-backend pipelines used more than two MemoryCtxs.
161 // (See the comment in SkRasterPipelineOpContexts.h for how MemoryCtx patching works)
163};
164
165template <size_t bytes>
167public:
169 : SkRasterPipeline(&fBuiltinAlloc) {}
170
171private:
172 SkSTArenaAlloc<bytes> fBuiltinAlloc;
173};
174
175
176#endif//SkRasterPipeline_DEFINED
static const uint32_t rgba[kNumPixels]
SkColorType
Definition: SkColorType.h:19
#define SK_BEGIN_REQUIRE_DENSE
Definition: SkMacros.h:37
#define SK_END_REQUIRE_DENSE
Definition: SkMacros.h:38
SI void store(P *ptr, const T &val)
SI T load(const P *ptr)
Definition: Transform_inl.h:98
bool empty() const
int getNumStages() const
void appendClampIfNormalized(const SkImageInfo &)
void run(size_t x, size_t y, size_t w, size_t h) const
void appendTransferFunction(const skcms_TransferFunction &)
void append(SkRasterPipelineOp op, const void *ctx)
void appendSetRGB(SkArenaAlloc *alloc, const SkColor4f &color)
void appendLoad(SkColorType, const SkRasterPipeline_MemoryCtx *)
SkRasterPipeline & operator=(const SkRasterPipeline &)=delete
void appendStore(SkColorType, const SkRasterPipeline_MemoryCtx *)
SkRasterPipeline(SkArenaAlloc *)
void append(SkRasterPipelineOp, void *=nullptr)
void appendSetRGB(SkArenaAlloc *, const float rgb[3])
static const char * GetOpName(SkRasterPipelineOp op)
SkRasterPipeline & operator=(SkRasterPipeline &&)=default
std::function< void(size_t, size_t, size_t, size_t)> compile() const
void extend(const SkRasterPipeline &)
SkRasterPipeline(const SkRasterPipeline &)=delete
void appendLoadDst(SkColorType, const SkRasterPipeline_MemoryCtx *)
SkRasterPipeline(SkRasterPipeline &&)=default
void appendConstantColor(SkArenaAlloc *, const float rgba[4])
void appendConstantColor(SkArenaAlloc *alloc, const SkColor4f &color)
void appendMatrix(SkArenaAlloc *, const SkMatrix &)
const StageList * getStageList() const
DlColor color
Dart_NativeFunction function
Definition: fuchsia.cc:51
double y
double x
SkScalar w
SkScalar h