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 
15 FillPathSourceGeometry::FillPathSourceGeometry(std::optional<Rect> inner_rect)
16  : inner_rect_(inner_rect) {}
17 
19 
20 GeometryResult FillPathSourceGeometry::GetPositionBuffer(
21  const ContentContext& renderer,
22  const Entity& entity,
23  RenderPass& pass) const {
24  auto& host_buffer = renderer.GetTransientsBuffer();
25 
26  const auto& bounding_box = GetSource().GetBounds();
27  if (bounding_box.IsEmpty()) {
28  return GeometryResult{
30  .vertex_buffer =
32  .vertex_buffer = {},
33  .vertex_count = 0,
34  .index_type = IndexType::k16bit,
35  },
36  .transform = pass.GetOrthographicTransform() * entity.GetTransform(),
37  };
38  }
39 
40  bool supports_primitive_restart =
42  bool supports_triangle_fan =
44  supports_primitive_restart;
45  VertexBuffer vertex_buffer = renderer.GetTessellator().TessellateConvex(
46  GetSource(), host_buffer, entity.GetTransform().GetMaxBasisLengthXY(),
47  /*supports_primitive_restart=*/supports_primitive_restart,
48  /*supports_triangle_fan=*/supports_triangle_fan);
49 
50  return GeometryResult{
51  .type = supports_triangle_fan ? PrimitiveType::kTriangleFan
53  .vertex_buffer = std::move(vertex_buffer),
54  .transform = entity.GetShaderTransform(pass),
55  .mode = GetResultMode(),
56  };
57 }
58 
59 GeometryResult::Mode FillPathSourceGeometry::GetResultMode() const {
60  const PathSource& source = GetSource();
61  const auto& bounding_box = source.GetBounds();
62  if (source.IsConvex() || bounding_box.IsEmpty()) {
64  }
65 
66  switch (source.GetFillType()) {
67  case FillType::kNonZero:
69  case FillType::kOdd:
71  }
72 
73  FML_UNREACHABLE();
74 }
75 
76 std::optional<Rect> FillPathSourceGeometry::GetCoverage(
77  const Matrix& transform) const {
79 }
80 
82  const Rect& rect) const {
83  if (!inner_rect_.has_value()) {
84  return false;
85  }
86  if (!transform.IsTranslationScaleOnly()) {
87  return false;
88  }
89  Rect coverage = inner_rect_->TransformBounds(transform);
90  return coverage.Contains(rect);
91 }
92 
94  std::optional<Rect> inner_rect)
95  : FillPathSourceGeometry(inner_rect), path_(path) {}
96 
98  return path_;
99 }
100 
102  const RoundRect& inner)
103  : FillPathSourceGeometry(std::nullopt), source_(outer, inner) {}
104 
106  return source_;
107 }
108 
109 } // 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
Definition: entity.cc:48
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:44
const PathSource & GetSource() const override
FillDiffRoundRectGeometry(const RoundRect &outer, const RoundRect &inner)
FillPathGeometry(const flutter::DlPath &path, std::optional< Rect > inner_rect=std::nullopt)
const PathSource & GetSource() const override
An abstract Geometry base class that produces fillable vertices for the interior of any |PathSource| ...
FillPathSourceGeometry(std::optional< Rect > inner_rect)
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...
virtual const PathSource & GetSource() const =0
virtual Rect GetBounds() const =0
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 PathSource &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:314
flutter::DlPath DlPath
Definition: dl_dispatcher.h:29
Definition: comparable.h:95
PrimitiveType type
Definition: geometry.h:37
@ kNormal
The geometry has no overlapping triangles.
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
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
constexpr TRect TransformAndClipBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle, clipped against the near clippin...
Definition: rect.h:442