Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
3 changes: 2 additions & 1 deletion impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ bool ClipContents::Render(const ContentContext& renderer,
auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = geometry_->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize());
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Expand Down
3 changes: 2 additions & 1 deletion impeller/entity/contents/linear_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ bool LinearGradientContents::Render(const ContentContext& renderer,
auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = GetGeometry()->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize());
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;
FS::BindGradientInfo(
Expand Down
3 changes: 2 additions & 1 deletion impeller/entity/contents/radial_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ bool RadialGradientContents::Render(const ContentContext& renderer,
auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = GetGeometry()->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize());
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;
FS::BindGradientInfo(
Expand Down
3 changes: 2 additions & 1 deletion impeller/entity/contents/solid_color_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ bool SolidColorContents::Render(const ContentContext& renderer,
auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = geometry_->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize());
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;

Expand Down
38 changes: 19 additions & 19 deletions impeller/entity/contents/solid_stroke_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static VertexBuffer CreateSolidStrokeVertices(
const SolidStrokeContents::CapProc& cap_proc,
const SolidStrokeContents::JoinProc& join_proc,
Scalar miter_limit,
const SmoothingApproximation& smoothing) {
Scalar tolerance) {
using VS = SolidFillVertexShader;

VertexBufferBuilder<VS::PerVertexData> vtx_builder;
Expand Down Expand Up @@ -101,8 +101,8 @@ static VertexBuffer CreateSolidStrokeVertices(
switch (contour_end_point_i - contour_start_point_i) {
case 1: {
Point p = polyline.points[contour_start_point_i];
cap_proc(vtx_builder, p, {-stroke_width * 0.5f, 0}, smoothing);
cap_proc(vtx_builder, p, {stroke_width * 0.5f, 0}, smoothing);
cap_proc(vtx_builder, p, {-stroke_width * 0.5f, 0}, tolerance);
cap_proc(vtx_builder, p, {stroke_width * 0.5f, 0}, tolerance);
continue;
}
case 0:
Expand Down Expand Up @@ -140,7 +140,7 @@ static VertexBuffer CreateSolidStrokeVertices(
// Generate start cap.
if (!polyline.contours[contour_i].is_closed) {
cap_proc(vtx_builder, polyline.points[contour_start_point_i], -offset,
smoothing);
tolerance);
}

// Generate contour geometry.
Expand All @@ -162,18 +162,18 @@ static VertexBuffer CreateSolidStrokeVertices(

// Generate join from the current line to the next line.
join_proc(vtx_builder, polyline.points[point_i], previous_offset,
offset, miter_limit, smoothing);
offset, miter_limit, tolerance);
}
}
}

// Generate end cap or join.
if (!polyline.contours[contour_i].is_closed) {
cap_proc(vtx_builder, polyline.points[contour_end_point_i - 1], offset,
smoothing);
tolerance);
} else {
join_proc(vtx_builder, polyline.points[contour_start_point_i], offset,
contour_first_offset, miter_limit, smoothing);
contour_first_offset, miter_limit, tolerance);
}
}

Expand Down Expand Up @@ -209,15 +209,15 @@ bool SolidStrokeContents::Render(const ContentContext& renderer,
cmd.pipeline = renderer.GetSolidFillPipeline(options);
cmd.stencil_reference = entity.GetStencilDepth();

auto smoothing = SmoothingApproximation(
60.0 / (stroke_size_ * entity.GetTransformation().GetMaxBasisLength()),
0.0, 0.0);
auto tolerance =
kDefaultCurveTolerance /
(stroke_size_ * entity.GetTransformation().GetMaxBasisLength());

Scalar min_size = 1.0f / sqrt(std::abs(determinant));
Scalar stroke_width = std::max(stroke_size_, min_size);
cmd.BindVertices(CreateSolidStrokeVertices(
path_, pass.GetTransientsBuffer(), stroke_width, cap_proc_, join_proc_,
miter_limit_ * stroke_width * 0.5, smoothing));
miter_limit_ * stroke_width * 0.5, tolerance));
VS::BindVertInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(vert_info));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));

