5#include "flutter/lib/ui/painting/path.h"
9#include "flutter/lib/ui/floating_point.h"
10#include "flutter/lib/ui/painting/matrix.h"
11#include "flutter/lib/ui/ui_dart_state.h"
21typedef CanvasPath
Path;
25CanvasPath::CanvasPath()
26 : path_tracker_(
UIDartState::Current()->GetVolatilePathTracker()),
32CanvasPath::~CanvasPath() =
default;
34void CanvasPath::resetVolatility() {
35 if (!tracked_path_->tracking_volatility) {
36 mutable_path().setIsVolatile(
true);
37 tracked_path_->frame_count = 0;
38 tracked_path_->tracking_volatility =
true;
39 path_tracker_->Track(tracked_path_);
43int CanvasPath::getFillType() {
44 return static_cast<int>(
path().getFillType());
47void CanvasPath::setFillType(
int fill_type) {
48 mutable_path().setFillType(
static_cast<SkPathFillType>(fill_type));
52void CanvasPath::moveTo(
double x,
double y) {
53 mutable_path().moveTo(SafeNarrow(
x), SafeNarrow(
y));
57void CanvasPath::relativeMoveTo(
double x,
double y) {
58 mutable_path().rMoveTo(SafeNarrow(
x), SafeNarrow(
y));
62void CanvasPath::lineTo(
double x,
double y) {
63 mutable_path().lineTo(SafeNarrow(
x), SafeNarrow(
y));
67void CanvasPath::relativeLineTo(
double x,
double y) {
68 mutable_path().rLineTo(SafeNarrow(
x), SafeNarrow(
y));
72void CanvasPath::quadraticBezierTo(
double x1,
double y1,
double x2,
double y2) {
73 mutable_path().quadTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2),
78void CanvasPath::relativeQuadraticBezierTo(
double x1,
82 mutable_path().rQuadTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2),
87void CanvasPath::cubicTo(
double x1,
93 mutable_path().cubicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2),
94 SafeNarrow(y2), SafeNarrow(x3), SafeNarrow(y3));
98void CanvasPath::relativeCubicTo(
double x1,
104 mutable_path().rCubicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2),
105 SafeNarrow(y2), SafeNarrow(x3), SafeNarrow(y3));
109void CanvasPath::conicTo(
double x1,
double y1,
double x2,
double y2,
double w) {
110 mutable_path().conicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2),
111 SafeNarrow(y2), SafeNarrow(
w));
115void CanvasPath::relativeConicTo(
double x1,
120 mutable_path().rConicTo(SafeNarrow(x1), SafeNarrow(y1), SafeNarrow(x2),
121 SafeNarrow(y2), SafeNarrow(
w));
125void CanvasPath::arcTo(
double left,
132 mutable_path().arcTo(
135 SafeNarrow(startAngle) * 180.0f /
static_cast<float>(
M_PI),
136 SafeNarrow(sweepAngle) * 180.0f /
static_cast<float>(
M_PI), forceMoveTo);
140void CanvasPath::arcToPoint(
double arcEndX,
144 double xAxisRotation,
146 bool isClockwiseDirection) {
149 const auto direction =
152 mutable_path().arcTo(SafeNarrow(radiusX), SafeNarrow(radiusY),
153 SafeNarrow(xAxisRotation), arcSize, direction,
154 SafeNarrow(arcEndX), SafeNarrow(arcEndY));
158void CanvasPath::relativeArcToPoint(
double arcEndDeltaX,
162 double xAxisRotation,
164 bool isClockwiseDirection) {
167 const auto direction =
169 mutable_path().rArcTo(SafeNarrow(radiusX), SafeNarrow(radiusY),
170 SafeNarrow(xAxisRotation), arcSize, direction,
171 SafeNarrow(arcEndDeltaX), SafeNarrow(arcEndDeltaY));
175void CanvasPath::addRect(
double left,
double top,
double right,
double bottom) {
178 SafeNarrow(bottom)));
182void CanvasPath::addOval(
double left,
double top,
double right,
double bottom) {
185 SafeNarrow(bottom)));
189void CanvasPath::addArc(
double left,
195 mutable_path().addArc(
198 SafeNarrow(startAngle) * 180.0f /
static_cast<float>(
M_PI),
199 SafeNarrow(sweepAngle) * 180.0f /
static_cast<float>(
M_PI));
203void CanvasPath::addPolygon(
const tonic::Float32List&
points,
bool close) {
204 mutable_path().addPoly(
reinterpret_cast<const SkPoint*
>(
points.data()),
205 points.num_elements() / 2, close);
209void CanvasPath::addRRect(
const RRect& rrect) {
210 mutable_path().addRRect(rrect.sk_rrect);
214void CanvasPath::addPath(
CanvasPath* path,
double dx,
double dy) {
219 mutable_path().addPath(
path->path(), SafeNarrow(dx), SafeNarrow(dy),
228 tonic::Float64List matrix4(matrix4_handle);
233 ToDart(
"Path.addPathWithMatrix called with non-genuine Path."));
239 matrix.setTranslateX(matrix.getTranslateX() + SafeNarrow(dx));
240 matrix.setTranslateY(matrix.getTranslateY() + SafeNarrow(dy));
245void CanvasPath::extendWithPath(
CanvasPath* path,
double dx,
double dy) {
248 ToDart(
"Path.extendWithPath called with non-genuine Path."));
251 mutable_path().addPath(
path->path(), SafeNarrow(dx), SafeNarrow(dy),
260 tonic::Float64List matrix4(matrix4_handle);
265 ToDart(
"Path.addPathWithMatrix called with non-genuine Path."));
271 matrix.setTranslateX(matrix.getTranslateX() + SafeNarrow(dx));
272 matrix.setTranslateY(matrix.getTranslateY() + SafeNarrow(dy));
277void CanvasPath::close() {
278 mutable_path().close();
282void CanvasPath::reset() {
283 mutable_path().reset();
287bool CanvasPath::contains(
double x,
double y) {
288 return path().contains(SafeNarrow(
x), SafeNarrow(
y));
291void CanvasPath::shift(
Dart_Handle path_handle,
double dx,
double dy) {
293 auto& other_mutable_path =
path->mutable_path();
294 mutable_path().offset(SafeNarrow(dx), SafeNarrow(dy), &other_mutable_path);
300 tonic::Float64List matrix4(matrix4_handle);
304 auto& other_mutable_path =
path->mutable_path();
305 mutable_path().transform(
sk_matrix, &other_mutable_path);
308tonic::Float32List CanvasPath::getBounds() {
311 rect[0] = bounds.left();
312 rect[1] = bounds.top();
313 rect[2] = bounds.right();
314 rect[3] = bounds.bottom();
329 path->mutable_path() = this->path();
static const int points[]
static sk_sp< Effect > Create()
static void operation(T operation, uint32_t &a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint8_t s, uint32_t t)
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
@ kSmall_ArcSize
smaller of arc pair
@ kLarge_ArcSize
larger of arc pair
struct _Dart_Handle * Dart_Handle
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
@ Dart_TypedData_kFloat32
DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, intptr_t length)
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
#define FML_DCHECK(condition)
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
SkMatrix ToSkMatrix(const tonic::Float64List &matrix4)
Dart_Handle ToDart(const T &object)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)