mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix solid stroke contour switching + round cap smoothing, and add transparent path overdraw example (flutter/engine#112)
This commit is contained in:
parent
95dfbcf504
commit
b2abb9a511
@ -482,5 +482,43 @@ TEST_F(AiksTest, TransformMultipliesCorrectly) {
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST_F(AiksTest, PathsShouldHaveUniformAlpha) {
|
||||
// Compare with https://fiddle.skia.org/c/027392122bec8ac2b5d5de00a4b9bbe2
|
||||
Canvas canvas;
|
||||
Paint paint;
|
||||
|
||||
paint.color = Color::White();
|
||||
canvas.DrawPaint(paint);
|
||||
|
||||
paint.color = Color::Black().WithAlpha(0.5);
|
||||
paint.style = Paint::Style::kStroke;
|
||||
paint.stroke_width = 10;
|
||||
|
||||
Path path = PathBuilder{}
|
||||
.MoveTo({20, 20})
|
||||
.QuadraticCurveTo({60, 20}, {60, 60})
|
||||
.Close()
|
||||
.MoveTo({60, 20})
|
||||
.QuadraticCurveTo({60, 60}, {20, 60})
|
||||
.TakePath();
|
||||
|
||||
canvas.Scale({3, 3});
|
||||
for (auto join :
|
||||
{SolidStrokeContents::Join::kBevel, SolidStrokeContents::Join::kRound,
|
||||
SolidStrokeContents::Join::kMiter}) {
|
||||
paint.stroke_join = join;
|
||||
for (auto cap :
|
||||
{SolidStrokeContents::Cap::kButt, SolidStrokeContents::Cap::kSquare,
|
||||
SolidStrokeContents::Cap::kRound}) {
|
||||
paint.stroke_cap = cap;
|
||||
canvas.DrawPath(path, paint);
|
||||
canvas.Translate({80, 0});
|
||||
}
|
||||
canvas.Translate({-240, 60});
|
||||
}
|
||||
|
||||
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@ -79,7 +79,11 @@ static VertexBuffer CreateSolidStrokeVertices(
|
||||
vtx.vertex_normal = {};
|
||||
vtx.pen_down = 0.0;
|
||||
vtx_builder.AppendVertex(vtx);
|
||||
|
||||
vtx.vertex_position = polyline.points[contour_start_point_i];
|
||||
// Append two transparent vertices at the beginning of the new contour
|
||||
// because it's a triangle strip.
|
||||
vtx_builder.AppendVertex(vtx);
|
||||
vtx_builder.AppendVertex(vtx);
|
||||
}
|
||||
|
||||
@ -152,9 +156,13 @@ bool SolidStrokeContents::Render(const ContentContext& renderer,
|
||||
cmd.pipeline =
|
||||
renderer.GetSolidStrokePipeline(OptionsFromPassAndEntity(pass, entity));
|
||||
cmd.stencil_reference = entity.GetStencilDepth();
|
||||
|
||||
auto smoothing = SmoothingApproximation(
|
||||
5.0 / (stroke_size_ * entity.GetTransformation().GetMaxBasisLength()),
|
||||
0.0, 0.0);
|
||||
cmd.BindVertices(CreateSolidStrokeVertices(
|
||||
entity.GetPath(), pass.GetTransientsBuffer(), cap_proc_, join_proc_,
|
||||
miter_limit_, arc_smoothing_approximation_));
|
||||
miter_limit_, smoothing));
|
||||
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
|
||||
VS::BindStrokeInfo(cmd,
|
||||
pass.GetTransientsBuffer().EmplaceUniform(stroke_info));
|
||||
@ -166,7 +174,6 @@ bool SolidStrokeContents::Render(const ContentContext& renderer,
|
||||
|
||||
void SolidStrokeContents::SetStrokeSize(Scalar size) {
|
||||
stroke_size_ = size;
|
||||
arc_smoothing_approximation_ = SmoothingApproximation(5.0 / size, 0.0, 0.0);
|
||||
}
|
||||
|
||||
Scalar SolidStrokeContents::GetStrokeSize() const {
|
||||
|
||||
@ -74,8 +74,6 @@ class SolidStrokeContents final : public Contents {
|
||||
RenderPass& pass) const override;
|
||||
|
||||
private:
|
||||
SmoothingApproximation arc_smoothing_approximation_;
|
||||
|
||||
Color color_;
|
||||
Scalar stroke_size_ = 0.0;
|
||||
Scalar miter_limit_ = 4.0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user