| Flutter Impeller |

fill_path_geometry.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/entity/geometry/fill_path_geometry.h"
6
7 #include "fml/logging.h"
8 #include "impeller/core/formats.h"
9 #include "impeller/core/vertex_buffer.h"
10 #include "impeller/entity/contents/content_context.h"
11 #include "impeller/entity/geometry/geometry.h"
12
13 namespace impeller {
14
15 FillPathGeometry::FillPathGeometry(const Path& path,
16 std::optional<Rect> inner_rect)
17 : path_(path), inner_rect_(inner_rect) {}
18
19 FillPathGeometry::~FillPathGeometry() {}
20
21 GeometryResult FillPathGeometry::GetPositionBuffer(
22 const ContentContext& renderer,
23 const Entity& entity,
24 RenderPass& pass) const {
25 auto& host_buffer = renderer.GetTransientsBuffer();
26
27 const auto& bounding_box = path_.GetBoundingBox();
28 if (bounding_box.has_value() && bounding_box->IsEmpty()) {
29 return GeometryResult{
30 .type = PrimitiveType::kTriangle,
31 .vertex_buffer =
32 VertexBuffer{
33 .vertex_buffer = {},
34 .vertex_count = 0,
35 .index_type = IndexType::k16bit,
36 },
37 .transform = pass.GetOrthographicTransform() * entity.GetTransform(),
38 };
39 }
40
41 VertexBuffer vertex_buffer = renderer.GetTessellator()->TessellateConvex(
42 path_, host_buffer, entity.GetTransform().GetMaxBasisLengthXY());
43
44 return GeometryResult{
45 .type = PrimitiveType::kTriangleStrip,
46 .vertex_buffer = vertex_buffer,
47 .transform = entity.GetShaderTransform(pass),
48 .mode = GetResultMode(),
49 };
50 }
51
52 GeometryResult::Mode FillPathGeometry::GetResultMode() const {
53 const auto& bounding_box = path_.GetBoundingBox();
54 if (path_.IsConvex() ||
55 (bounding_box.has_value() && bounding_box->IsEmpty())) {
56 return GeometryResult::Mode::kNormal;
57 }
58
59 switch (path_.GetFillType()) {
60 case FillType::kNonZero:
61 return GeometryResult::Mode::kNonZero;
62 case FillType::kOdd:
63 return GeometryResult::Mode::kEvenOdd;
64 }
65
66 FML_UNREACHABLE();
67 }
68
69 std::optional<Rect> FillPathGeometry::GetCoverage(
70 const Matrix& transform) const {
71 return path_.GetTransformedBoundingBox(transform);
72 }
73
74 bool FillPathGeometry::CoversArea(const Matrix& transform,
75 const Rect& rect) const {
76 if (!inner_rect_.has_value()) {
77 return false;
78 }
79 if (!transform.IsTranslationScaleOnly()) {
80 return false;
81 }
82 Rect coverage = inner_rect_->TransformBounds(transform);
83 return coverage.Contains(rect);
84 }
85
86 } // namespace impeller
impeller::GeometryResult::Mode::kNormal
@ kNormal
The geometry has no overlapping triangles.
impeller::Entity::GetShaderTransform
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition: entity.cc:51
impeller::FillPathGeometry::~FillPathGeometry
~FillPathGeometry() override
Definition: fill_path_geometry.cc:19
impeller::IndexType::k16bit
@ k16bit
geometry.h
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:47
vertex_buffer.h
impeller::FillType::kOdd
@ kOdd
impeller::VertexBuffer
Definition: vertex_buffer.h:13
impeller::Path::GetBoundingBox
std::optional< Rect > GetBoundingBox() const
Definition: path.cc:387
formats.h
impeller::VertexBuffer::vertex_buffer
BufferView vertex_buffer
Definition: vertex_buffer.h:14
impeller::GeometryResult::Mode::kEvenOdd
@ kEvenOdd
impeller::RenderPass::GetOrthographicTransform
const Matrix & GetOrthographicTransform() const
Definition: render_pass.cc:47
impeller::GeometryResult::Mode
Mode
Definition: geometry.h:27
impeller::PrimitiveType::kTriangle
@ kTriangle
impeller::Entity
Definition: entity.h:20
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:42
impeller::Path
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:52
impeller::Path::GetTransformedBoundingBox
std::optional< Rect > GetTransformedBoundingBox(const Matrix &transform) const
Definition: path.cc:391
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:213
impeller::GeometryResult
Definition: geometry.h:26
impeller::ContentContext::GetTessellator
std::shared_ptr< Tessellator > GetTessellator() const
Definition: content_context.cc:546
fill_path_geometry.h
impeller::FillType::kNonZero
@ kNonZero
impeller::TRect::Contains
constexpr bool Contains(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
Definition: rect.h:225
impeller::FillPathGeometry::CoversArea
bool CoversArea(const Matrix &transform, const Rect &rect) const override
Determines if this geometry, transformed by the given transform, will completely cover all surface ar...
Definition: fill_path_geometry.cc:74
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
content_context.h
impeller::Matrix::GetMaxBasisLengthXY
constexpr Scalar GetMaxBasisLengthXY() const
Definition: matrix.h:298
impeller::Path::IsConvex
bool IsConvex() const
Definition: path.cc:51
impeller
Definition: allocation.cc:12
impeller::ContentContext
Definition: content_context.h:366
impeller::TRect
Definition: rect.h:122
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::ContentContext::GetTransientsBuffer
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
Definition: content_context.h:753
impeller::GeometryResult::Mode::kNonZero
@ kNonZero
impeller::Path::GetFillType
FillType GetFillType() const
Definition: path.cc:47
impeller::FillPathGeometry::FillPathGeometry
FillPathGeometry(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
Definition: fill_path_geometry.cc:15