Flutter Impeller
circle_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 <algorithm>
6 
8 
10 
11 namespace impeller {
12 
14  : center_(center), radius_(radius), stroke_width_(-1.0f) {
15  FML_DCHECK(radius >= 0);
16 }
17 
19  Scalar radius,
20  Scalar stroke_width)
21  : center_(center),
22  radius_(radius),
23  stroke_width_(std::max(stroke_width, 0.0f)) {
24  FML_DCHECK(radius >= 0);
25  FML_DCHECK(stroke_width >= 0);
26 }
27 
28 GeometryResult CircleGeometry::GetPositionBuffer(const ContentContext& renderer,
29  const Entity& entity,
30  RenderPass& pass) const {
31  auto& transform = entity.GetTransform();
32 
33  Scalar half_width = stroke_width_ < 0 ? 0.0
35  transform, stroke_width_);
36 
37  std::shared_ptr<Tessellator> tessellator = renderer.GetTessellator();
38 
39  // We call the StrokedCircle method which will simplify to a
40  // FilledCircleGenerator if the inner_radius is <= 0.
41  auto generator =
42  tessellator->StrokedCircle(transform, center_, radius_, half_width);
43 
44  return ComputePositionGeometry(generator, entity, pass);
45 }
46 
47 // |Geometry|
48 GeometryResult CircleGeometry::GetPositionUVBuffer(
49  Rect texture_coverage,
50  Matrix effect_transform,
51  const ContentContext& renderer,
52  const Entity& entity,
53  RenderPass& pass) const {
54  auto& transform = entity.GetTransform();
55  auto uv_transform =
56  texture_coverage.GetNormalizingTransform() * effect_transform;
57 
58  Scalar half_width = stroke_width_ < 0 ? 0.0
60  transform, stroke_width_);
61  std::shared_ptr<Tessellator> tessellator = renderer.GetTessellator();
62 
63  // We call the StrokedCircle method which will simplify to a
64  // FilledCircleGenerator if the inner_radius is <= 0.
65  auto generator =
66  tessellator->StrokedCircle(transform, center_, radius_, half_width);
67 
68  return ComputePositionUVGeometry(generator, uv_transform, entity, pass);
69 }
70 
71 GeometryVertexType CircleGeometry::GetVertexType() const {
73 }
74 
75 std::optional<Rect> CircleGeometry::GetCoverage(const Matrix& transform) const {
76  Point corners[4]{
77  {center_.x, center_.y - radius_},
78  {center_.x + radius_, center_.y},
79  {center_.x, center_.y + radius_},
80  {center_.x - radius_, center_.y},
81  };
82 
83  for (int i = 0; i < 4; i++) {
84  corners[i] = transform * corners[i];
85  }
86  return Rect::MakePointBounds(std::begin(corners), std::end(corners));
87 }
88 
89 bool CircleGeometry::CoversArea(const Matrix& transform,
90  const Rect& rect) const {
91  return false;
92 }
93 
95  return false;
96 }
97 
98 } // namespace impeller
impeller::TPoint::y
Type y
Definition: point.h:26
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::CircleGeometry::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: circle_geometry.cc:89
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:49
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:34
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:49
impeller::Entity
Definition: entity.h:21
impeller::Point
TPoint< Scalar > Point
Definition: point.h:308
impeller::GeometryResult
Definition: geometry.h:20
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:23
impeller::CircleGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: circle_geometry.cc:94
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:488
impeller::ContentContext::GetTessellator
std::shared_ptr< Tessellator > GetTessellator() const
Definition: content_context.cc:475
impeller::LineGeometry::ComputePixelHalfWidth
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width)
Definition: line_geometry.cc:14
impeller::TPoint::x
Type x
Definition: point.h:25
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
std
Definition: comparable.h:95
impeller::TPoint< Scalar >
line_geometry.h
impeller::CircleGeometry::CircleGeometry
CircleGeometry(const Point &center, Scalar radius)
Definition: circle_geometry.cc:13
circle_geometry.h
impeller
Definition: aiks_context.cc:10
impeller::Geometry::ComputePositionUVGeometry
static GeometryResult ComputePositionUVGeometry(const Tessellator::VertexGenerator &generator, const Matrix &uv_transform, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:55
impeller::kPosition
@ kPosition
Definition: geometry.h:35
impeller::ContentContext
Definition: content_context.h:332
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37