WIP on stroke rendering.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user