Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions impeller/entity/contents/color_source_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class ColorSourceContents : public Contents {

GeometryResult stencil_geometry_result =
GetGeometry()->GetPositionBuffer(renderer, entity, pass);
if (stencil_geometry_result.vertex_buffer.vertex_count == 0u) {
return true;
}
pass.SetVertexBuffer(std::move(stencil_geometry_result.vertex_buffer));
options.primitive_type = stencil_geometry_result.type;

Expand Down Expand Up @@ -182,6 +185,9 @@ class ColorSourceContents : public Contents {
? geometry.GetPositionUVBuffer(texture_coverage, effect_transform,
renderer, entity, pass)
: geometry.GetPositionBuffer(renderer, entity, pass);
if (geometry_result.vertex_buffer.vertex_count == 0u) {
return true;
}
pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
options.primitive_type = geometry_result.type;

Expand Down
45 changes: 45 additions & 0 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2812,6 +2812,51 @@ TEST_P(EntityTest, FailOnValidationError) {
"");
}

TEST_P(EntityTest, CanComputeGeometryForEmptyPathsWithoutCrashing) {
PathBuilder builder = {};
builder.AddRect(Rect::MakeLTRB(0, 0, 0, 0));
Path path = builder.TakePath();

EXPECT_TRUE(path.GetBoundingBox()->IsEmpty());

auto geom = Geometry::MakeFillPath(path);

Entity entity;
RenderTarget target =
GetContentContext()->GetRenderTargetCache()->CreateOffscreen(
*GetContext(), {1, 1}, 1u);
testing::MockRenderPass render_pass(GetContext(), target);
auto position_result =
geom->GetPositionBuffer(*GetContentContext(), entity, render_pass);

auto uv_result =
geom->GetPositionUVBuffer(Rect::MakeLTRB(0, 0, 100, 100), Matrix(),
*GetContentContext(), entity, render_pass);

EXPECT_EQ(position_result.vertex_buffer.vertex_count, 0u);
EXPECT_EQ(uv_result.vertex_buffer.vertex_count, 0u);

EXPECT_EQ(geom->GetResultMode(), GeometryResult::Mode::kNormal);
}

TEST_P(EntityTest, CanRenderEmptyPathsWithoutCrashing) {
PathBuilder builder = {};
builder.AddRect(Rect::MakeLTRB(0, 0, 0, 0));
Path path = builder.TakePath();

EXPECT_TRUE(path.GetBoundingBox()->IsEmpty());

auto contents = std::make_shared<SolidColorContents>();
contents->SetGeometry(Geometry::MakeFillPath(path));
contents->SetColor(Color::Red());

Entity entity;
entity.SetTransform(Matrix::MakeScale(GetContentScale()));
entity.SetContents(contents);

ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
}

} // namespace testing
} // namespace impeller

Expand Down
35 changes: 33 additions & 2 deletions impeller/entity/geometry/fill_path_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "fml/logging.h"
#include "impeller/core/formats.h"
#include "impeller/core/vertex_buffer.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/geometry/geometry.h"

Expand All @@ -20,8 +21,22 @@ GeometryResult FillPathGeometry::GetPositionBuffer(
const Entity& entity,
RenderPass& pass) const {
auto& host_buffer = renderer.GetTransientsBuffer();
VertexBuffer vertex_buffer;

const auto& bounding_box = path_.GetBoundingBox();
if (bounding_box.has_value() && bounding_box->IsEmpty()) {
return GeometryResult{
.type = PrimitiveType::kTriangle,
.vertex_buffer =
VertexBuffer{
.vertex_buffer = {},
.vertex_count = 0,
.index_type = IndexType::k16bit,
},
.transform = pass.GetOrthographicTransform() * entity.GetTransform(),
};
}

VertexBuffer vertex_buffer;
if constexpr (!ContentContext::kEnableStencilThenCover) {
if (!path_.IsConvex()) {
auto tesselation_result = renderer.GetTessellator()->Tessellate(
Expand Down Expand Up @@ -79,6 +94,20 @@ GeometryResult FillPathGeometry::GetPositionUVBuffer(
RenderPass& pass) const {
using VS = TextureFillVertexShader;

const auto& bounding_box = path_.GetBoundingBox();
if (bounding_box.has_value() && bounding_box->IsEmpty()) {
return GeometryResult{
.type = PrimitiveType::kTriangle,
.vertex_buffer =
VertexBuffer{
.vertex_buffer = {},
.vertex_count = 0,
.index_type = IndexType::k16bit,
},
.transform = pass.GetOrthographicTransform() * entity.GetTransform(),
};
}

auto uv_transform =
texture_coverage.GetNormalizingTransform() * effect_transform;

Expand Down Expand Up @@ -139,7 +168,9 @@ GeometryResult FillPathGeometry::GetPositionUVBuffer(
}

GeometryResult::Mode FillPathGeometry::GetResultMode() const {
if (!ContentContext::kEnableStencilThenCover || path_.IsConvex()) {
const auto& bounding_box = path_.GetBoundingBox();
if (!ContentContext::kEnableStencilThenCover || path_.IsConvex() ||
(bounding_box.has_value() && bounding_box->IsEmpty())) {
return GeometryResult::Mode::kNormal;
}

Expand Down
3 changes: 3 additions & 0 deletions impeller/entity/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>
#include "flutter/testing/testing.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/geometry/geometry.h"
#include "impeller/entity/geometry/stroke_path_geometry.h"
#include "impeller/geometry/geometry_asserts.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/renderer/testing/mocks.h"

inline ::testing::AssertionResult SolidVerticesNear(
std::vector<impeller::SolidFillVertexShader::PerVertexData> a,
Expand Down
1 change: 1 addition & 0 deletions impeller/tessellator/tessellator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Path::Polyline Tessellator::CreateTempPolyline(const Path& path,
std::vector<Point> Tessellator::TessellateConvex(const Path& path,
Scalar tolerance) {
FML_DCHECK(point_buffer_);

std::vector<Point> output;
point_buffer_->clear();
auto polyline =
Expand Down