Skip to content

Commit

Permalink
[Impeller] Add DrawLine/DrawOval/ClipOval operations to the canvas re…
Browse files Browse the repository at this point in the history
…corder (flutter#49697)
  • Loading branch information
jason-simmons authored Jan 11, 2024
1 parent b7d360e commit 6202fd2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
20 changes: 20 additions & 0 deletions impeller/aiks/canvas_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ enum CanvasRecorderOp : uint16_t {
kRotate,
kDrawPath,
kDrawPaint,
kDrawLine,
kDrawRect,
kDrawOval,
kDrawRRect,
kDrawCircle,
kDrawPoints,
kDrawImage,
kDrawImageRect,
kClipPath,
kClipRect,
kClipOval,
kClipRRect,
kDrawPicture,
kDrawTextFrame,
Expand Down Expand Up @@ -191,11 +194,21 @@ class CanvasRecorder {
return ExecuteAndSerialize(FLT_CANVAS_RECORDER_OP_ARG(DrawPaint), paint);
}

void DrawLine(const Point& p0, const Point& p1, const Paint& paint) {
return ExecuteAndSerialize(FLT_CANVAS_RECORDER_OP_ARG(DrawLine), p0, p1,
paint);
}

void DrawRect(Rect rect, const Paint& paint) {
return ExecuteAndSerialize(FLT_CANVAS_RECORDER_OP_ARG(DrawRect), rect,
paint);
}

void DrawOval(const Rect& rect, const Paint& paint) {
return ExecuteAndSerialize(FLT_CANVAS_RECORDER_OP_ARG(DrawOval), rect,
paint);
}

void DrawRRect(const Rect& rect,
const Size& corner_radii,
const Paint& paint) {
Expand Down Expand Up @@ -249,6 +262,13 @@ class CanvasRecorder {
clip_op);
}

void ClipOval(
const Rect& bounds,
Entity::ClipOperation clip_op = Entity::ClipOperation::kIntersect) {
return ExecuteAndSerialize(FLT_CANVAS_RECORDER_OP_ARG(ClipOval), bounds,
clip_op);
}

void ClipRRect(
const Rect& rect,
const Size& corner_radii,
Expand Down
18 changes: 18 additions & 0 deletions impeller/aiks/canvas_recorder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,24 @@ TEST(CanvasRecorder, DrawPaint) {
ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawPaint);
}

TEST(CanvasRecorder, DrawLine) {
CanvasRecorder<Serializer> recorder;
recorder.DrawLine(Point(), Point(), Paint());
ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawLine);
}

TEST(CanvasRecorder, DrawRect) {
CanvasRecorder<Serializer> recorder;
recorder.DrawRect(Rect(), Paint());
ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawRect);
}

TEST(CanvasRecorder, DrawOval) {
CanvasRecorder<Serializer> recorder;
recorder.DrawOval(Rect(), Paint());
ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawOval);
}

TEST(CanvasRecorder, DrawRRect) {
CanvasRecorder<Serializer> recorder;
recorder.DrawRRect(Rect(), {}, Paint());
Expand Down Expand Up @@ -201,6 +213,12 @@ TEST(CanvasRecorder, ClipRect) {
ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kClipRect);
}

TEST(CanvasRecorder, ClipOval) {
CanvasRecorder<Serializer> recorder;
recorder.ClipOval({});
ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kClipOval);
}

TEST(CanvasRecorder, ClipRRect) {
CanvasRecorder<Serializer> recorder;
recorder.ClipRRect({}, {});
Expand Down
19 changes: 9 additions & 10 deletions impeller/aiks/trace_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,20 @@ std::ostream& operator<<(std::ostream& os, const ColorSource& color_source) {
std::ostream& operator<<(std::ostream& os, const Paint& paint) {
os << "{" << std::endl;
os << " color: [" << paint.color << "]" << std::endl;
os << " color_source:"
<< "[" << paint.color_source << "]" << std::endl;
os << " color_source:" << "[" << paint.color_source << "]" << std::endl;
os << " dither: [" << paint.dither << "]" << std::endl;
os << " stroke_width: [" << paint.stroke_width << "]" << std::endl;
os << " stroke_cap: "
<< "[Paint::Cap]" << std::endl;
os << " stroke_join: "
<< "[Paint::Join]" << std::endl;
os << " stroke_cap: " << "[Paint::Cap]" << std::endl;
os << " stroke_join: " << "[Paint::Join]" << std::endl;
os << " stroke_miter: [" << paint.stroke_miter << "]" << std::endl;
os << " style:"
<< "[Paint::Style]" << std::endl;
os << " style:" << "[Paint::Style]" << std::endl;
os << " blend_mode: [" << BlendModeToString(paint.blend_mode) << "]"
<< std::endl;
os << " invert_colors: [" << paint.invert_colors << "]" << std::endl;
os << " image_filter: " << paint.image_filter << std::endl;
os << " color_filter: " << paint.color_filter << std::endl;
os << " mask_blur_descriptor: "
<< "[std::optional<MaskBlurDescriptor>]" << std::endl;
os << " mask_blur_descriptor: " << "[std::optional<MaskBlurDescriptor>]"
<< std::endl;
os << "}";
return os;
}
Expand Down Expand Up @@ -132,14 +128,17 @@ std::string_view CanvasRecorderOpToString(CanvasRecorderOp op) {
FLT_CANVAS_RECORDER_OP_TO_STRING(kRotate);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPath);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPaint);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawLine);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawRect);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawOval);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawRRect);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawCircle);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPoints);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawImage);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawImageRect);
FLT_CANVAS_RECORDER_OP_TO_STRING(kClipPath);
FLT_CANVAS_RECORDER_OP_TO_STRING(kClipRect);
FLT_CANVAS_RECORDER_OP_TO_STRING(kClipOval);
FLT_CANVAS_RECORDER_OP_TO_STRING(kClipRRect);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPicture);
FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawTextFrame);
Expand Down

0 comments on commit 6202fd2

Please sign in to comment.