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_LIB_UI_PAINTING_PATH_MEASURE_H_
6#define FLUTTER_LIB_UI_PAINTING_PATH_MEASURE_H_
7
8#include <vector>
9
10#include "flutter/lib/ui/dart_wrapper.h"
11#include "flutter/lib/ui/painting/path.h"
12#include "third_party/skia/include/core/SkContourMeasure.h"
13#include "third_party/skia/include/core/SkPath.h"
14#include "third_party/tonic/typed_data/typed_list.h"
15
16namespace tonic {
17class DartLibraryNatives;
18} // namespace tonic
19
20// Be sure that the client doesn't modify a path on us before Skia finishes
21// See AOSP's reasoning in PathMeasure.cpp
22
23namespace flutter {
24
25class CanvasPathMeasure : public RefCountedDartWrappable<CanvasPathMeasure> {
26 DEFINE_WRAPPERTYPEINFO();
27 FML_FRIEND_MAKE_REF_COUNTED(CanvasPathMeasure);
28
29 public:
30 ~CanvasPathMeasure() override;
31 static fml::RefPtr<CanvasPathMeasure> Create(const CanvasPath* path,
32 bool forceClosed);
33
34 void setPath(const CanvasPath* path, bool isClosed);
35 float getLength(int contour_index);
36 tonic::Float32List getPosTan(int contour_index, float distance);
37 void getSegment(Dart_Handle path_handle,
38 int contour_index,
39 float start_d,
40 float stop_d,
41 bool start_with_move_to);
42 bool isClosed(int contour_index);
43 bool nextContour();
44
45 static void RegisterNatives(tonic::DartLibraryNatives* natives);
46
47 const SkContourMeasureIter& pathMeasure() const { return *path_measure_; }
48
49 private:
50 CanvasPathMeasure();
51
52 std::unique_ptr<SkContourMeasureIter> path_measure_;
53 std::vector<sk_sp<SkContourMeasure>> measures_;
54};
55
56} // namespace flutter
57
58#endif // FLUTTER_LIB_UI_PAINTING_PATH_MEASURE_H_
59