• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 namespace tonic {
16 class DartLibraryNatives;
17 }  // namespace tonic
18 
19 // Be sure that the client doesn't modify a path on us before Skia finishes
20 // See AOSP's reasoning in PathMeasure.cpp
21 
22 namespace flutter {
23 
24 class CanvasPathMeasure : public RefCountedDartWrappable<CanvasPathMeasure> {
25   DEFINE_WRAPPERTYPEINFO();
26   FML_FRIEND_MAKE_REF_COUNTED(CanvasPathMeasure);
27 
28  public:
29   ~CanvasPathMeasure() override;
30   static fml::RefPtr<CanvasPathMeasure> Create(const CanvasPath* path,
31                                                bool forceClosed);
32 
33   void setPath(const CanvasPath* path, bool isClosed);
34   float getLength(int contourIndex);
35   tonic::Float32List getPosTan(int contourIndex, float distance);
36   fml::RefPtr<CanvasPath> getSegment(int contourIndex,
37                                      float startD,
38                                      float stopD,
39                                      bool startWithMoveTo);
40   bool isClosed(int contourIndex);
41   bool nextContour();
42 
43   static void RegisterNatives(tonic::DartLibraryNatives* natives);
44 
pathMeasure()45   const SkContourMeasureIter& pathMeasure() const { return *path_measure_; }
46 
47  private:
48   CanvasPathMeasure();
49 
50   std::unique_ptr<SkContourMeasureIter> path_measure_;
51   std::vector<sk_sp<SkContourMeasure>> measures_;
52 };
53 
54 }  // namespace flutter
55 
56 #endif  // FLUTTER_LIB_UI_PAINTING_PATH_MEASURE_H_
57