WIP on stroke rendering.

This commit is contained in:
Chinmay Garde
2021-11-16 15:58:29 -08:00
committed by Dan Field
parent 6dc7ec06f9
commit 04fadf5652
5 changed files with 72 additions and 21 deletions

View File

@@ -56,10 +56,10 @@ TEST_F(AiksTest, CanRenderImage) {
auto image = std::make_shared<Image>(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<Image>(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

View File

@@ -7,10 +7,18 @@
namespace impeller {
std::shared_ptr<Contents> Paint::CreateContentsForEntity() const {
if (!color.IsTransparent()) {
auto solid_color = std::make_shared<SolidColorContents>();
solid_color->SetColor(color);
return solid_color;
switch (style) {
case Style::kFill: {
auto solid_color = std::make_shared<SolidColorContents>();
solid_color->SetColor(color);
return solid_color;
}
case Style::kStroke: {
auto solid_stroke = std::make_shared<SolidStrokeContents>();
solid_stroke->SetColor(color);
solid_stroke->SetStrokeSize(stroke_width);
return solid_stroke;
}
}
return nullptr;

View File

@@ -4,16 +4,23 @@
#pragma once
#include "flutter/fml/macros.h"
#include <memory>
#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<Contents> CreateContentsForEntity() const;
};

View File

@@ -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> 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

View File

@@ -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,