| Flutter Impeller |

arc_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 "flutter/impeller/entity/geometry/arc_geometry.h"
6
7 #include "flutter/impeller/entity/geometry/line_geometry.h"
8
9 namespace impeller {
10
11 ArcGeometry::ArcGeometry(const Arc& arc)
12 : arc_(arc), stroke_width_(-1.0f), cap_(Cap::kButt) {}
13
14 ArcGeometry::ArcGeometry(const Arc& arc, const StrokeParameters& stroke)
15 : arc_(arc), stroke_width_(stroke.width), cap_(stroke.cap) {
16 FML_DCHECK(arc.IsPerfectCircle());
17 FML_DCHECK(!arc.IncludeCenter());
18 }
19
20 ArcGeometry::~ArcGeometry() = default;
21
22 // |Geometry|
23 Scalar ArcGeometry::ComputeAlphaCoverage(const Matrix& transform) const {
24 if (stroke_width_ < 0) {
25 return 1;
26 }
27 return Geometry::ComputeStrokeAlphaCoverage(transform, stroke_width_);
28 }
29
30 GeometryResult ArcGeometry::GetPositionBuffer(const ContentContext& renderer,
31 const Entity& entity,
32 RenderPass& pass) const {
33 auto& transform = entity.GetTransform();
34
35 if (stroke_width_ < 0) {
36 auto generator = renderer.GetTessellator().FilledArc(
37 transform, arc_,
38 renderer.GetDeviceCapabilities().SupportsTriangleFan());
39
40 return ComputePositionGeometry(renderer, generator, entity, pass);
41 } else {
42 FML_DCHECK(arc_.IsPerfectCircle());
43 FML_DCHECK(!arc_.IncludeCenter());
44 Scalar half_width =
45 LineGeometry::ComputePixelHalfWidth(transform, stroke_width_);
46
47 auto generator =
48 renderer.GetTessellator().StrokedArc(transform, arc_, cap_, half_width);
49
50 return ComputePositionGeometry(renderer, generator, entity, pass);
51 }
52 }
53
54 std::optional<Rect> ArcGeometry::GetCoverage(const Matrix& transform) const {
55 Scalar padding = //
56 stroke_width_ < 0
57 ? 0.0
58 : LineGeometry::ComputePixelHalfWidth(transform, stroke_width_);
59
60 if (arc_.IsFullCircle()) {
61 // Simpler calculation than below and we don't pad by the extra distance
62 // that square caps take up because we aren't going to use caps.
63 return arc_.GetOvalBounds().Expand(padding).TransformAndClipBounds(
64 transform);
65 }
66
67 if (cap_ == Cap::kSquare) {
68 padding = padding * kSqrt2;
69 }
70
71 return arc_.GetTightArcBounds().Expand(padding).TransformAndClipBounds(
72 transform);
73 }
74
75 bool ArcGeometry::CoversArea(const Matrix& transform, const Rect& rect) const {
76 return false;
77 }
78
79 bool ArcGeometry::IsAxisAlignedRect() const {
80 return false;
81 }
82
83 } // namespace impeller
arc_geometry.h
impeller::ArcGeometry::~ArcGeometry
~ArcGeometry() override
impeller::ArcGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: arc_geometry.cc:79
impeller::ArcGeometry::ComputeAlphaCoverage
Scalar ComputeAlphaCoverage(const Matrix &transform) const override
Definition: arc_geometry.cc:23
impeller::ArcGeometry::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: arc_geometry.cc:75
impeller::ArcGeometry::ArcGeometry
ArcGeometry(const Arc &arc)
Definition: arc_geometry.cc:11
impeller::Capabilities::SupportsTriangleFan
virtual bool SupportsTriangleFan() const =0
Whether the primitive type TriangleFan is supported by the backend.
impeller::ContentContext
Definition: content_context.h:138
impeller::ContentContext::GetDeviceCapabilities
const Capabilities & GetDeviceCapabilities() const
Definition: content_context.cc:966
impeller::ContentContext::GetTessellator
Tessellator & GetTessellator() const
Definition: content_context.cc:958
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::StrokedArc
ArcVertexGenerator StrokedArc(const Matrix &view_transform, const Arc &arc, Cap cap, Scalar half_width)
Create a |VertexGenerator| that can produce vertices for a stroked arc inscribed within the given ova...
Definition: tessellator.cc:621
impeller::Tessellator::FilledArc
ArcVertexGenerator FilledArc(const Matrix &view_transform, const Arc &arc, bool supports_triangle_fans)
Create a |VertexGenerator| that can produce vertices for a stroked arc inscribed within the given ova...
Definition: tessellator.cc:610
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
padding
Vector2 padding
The halo padding in source space.
Definition: gaussian_blur_filter_contents.cc:86
line_geometry.h
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::Cap
Cap
An enum that describes ways to decorate the end of a path contour.
Definition: stroke_parameters.h:13
impeller::Cap::kButt
@ kButt
impeller::Cap::kSquare
@ kSquare
impeller::kSqrt2
constexpr float kSqrt2
Definition: constants.h:47
impeller::Arc
Definition: arc.h:13
impeller::Arc::GetTightArcBounds
Rect GetTightArcBounds() const
Definition: arc.cc:59
impeller::Arc::IncludeCenter
constexpr bool IncludeCenter() const
Definition: arc.h:110
impeller::Arc::IsFullCircle
constexpr bool IsFullCircle() const
Definition: arc.h:114
impeller::Arc::IsPerfectCircle
constexpr bool IsPerfectCircle() const
Definition: arc.h:112
impeller::Arc::GetOvalBounds
const Rect & GetOvalBounds() const
Return the bounds of the oval in which this arc is inscribed.
Definition: arc.h:94
impeller::GeometryResult
Definition: geometry.h:21
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::StrokeParameters
A structure to store all of the parameters related to stroking a path or basic geometry object.
Definition: stroke_parameters.h:28
impeller::TRect< Scalar >
impeller::TRect::Expand
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition: rect.h:618
impeller::TRect::TransformAndClipBounds
constexpr TRect TransformAndClipBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle, clipped against the near clippin...
Definition: rect.h:438