| 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 Point corners[4]{
59 {center_.x, center_.y - radius_},
60 {center_.x + radius_, center_.y},
61 {center_.x, center_.y + radius_},
62 {center_.x - radius_, center_.y},
63 };
64
65 for (int i = 0; i < 4; i++) {
66 corners[i] = transform * corners[i];
67 }
68 return Rect::MakePointBounds(std::begin(corners), std::end(corners));
69 }
70
71 bool CircleGeometry::CoversArea(const Matrix& transform,
72 const Rect& rect) const {
73 return false;
74 }
75
76 bool CircleGeometry::IsAxisAlignedRect() const {
77 return false;
78 }
79
80 } // 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:71
impeller::CircleGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: circle_geometry.cc:76
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:371
impeller::ContentContext::GetTessellator
Tessellator & GetTessellator() const
Definition: content_context.cc:609
impeller::Entity
Definition: entity.h:20
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:126
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:23
impeller::LineGeometry::ComputePixelHalfWidth
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width)
Definition: line_geometry.cc:17
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:355
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:18
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
std
Definition: comparable.h:95
stroke_width
const Scalar stroke_width
Definition: stroke_path_geometry.cc:312
impeller::GeometryResult
Definition: geometry.h:21
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TPoint< Scalar >
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::TRect< Scalar >
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:165