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,
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(renderer, 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(renderer, generator, uv_transform, entity,
69  pass);
70 }
71 
72 GeometryVertexType CircleGeometry::GetVertexType() const {
74 }
75 
76 std::optional<Rect> CircleGeometry::GetCoverage(const Matrix& transform) const {
77  Point corners[4]{
78  {center_.x, center_.y - radius_},
79  {center_.x + radius_, center_.y},
80  {center_.x, center_.y + radius_},
81  {center_.x - radius_, center_.y},
82  };
83 
84  for (int i = 0; i < 4; i++) {
85  corners[i] = transform * corners[i];
86  }
87  return Rect::MakePointBounds(std::begin(corners), std::end(corners));
88 }
89 
90 bool CircleGeometry::CoversArea(const Matrix& transform,
91  const Rect& rect) const {
92  return false;
93 }
94 
96  return false;
97 }
98 
99 } // namespace impeller
impeller::TPoint::y
Type y
Definition: point.h:31
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:90
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:49
stroke_width
const Scalar stroke_width
Definition: stroke_path_geometry.cc:293
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:49
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:151
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::Point
TPoint< Scalar > Point
Definition: point.h:316
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::GeometryResult
Definition: geometry.h:20
impeller::CircleGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: circle_geometry.cc:95
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:661
impeller::ContentContext::GetTessellator
std::shared_ptr< Tessellator > GetTessellator() const
Definition: content_context.cc:560
impeller::LineGeometry::ComputePixelHalfWidth
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width)
Definition: line_geometry.cc:14
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
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_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