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 #include "impeller/core/formats.h"
13 
14 namespace impeller {
15 
17  : center_(center),
18  radius_(radius),
19  stroke_width_(-1.0f),
20  padding_pixels_(0.0f) {
21  FML_DCHECK(radius >= 0);
22 }
23 
25 
27  Scalar radius,
28  Scalar stroke_width)
29  : center_(center),
30  radius_(radius),
31  stroke_width_(std::max(stroke_width, 0.0f)),
32  padding_pixels_(0.0) {
33  FML_DCHECK(radius >= 0);
34  FML_DCHECK(stroke_width >= 0);
35 }
36 
37 // |Geometry|
39  if (stroke_width_ < 0) {
40  return 1;
41  }
42  return Geometry::ComputeStrokeAlphaCoverage(transform, stroke_width_);
43 }
44 
46  return center_;
47 }
48 
50  return radius_;
51 }
52 
54  return stroke_width_;
55 }
56 
58  padding_pixels_ = extra_padding;
59 }
60 
62  return padding_pixels_;
63 }
64 
66  const Entity& entity,
67  RenderPass& pass) const {
68  auto& transform = entity.GetTransform();
69 
70  Scalar max_basis = transform.GetMaxBasisLengthXY();
71  Scalar expansion = max_basis == 0 ? 0.0 : padding_pixels_ / max_basis;
72 
73  if (stroke_width_ < 0) {
74  auto generator = renderer.GetTessellator().FilledCircle(
75  transform, center_, radius_ + expansion);
76  return ComputePositionGeometry(renderer, generator, entity, pass);
77  }
78 
79  Scalar half_width =
81 
82  auto generator = renderer.GetTessellator().StrokedCircle(
83  transform, center_, radius_, half_width + expansion);
84 
85  return ComputePositionGeometry(renderer, generator, entity, pass);
86 }
87 
88 std::optional<Rect> CircleGeometry::GetCoverage(const Matrix& transform) const {
89  Scalar max_basis = transform.GetMaxBasisLengthXY();
90  Scalar expansion = max_basis == 0 ? 0.0 : padding_pixels_ / max_basis;
91 
92  Scalar half_width = stroke_width_ < 0 ? 0.0 : stroke_width_ * 0.5f;
93  Scalar outer_radius = radius_ + half_width + expansion;
94  return Rect::MakeLTRB(-outer_radius, -outer_radius, //
95  +outer_radius, +outer_radius)
96  .Shift(center_)
97  .TransformAndClipBounds(transform);
98 }
99 
101  const Rect& rect) const {
102  return false;
103 }
104 
106  return false;
107 }
108 
109 } // namespace impeller
Scalar ComputeAlphaCoverage(const Matrix &transform) const override
Scalar GetAntialiasPadding() const
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...
GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
bool IsAxisAlignedRect() const override
CircleGeometry(const Point &center, Scalar radius)
void SetAntialiasPadding(Scalar extra_pixels)
std::optional< Rect > GetCoverage(const Matrix &transform) const override
Scalar GetStrokeWidth() const
Tessellator & GetTessellator() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:46
static Scalar ComputeStrokeAlphaCoverage(const Matrix &entity, Scalar stroke_width)
Compute an alpha value to simulate lower coverage of fractional pixel strokes.
Definition: geometry.cc:149
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:26
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width)
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
EllipticalVertexGenerator FilledCircle(const Matrix &view_transform, const Point &center, Scalar radius)
Create a |VertexGenerator| that can produce vertices for a filled circle of the given radius around t...
Definition: tessellator.cc:488
EllipticalVertexGenerator StrokedCircle(const Matrix &view_transform, const Point &center, Scalar radius, Scalar half_width)
Create a |VertexGenerator| that can produce vertices for a stroked circle of the given radius and hal...
Definition: tessellator.cc:504
float Scalar
Definition: scalar.h:19
Definition: comparable.h:93
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
Definition: rect.h:602
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129