| 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 GeometryResult FillPathGeometry::GetPositionBuffer(
20 const ContentContext& renderer,
21 const Entity& entity,
22 RenderPass& pass) const {
23 auto& host_buffer = renderer.GetTransientsBuffer();
24
25 const auto& bounding_box = path_.GetBoundingBox();
26 if (bounding_box.has_value() && bounding_box->IsEmpty()) {
27 return GeometryResult{
28 .type = PrimitiveType::kTriangle,
29 .vertex_buffer =
30 VertexBuffer{
31 .vertex_buffer = {},
32 .vertex_count = 0,
33 .index_type = IndexType::k16bit,
34 },
35 .transform = pass.GetOrthographicTransform() * entity.GetTransform(),
36 };
37 }
38
39 VertexBuffer vertex_buffer = renderer.GetTessellator()->TessellateConvex(
40 path_, host_buffer, entity.GetTransform().GetMaxBasisLength());
41
42 return GeometryResult{
43 .type = PrimitiveType::kTriangleStrip,
44 .vertex_buffer = vertex_buffer,
45 .transform = entity.GetShaderTransform(pass),
46 .mode = GetResultMode(),
47 };
48 }
49
50 GeometryResult::Mode FillPathGeometry::GetResultMode() const {
51 const auto& bounding_box = path_.GetBoundingBox();
52 if (path_.IsConvex() ||
53 (bounding_box.has_value() && bounding_box->IsEmpty())) {
54 return GeometryResult::Mode::kNormal;
55 }
56
57 switch (path_.GetFillType()) {
58 case FillType::kNonZero:
59 return GeometryResult::Mode::kNonZero;
60 case FillType::kOdd:
61 return GeometryResult::Mode::kEvenOdd;
62 }
63
64 FML_UNREACHABLE();
65 }
66
67 std::optional<Rect> FillPathGeometry::GetCoverage(
68 const Matrix& transform) const {
69 return path_.GetTransformedBoundingBox(transform);
70 }
71
72 bool FillPathGeometry::CoversArea(const Matrix& transform,
73 const Rect& rect) const {
74 if (!inner_rect_.has_value()) {
75 return false;
76 }
77 if (!transform.IsTranslationScaleOnly()) {
78 return false;
79 }
80 Rect coverage = inner_rect_->TransformBounds(transform);
81 return coverage.Contains(rect);
82 }
83
84 } // 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:50
impeller::IndexType::k16bit
@ k16bit
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:46
vertex_buffer.h
impeller::FillType::kOdd
@ kOdd
impeller::VertexBuffer
Definition: vertex_buffer.h:13
formats.h
impeller::Path::GetBoundingBox
std::optional< Rect > GetBoundingBox() const
Definition: path.cc:405
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:20
impeller::PrimitiveType::kTriangle
@ kTriangle
impeller::Entity
Definition: entity.h:20
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:35
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:409
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:231
impeller::Matrix::GetMaxBasisLength
Scalar GetMaxBasisLength() const
Definition: matrix.cc:196
geometry.h
impeller::GeometryResult
Definition: geometry.h:19
impeller::ContentContext::GetTessellator
std::shared_ptr< Tessellator > GetTessellator() const
Definition: content_context.cc:549
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:221
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:72
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::Path::IsConvex
bool IsConvex() const
Definition: path.cc:55
impeller
Definition: aiks_blend_unittests.cc:18
impeller::ContentContext
Definition: content_context.h:366
impeller::TRect< Scalar >
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:752
impeller::GeometryResult::Mode::kNonZero
@ kNonZero
impeller::Path::GetFillType
FillType GetFillType() const
Definition: path.cc:51
impeller::FillPathGeometry::FillPathGeometry
FillPathGeometry(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
Definition: fill_path_geometry.cc:15