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 
8 
10 #include "impeller/core/formats.h"
12 
13 namespace 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  }
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
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 
67  const Rect& rect) const {
68  return false;
69 }
70 
72  return false;
73 }
74 
75 } // 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...
bool IsAxisAlignedRect() const override
CircleGeometry(const Point &center, Scalar radius)
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...
Definition: tessellator.cc:468
float Scalar
Definition: scalar.h:19
Definition: comparable.h:95
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:606
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129