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& data_host_buffer = renderer.GetTransientsDataBuffer();
25  auto& indexes_host_buffer = renderer.GetTransientsIndexesBuffer();
26 
27  const auto& bounding_box = GetSource().GetBounds();
28  if (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  GetSource(), data_host_buffer, indexes_host_buffer,
49  /*supports_primitive_restart=*/supports_primitive_restart,
50  /*supports_triangle_fan=*/supports_triangle_fan);
51 
52  return GeometryResult{
53  .type = supports_triangle_fan ? PrimitiveType::kTriangleFan
55  .vertex_buffer = std::move(vertex_buffer),
56  .transform = entity.GetShaderTransform(pass),
57  .mode = GetResultMode(),
58  };
59 }
60 
61 GeometryResult::Mode FillPathSourceGeometry::GetResultMode() const {
62  const PathSource& source = GetSource();
63  const auto& bounding_box = source.GetBounds();
64  if (source.IsConvex() || bounding_box.IsEmpty()) {
66  }
67 
68  switch (source.GetFillType()) {
69  case FillType::kNonZero:
71  case FillType::kOdd:
73  }
74 
75  FML_UNREACHABLE();
76 }
77 
78 std::optional<Rect> FillPathSourceGeometry::GetCoverage(
79  const Matrix& transform) const {
81 }
82 
84  const Rect& rect) const {
85  if (!inner_rect_.has_value()) {
86  return false;
87  }
88  if (!transform.IsTranslationScaleOnly()) {
89  return false;
90  }
91  Rect coverage = inner_rect_->TransformBounds(transform);
92  return coverage.Contains(rect);
93 }
94 
96  std::optional<Rect> inner_rect)
97  : FillPathSourceGeometry(inner_rect), path_(path) {}
98 
100  return path_;
101 }
102 
104  const RoundRect& inner)
105  : FillPathSourceGeometry(std::nullopt), source_(outer, inner) {}
106 
108  return source_;
109 }
110 
111 } // 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.
const Capabilities & GetDeviceCapabilities() const
HostBuffer & GetTransientsIndexesBuffer() const
Retrieve the current host buffer for transient storage of indexes used for indexed draws.
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
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 &data_host_buffer, HostBuffer &indexes_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
Return the maximum scale applied specifically to either the X axis or Y axis unit vectors (the bases)...
Definition: matrix.h:328
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:231
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:438