Flutter Impeller
round_rect_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 namespace impeller {
8 
9 RoundRectGeometry::RoundRectGeometry(const Rect& bounds, const Size& radii)
10  : bounds_(bounds), radii_(radii) {}
11 
13 
14 GeometryResult RoundRectGeometry::GetPositionBuffer(
15  const ContentContext& renderer,
16  const Entity& entity,
17  RenderPass& pass) const {
18  return ComputePositionGeometry(renderer,
20  entity.GetTransform(), bounds_, radii_),
21  entity, pass);
22 }
23 
24 std::optional<Rect> RoundRectGeometry::GetCoverage(
25  const Matrix& transform) const {
26  return bounds_.TransformBounds(transform);
27 }
28 
30  const Rect& rect) const {
31  if (!transform.IsTranslationScaleOnly()) {
32  return false;
33  }
34  bool flat_on_tb = bounds_.GetWidth() > radii_.width * 2;
35  bool flat_on_lr = bounds_.GetHeight() > radii_.height * 2;
36  if (!flat_on_tb && !flat_on_lr) {
37  return false;
38  }
39  // We either transform the bounds and delta-transform the radii,
40  // or we compute the vertical and horizontal bounds and then
41  // transform each. Either way there are 2 transform operations.
42  // We could also get a weaker answer by computing just the
43  // "inner rect" and only doing a coverage analysis on that,
44  // but this process will produce more culling results.
45  if (flat_on_tb) {
46  Rect vertical_bounds = bounds_.Expand(Size{-radii_.width, 0});
47  Rect coverage = vertical_bounds.TransformBounds(transform);
48  if (coverage.Contains(rect)) {
49  return true;
50  }
51  }
52  if (flat_on_lr) {
53  Rect horizontal_bounds = bounds_.Expand(Size{0, -radii_.height});
54  Rect coverage = horizontal_bounds.TransformBounds(transform);
55  if (coverage.Contains(rect)) {
56  return true;
57  }
58  }
59  return false;
60 }
61 
63  return false;
64 }
65 
67  : FillPathSourceGeometry(std::nullopt), round_rect_source_(round_rect) {}
68 
70  return round_rect_source_;
71 }
72 
74  const Rect& rect) const {
75  // Similar procedure to |RoundRectGeometry| except that we have different
76  // radii at every corner.
77  if (!transform.IsTranslationScaleOnly()) {
78  return false;
79  }
80  const RoundRect& round_rect = round_rect_source_.GetRoundRect();
81 
82  const Rect& bounds = round_rect.GetBounds();
83  const RoundingRadii& radii = round_rect.GetRadii();
84 
85  Scalar left_margin = std::max(radii.top_left.width, radii.bottom_left.width);
86  Scalar right_margin =
87  std::max(radii.top_right.width, radii.bottom_right.width);
88  Scalar top_margin = std::max(radii.top_left.height, radii.top_right.height);
89  Scalar bottom_margin =
90  std::max(radii.bottom_left.height, radii.bottom_right.height);
91 
92  bool flat_on_tb = bounds.GetWidth() > left_margin + right_margin;
93  bool flat_on_lr = bounds.GetHeight() > top_margin + bottom_margin;
94  if (!flat_on_tb && !flat_on_lr) {
95  return false;
96  }
97  // We either transform the bounds and delta-transform the radii,
98  // or we compute the vertical and horizontal bounds and then
99  // transform each. Either way there are 2 transform operations.
100  // We could also get a weaker answer by computing just the
101  // "inner rect" and only doing a coverage analysis on that,
102  // but this process will produce more culling results.
103  if (flat_on_tb) {
104  Rect vertical_bounds = bounds.Expand(-left_margin, 0, -right_margin, 0);
105  Rect coverage = vertical_bounds.TransformBounds(transform);
106  if (coverage.Contains(rect)) {
107  return true;
108  }
109  }
110  if (flat_on_lr) {
111  Rect horizontal_bounds = bounds.Expand(0, -top_margin, 0, -bottom_margin);
112  Rect coverage = horizontal_bounds.TransformBounds(transform);
113  if (coverage.Contains(rect)) {
114  return true;
115  }
116  }
117  return false;
118 }
119 
121  const RoundRect& round_rect,
122  const StrokeParameters& parameters)
123  : StrokePathSourceGeometry(parameters), round_rect_source_(round_rect) {}
124 
126  return round_rect_source_;
127 }
128 
129 } // namespace impeller
Tessellator & GetTessellator() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:44
An abstract Geometry base class that produces fillable vertices for the interior of any |PathSource| ...
const PathSource & GetSource() const override
FillRoundRectGeometry(const RoundRect &round_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...
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:26
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
RoundRectGeometry(const Rect &bounds, const Size &radii)
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...
bool IsAxisAlignedRect() const override
const RoundRect & GetRoundRect() const
Definition: round_rect.h:155
An abstract Geometry base class that produces fillable vertices representing the stroked outline from...
StrokeRoundRectGeometry(const RoundRect &rect, const StrokeParameters &parameters)
const PathSource & GetSource() const override
EllipticalVertexGenerator FilledRoundRect(const Matrix &view_transform, const Rect &bounds, const Size &radii)
Create a |VertexGenerator| that can produce vertices for a filled round rect within the given bounds ...
Definition: tessellator.cc:627
float Scalar
Definition: scalar.h:19
Definition: comparable.h:95
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
constexpr const RoundingRadii & GetRadii() const
Definition: round_rect.h:55
constexpr const Rect & GetBounds() const
Definition: round_rect.h:53
A structure to store all of the parameters related to stroking a path or basic geometry object.
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition: rect.h:622
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:476
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:351
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 Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:345
Type height
Definition: size.h:29
Type width
Definition: size.h:28