14 {
15
16
17
50};
51
52
53
54#ifdef IMPELLER_TRACE_CANVAS
55
56
57
58
59
60template <typename Serializer>
61class CanvasRecorder {
62 public:
63 CanvasRecorder() : canvas_() { serializer_.Write(CanvasRecorderOp::kNew); }
64
65 explicit CanvasRecorder(Rect cull_rect) : canvas_(cull_rect) {
66 serializer_.Write(CanvasRecorderOp::kNew);
67 }
68
69 explicit CanvasRecorder(IRect cull_rect) : canvas_(cull_rect) {
70 serializer_.Write(CanvasRecorderOp::kNew);
71 }
72
73 ~CanvasRecorder() {}
74
75 const Serializer& GetSerializer() const { return serializer_; }
76
77 template <typename ReturnType>
78 ReturnType ExecuteAndSerialize(CanvasRecorderOp op,
79 ReturnType (Canvas::*canvasMethod)()) {
80 serializer_.Write(op);
81 return (canvas_.*canvasMethod)();
82 }
83
84 template <typename FuncType, typename... Args>
85 auto ExecuteAndSerialize(CanvasRecorderOp op,
86 FuncType canvasMethod,
88 -> decltype((std::declval<Canvas>().*
89 canvasMethod)(std::forward<Args>(
args)...)) {
90
91 (serializer_.Write(
args), ...);
92 serializer_.Write(op);
93 return (canvas_.*canvasMethod)(std::forward<Args>(
args)...);
94 }
95
96 template <typename FuncType, typename... Args>
97 auto ExecuteAndSkipArgSerialize(CanvasRecorderOp op,
98 FuncType canvasMethod,
100 -> decltype((std::declval<Canvas>().*
101 canvasMethod)(std::forward<Args>(
args)...)) {
102 serializer_.Write(op);
103 return (canvas_.*canvasMethod)(std::forward<Args>(
args)...);
104 }
105
106
107
108
109
110
111 void Save(uint32_t total_content_depth = Canvas::kMaxDepth) {
112 void (Canvas::*save_method)(uint32_t) = &Canvas::Save;
113 return ExecuteAndSerialize(CanvasRecorderOp::kSave, save_method,
114 total_content_depth);
115 }
116
117 void SaveLayer(
119 std::optional<Rect> bounds = std::nullopt,
120 const std::shared_ptr<ImageFilter>& backdrop_filter = nullptr,
121 ContentBoundsPromise bounds_promise = ContentBoundsPromise::kUnknown,
122 uint32_t total_content_depth = Canvas::kMaxDepth) {
124 bounds, backdrop_filter, bounds_promise,
125 total_content_depth);
126 }
127
128 bool Restore() {
130 }
131
132 size_t GetSaveCount() const { return canvas_.GetSaveCount(); }
133
134 void RestoreToCount(
size_t count) {
137 }
138
139 const Matrix& GetCurrentTransform() const {
140 return canvas_.GetCurrentTransform();
141 }
142
143 const std::optional<Rect> GetCurrentLocalCullingBounds() const {
144 return canvas_.GetCurrentLocalCullingBounds();
145 }
146
147 void ResetTransform() {
149 }
150
154 }
155
158 }
159
160 void PreConcat(
const Matrix&
transform) {
163 }
164
165 void Translate(
const Vector3&
offset) {
167 }
168
170 return ExecuteAndSerialize(
171 CanvasRecorderOp::kScale2,
172 static_cast<void (Canvas::*)(
const Vector2&)
>(&Canvas::Scale),
scale);
173 }
174
176 return ExecuteAndSerialize(
177 CanvasRecorderOp::kScale3,
178 static_cast<void (Canvas::*)(
const Vector3&)
>(&Canvas::Scale),
scale);
179 }
180
181 void Skew(Scalar sx, Scalar sy) {
183 }
184
185 void Rotate(Radians radians) {
187 }
188
189 void DrawPath(Path path,
const Paint&
paint) {
190 serializer_.Write(path);
191 serializer_.Write(
paint);
193 std::move(path),
paint);
194 }
195
198 }
199
200 void DrawLine(
const Point& p0,
const Point& p1,
const Paint&
paint) {
203 }
204
205 void DrawRect(Rect rect,
const Paint&
paint) {
208 }
209
210 void DrawOval(
const Rect& rect,
const Paint&
paint) {
213 }
214
215 void DrawRRect(const Rect& rect,
216 const Size& corner_radii,
219 corner_radii,
paint);
220 }
221
225 }
226
227 void DrawPoints(std::vector<Point>
points,
228 Scalar radius,
230 PointStyle point_style) {
232 radius,
paint, point_style);
233 }
234
238 SamplerDescriptor sampler = {}) {
241 }
242
244 const std::shared_ptr<Image>&
image,
246 Rect dest,
248 SamplerDescriptor sampler = {},
252 src_rect_constraint);
253 }
254
255 void ClipPath(
256 Path path,
257 Entity::ClipOperation clip_op = Entity::ClipOperation::kIntersect) {
258 serializer_.Write(path);
259 serializer_.Write(clip_op);
261 std::move(path), clip_op);
262 }
263
265 const Rect& rect,
266 Entity::ClipOperation clip_op = Entity::ClipOperation::kIntersect) {
268 clip_op);
269 }
270
271 void ClipOval(
272 const Rect& bounds,
273 Entity::ClipOperation clip_op = Entity::ClipOperation::kIntersect) {
275 clip_op);
276 }
277
278 void ClipRRect(
279 const Rect& rect,
280 const Size& corner_radii,
281 Entity::ClipOperation clip_op = Entity::ClipOperation::kIntersect) {
283 corner_radii, clip_op);
284 }
285
286 void DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
287 Point position,
290 text_frame, position,
paint);
291 }
292
293 void DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
294 BlendMode blend_mode,
297 vertices, blend_mode,
paint);
298 }
299
300 void DrawAtlas(
const std::shared_ptr<Image>& atlas,
301 std::vector<Matrix> transforms,
302 std::vector<Rect> texture_coordinates,
303 std::vector<Color> colors,
304 BlendMode blend_mode,
305 SamplerDescriptor sampler,
306 std::optional<Rect> cull_rect,
309 atlas,
310 transforms,
311 texture_coordinates,
312 colors,
313 blend_mode,
314 sampler,
315 cull_rect,
317 }
318
319 Picture EndRecordingAsPicture() {
return canvas_.EndRecordingAsPicture(); }
320
321 private:
322 Canvas canvas_;
323 Serializer serializer_;
324};
325#endif
326
327}
328
329#endif
static const SkRect kDrawRect
static const int points[]
static SkScalar center(float pos0, float pos1)
#define FLT_CANVAS_RECORDER_OP_ARG(name)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static constexpr char kTransform[]
void DrawImage(SkCanvas *canvas, const SkImage *image, SkScalar x, SkScalar y, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
SK_API void DrawImageRect(SkCanvas *canvas, const SkImage *image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
SourceRectConstraint
Controls the behavior of the source rectangle given to DrawImageRect.
SK_API sk_sp< PrecompileShader > Picture()
skgpu::graphite::DrawAtlas DrawAtlas
skgpu::graphite::Transform Transform
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)