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,
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
46  ? 0.0
48  transform, stroke_width_,
50 
51  const std::shared_ptr<Tessellator>& tessellator = renderer.GetTessellator();
52 
53  // We call the StrokedCircle method which will simplify to a
54  // FilledCircleGenerator if the inner_radius is <= 0.
55  auto generator =
56  tessellator->StrokedCircle(transform, center_, radius_, half_width);
57 
58  return ComputePositionGeometry(renderer, generator, entity, pass);
59 }
60 
61 std::optional<Rect> CircleGeometry::GetCoverage(const Matrix& transform) const {
62  Point corners[4]{
63  {center_.x, center_.y - radius_},
64  {center_.x + radius_, center_.y},
65  {center_.x, center_.y + radius_},
66  {center_.x - radius_, center_.y},
67  };
68 
69  for (int i = 0; i < 4; i++) {
70  corners[i] = transform * corners[i];
71  }
72  return Rect::MakePointBounds(std::begin(corners), std::end(corners));
73 }
74 
76  const Rect& rect) const {
77  return false;
78 }
79 
81  return false;
82 }
83 
84 } // namespace impeller
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::Scalar
float Scalar
Definition: scalar.h:18
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:75
geometry.h
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:47
impeller::CircleGeometry::ComputeAlphaCoverage
Scalar ComputeAlphaCoverage(const Matrix &transform) const override
Definition: circle_geometry.cc:33
impeller::CircleGeometry::~CircleGeometry
~CircleGeometry() override
formats.h
stroke_width
const Scalar stroke_width
Definition: stroke_path_geometry.cc:297
impeller::LineGeometry::ComputePixelHalfWidth
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width, bool msaa)
Definition: line_geometry.cc:17
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:155
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:24
impeller::Entity
Definition: entity.h:20
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:213
impeller::RenderPass::GetSampleCount
SampleCount GetSampleCount() const
The sample count of the attached render target.
Definition: render_pass.cc:23
impeller::GeometryResult
Definition: geometry.h:26
impeller::CircleGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: circle_geometry.cc:80
impeller::ContentContext::GetTessellator
std::shared_ptr< Tessellator > GetTessellator() const
Definition: content_context.cc:546
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
std
Definition: comparable.h:95
impeller::TPoint< Scalar >
line_geometry.h
impeller::SampleCount::kCount4
@ kCount4
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:133
impeller::CircleGeometry::CircleGeometry
CircleGeometry(const Point &center, Scalar radius)
Definition: circle_geometry.cc:15
circle_geometry.h
impeller
Definition: allocation.cc:12
impeller::ContentContext
Definition: content_context.h:366
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37