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 
5 #include <algorithm>
6 
8 
10 
11 namespace impeller {
12 
13 RoundRectGeometry::RoundRectGeometry(const Rect& bounds, const Size& radii)
14  : bounds_(bounds), radii_(radii) {}
15 
16 GeometryResult RoundRectGeometry::GetPositionBuffer(
17  const ContentContext& renderer,
18  const Entity& entity,
19  RenderPass& pass) const {
20  return ComputePositionGeometry(renderer.GetTessellator()->FilledRoundRect(
21  entity.GetTransform(), bounds_, radii_),
22  entity, pass);
23 }
24 
25 // |Geometry|
26 GeometryResult RoundRectGeometry::GetPositionUVBuffer(
27  Rect texture_coverage,
28  Matrix effect_transform,
29  const ContentContext& renderer,
30  const Entity& entity,
31  RenderPass& pass) const {
33  renderer.GetTessellator()->FilledRoundRect(entity.GetTransform(), bounds_,
34  radii_),
35  texture_coverage.GetNormalizingTransform() * effect_transform, entity,
36  pass);
37 }
38 
39 GeometryVertexType RoundRectGeometry::GetVertexType() const {
41 }
42 
43 std::optional<Rect> RoundRectGeometry::GetCoverage(
44  const Matrix& transform) const {
45  return bounds_.TransformBounds(transform);
46 }
47 
48 bool RoundRectGeometry::CoversArea(const Matrix& transform,
49  const Rect& rect) const {
50  if (!transform.IsTranslationScaleOnly()) {
51  return false;
52  }
53  bool flat_on_tb = bounds_.GetWidth() > radii_.width * 2;
54  bool flat_on_lr = bounds_.GetHeight() > radii_.height * 2;
55  if (!flat_on_tb && !flat_on_lr) {
56  return false;
57  }
58  // We either transform the bounds and delta-transform the radii,
59  // or we compute the vertical and horizontal bounds and then
60  // transform each. Either way there are 2 transform operations.
61  // We could also get a weaker answer by computing just the
62  // "inner rect" and only doing a coverage analysis on that,
63  // but this process will produce more culling results.
64  if (flat_on_tb) {
65  Rect vertical_bounds = bounds_.Expand(Size{-radii_.width, 0});
66  Rect coverage = vertical_bounds.TransformBounds(transform);
67  if (coverage.Contains(rect)) {
68  return true;
69  }
70  }
71  if (flat_on_lr) {
72  Rect horizontal_bounds = bounds_.Expand(Size{0, -radii_.height});
73  Rect coverage = horizontal_bounds.TransformBounds(transform);
74  if (coverage.Contains(rect)) {
75  return true;
76  }
77  }
78  return false;
79 }
80 
82  return false;
83 }
84 
85 } // namespace impeller
impeller::RoundRectGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: round_rect_geometry.cc:81
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:49
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:264
impeller::RoundRectGeometry::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: round_rect_geometry.cc:48
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:175
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:34
impeller::Entity
Definition: entity.h:21
impeller::TSize< Scalar >
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:171
impeller::Matrix::IsTranslationScaleOnly
constexpr bool IsTranslationScaleOnly() const
Returns true if the matrix has a scale-only basis and is non-projective. Note that an identity matrix...
Definition: matrix.h:360
impeller::GeometryResult
Definition: geometry.h:20
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:23
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:488
impeller::ContentContext::GetTessellator
std::shared_ptr< Tessellator > GetTessellator() const
Definition: content_context.cc:475
impeller::TSize::width
Type width
Definition: size.h:22
impeller::TRect::Contains
constexpr bool Contains(const TPoint< Type > &p) const
Definition: rect.h:127
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
line_geometry.h
impeller::TSize::height
Type height
Definition: size.h:23
round_rect_geometry.h
impeller
Definition: aiks_context.cc:10
impeller::Geometry::ComputePositionUVGeometry
static GeometryResult ComputePositionUVGeometry(const Tessellator::VertexGenerator &generator, const Matrix &uv_transform, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:55
impeller::kPosition
@ kPosition
Definition: geometry.h:35
impeller::ContentContext
Definition: content_context.h:332
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TRect::Expand
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:373
impeller::RoundRectGeometry::RoundRectGeometry
RoundRectGeometry(const Rect &bounds, const Size &radii)
Definition: round_rect_geometry.cc:13