Skip to content

Commit 866045d

Browse files
chinmaygardednfield
authored andcommitted
WIP on stroke rendering.
1 parent 5405b9a commit 866045d

File tree

5 files changed

+72
-21
lines changed

5 files changed

+72
-21
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ TEST_F(AiksTest, CanRenderImage) {
5656
auto image = std::make_shared<Image>(CreateTextureForFixture("kalimba.jpg"));
5757
paint.color = Color::Red();
5858
canvas.DrawImage(image, Point::MakeXY(100.0, 100.0), paint);
59-
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
59+
// ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
6060
}
6161

62-
TEST_F(AiksTest, CanRenderImageRect) {
62+
TEST_F(AiksTest, DISABLED_CanRenderImageRect) {
6363
Canvas canvas;
6464
Paint paint;
6565
auto image = std::make_shared<Image>(CreateTextureForFixture("kalimba.jpg"));
@@ -76,5 +76,14 @@ TEST_F(AiksTest, CanRenderImageRect) {
7676
// ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
7777
}
7878

79+
TEST_F(AiksTest, CanRenderStrokes) {
80+
Canvas canvas;
81+
Paint paint;
82+
paint.color = Color::Red();
83+
paint.stroke_width = 20.0;
84+
canvas.DrawPath(PathBuilder{}.AddCircle({500, 500}, 250).CreatePath(), paint);
85+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
86+
}
87+
7988
} // namespace testing
8089
} // namespace impeller

impeller/aiks/paint.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
namespace impeller {
88

99
std::shared_ptr<Contents> Paint::CreateContentsForEntity() const {
10-
if (!color.IsTransparent()) {
11-
auto solid_color = std::make_shared<SolidColorContents>();
12-
solid_color->SetColor(color);
13-
return solid_color;
10+
switch (style) {
11+
case Style::kFill: {
12+
auto solid_color = std::make_shared<SolidColorContents>();
13+
solid_color->SetColor(color);
14+
return solid_color;
15+
}
16+
case Style::kStroke: {
17+
auto solid_stroke = std::make_shared<SolidStrokeContents>();
18+
solid_stroke->SetColor(color);
19+
solid_stroke->SetStrokeSize(stroke_width);
20+
return solid_stroke;
21+
}
1422
}
1523

1624
return nullptr;

impeller/aiks/paint.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44

55
#pragma once
66

7-
#include "flutter/fml/macros.h"
7+
#include <memory>
88

9+
#include "flutter/fml/macros.h"
910
#include "impeller/entity/contents.h"
1011
#include "impeller/geometry/color.h"
1112

1213
namespace impeller {
1314

1415
struct Paint {
16+
enum class Style {
17+
kFill,
18+
kStroke,
19+
};
20+
1521
Color color;
1622
Scalar stroke_width = 0.0;
23+
Style style = Style::kFill;
1724

1825
std::shared_ptr<Contents> CreateContentsForEntity() const;
1926
};

impeller/entity/contents.cc

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ bool SolidColorContents::Render(const ContentRenderer& renderer,
115115
const Entity& entity,
116116
const Surface& surface,
117117
RenderPass& pass) const {
118+
if (color_.IsTransparent()) {
119+
return true;
120+
}
121+
118122
using VS = SolidFillPipeline::VertexShader;
119123

120124
Command cmd;
@@ -165,18 +169,6 @@ std::unique_ptr<SolidColorContents> SolidColorContents::Make(Color color) {
165169
return contents;
166170
}
167171

168-
/*******************************************************************************
169-
******* SolidStrokeContents
170-
******************************************************************************/
171-
172-
void SolidStrokeContents::SetColor(Color color) {
173-
color_ = color;
174-
}
175-
176-
const Color& SolidStrokeContents::GetColor() const {
177-
return color_;
178-
}
179-
180172
/*******************************************************************************
181173
******* TextureContents
182174
******************************************************************************/
@@ -267,4 +259,39 @@ const IRect& TextureContents::GetSourceRect() const {
267259
return source_rect_;
268260
}
269261

262+
/*******************************************************************************
263+
******* SolidStrokeContents
264+
******************************************************************************/
265+
266+
SolidStrokeContents::SolidStrokeContents() = default;
267+
268+
SolidStrokeContents::~SolidStrokeContents() = default;
269+
270+
void SolidStrokeContents::SetColor(Color color) {
271+
color_ = color;
272+
}
273+
274+
const Color& SolidStrokeContents::GetColor() const {
275+
return color_;
276+
}
277+
278+
bool SolidStrokeContents::Render(const ContentRenderer& renderer,
279+
const Entity& entity,
280+
const Surface& surface,
281+
RenderPass& pass) const {
282+
if (color_.IsTransparent() || stroke_size_ <= 0.0) {
283+
return true;
284+
}
285+
286+
return false;
287+
}
288+
289+
void SolidStrokeContents::SetStrokeSize(Scalar size) {
290+
stroke_size_ = size;
291+
}
292+
293+
Scalar SolidStrokeContents::GetStrokeSize() const {
294+
return stroke_size_;
295+
}
296+
270297
} // namespace impeller

impeller/entity/contents.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ class SolidStrokeContents final : public Contents {
122122

123123
const Color& GetColor() const;
124124

125-
void SetStrokeSize(Scalar size) { stroke_size_ = size; }
125+
void SetStrokeSize(Scalar size);
126126

127-
Scalar GetStrokeSize() const { return stroke_size_; }
127+
Scalar GetStrokeSize() const;
128128

129129
// |Contents|
130130
bool Render(const ContentRenderer& renderer,

0 commit comments

Comments
 (0)