mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] Add DrawLine/DrawOval/ClipOval operations to the canvas recorder (flutter/engine#49697)
This commit is contained in:
parent
2fb99c5544
commit
4610aea866
@ -33,7 +33,9 @@ enum CanvasRecorderOp : uint16_t {
|
||||
kRotate,
|
||||
kDrawPath,
|
||||
kDrawPaint,
|
||||
kDrawLine,
|
||||
kDrawRect,
|
||||
kDrawOval,
|
||||
kDrawRRect,
|
||||
kDrawCircle,
|
||||
kDrawPoints,
|
||||
@ -41,6 +43,7 @@ enum CanvasRecorderOp : uint16_t {
|
||||
kDrawImageRect,
|
||||
kClipPath,
|
||||
kClipRect,
|
||||
kClipOval,
|
||||
kClipRRect,
|
||||
kDrawPicture,
|
||||
kDrawTextFrame,
|
||||
@ -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) {
|
||||
@ -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,
|
||||
|
||||
@ -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());
|
||||
@ -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({}, {});
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -132,7 +128,9 @@ 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);
|
||||
@ -140,6 +138,7 @@ std::string_view CanvasRecorderOpToString(CanvasRecorderOp op) {
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user