diff --git a/engine/src/flutter/impeller/aiks/aiks_unittests.cc b/engine/src/flutter/impeller/aiks/aiks_unittests.cc index d5fbae03db..d0135aa868 100644 --- a/engine/src/flutter/impeller/aiks/aiks_unittests.cc +++ b/engine/src/flutter/impeller/aiks/aiks_unittests.cc @@ -56,10 +56,10 @@ TEST_F(AiksTest, CanRenderImage) { auto image = std::make_shared(CreateTextureForFixture("kalimba.jpg")); paint.color = Color::Red(); canvas.DrawImage(image, Point::MakeXY(100.0, 100.0), paint); - ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); + // ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } -TEST_F(AiksTest, CanRenderImageRect) { +TEST_F(AiksTest, DISABLED_CanRenderImageRect) { Canvas canvas; Paint paint; auto image = std::make_shared(CreateTextureForFixture("kalimba.jpg")); @@ -76,5 +76,14 @@ TEST_F(AiksTest, CanRenderImageRect) { // ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_F(AiksTest, CanRenderStrokes) { + Canvas canvas; + Paint paint; + paint.color = Color::Red(); + paint.stroke_width = 20.0; + canvas.DrawPath(PathBuilder{}.AddCircle({500, 500}, 250).CreatePath(), paint); + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + } // namespace testing } // namespace impeller diff --git a/engine/src/flutter/impeller/aiks/paint.cc b/engine/src/flutter/impeller/aiks/paint.cc index e45f9a7645..ca1f6169f2 100644 --- a/engine/src/flutter/impeller/aiks/paint.cc +++ b/engine/src/flutter/impeller/aiks/paint.cc @@ -7,10 +7,18 @@ namespace impeller { std::shared_ptr Paint::CreateContentsForEntity() const { - if (!color.IsTransparent()) { - auto solid_color = std::make_shared(); - solid_color->SetColor(color); - return solid_color; + switch (style) { + case Style::kFill: { + auto solid_color = std::make_shared(); + solid_color->SetColor(color); + return solid_color; + } + case Style::kStroke: { + auto solid_stroke = std::make_shared(); + solid_stroke->SetColor(color); + solid_stroke->SetStrokeSize(stroke_width); + return solid_stroke; + } } return nullptr; diff --git a/engine/src/flutter/impeller/aiks/paint.h b/engine/src/flutter/impeller/aiks/paint.h index 7f59475fce..98cb1ce1ca 100644 --- a/engine/src/flutter/impeller/aiks/paint.h +++ b/engine/src/flutter/impeller/aiks/paint.h @@ -4,16 +4,23 @@ #pragma once -#include "flutter/fml/macros.h" +#include +#include "flutter/fml/macros.h" #include "impeller/entity/contents.h" #include "impeller/geometry/color.h" namespace impeller { struct Paint { + enum class Style { + kFill, + kStroke, + }; + Color color; Scalar stroke_width = 0.0; + Style style = Style::kFill; std::shared_ptr CreateContentsForEntity() const; }; diff --git a/engine/src/flutter/impeller/entity/contents.cc b/engine/src/flutter/impeller/entity/contents.cc index 24edc049c8..e99e442c78 100644 --- a/engine/src/flutter/impeller/entity/contents.cc +++ b/engine/src/flutter/impeller/entity/contents.cc @@ -115,6 +115,10 @@ bool SolidColorContents::Render(const ContentRenderer& renderer, const Entity& entity, const Surface& surface, RenderPass& pass) const { + if (color_.IsTransparent()) { + return true; + } + using VS = SolidFillPipeline::VertexShader; Command cmd; @@ -165,18 +169,6 @@ std::unique_ptr SolidColorContents::Make(Color color) { return contents; } -/******************************************************************************* - ******* SolidStrokeContents - ******************************************************************************/ - -void SolidStrokeContents::SetColor(Color color) { - color_ = color; -} - -const Color& SolidStrokeContents::GetColor() const { - return color_; -} - /******************************************************************************* ******* TextureContents ******************************************************************************/ @@ -267,4 +259,39 @@ const IRect& TextureContents::GetSourceRect() const { return source_rect_; } +/******************************************************************************* + ******* SolidStrokeContents + ******************************************************************************/ + +SolidStrokeContents::SolidStrokeContents() = default; + +SolidStrokeContents::~SolidStrokeContents() = default; + +void SolidStrokeContents::SetColor(Color color) { + color_ = color; +} + +const Color& SolidStrokeContents::GetColor() const { + return color_; +} + +bool SolidStrokeContents::Render(const ContentRenderer& renderer, + const Entity& entity, + const Surface& surface, + RenderPass& pass) const { + if (color_.IsTransparent() || stroke_size_ <= 0.0) { + return true; + } + + return false; +} + +void SolidStrokeContents::SetStrokeSize(Scalar size) { + stroke_size_ = size; +} + +Scalar SolidStrokeContents::GetStrokeSize() const { + return stroke_size_; +} + } // namespace impeller diff --git a/engine/src/flutter/impeller/entity/contents.h b/engine/src/flutter/impeller/entity/contents.h index 3e3b9ecc3f..855ec0adfd 100644 --- a/engine/src/flutter/impeller/entity/contents.h +++ b/engine/src/flutter/impeller/entity/contents.h @@ -122,9 +122,9 @@ class SolidStrokeContents final : public Contents { const Color& GetColor() const; - void SetStrokeSize(Scalar size) { stroke_size_ = size; } + void SetStrokeSize(Scalar size); - Scalar GetStrokeSize() const { return stroke_size_; } + Scalar GetStrokeSize() const; // |Contents| bool Render(const ContentRenderer& renderer,