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  const Entity& entity,
63  RenderPass& pass) const {
64  auto& transform = entity.GetTransform();
65 
66  Scalar max_basis = transform.GetMaxBasisLengthXY();
67  Scalar expansion = max_basis == 0 ? 0.0 : padding_pixels_ / max_basis;
68 
69  if (stroke_width_ < 0) {
70  auto generator = renderer.GetTessellator().FilledCircle(
71  transform, center_, radius_ + expansion);
72  return ComputePositionGeometry(renderer, generator, entity, pass);
73  }
74 
75  Scalar half_width =
77 
78  auto generator = renderer.GetTessellator().StrokedCircle(
79  transform, center_, radius_, half_width + expansion);
80 
81  return ComputePositionGeometry(renderer, generator, entity, pass);
82 }
83 
84 std::optional<Rect> CircleGeometry::GetCoverage(const Matrix& transform) const {
85  Scalar max_basis = transform.GetMaxBasisLengthXY();
86  Scalar expansion = max_basis == 0 ? 0.0 : padding_pixels_ / max_basis;
87 
88  Scalar half_width = stroke_width_ < 0 ? 0.0 : stroke_width_ * 0.5f;
89  Scalar outer_radius = radius_ + half_width + expansion;
90  return Rect::MakeLTRB(-outer_radius, -outer_radius, //
91  +outer_radius, +outer_radius)
92  .Shift(center_)
93  .TransformAndClipBounds(transform);
94 }
95 
97  const Rect& rect) const {
98  return false;
99 }
100 
102  return false;
103 }
104 
105 } // namespace impeller
Scalar ComputeAlphaCoverage(const Matrix &transform) const override
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:95
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