| 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 GeometryResult CircleGeometry::GetPositionBuffer(const ContentContext& renderer,
41 const Entity& entity,
42 RenderPass& pass) const {
43 auto& transform = entity.GetTransform();
44
45 Scalar half_width = stroke_width_ < 0 ? 0.0
46 : LineGeometry::ComputePixelHalfWidth(
47 transform, stroke_width_);
48
49 // We call the StrokedCircle method which will simplify to a
50 // FilledCircleGenerator if the inner_radius is <= 0.
51 auto generator = renderer.GetTessellator().StrokedCircle(transform, center_,
52 radius_, half_width);
53
54 return ComputePositionGeometry(renderer, generator, entity, pass);
55 }
56
57 std::optional<Rect> CircleGeometry::GetCoverage(const Matrix& transform) const {
58 Scalar half_width = stroke_width_ < 0 ? 0.0 : stroke_width_ * 0.5f;
59 Scalar outer_radius = radius_ + half_width;
60 return Rect::MakeLTRB(-outer_radius, -outer_radius, //
61 +outer_radius, +outer_radius)
62 .Shift(center_)
63 .TransformAndClipBounds(transform);
64 }
65
66 bool CircleGeometry::CoversArea(const Matrix& transform,
67 const Rect& rect) const {
68 return false;
69 }
70
71 bool CircleGeometry::IsAxisAlignedRect() const {
72 return false;
73 }
74
75 } // 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:66
impeller::CircleGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: circle_geometry.cc:71
impeller::CircleGeometry::CircleGeometry
CircleGeometry(const Point &center, Scalar radius)
Definition: circle_geometry.cc:15
impeller::CircleGeometry::~CircleGeometry
~CircleGeometry() override
impeller::ContentContext
Definition: content_context.h:138
impeller::ContentContext::GetTessellator
Tessellator & GetTessellator() const
Definition: content_context.cc:935
impeller::Entity
Definition: entity.h:26
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:44
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:468
formats.h
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
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:606
impeller::TRect< Scalar >::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129