| 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
7 #include "flutter/impeller/entity/geometry/circle_geometry.h"
8
9 #include "flutter/impeller/entity/geometry/line_geometry.h"
10 #include "impeller/core/formats.h"
11 #include "impeller/entity/geometry/geometry.h"
12
13 namespace impeller {
14
15 CircleGeometry::CircleGeometry(const Point& center, Scalar radius)
16 : center_(center), radius_(radius), stroke_width_(-1.0f) {
17 FML_DCHECK(radius >= 0);
18 }
19
20 CircleGeometry::~CircleGeometry() = default;
21
22 CircleGeometry::CircleGeometry(const Point& center,
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|
33 Scalar CircleGeometry::ComputeAlphaCoverage(const Matrix& transform) const {
34 if (stroke_width_ < 0) {
35 return 1;
36 }
37 return Geometry::ComputeStrokeAlphaCoverage(transform, stroke_width_);
38 }
39
40 Point CircleGeometry::GetCenter() const {
41 return center_;
42 }
43
44 Scalar CircleGeometry::GetRadius() const {
45 return radius_;
46 }
47
48 Scalar CircleGeometry::GetStrokeWidth() const {
49 return stroke_width_;
50 }
51
52 GeometryResult CircleGeometry::GetPositionBuffer(const ContentContext& renderer,
53 const Entity& entity,
54 RenderPass& pass) const {
55 auto& transform = entity.GetTransform();
56
57 Scalar half_width = stroke_width_ < 0 ? 0.0
58 : LineGeometry::ComputePixelHalfWidth(
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
69 std::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
78 bool CircleGeometry::CoversArea(const Matrix& transform,
79 const Rect& rect) const {
80 return false;
81 }
82
83 bool CircleGeometry::IsAxisAlignedRect() const {
84 return false;
85 }
86
87 } // namespace impeller
circle_geometry.h
impeller::CircleGeometry::ComputeAlphaCoverage
Scalar ComputeAlphaCoverage(const Matrix &transform) const override
Definition: circle_geometry.cc:33
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:78
impeller::CircleGeometry::GetPositionBuffer
GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: circle_geometry.cc:52
impeller::CircleGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: circle_geometry.cc:83
impeller::CircleGeometry::CircleGeometry
CircleGeometry(const Point &center, Scalar radius)
Definition: circle_geometry.cc:15
impeller::CircleGeometry::GetRadius
Scalar GetRadius() const
Definition: circle_geometry.cc:44
impeller::CircleGeometry::GetCoverage
std::optional< Rect > GetCoverage(const Matrix &transform) const override
Definition: circle_geometry.cc:69
impeller::CircleGeometry::~CircleGeometry
~CircleGeometry() override
impeller::CircleGeometry::GetCenter
Point GetCenter() const
Definition: circle_geometry.cc:40
impeller::CircleGeometry::GetStrokeWidth
Scalar GetStrokeWidth() const
Definition: circle_geometry.cc:48
impeller::ContentContext
Definition: content_context.h:122
impeller::ContentContext::GetTessellator
Tessellator & GetTessellator() const
Definition: content_context.cc:965
impeller::Entity
Definition: entity.h:26
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:46
impeller::Geometry::ComputeStrokeAlphaCoverage
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
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:26
impeller::LineGeometry::ComputePixelHalfWidth
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width)
Definition: line_geometry.cc:18
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::Tessellator::StrokedCircle
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
formats.h
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:312
geometry.h
line_geometry.h
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
std
Definition: comparable.h:95
impeller::GeometryResult
Definition: geometry.h:21
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TPoint< Scalar >
impeller::TRect< Scalar >
impeller::TRect::Shift
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
Definition: rect.h:602
impeller::TRect< Scalar >::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129