5#ifndef FLUTTER_IMPELLER_AIKS_CANVAS_RECORDER_H_
6#define FLUTTER_IMPELLER_AIKS_CANVAS_RECORDER_H_
12#define FLT_CANVAS_RECORDER_OP_ARG(name) \
13 CanvasRecorderOp::k##name, &Canvas::name
55#ifdef IMPELLER_TRACE_CANVAS
61template <
typename Serializer>
64 CanvasRecorder() : canvas_() { serializer_.Write(CanvasRecorderOp::kNew); }
66 explicit CanvasRecorder(Rect cull_rect) : canvas_(cull_rect) {
67 serializer_.Write(CanvasRecorderOp::kNew);
70 explicit CanvasRecorder(IRect cull_rect) : canvas_(cull_rect) {
71 serializer_.Write(CanvasRecorderOp::kNew);
76 const Serializer& GetSerializer()
const {
return serializer_; }
78 template <
typename ReturnType>
79 ReturnType ExecuteAndSerialize(CanvasRecorderOp op,
80 ReturnType (Canvas::*canvasMethod)()) {
81 serializer_.Write(op);
82 return (canvas_.*canvasMethod)();
85 template <
typename FuncType,
typename... Args>
86 auto ExecuteAndSerialize(CanvasRecorderOp op,
87 FuncType canvasMethod,
89 ->
decltype((std::declval<Canvas>().*
90 canvasMethod)(std::forward<Args>(
args)...)) {
92 (serializer_.Write(
args), ...);
93 serializer_.Write(op);
94 return (canvas_.*canvasMethod)(std::forward<Args>(
args)...);
97 template <
typename FuncType,
typename... Args>
98 auto ExecuteAndSkipArgSerialize(CanvasRecorderOp op,
99 FuncType canvasMethod,
101 ->
decltype((std::declval<Canvas>().*
102 canvasMethod)(std::forward<Args>(
args)...)) {
103 serializer_.Write(op);
104 return (canvas_.*canvasMethod)(std::forward<Args>(
args)...);
112 void Save(uint32_t total_content_depth = Canvas::kMaxDepth) {
113 void (Canvas::*save_method)(uint32_t) = &Canvas::Save;
114 return ExecuteAndSerialize(CanvasRecorderOp::kSave, save_method,
115 total_content_depth);
120 std::optional<Rect> bounds = std::nullopt,
121 const std::shared_ptr<ImageFilter>& backdrop_filter =
nullptr,
122 ContentBoundsPromise bounds_promise = ContentBoundsPromise::kUnknown,
123 uint32_t total_content_depth = Canvas::kMaxDepth) {
125 bounds, backdrop_filter, bounds_promise,
126 total_content_depth);
133 size_t GetSaveCount()
const {
return canvas_.GetSaveCount(); }
135 void RestoreToCount(
size_t count) {
140 const Matrix& GetCurrentTransform()
const {
141 return canvas_.GetCurrentTransform();
144 const std::optional<Rect> GetCurrentLocalCullingBounds()
const {
145 return canvas_.GetCurrentLocalCullingBounds();
148 void ResetTransform() {
161 void PreConcat(
const Matrix&
transform) {
166 void Translate(
const Vector3&
offset) {
171 return ExecuteAndSerialize(
172 CanvasRecorderOp::kScale2,
173 static_cast<void (Canvas::*)(
const Vector2&)
>(&Canvas::Scale),
scale);
177 return ExecuteAndSerialize(
178 CanvasRecorderOp::kScale3,
179 static_cast<void (Canvas::*)(
const Vector3&)
>(&Canvas::Scale),
scale);
182 void Skew(Scalar sx, Scalar sy) {
186 void Rotate(Radians radians) {
190 void DrawPath(Path path,
const Paint&
paint) {
191 serializer_.Write(path);
192 serializer_.Write(
paint);
194 std::move(path),
paint);
201 void DrawLine(
const Point& p0,
const Point& p1,
const Paint&
paint) {
206 void DrawRect(Rect rect,
const Paint&
paint) {
211 void DrawOval(
const Rect& rect,
const Paint&
paint) {
216 void DrawRRect(
const Rect& rect,
217 const Size& corner_radii,
220 corner_radii,
paint);
228 void DrawPoints(std::vector<Point>
points,
231 PointStyle point_style) {
233 radius,
paint, point_style);
239 SamplerDescriptor sampler = {}) {
245 const std::shared_ptr<Image>&
image,
249 SamplerDescriptor sampler = {},
253 src_rect_constraint);
258 Entity::ClipOperation clip_op = Entity::ClipOperation::kIntersect) {
259 serializer_.Write(path);
260 serializer_.Write(clip_op);
262 std::move(path), clip_op);
267 Entity::ClipOperation clip_op = Entity::ClipOperation::kIntersect) {
274 Entity::ClipOperation clip_op = Entity::ClipOperation::kIntersect) {
281 const Size& corner_radii,
282 Entity::ClipOperation clip_op = Entity::ClipOperation::kIntersect) {
284 corner_radii, clip_op);
287 void DrawTextFrame(
const std::shared_ptr<TextFrame>& text_frame,
291 text_frame, position,
paint);
294 void DrawVertices(
const std::shared_ptr<VerticesGeometry>& vertices,
295 BlendMode blend_mode,
298 vertices, blend_mode,
paint);
301 void DrawAtlas(
const std::shared_ptr<Image>& atlas,
302 std::vector<Matrix> transforms,
303 std::vector<Rect> texture_coordinates,
304 std::vector<Color> colors,
305 BlendMode blend_mode,
306 SamplerDescriptor sampler,
307 std::optional<Rect> cull_rect,
320 Picture EndRecordingAsPicture() {
return canvas_.EndRecordingAsPicture(); }
324 Serializer serializer_;
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
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)