| 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 std::optional<Rect> RoundRectGeometry::GetCoverage(
23 const Matrix& transform) const {
24 return bounds_.TransformBounds(transform);
25 }
26
27 bool RoundRectGeometry::CoversArea(const Matrix& transform,
28 const Rect& rect) const {
29 if (!transform.IsTranslationScaleOnly()) {
30 return false;
31 }
32 bool flat_on_tb = bounds_.GetWidth() > radii_.width * 2;
33 bool flat_on_lr = bounds_.GetHeight() > radii_.height * 2;
34 if (!flat_on_tb && !flat_on_lr) {
35 return false;
36 }
37 // We either transform the bounds and delta-transform the radii,
38 // or we compute the vertical and horizontal bounds and then
39 // transform each. Either way there are 2 transform operations.
40 // We could also get a weaker answer by computing just the
41 // "inner rect" and only doing a coverage analysis on that,
42 // but this process will produce more culling results.
43 if (flat_on_tb) {
44 Rect vertical_bounds = bounds_.Expand(Size{-radii_.width, 0});
45 Rect coverage = vertical_bounds.TransformBounds(transform);
46 if (coverage.Contains(rect)) {
47 return true;
48 }
49 }
50 if (flat_on_lr) {
51 Rect horizontal_bounds = bounds_.Expand(Size{0, -radii_.height});
52 Rect coverage = horizontal_bounds.TransformBounds(transform);
53 if (coverage.Contains(rect)) {
54 return true;
55 }
56 }
57 return false;
58 }
59
60 bool RoundRectGeometry::IsAxisAlignedRect() const {
61 return false;
62 }
63
64 } // namespace impeller
impeller::RoundRectGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: round_rect_geometry.cc:60
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:46
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:463
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:27
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:337
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:231
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:331
impeller::GeometryResult
Definition: geometry.h:19
impeller::ContentContext::GetTessellator
std::shared_ptr< Tessellator > GetTessellator() const
Definition: content_context.cc:549
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:221
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_blend_unittests.cc:18
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:605
impeller::RoundRectGeometry::RoundRectGeometry
RoundRectGeometry(const Rect &bounds, const Size &radii)
Definition: round_rect_geometry.cc:9