Expand Down Expand Up @@ -256,12 +256,12 @@ void SolidStrokeContents::SetStrokeCap(Cap cap) {
case Cap::kButt:
cap_proc_ = [](VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
const Point& position, const Point& offset,
const SmoothingApproximation& smoothing) {};
Scalar tolerance) {};
break;
case Cap::kRound:
cap_proc_ = [](VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
const Point& position, const Point& offset,
const SmoothingApproximation& smoothing) {
Scalar tolerance) {
VS::PerVertexData vtx;

Point forward(offset.y, -offset.x);
Expand All @@ -271,7 +271,7 @@ void SolidStrokeContents::SetStrokeCap(Cap cap) {
CubicPathComponent(
offset, offset + forward * PathBuilder::kArcApproximationMagic,
forward + offset * PathBuilder::kArcApproximationMagic, forward)
.CreatePolyline(smoothing);
.CreatePolyline(tolerance);

vtx.position = position + offset;
vtx_builder.AppendVertex(vtx);
Expand All @@ -288,7 +288,7 @@ void SolidStrokeContents::SetStrokeCap(Cap cap) {
case Cap::kSquare:
cap_proc_ = [](VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
const Point& position, const Point& offset,
const SmoothingApproximation& smoothing) {
Scalar tolerance) {
VS::PerVertexData vtx;
vtx.position = position;

Expand Down Expand Up @@ -337,7 +337,7 @@ void SolidStrokeContents::SetStrokeJoin(Join join) {
join_proc_ = [](VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
const Point& position, const Point& start_offset,
const Point& end_offset, Scalar miter_limit,
const SmoothingApproximation& smoothing) {
Scalar tolerance) {
CreateBevelAndGetDirection(vtx_builder, position, start_offset,
end_offset);
};
Expand All @@ -346,7 +346,7 @@ void SolidStrokeContents::SetStrokeJoin(Join join) {
join_proc_ = [](VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
const Point& position, const Point& start_offset,
const Point& end_offset, Scalar miter_limit,
const SmoothingApproximation& smoothing) {
Scalar tolerance) {
Point start_normal = start_offset.Normalize();
Point end_normal = end_offset.Normalize();

Expand Down Expand Up @@ -375,7 +375,7 @@ void SolidStrokeContents::SetStrokeJoin(Join join) {
join_proc_ = [](VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
const Point& position, const Point& start_offset,
const Point& end_offset, Scalar miter_limit,
const SmoothingApproximation& smoothing) {
Scalar tolerance) {
Point start_normal = start_offset.Normalize();
Point end_normal = end_offset.Normalize();

Expand All @@ -402,7 +402,7 @@ void SolidStrokeContents::SetStrokeJoin(Join join) {

auto arc_points = CubicPathComponent(start_offset, start_handle,
middle_handle, middle)
.CreatePolyline(smoothing);
.CreatePolyline(tolerance);

VS::PerVertexData vtx;
for (const auto& point : arc_points) {
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/solid_stroke_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class SolidStrokeContents final : public Contents {
std::function<void(VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
const Point& position,
const Point& offset,
const SmoothingApproximation& smoothing)>;
Scalar tolerance)>;
using JoinProc =
std::function<void(VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
const Point& position,
const Point& start_offset,
const Point& end_offset,
Scalar miter_limit,
const SmoothingApproximation& smoothing)>;
Scalar tolerance)>;

SolidStrokeContents();

Expand Down
3 changes: 2 additions & 1 deletion impeller/entity/contents/sweep_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ bool SweepGradientContents::Render(const ContentContext& renderer,
auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = GetGeometry()->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize());
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;
FS::BindGradientInfo(
Expand Down
3 changes: 2 additions & 1 deletion impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
auto allocator = renderer.GetContext()->GetResourceAllocator();
auto geometry_result = GetGeometry()->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize());
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
cmd.BindVertices(geometry_result.vertex_buffer);
cmd.primitive_type = geometry_result.type;
VS::BindVertInfo(cmd, host_buffer.EmplaceUniform(vert_info));
Expand Down
3 changes: 2 additions & 1 deletion impeller/entity/contents/vertices_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ bool VerticesContents::Render(const ContentContext& renderer,

auto geometry_result = geometry_->GetPositionBuffer(
allocator, host_buffer, renderer.GetTessellator(),
pass.GetRenderTargetSize());
pass.GetRenderTargetSize(),
entity.GetTransformation().GetMaxBasisLength());
cmd.pipeline = renderer.GetGeometryPositionPipeline(
OptionsFromPassAndEntity(pass, entity));
cmd.primitive_type = geometry_result.type;
Expand Down
12 changes: 8 additions & 4 deletions impeller/entity/geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ GeometryResult VerticesGeometry::GetPositionBuffer(
std::shared_ptr<Allocator> device_allocator,
HostBuffer& host_buffer,
std::shared_ptr<Tessellator> tessellator,
ISize render_target_size) {
ISize render_target_size,
Scalar max_basis_length) {
if (!vertices_.IsValid()) {
return {};
}
Expand Down Expand Up @@ -182,10 +183,12 @@ GeometryResult PathGeometry::GetPositionBuffer(
std::shared_ptr<Allocator> device_allocator,
HostBuffer& host_buffer,
std::shared_ptr<Tessellator> tessellator,
ISize render_target_size) {
ISize render_target_size,
Scalar max_basis_length) {
VertexBuffer vertex_buffer;
auto tesselation_result = tessellator->Tessellate(
path_.GetFillType(), path_.CreatePolyline(),
path_.GetFillType(),
path_.CreatePolyline(kDefaultCurveTolerance / max_basis_length),
[&vertex_buffer, &host_buffer](
const float* vertices, size_t vertices_count, const uint16_t* indices,
size_t indices_count) {
Expand Down Expand Up @@ -244,7 +247,8 @@ GeometryResult CoverGeometry::GetPositionBuffer(
std::shared_ptr<Allocator> device_allocator,
HostBuffer& host_buffer,
std::shared_ptr<Tessellator> tessellator,
ISize render_target_size) {
ISize render_target_size,
Scalar max_basis_length) {
auto rect = Rect(Size(render_target_size));
constexpr uint16_t kRectIndicies[4] = {0, 1, 2, 3};
return GeometryResult{
Expand Down
12 changes: 8 additions & 4 deletions impeller/entity/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Geometry {
std::shared_ptr<Allocator> device_allocator,
HostBuffer& host_buffer,
std::shared_ptr<Tessellator> tessellator,
ISize render_target_size) = 0;
ISize render_target_size,
Scalar max_basis_length) = 0;

virtual GeometryResult GetPositionColorBuffer(
std::shared_ptr<Allocator> device_allocator,
Expand Down Expand Up @@ -75,7 +76,8 @@ class VerticesGeometry : public Geometry {
GeometryResult GetPositionBuffer(std::shared_ptr<Allocator> device_allocator,
HostBuffer& host_buffer,
std::shared_ptr<Tessellator> tessellator,
ISize render_target_size) override;
ISize render_target_size,
Scalar max_basis_length) override;

// |Geometry|
GeometryResult GetPositionColorBuffer(
Expand Down Expand Up @@ -115,7 +117,8 @@ class PathGeometry : public Geometry {
GeometryResult GetPositionBuffer(std::shared_ptr<Allocator> device_allocator,
HostBuffer& host_buffer,
std::shared_ptr<Tessellator> tessellator,
ISize render_target_size) override;
ISize render_target_size,
Scalar max_basis_length) override;

// |Geometry|
GeometryResult GetPositionColorBuffer(
Expand Down Expand Up @@ -156,7 +159,8 @@ class CoverGeometry : public Geometry {
GeometryResult GetPositionBuffer(std::shared_ptr<Allocator> device_allocator,
HostBuffer& host_buffer,
std::shared_ptr<Tessellator> tessellator,
ISize render_target_size) override;
ISize render_target_size,
Scalar max_basis_length) override;

// |Geometry|
GeometryResult GetPositionColorBuffer(
Expand Down
4 changes: 2 additions & 2 deletions impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "impeller/geometry/rect.h"
#include "impeller/geometry/scalar.h"
#include "impeller/geometry/size.h"
#include "path_component.h"

namespace impeller {
namespace testing {
Expand Down Expand Up @@ -1426,8 +1427,7 @@ TEST(GeometryTest, RectGetPositive) {

TEST(GeometryTest, CubicPathComponentPolylineDoesNotIncludePointOne) {
CubicPathComponent component({10, 10}, {20, 35}, {35, 20}, {40, 40});
SmoothingApproximation approximation;
auto polyline = component.CreatePolyline(approximation);
auto polyline = component.CreatePolyline();
ASSERT_NE(polyline.front().x, 10);
ASSERT_NE(polyline.front().y, 10);
ASSERT_EQ(polyline.back().x, 40);
Expand Down
7 changes: 3 additions & 4 deletions impeller/geometry/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ bool Path::UpdateContourComponentAtIndex(size_t index,
return true;
}

Path::Polyline Path::CreatePolyline(
const SmoothingApproximation& approximation) const {
Path::Polyline Path::CreatePolyline(Scalar tolerance) const {
Polyline polyline;

std::optional<Point> previous_contour_point;
Expand Down Expand Up @@ -251,10 +250,10 @@ Path::Polyline Path::CreatePolyline(
collect_points(linears_[component.index].CreatePolyline());
break;
case ComponentType::kQuadratic:
collect_points(quads_[component.index].CreatePolyline(approximation));
collect_points(quads_[component.index].CreatePolyline(tolerance));
break;
case ComponentType::kCubic:
collect_points(cubics_[component.index].CreatePolyline(approximation));
collect_points(cubics_[component.index].CreatePolyline(tolerance));
break;
case ComponentType::kContour:
if (component_i == components_.size() - 1) {
Expand Down
3 changes: 1 addition & 2 deletions impeller/geometry/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ class Path {
bool UpdateContourComponentAtIndex(size_t index,
const ContourComponent& contour);

Polyline CreatePolyline(
const SmoothingApproximation& approximation = {}) const;
Polyline CreatePolyline(Scalar tolerance = kDefaultCurveTolerance) const;

std::optional<Rect> GetBoundingBox() const;

Expand Down
Loading