Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
13
14namespace 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 }
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
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
88std::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::MakeCircleBounds(center_, outer_radius)
96}
97
99 const IRect& rect) const {
100 return false;
101}
102
104 return false;
105}
106
107} // namespace impeller
Scalar ComputeAlphaCoverage(const Matrix &transform) const override
Scalar GetAntialiasPadding() const
bool CoversArea(const Matrix &transform, const IRect &rect) const override
Determines if this geometry, transformed by the given transform, will completely cover all of the pix...
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
The coverage rectangle of this geometry, transformed by the transform argument.
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...
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...
#define FML_DCHECK(condition)
Definition logging.h:122
float Scalar
Definition scalar.h:19
Definition ref_ptr.h:261
A 4x4 matrix using column-major storage.
Definition matrix.h:37
Scalar GetMaxBasisLengthXY() const
Return the maximum scale applied specifically to either the X axis or Y axis unit vectors (the bases)...
Definition matrix.h:328
static constexpr TRect MakeCircleBounds(const TPoint< Type > &center, Type radius)
Definition rect.h:156
constexpr TRect TransformAndClipBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle, clipped against the near clippin...
Definition rect.h:472