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,
19  renderer.GetTessellator()->FilledRoundRect(
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 
66 } // namespace impeller
impeller::RoundRectGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: round_rect_geometry.cc:62
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:47
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:466
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:29
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:341
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:24
impeller::Entity
Definition: entity.h:20
impeller::TSize< Scalar >
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:213
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:335
impeller::GeometryResult
Definition: geometry.h:26
impeller::RoundRectGeometry::~RoundRectGeometry
~RoundRectGeometry() override
impeller::ContentContext::GetTessellator
std::shared_ptr< Tessellator > GetTessellator() const
Definition: content_context.cc:546
impeller::TSize::width
Type width
Definition: size.h:22
impeller::TRect::Contains
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:225
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
impeller::TSize::height
Type height
Definition: size.h:23
round_rect_geometry.h
impeller
Definition: allocation.cc:12
impeller::ContentContext
Definition: content_context.h:366
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:612
impeller::RoundRectGeometry::RoundRectGeometry
RoundRectGeometry(const Rect &bounds, const Size &radii)
Definition: round_rect_geometry.cc:9