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 
6 
7 #include "fml/logging.h"
12 
13 namespace impeller {
14 
16  std::optional<Rect> inner_rect)
17  : path_(path), inner_rect_(inner_rect) {}
18 
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{
31  .vertex_buffer =
33  .vertex_buffer = {},
34  .vertex_count = 0,
35  .index_type = IndexType::k16bit,
36  },
37  .transform = pass.GetOrthographicTransform() * entity.GetTransform(),
38  };
39  }
40 
41  bool supports_primitive_restart =
43  bool supports_triangle_fan =
45  supports_primitive_restart;
46  VertexBuffer vertex_buffer = renderer.GetTessellator().TessellateConvex(
47  path_, host_buffer, entity.GetTransform().GetMaxBasisLengthXY(),
48  /*supports_primitive_restart=*/supports_primitive_restart,
49  /*supports_triangle_fan=*/supports_triangle_fan);
50 
51  return GeometryResult{
52  .type = supports_triangle_fan ? PrimitiveType::kTriangleFan
54  .vertex_buffer = std::move(vertex_buffer),
55  .transform = entity.GetShaderTransform(pass),
56  .mode = GetResultMode(),
57  };
58 }
59 
60 GeometryResult::Mode FillPathGeometry::GetResultMode() const {
61  const auto& bounding_box = path_.GetBoundingBox();
62  if (path_.IsConvex() ||
63  (bounding_box.has_value() && bounding_box->IsEmpty())) {
65  }
66 
67  switch (path_.GetFillType()) {
68  case FillType::kNonZero:
70  case FillType::kOdd:
72  }
73 
74  FML_UNREACHABLE();
75 }
76 
77 std::optional<Rect> FillPathGeometry::GetCoverage(
78  const Matrix& transform) const {
80 }
81 
83  const Rect& rect) const {
84  if (!inner_rect_.has_value()) {
85  return false;
86  }
87  if (!transform.IsTranslationScaleOnly()) {
88  return false;
89  }
90  Rect coverage = inner_rect_->TransformBounds(transform);
91  return coverage.Contains(rect);
92 }
93 
94 } // namespace impeller
virtual bool SupportsTriangleFan() const =0
Whether the primitive type TriangleFan is supported by the backend.
virtual bool SupportsPrimitiveRestart() const =0
Whether primitive restart is supported.
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
const Capabilities & GetDeviceCapabilities() const
Tessellator & GetTessellator() const
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition: entity.cc:48
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:44
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...
FillPathGeometry(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:54
FillType GetFillType() const
Definition: path.cc:110
std::optional< Rect > GetTransformedBoundingBox(const Matrix &transform) const
Definition: path.cc:470
bool IsConvex() const
Definition: path.cc:114
std::optional< Rect > GetBoundingBox() const
Definition: path.cc:466
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
const Matrix & GetOrthographicTransform() const
Definition: render_pass.cc:51
VertexBuffer TessellateConvex(const Path &path, HostBuffer &host_buffer, Scalar tolerance, bool supports_primitive_restart=false, bool supports_triangle_fan=false)
Given a convex path, create a triangle fan structure.
Definition: tessellator.cc:40
PrimitiveType type
Definition: geometry.h:37
@ kNormal
The geometry has no overlapping triangles.
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
constexpr Scalar GetMaxBasisLengthXY() const
Definition: matrix.h:323
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:235