Flutter Impeller
line_geometry.h
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 #ifndef FLUTTER_IMPELLER_ENTITY_GEOMETRY_LINE_GEOMETRY_H_
6 #define FLUTTER_IMPELLER_ENTITY_GEOMETRY_LINE_GEOMETRY_H_
7 
9 
10 namespace impeller {
11 
12 class LineGeometry final : public Geometry {
13  public:
14  explicit LineGeometry(Point p0, Point p1, const StrokeParameters& stroke);
15 
16  ~LineGeometry() override;
17 
18  static Scalar ComputePixelHalfWidth(const Matrix& transform, Scalar width);
19 
20  // |Geometry|
21  bool CoversArea(const Matrix& transform, const Rect& rect) const override;
22 
23  // |Geometry|
24  bool IsAxisAlignedRect() const override;
25 
26  Scalar ComputeAlphaCoverage(const Matrix& transform) const override;
27 
28  // |Geometry|
29  std::optional<Rect> GetCoverage(const Matrix& transform) const override;
30 
31  Point GetP0() const { return p0_; }
32  Point GetP1() const { return p1_; }
33  Scalar GetWidth() const { return width_; }
34  Cap GetCap() const { return cap_; }
35 
37  bool allow_zero_length,
38  Point p0,
39  Point p1,
40  Scalar width);
41 
42  // Computes the 4 corners of a rectangle that defines the line and
43  // possibly extended endpoints which will be rendered under the given
44  // transform, and returns true if such a rectangle is defined.
45  //
46  // The coordinates will be generated in the original coordinate system
47  // of the line end points and the transform will only be used to determine
48  // the minimum line width.
49  //
50  // For kButt and kSquare end caps the ends should always be exteded as
51  // per that decoration, but for kRound caps the ends might be extended
52  // if the goal is to get a conservative bounds and might not be extended
53  // if the calling code is planning to draw the round caps on the ends.
54  //
55  // @return true if the transform and width were not degenerate
56  static bool ComputeCorners(Point corners[4],
57  const Matrix& transform,
58  bool extend_endpoints,
59  Point p0,
60  Point p1,
61  Scalar width);
62 
63  private:
64  // |Geometry|
65  GeometryResult GetPositionBuffer(const ContentContext& renderer,
66  const Entity& entity,
67  RenderPass& pass) const override;
68 
69  Point p0_;
70  Point p1_;
71  Scalar width_;
72  Cap cap_;
73 
74  LineGeometry(const LineGeometry&) = delete;
75 
76  LineGeometry& operator=(const LineGeometry&) = delete;
77 };
78 
79 } // namespace impeller
80 
81 #endif // FLUTTER_IMPELLER_ENTITY_GEOMETRY_LINE_GEOMETRY_H_
static Vector2 ComputeAlongVector(const Matrix &transform, bool allow_zero_length, Point p0, Point p1, Scalar width)
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width)
Scalar GetWidth() const
Definition: line_geometry.h:33
LineGeometry(Point p0, Point p1, const StrokeParameters &stroke)
bool IsAxisAlignedRect() const override
Scalar ComputeAlphaCoverage(const Matrix &transform) const override
static bool ComputeCorners(Point corners[4], const Matrix &transform, bool extend_endpoints, Point p0, Point p1, Scalar width)
std::optional< Rect > GetCoverage(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...
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
float Scalar
Definition: scalar.h:19
Cap
An enum that describes ways to decorate the end of a path contour.
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
A structure to store all of the parameters related to stroking a path or basic geometry object.