Flutter Engine
 
Loading...
Searching...
No Matches
dl_path.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_DISPLAY_LIST_GEOMETRY_DL_PATH_H_
6#define FLUTTER_DISPLAY_LIST_GEOMETRY_DL_PATH_H_
7
8#include <functional>
9
12#include "flutter/third_party/skia/include/core/SkPath.h"
13
14namespace flutter {
15
18
20 public:
21 static constexpr uint32_t kMaxVolatileUses = 2;
22
23 static DlPath MakeRect(const DlRect& rect);
24 static DlPath MakeRectLTRB(DlScalar left,
25 DlScalar top,
26 DlScalar right,
27 DlScalar bottom);
29 DlScalar y,
32
33 static DlPath MakeOval(const DlRect& bounds);
34 static DlPath MakeOvalLTRB(DlScalar left,
35 DlScalar top,
36 DlScalar right,
37 DlScalar bottom);
38
39 static DlPath MakeCircle(const DlPoint center, DlScalar radius);
40
41 static DlPath MakeRoundRect(const DlRoundRect& rrect);
42 static DlPath MakeRoundRectXY(const DlRect& rect,
43 DlScalar x_radius,
44 DlScalar y_radius,
45 bool counter_clock_wise = false);
47
48 static DlPath MakeLine(const DlPoint a, const DlPoint b);
49 static DlPath MakePoly(const DlPoint pts[],
50 int count,
51 bool close,
52 DlPathFillType fill_type = DlPathFillType::kNonZero);
53
54 static DlPath MakeArc(const DlRect& bounds,
55 DlDegrees start,
56 DlDegrees sweep,
57 bool use_center);
58
59 DlPath() : data_(std::make_shared<Data>(SkPath())) {}
60 explicit DlPath(const SkPath& path) : data_(std::make_shared<Data>(path)) {}
61
62 DlPath(const DlPath& path) = default;
63 DlPath(DlPath&& path) = default;
64 DlPath& operator=(const DlPath&) = default;
65
66 ~DlPath() override = default;
67
68 const SkPath& GetSkPath() const;
69
70 void Dispatch(DlPathReceiver& receiver) const override;
71
72 /// Intent to render an SkPath multiple times will make the path
73 /// non-volatile to enable caching in Skia. Calling this method
74 /// before every rendering call that uses the SkPath will count
75 /// down the uses and eventually reset the volatile flag.
76 ///
77 /// @see |kMaxVolatileUses|
78 void WillRenderSkPath() const;
79
80 [[nodiscard]] DlPath WithOffset(const DlPoint offset) const;
81 [[nodiscard]] DlPath WithFillType(DlPathFillType type) const;
82
83 bool IsEmpty() const;
84 bool IsRect(DlRect* rect = nullptr, bool* is_closed = nullptr) const;
85 bool IsOval(DlRect* bounds = nullptr) const;
86 bool IsLine(DlPoint* start = nullptr, DlPoint* end = nullptr) const;
87 bool IsRoundRect(DlRoundRect* rrect = nullptr) const;
88
89 bool Contains(const DlPoint point) const;
90
91 DlRect GetBounds() const override;
92 DlPathFillType GetFillType() const override;
93
94 bool operator==(const DlPath& other) const;
95
96 bool IsVolatile() const;
97 bool IsConvex() const override;
98
99 DlPath operator+(const DlPath& other) const;
100
101 private:
102 struct Data {
103 explicit Data(const SkPath& path) : sk_path(path) {
104 FML_DCHECK(!SkPathFillType_IsInverse(path.getFillType()));
105 }
106
107 SkPath sk_path;
108 uint32_t render_count = 0u;
109 };
110
111 std::shared_ptr<Data> data_;
112
113 static void ReduceConic(DlPathReceiver& receiver,
114 const DlPoint& p1,
115 const DlPoint& cp,
116 const DlPoint& p2,
117 DlScalar weight);
118};
119
120} // namespace flutter
121
122#endif // FLUTTER_DISPLAY_LIST_GEOMETRY_DL_PATH_H_
GLenum type
bool Contains(const DlPoint point) const
Definition dl_path.cc:237
bool IsEmpty() const
Definition dl_path.cc:206
bool IsRect(DlRect *rect=nullptr, bool *is_closed=nullptr) const
Definition dl_path.cc:210
static constexpr uint32_t kMaxVolatileUses
Definition dl_path.h:21
bool operator==(const DlPath &other) const
Definition dl_path.cc:249
static DlPath MakeRectLTRB(DlScalar left, DlScalar top, DlScalar right, DlScalar bottom)
Definition dl_path.cc:43
static DlPath MakeLine(const DlPoint a, const DlPoint b)
Definition dl_path.cc:89
DlPath WithOffset(const DlPoint offset) const
Definition dl_path.cc:184
~DlPath() override=default
DlPath operator+(const DlPath &other) const
Definition dl_path.cc:261
static DlPath MakeRoundRect(const DlRoundRect &rrect)
Definition dl_path.cc:72
static DlPath MakeCircle(const DlPoint center, DlScalar radius)
Definition dl_path.cc:68
static DlPath MakeArc(const DlRect &bounds, DlDegrees start, DlDegrees sweep, bool use_center)
Definition dl_path.cc:101
static DlPath MakeRectXYWH(DlScalar x, DlScalar y, DlScalar width, DlScalar height)
Definition dl_path.cc:50
static DlPath MakeRect(const DlRect &rect)
Definition dl_path.cc:39
static DlPath MakeRoundSuperellipse(const DlRoundSuperellipse &rse)
Definition dl_path.cc:85
static DlPath MakeRoundRectXY(const DlRect &rect, DlScalar x_radius, DlScalar y_radius, bool counter_clock_wise=false)
Definition dl_path.cc:76
bool IsRoundRect(DlRoundRect *rrect=nullptr) const
Definition dl_path.cc:228
static DlPath MakeOvalLTRB(DlScalar left, DlScalar top, DlScalar right, DlScalar bottom)
Definition dl_path.cc:61
DlRect GetBounds() const override
Definition dl_path.cc:245
const SkPath & GetSkPath() const
Definition dl_path.cc:116
DlPathFillType GetFillType() const override
Definition dl_path.cc:241
DlPath WithFillType(DlPathFillType type) const
Definition dl_path.cc:196
bool IsLine(DlPoint *start=nullptr, DlPoint *end=nullptr) const
Definition dl_path.cc:218
void WillRenderSkPath() const
Definition dl_path.cc:174
static DlPath MakeOval(const DlRect &bounds)
Definition dl_path.cc:57
bool IsVolatile() const
Definition dl_path.cc:253
void Dispatch(DlPathReceiver &receiver) const override
Definition dl_path.cc:120
DlPath(const DlPath &path)=default
bool IsConvex() const override
Definition dl_path.cc:257
DlPath & operator=(const DlPath &)=default
DlPath(const SkPath &path)
Definition dl_path.h:60
bool IsOval(DlRect *bounds=nullptr) const
Definition dl_path.cc:214
static DlPath MakePoly(const DlPoint pts[], int count, bool close, DlPathFillType fill_type=DlPathFillType::kNonZero)
Definition dl_path.cc:93
DlPath(DlPath &&path)=default
Collection of functions to receive path segments from the underlying path representation via the DlPa...
Definition path_source.h:42
int32_t x
#define FML_DCHECK(condition)
Definition logging.h:122
double y
impeller::Scalar DlScalar
impeller::PathReceiver DlPathReceiver
Definition dl_path.h:17
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52
struct PathData * Data(SkPath *path)
Definition path_ops.cc:52
impeller::Point DlPoint
Definition ref_ptr.h:261
int32_t height
int32_t width
const size_t end