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
61 template <
typename Serializer>
62 class CanvasRecorder {
66 explicit CanvasRecorder(
Rect cull_rect) : canvas_(cull_rect) {
70 explicit CanvasRecorder(
IRect cull_rect) : canvas_(cull_rect) {
76 const Serializer& GetSerializer()
const {
return serializer_; }
78 template <
typename ReturnType>
80 ReturnType (Canvas::*canvasMethod)()) {
81 serializer_.Write(op);
82 return (canvas_.*canvasMethod)();
85 template <
typename FuncType,
typename... Args>
87 FuncType canvasMethod,
89 -> decltype((std::declval<Canvas>().*
90 canvasMethod)(std::forward<Args>(args)...)) {
92 (serializer_.Write(std::forward<Args>(args)), ...);
93 serializer_.Write(op);
94 return (canvas_.*canvasMethod)(std::forward<Args>(args)...);
97 template <
typename FuncType,
typename... Args>
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)...);
118 std::optional<Rect> bounds = std::nullopt,
119 const std::shared_ptr<ImageFilter>& backdrop_filter =
nullptr,
122 bounds, backdrop_filter, bounds_promise);
129 size_t GetSaveCount()
const {
return canvas_.GetSaveCount(); }
131 void RestoreToCount(
size_t count) {
136 const Matrix& GetCurrentTransform()
const {
137 return canvas_.GetCurrentTransform();
140 const std::optional<Rect> GetCurrentLocalCullingBounds()
const {
141 return canvas_.GetCurrentLocalCullingBounds();
144 void ResetTransform() {
148 void Transform(
const Matrix& transform) {
153 void Concat(
const Matrix& transform) {
157 void PreConcat(
const Matrix& transform) {
162 void Translate(
const Vector3&
offset) {
167 return ExecuteAndSerialize(
172 void Scale(
const Vector3&
scale) {
173 return ExecuteAndSerialize(
182 void Rotate(Radians radians) {
186 void DrawPath(Path path,
const Paint& paint) {
187 serializer_.Write(path);
188 serializer_.Write(paint);
190 std::move(path), paint);
193 void DrawPaint(
const Paint& paint) {
197 void DrawLine(
const Point& p0,
const Point& p1,
const Paint& paint) {
202 void DrawRect(
Rect rect,
const Paint& paint) {
207 void DrawOval(
const Rect& rect,
const Paint& paint) {
212 void DrawRRect(
const Rect& rect,
213 const Size& corner_radii,
214 const Paint& paint) {
216 corner_radii, paint);
219 void DrawCircle(
Point center,
Scalar radius,
const Paint& paint) {
224 void DrawPoints(std::vector<Point> points,
229 radius, paint, point_style);
232 void DrawImage(
const std::shared_ptr<Image>& image,
235 SamplerDescriptor sampler = {}) {
241 const std::shared_ptr<Image>& image,
245 SamplerDescriptor sampler = {},
248 source, dest, paint, sampler,
249 src_rect_constraint);
255 serializer_.Write(path);
256 serializer_.Write(clip_op);
258 std::move(path), clip_op);
277 const Size& corner_radii,
280 corner_radii, clip_op);
283 void DrawTextFrame(
const std::shared_ptr<TextFrame>& text_frame,
285 const Paint& paint) {
287 text_frame, position, paint);
290 void DrawVertices(
const std::shared_ptr<VerticesGeometry>& vertices,
292 const Paint& paint) {
294 vertices, blend_mode, paint);
297 void DrawAtlas(
const std::shared_ptr<Image>& atlas,
298 std::vector<Matrix> transforms,
299 std::vector<Rect> texture_coordinates,
300 std::vector<Color> colors,
302 SamplerDescriptor sampler,
303 std::optional<Rect> cull_rect,
304 const Paint& paint) {
316 Picture EndRecordingAsPicture() {
return canvas_.EndRecordingAsPicture(); }
320 Serializer serializer_;
326 #endif // FLUTTER_IMPELLER_AIKS_CANVAS_RECORDER_H_