| 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 "flutter/impeller/entity/geometry/round_rect_geometry.h"
6
7 namespace impeller {
8
9 RoundRectGeometry::RoundRectGeometry(const Rect& bounds, const Size& radii)
10 : bounds_(bounds), radii_(radii) {}
11
12 GeometryResult RoundRectGeometry::GetPositionBuffer(
13 const ContentContext& renderer,
14 const Entity& entity,
15 RenderPass& pass) const {
16 return ComputePositionGeometry(renderer,
17 renderer.GetTessellator()->FilledRoundRect(
18 entity.GetTransform(), bounds_, radii_),
19 entity, pass);
20 }
21
22 // |Geometry|
23 GeometryResult RoundRectGeometry::GetPositionUVBuffer(
24 Rect texture_coverage,
25 Matrix effect_transform,
26 const ContentContext& renderer,
27 const Entity& entity,
28 RenderPass& pass) const {
29 return ComputePositionUVGeometry(
30 renderer,
31 renderer.GetTessellator()->FilledRoundRect(entity.GetTransform(), bounds_,
32 radii_),
33 texture_coverage.GetNormalizingTransform() * effect_transform, entity,
34 pass);
35 }
36
37 GeometryVertexType RoundRectGeometry::GetVertexType() const {
38 return GeometryVertexType::kPosition;
39 }
40
41 std::optional<Rect> RoundRectGeometry::GetCoverage(
42 const Matrix& transform) const {
43 return bounds_.TransformBounds(transform);
44 }
45
46 bool RoundRectGeometry::CoversArea(const Matrix& transform,
47 const Rect& rect) const {
48 if (!transform.IsTranslationScaleOnly()) {
49 return false;
50 }
51 bool flat_on_tb = bounds_.GetWidth() > radii_.width * 2;
52 bool flat_on_lr = bounds_.GetHeight() > radii_.height * 2;
53 if (!flat_on_tb && !flat_on_lr) {
54 return false;
55 }
56 // We either transform the bounds and delta-transform the radii,
57 // or we compute the vertical and horizontal bounds and then
58 // transform each. Either way there are 2 transform operations.
59 // We could also get a weaker answer by computing just the
60 // "inner rect" and only doing a coverage analysis on that,
61 // but this process will produce more culling results.
62 if (flat_on_tb) {
63 Rect vertical_bounds = bounds_.Expand(Size{-radii_.width, 0});
64 Rect coverage = vertical_bounds.TransformBounds(transform);
65 if (coverage.Contains(rect)) {
66 return true;
67 }
68 }
69 if (flat_on_lr) {
70 Rect horizontal_bounds = bounds_.Expand(Size{0, -radii_.height});
71 Rect coverage = horizontal_bounds.TransformBounds(transform);
72 if (coverage.Contains(rect)) {
73 return true;
74 }
75 }
76 return false;
77 }
78
79 bool RoundRectGeometry::IsAxisAlignedRect() const {
80 return false;
81 }
82
83 } // namespace impeller
impeller::RoundRectGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: round_rect_geometry.cc:79
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:405
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:46
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:314
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:49
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:25
impeller::Entity
Definition: entity.h:21
impeller::TSize< Scalar >
impeller::Geometry::ComputePositionUVGeometry
static GeometryResult ComputePositionUVGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Matrix &uv_transform, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:57
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:308
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:363
impeller::GeometryResult
Definition: geometry.h:20
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:661
impeller::ContentContext::GetTessellator
std::shared_ptr< Tessellator > GetTessellator() const
Definition: content_context.cc:560
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:217
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: aiks_blur_unittests.cc:20
impeller::kPosition
@ kPosition
Definition: geometry.h:50
impeller::ContentContext
Definition: content_context.h:392
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:547
impeller::RoundRectGeometry::RoundRectGeometry
RoundRectGeometry(const Rect &bounds, const Size &radii)
Definition: round_rect_geometry.cc:9