| 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 RoundRectGeometry::~RoundRectGeometry() = default;
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
29 bool RoundRectGeometry::CoversArea(const Matrix& transform,
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
62 bool RoundRectGeometry::IsAxisAlignedRect() const {
63 return false;
64 }
65
66 } // namespace impeller
impeller::ContentContext
Definition: content_context.h:138
impeller::ContentContext::GetTessellator
Tessellator & GetTessellator() const
Definition: content_context.cc:909
impeller::Entity
Definition: entity.h:20
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:44
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:25
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::RoundRectGeometry::~RoundRectGeometry
~RoundRectGeometry() override
impeller::RoundRectGeometry::RoundRectGeometry
RoundRectGeometry(const Rect &bounds, const Size &radii)
Definition: round_rect_geometry.cc:9
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::RoundRectGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: round_rect_geometry.cc:62
impeller::Tessellator::FilledRoundRect
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:420
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
impeller
Definition: allocation.cc:12
round_rect_geometry.h
impeller::GeometryResult
Definition: geometry.h:21
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TRect< Scalar >
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:622
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:476
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:351
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:235
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:345
impeller::TSize< Scalar >
impeller::TSize::height
Type height
Definition: size.h:29
impeller::TSize::width
Type width
Definition: size.h:28