Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
7namespace impeller {
8
9RoundRectGeometry::RoundRectGeometry(const Rect& bounds, const Size& radii)
10 : bounds_(bounds), radii_(radii) {}
11
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
23 const Matrix& transform) const {
24 return bounds_.TransformBounds(transform);
25}
26
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
61 return false;
62}
63
64} // namespace impeller
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition entity.cc:46
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition geometry.cc:24
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:33
GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
std::optional< Rect > GetCoverage(const Matrix &transform) const override
RoundRectGeometry(const Rect &bounds, const Size &radii)
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...
bool IsAxisAlignedRect() const override
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
A 4x4 matrix using column-major storage.
Definition matrix.h:37
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition rect.h:440
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition rect.h:314
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition rect.h:308
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:582
Type height
Definition size.h:23
Type width
Definition size.h:22