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
53 #ifdef IMPELLER_TRACE_CANVAS
59 template <
typename Serializer>
60 class CanvasRecorder {
64 explicit CanvasRecorder(
Rect cull_rect) : canvas_(cull_rect) {
68 explicit CanvasRecorder(
IRect cull_rect) : canvas_(cull_rect) {
74 const Serializer& GetSerializer()
const {
return serializer_; }
76 template <
typename ReturnType>
78 ReturnType (Canvas::*canvasMethod)()) {
79 serializer_.Write(op);
80 return (canvas_.*canvasMethod)();
83 template <
typename FuncType,
typename... Args>
85 FuncType canvasMethod,
87 -> decltype((std::declval<Canvas>().*
88 canvasMethod)(std::forward<Args>(args)...)) {
90 (serializer_.Write(std::forward<Args>(args)), ...);
91 serializer_.Write(op);
92 return (canvas_.*canvasMethod)(std::forward<Args>(args)...);
95 template <
typename FuncType,
typename... Args>
97 FuncType canvasMethod,
99 -> decltype((std::declval<Canvas>().*
100 canvasMethod)(std::forward<Args>(args)...)) {
101 serializer_.Write(op);
102 return (canvas_.*canvasMethod)(std::forward<Args>(args)...);
116 std::optional<Rect> bounds = std::nullopt,
117 const std::shared_ptr<ImageFilter>& backdrop_filter =
nullptr) {
119 bounds, backdrop_filter);
126 size_t GetSaveCount()
const {
return canvas_.GetSaveCount(); }
128 void RestoreToCount(
size_t count) {
133 const Matrix& GetCurrentTransform()
const {
134 return canvas_.GetCurrentTransform();
137 const std::optional<Rect> GetCurrentLocalCullingBounds()
const {
138 return canvas_.GetCurrentLocalCullingBounds();
141 void ResetTransform() {
145 void Transform(
const Matrix& transform) {
150 void Concat(
const Matrix& transform) {
154 void PreConcat(
const Matrix& transform) {
159 void Translate(
const Vector3& offset) {
163 void Scale(
const Vector2& scale) {
164 return ExecuteAndSerialize(
169 void Scale(
const Vector3& scale) {
170 return ExecuteAndSerialize(
172 static_cast<void (Canvas::*)(
const Vector3&)
>(&
Canvas::Scale), scale);
179 void Rotate(Radians radians) {
183 void DrawPath(Path path,
const Paint& paint) {
184 serializer_.Write(path);
185 serializer_.Write(paint);
187 std::move(path), paint);
190 void DrawPaint(
const Paint& paint) {
194 void DrawRect(
Rect rect,
const Paint& paint) {
199 void DrawRRect(
const Rect& rect,
200 const Size& corner_radii,
201 const Paint& paint) {
203 corner_radii, paint);
206 void DrawCircle(
Point center,
Scalar radius,
const Paint& paint) {
211 void DrawPoints(std::vector<Point> points,
216 radius, paint, point_style);
219 void DrawImage(
const std::shared_ptr<Image>& image,
222 SamplerDescriptor sampler = {}) {
224 offset, paint, sampler);
227 void DrawImageRect(
const std::shared_ptr<Image>& image,
231 SamplerDescriptor sampler = {}) {
233 source, dest, paint, sampler);
239 serializer_.Write(path);
240 serializer_.Write(clip_op);
242 std::move(path), clip_op);
254 const Size& corner_radii,
257 corner_radii, clip_op);
260 void DrawPicture(
const Picture& picture) {
265 void DrawTextFrame(
const std::shared_ptr<TextFrame>& text_frame,
267 const Paint& paint) {
269 text_frame, position, paint);
272 void DrawVertices(
const std::shared_ptr<VerticesGeometry>& vertices,
274 const Paint& paint) {
276 vertices, blend_mode, paint);
279 void DrawAtlas(
const std::shared_ptr<Image>& atlas,
280 std::vector<Matrix> transforms,
281 std::vector<Rect> texture_coordinates,
282 std::vector<Color> colors,
284 SamplerDescriptor sampler,
285 std::optional<Rect> cull_rect,
286 const Paint& paint) {
298 Picture EndRecordingAsPicture() {
return canvas_.EndRecordingAsPicture(); }
302 Serializer serializer_;
308 #endif // FLUTTER_IMPELLER_AIKS_CANVAS_RECORDER_H_