Skip to content

Commit

Permalink
[Impeller] give geometry classes similar API as entity / implement st…
Browse files Browse the repository at this point in the history
…rokepathgeom (flutter#36693)
  • Loading branch information
jonahwilliams authored Oct 20, 2022
1 parent 4e3a5e3 commit 3a7acb3
Show file tree
Hide file tree
Showing 19 changed files with 752 additions and 683 deletions.
8 changes: 2 additions & 6 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1481,13 +1481,9 @@ TEST_P(AiksTest, SolidStrokesRenderCorrectly) {
canvas.ClipPath(PathBuilder{}.AddCircle(middle, radius).TakePath());
}

for (auto join :
{SolidStrokeContents::Join::kBevel, SolidStrokeContents::Join::kRound,
SolidStrokeContents::Join::kMiter}) {
for (auto join : {Join::kBevel, Join::kRound, Join::kMiter}) {
paint.stroke_join = join;
for (auto cap :
{SolidStrokeContents::Cap::kButt, SolidStrokeContents::Cap::kSquare,
SolidStrokeContents::Cap::kRound}) {
for (auto cap : {Cap::kButt, Cap::kSquare, Cap::kRound}) {
paint.stroke_cap = cap;
canvas.DrawPath(path, paint);
canvas.Translate({80, 0});
Expand Down
2 changes: 1 addition & 1 deletion impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void Canvas::DrawCircle(Point center, Scalar radius, Paint paint) {

void Canvas::ClipPath(Path path, Entity::ClipOperation clip_op) {
auto contents = std::make_shared<ClipContents>();
contents->SetGeometry(Geometry::MakePath(std::move(path)));
contents->SetGeometry(Geometry::MakeFillPath(std::move(path)));
contents->SetClipOperation(clip_op);

Entity entity;
Expand Down
12 changes: 5 additions & 7 deletions impeller/aiks/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ std::shared_ptr<Contents> Paint::CreateContentsForEntity(Path path,
auto& source = color_source.value();
auto contents = source();
contents->SetGeometry(cover ? Geometry::MakeCover()
: Geometry::MakePath(std::move(path)));
: Geometry::MakeFillPath(std::move(path)));
contents->SetAlpha(color.alpha);
return contents;
}
Expand All @@ -24,18 +24,16 @@ std::shared_ptr<Contents> Paint::CreateContentsForEntity(Path path,
case Style::kFill: {
auto solid_color = std::make_shared<SolidColorContents>();
solid_color->SetGeometry(cover ? Geometry::MakeCover()
: Geometry::MakePath(std::move(path)));
: Geometry::MakeFillPath(std::move(path)));
solid_color->SetColor(color);
return solid_color;
}
case Style::kStroke: {
auto solid_stroke = std::make_shared<SolidStrokeContents>();
solid_stroke->SetPath(std::move(path));
solid_stroke->SetGeometry(
Geometry::MakeStrokePath(std::move(path), stroke_width, stroke_miter,
stroke_cap, stroke_join));
solid_stroke->SetColor(color);
solid_stroke->SetStrokeSize(stroke_width);
solid_stroke->SetStrokeMiter(stroke_miter);
solid_stroke->SetStrokeCap(stroke_cap);
solid_stroke->SetStrokeJoin(stroke_join);
return solid_stroke;
}
}
Expand Down
5 changes: 3 additions & 2 deletions impeller/aiks/paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "impeller/entity/contents/solid_stroke_contents.h"
#include "impeller/entity/contents/sweep_gradient_contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/geometry.h"
#include "impeller/geometry/color.h"

namespace impeller {
Expand Down Expand Up @@ -50,8 +51,8 @@ struct Paint {
std::optional<ColorSourceProc> color_source;

Scalar stroke_width = 0.0;
SolidStrokeContents::Cap stroke_cap = SolidStrokeContents::Cap::kButt;
SolidStrokeContents::Join stroke_join = SolidStrokeContents::Join::kMiter;
Cap stroke_cap = Cap::kButt;
Join stroke_join = Join::kMiter;
Scalar stroke_miter = 4.0;
Style style = Style::kFill;
BlendMode blend_mode = BlendMode::kSourceOver;
Expand Down
17 changes: 9 additions & 8 deletions impeller/display_list/display_list_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "impeller/entity/contents/sweep_gradient_contents.h"
#include "impeller/entity/contents/tiled_texture_contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/geometry.h"
#include "impeller/geometry/path.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/geometry/scalar.h"
Expand Down Expand Up @@ -227,13 +228,13 @@ void DisplayListDispatcher::setStrokeMiter(SkScalar limit) {
void DisplayListDispatcher::setStrokeCap(flutter::DlStrokeCap cap) {
switch (cap) {
case flutter::DlStrokeCap::kButt:
paint_.stroke_cap = SolidStrokeContents::Cap::kButt;
paint_.stroke_cap = Cap::kButt;
break;
case flutter::DlStrokeCap::kRound:
paint_.stroke_cap = SolidStrokeContents::Cap::kRound;
paint_.stroke_cap = Cap::kRound;
break;
case flutter::DlStrokeCap::kSquare:
paint_.stroke_cap = SolidStrokeContents::Cap::kSquare;
paint_.stroke_cap = Cap::kSquare;
break;
}
}
Expand All @@ -242,13 +243,13 @@ void DisplayListDispatcher::setStrokeCap(flutter::DlStrokeCap cap) {
void DisplayListDispatcher::setStrokeJoin(flutter::DlStrokeJoin join) {
switch (join) {
case flutter::DlStrokeJoin::kMiter:
paint_.stroke_join = SolidStrokeContents::Join::kMiter;
paint_.stroke_join = Join::kMiter;
break;
case flutter::DlStrokeJoin::kRound:
paint_.stroke_join = SolidStrokeContents::Join::kRound;
paint_.stroke_join = Join::kRound;
break;
case flutter::DlStrokeJoin::kBevel:
paint_.stroke_join = SolidStrokeContents::Join::kBevel;
paint_.stroke_join = Join::kBevel;
break;
}
}
Expand Down Expand Up @@ -1010,8 +1011,8 @@ void DisplayListDispatcher::drawPoints(SkCanvas::PointMode mode,
paint.style = Paint::Style::kStroke;
switch (mode) {
case SkCanvas::kPoints_PointMode:
if (paint.stroke_cap == SolidStrokeContents::Cap::kButt) {
paint.stroke_cap = SolidStrokeContents::Cap::kSquare;
if (paint.stroke_cap == Cap::kButt) {
paint.stroke_cap = Cap::kSquare;
}
for (uint32_t i = 0; i < count; i++) {
Point p0 = ToPoint(points[i]);
Expand Down
6 changes: 1 addition & 5 deletions impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,8 @@ bool ClipContents::Render(const ContentContext& renderer,

cmd.pipeline = renderer.GetClipPipeline(options);

auto& host_buffer = pass.GetTransientsBuffer();
auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = geometry_->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
auto geometry_result = geometry_->GetPositionBuffer(renderer, entity, pass);
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static std::optional<Snapshot> PipelineBlend(

if (foreground_color.has_value()) {
auto contents = std::make_shared<SolidColorContents>();
contents->SetGeometry(Geometry::MakePath(
contents->SetGeometry(Geometry::MakeFillPath(
PathBuilder{}
.AddRect(Rect::MakeSize(pass.GetRenderTargetSize()))
.TakePath()));
Expand Down
7 changes: 2 additions & 5 deletions impeller/entity/contents/linear_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ bool LinearGradientContents::Render(const ContentContext& renderer,
OptionsFromPassAndEntity(pass, entity));
cmd.stencil_reference = entity.GetStencilDepth();

auto& host_buffer = pass.GetTransientsBuffer();
auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = GetGeometry()->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
auto geometry_result =
GetGeometry()->GetPositionBuffer(renderer, entity, pass);
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;
FS::BindGradientInfo(
Expand Down
8 changes: 3 additions & 5 deletions impeller/entity/contents/radial_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ bool RadialGradientContents::Render(const ContentContext& renderer,
cmd.pipeline = renderer.GetRadialGradientFillPipeline(
OptionsFromPassAndEntity(pass, entity));
cmd.stencil_reference = entity.GetStencilDepth();
auto& host_buffer = pass.GetTransientsBuffer();

auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = GetGeometry()->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
auto geometry_result =
GetGeometry()->GetPositionBuffer(renderer, entity, pass);
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;
FS::BindGradientInfo(
Expand Down
6 changes: 2 additions & 4 deletions impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
/// Resolve geometry.
///

auto geometry_result = GetGeometry()->GetPositionBuffer(
context->GetResourceAllocator(), pass.GetTransientsBuffer(),
renderer.GetTessellator(), pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
auto geometry_result =
GetGeometry()->GetPositionBuffer(renderer, entity, pass);

//--------------------------------------------------------------------------
/// Get or create runtime stage pipeline.
Expand Down
9 changes: 2 additions & 7 deletions impeller/entity/contents/solid_color_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ bool SolidColorContents::Render(const ContentContext& renderer,
renderer.GetSolidFillPipeline(OptionsFromPassAndEntity(pass, entity));
cmd.stencil_reference = entity.GetStencilDepth();

auto& host_buffer = pass.GetTransientsBuffer();
auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = geometry_->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
auto geometry_result = geometry_->GetPositionBuffer(renderer, entity, pass);
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;

Expand All @@ -87,7 +82,7 @@ bool SolidColorContents::Render(const ContentContext& renderer,
std::unique_ptr<SolidColorContents> SolidColorContents::Make(Path path,
Color color) {
auto contents = std::make_unique<SolidColorContents>();
contents->SetGeometry(Geometry::MakePath(std::move(path)));
contents->SetGeometry(Geometry::MakeFillPath(std::move(path)));
contents->SetColor(color);
return contents;
}
Expand Down
Loading

0 comments on commit 3a7acb3

Please sign in to comment.