Flutter Engine
flutter::CanvasPathMeasure Class Reference

#include <path_measure.h>

Inheritance diagram for flutter::CanvasPathMeasure:
flutter::RefCountedDartWrappable< CanvasPathMeasure > fml::RefCountedThreadSafe< CanvasPathMeasure > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Member Functions

 ~CanvasPathMeasure () override
 
void setPath (const CanvasPath *path, bool isClosed)
 
float getLength (int contour_index)
 
tonic::Float32List getPosTan (int contour_index, float distance)
 
void getSegment (Dart_Handle path_handle, int contour_index, float start_d, float stop_d, bool start_with_move_to)
 
bool isClosed (int contour_index)
 
bool nextContour ()
 
const SkContourMeasureIter & pathMeasure () const
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< CanvasPathMeasure >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< CanvasPathMeasure >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
virtual size_t GetAllocationSize () const
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static fml::RefPtr< CanvasPathMeasureCreate (const CanvasPath *path, bool forceClosed)
 
static void RegisterNatives (tonic::DartLibraryNatives *natives)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
  kPeerIndex,
  kWrapperInfoIndex,
  kNumberOfNativeFields
}
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< CanvasPathMeasure >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 25 of file path_measure.h.

Constructor & Destructor Documentation

◆ ~CanvasPathMeasure()

flutter::CanvasPathMeasure::~CanvasPathMeasure ( )
override

Definition at line 62 of file path_measure.cc.

62 {}

Member Function Documentation

◆ Create()

fml::RefPtr< CanvasPathMeasure > flutter::CanvasPathMeasure::Create ( const CanvasPath path,
bool  forceClosed 
)
static

Definition at line 45 of file path_measure.cc.

References flutter::CanvasPath::path(), and pathMeasure().

Referenced by flutter::PathMeasure_constructor().

46  {
48  fml::MakeRefCounted<CanvasPathMeasure>();
49  if (path) {
50  const SkPath skPath = path->path();
51  SkScalar resScale = 1;
52  pathMeasure->path_measure_ =
53  std::make_unique<SkContourMeasureIter>(skPath, forceClosed, resScale);
54  } else {
55  pathMeasure->path_measure_ = std::make_unique<SkContourMeasureIter>();
56  }
57  return pathMeasure;
58 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
const SkContourMeasureIter & pathMeasure() const
Definition: path_measure.h:47

◆ getLength()

float flutter::CanvasPathMeasure::getLength ( int  contour_index)

Definition at line 69 of file path_measure.cc.

69  {
70  if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
71  contour_index) < measures_.size()) {
72  return measures_[contour_index]->length();
73  }
74  return -1;
75 }

◆ getPosTan()

tonic::Float32List flutter::CanvasPathMeasure::getPosTan ( int  contour_index,
float  distance 
)

Definition at line 77 of file path_measure.cc.

78  {
79  tonic::Float32List posTan(Dart_NewTypedData(Dart_TypedData_kFloat32, 5));
80  posTan[0] = 0; // dart code will check for this for failure
81  if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
82  contour_index) >= measures_.size()) {
83  return posTan;
84  }
85 
86  SkPoint pos;
87  SkVector tan;
88  bool success = measures_[contour_index]->getPosTan(distance, &pos, &tan);
89 
90  if (success) {
91  posTan[0] = 1; // dart code will check for this for success
92  posTan[1] = pos.x();
93  posTan[2] = pos.y();
94  posTan[3] = tan.x();
95  posTan[4] = tan.y();
96  }
97 
98  return posTan;
99 }

◆ getSegment()

void flutter::CanvasPathMeasure::getSegment ( Dart_Handle  path_handle,
int  contour_index,
float  start_d,
float  stop_d,
bool  start_with_move_to 
)

Definition at line 101 of file path_measure.cc.

References flutter::CanvasPath::Create(), and flutter::CanvasPath::CreateFrom().

105  {
106  if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
107  contour_index) >= measures_.size()) {
108  CanvasPath::Create(path_handle);
109  }
110  SkPath dst;
111  bool success = measures_[contour_index]->getSegment(start_d, stop_d, &dst,
112  start_with_move_to);
113  if (!success) {
114  CanvasPath::Create(path_handle);
115  } else {
116  CanvasPath::CreateFrom(path_handle, dst);
117  }
118 }
static fml::RefPtr< CanvasPath > Create(Dart_Handle path_handle)
Definition: path.h:30
static fml::RefPtr< CanvasPath > CreateFrom(Dart_Handle path_handle, const SkPath &src)
Definition: path.h:36

◆ isClosed()

bool flutter::CanvasPathMeasure::isClosed ( int  contour_index)

Definition at line 120 of file path_measure.cc.

120  {
121  if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
122  contour_index) < measures_.size()) {
123  return measures_[contour_index]->isClosed();
124  }
125  return false;
126 }

◆ nextContour()

bool flutter::CanvasPathMeasure::nextContour ( )

Definition at line 128 of file path_measure.cc.

128  {
129  auto measure = path_measure_->next();
130  if (measure) {
131  measures_.push_back(std::move(measure));
132  return true;
133  }
134  return false;
135 }

◆ pathMeasure()

const SkContourMeasureIter& flutter::CanvasPathMeasure::pathMeasure ( ) const
inline

Definition at line 47 of file path_measure.h.

Referenced by Create().

47 { return *path_measure_; }

◆ RegisterNatives()

void flutter::CanvasPathMeasure::RegisterNatives ( tonic::DartLibraryNatives natives)
static

Definition at line 39 of file path_measure.cc.

References DART_REGISTER_NATIVE, FOR_EACH_BINDING, and flutter::PathMeasure_constructor().

Referenced by flutter::DartUI::InitForGlobal().

39  {
40  natives->Register(
41  {{"PathMeasure_constructor", PathMeasure_constructor, 3, true},
43 }
#define FOR_EACH_BINDING(V)
Definition: path_measure.cc:29
static void PathMeasure_constructor(Dart_NativeArguments args)
Definition: path_measure.cc:22
void Register(std::initializer_list< Entry > entries)
#define DART_REGISTER_NATIVE(CLASS, METHOD)

◆ setPath()

void flutter::CanvasPathMeasure::setPath ( const CanvasPath path,
bool  isClosed 
)

Definition at line 64 of file path_measure.cc.

References flutter::CanvasPath::path().

64  {
65  const SkPath& skPath = path->path();
66  path_measure_->reset(skPath, isClosed);
67 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
bool isClosed(int contour_index)

The documentation for this class was generated from the following files: