Flutter Engine
 
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
12
13namespace impeller {
14
16 : center_(center), radius_(radius), stroke_width_(-1.0f) {
17 FML_DCHECK(radius >= 0);
18}
19
21
23 Scalar radius,
24 Scalar stroke_width)
25 : center_(center),
26 radius_(radius),
27 stroke_width_(std::max(stroke_width, 0.0f)) {
28 FML_DCHECK(radius >= 0);
29 FML_DCHECK(stroke_width >= 0);
30}
31
32// |Geometry|
34 if (stroke_width_ < 0) {
35 return 1;
36 }
38}
39
41 return center_;
42}
43
45 return radius_;
46}
47
49 return stroke_width_;
50}
51
53 const Entity& entity,
54 RenderPass& pass) const {
55 auto& transform = entity.GetTransform();
56
57 Scalar half_width = stroke_width_ < 0 ? 0.0
59 transform, stroke_width_);
60
61 // We call the StrokedCircle method which will simplify to a
62 // FilledCircleGenerator if the inner_radius is <= 0.
63 auto generator = renderer.GetTessellator().StrokedCircle(transform, center_,
64 radius_, half_width);
65
66 return ComputePositionGeometry(renderer, generator, entity, pass);
67}
68
69std::optional<Rect> CircleGeometry::GetCoverage(const Matrix& transform) const {
70 Scalar half_width = stroke_width_ < 0 ? 0.0 : stroke_width_ * 0.5f;
71 Scalar outer_radius = radius_ + half_width;
72 return Rect::MakeLTRB(-outer_radius, -outer_radius, //
73 +outer_radius, +outer_radius)
74 .Shift(center_)
75 .TransformAndClipBounds(transform);
76}
77
79 const Rect& rect) const {
80 return false;
81}
82
84 return false;
85}
86
87} // 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)
std::optional< Rect > GetCoverage(const Matrix &transform) const override
Tessellator & GetTessellator() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition entity.cc:44
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 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
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
Definition rect.h:602
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129