Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkContourMeasureIter::Impl Class Reference

Public Member Functions

 Impl (const SkPath &path, bool forceClosed, SkScalar resScale)
 
bool hasNextSegments () const
 
SkContourMeasurebuildSegments ()
 

Detailed Description

Definition at line 187 of file SkContourMeasure.cpp.

Constructor & Destructor Documentation

◆ Impl()

SkContourMeasureIter::Impl::Impl ( const SkPath path,
bool  forceClosed,
SkScalar  resScale 
)
inline

Definition at line 189 of file SkContourMeasure.cpp.

190 : fPath(path)
191 , fIter(SkPathPriv::Iterate(fPath).begin())
192 , fTolerance(CHEAP_DIST_LIMIT * sk_ieee_float_divide(1.0f, resScale))
193 , fForceClosed(forceClosed) {}
#define CHEAP_DIST_LIMIT
static constexpr float sk_ieee_float_divide(float numer, float denom)
static const char * begin(const StringSlice &s)
Definition: editor.cpp:252
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: switches.h:57

Member Function Documentation

◆ buildSegments()

SkContourMeasure * SkContourMeasureIter::Impl::buildSegments ( )

Definition at line 356 of file SkContourMeasure.cpp.

356 {
357 int ptIndex = -1;
358 SkScalar distance = 0;
359 bool haveSeenClose = fForceClosed;
360 bool haveSeenMoveTo = false;
361
362 /* Note:
363 * as we accumulate distance, we have to check that the result of +=
364 * actually made it larger, since a very small delta might be > 0, but
365 * still have no effect on distance (if distance >>> delta).
366 *
367 * We do this check below, and in compute_quad_segs and compute_cubic_segs
368 */
369
370 fSegments.reset();
371 fPts.reset();
372
373 auto end = SkPathPriv::Iterate(fPath).end();
374 for (; fIter != end; ++fIter) {
375 auto [verb, pts, w] = *fIter;
376 if (haveSeenMoveTo && verb == SkPathVerb::kMove) {
377 break;
378 }
379 switch (verb) {
381 ptIndex += 1;
382 fPts.append(1, pts);
383 SkASSERT(!haveSeenMoveTo);
384 haveSeenMoveTo = true;
385 break;
386
387 case SkPathVerb::kLine: {
388 SkASSERT(haveSeenMoveTo);
389 SkScalar prevD = distance;
390 distance = this->compute_line_seg(pts[0], pts[1], distance, ptIndex);
391 if (distance > prevD) {
392 fPts.append(1, pts + 1);
393 ptIndex++;
394 }
395 } break;
396
397 case SkPathVerb::kQuad: {
398 SkASSERT(haveSeenMoveTo);
399 SkScalar prevD = distance;
400 distance = this->compute_quad_segs(pts, distance, 0, kMaxTValue, ptIndex);
401 if (distance > prevD) {
402 fPts.append(2, pts + 1);
403 ptIndex += 2;
404 }
405 } break;
406
407 case SkPathVerb::kConic: {
408 SkASSERT(haveSeenMoveTo);
409 const SkConic conic(pts, *w);
410 SkScalar prevD = distance;
411 distance = this->compute_conic_segs(conic, distance, 0, conic.fPts[0],
412 kMaxTValue, conic.fPts[2], ptIndex);
413 if (distance > prevD) {
414 // we store the conic weight in our next point, followed by the last 2 pts
415 // thus to reconstitue a conic, you'd need to say
416 // SkConic(pts[0], pts[2], pts[3], weight = pts[1].fX)
417 fPts.append()->set(conic.fW, 0);
418 fPts.append(2, pts + 1);
419 ptIndex += 3;
420 }
421 } break;
422
423 case SkPathVerb::kCubic: {
424 SkASSERT(haveSeenMoveTo);
425 SkScalar prevD = distance;
426 distance = this->compute_cubic_segs(pts, distance, 0, kMaxTValue, ptIndex);
427 if (distance > prevD) {
428 fPts.append(3, pts + 1);
429 ptIndex += 3;
430 }
431 } break;
432
434 haveSeenClose = true;
435 break;
436 }
437
438 }
439
440 if (!SkIsFinite(distance)) {
441 return nullptr;
442 }
443 if (fSegments.empty()) {
444 return nullptr;
445 }
446
447 if (haveSeenClose) {
448 SkScalar prevD = distance;
449 SkPoint firstPt = fPts[0];
450 distance = this->compute_line_seg(fPts[ptIndex], firstPt, distance, ptIndex);
451 if (distance > prevD) {
452 *fPts.append() = firstPt;
453 }
454 }
455
456 SkDEBUGCODE(this->validate();)
457
458 return new SkContourMeasure(std::move(fSegments), std::move(fPts), distance, haveSeenClose);
459}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define kMaxTValue
static bool SkIsFinite(T x, Pack... values)
@ kClose
SkPath::RawIter returns 0 points.
@ kCubic
SkPath::RawIter returns 4 points.
@ kConic
SkPath::RawIter returns 3 points + 1 weight.
@ kQuad
SkPath::RawIter returns 3 points.
@ kMove
SkPath::RawIter returns 1 point.
@ kLine
SkPath::RawIter returns 2 points.
bool empty() const
Definition: SkTDArray.h:135
void reset()
Definition: SkTDArray.h:171
T * append()
Definition: SkTDArray.h:191
float SkScalar
Definition: extension.cpp:12
glong glong end
AI float conic(float tolerance, const SkPoint pts[], float w, const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:287
SkScalar w
SkPath::RangeIter end()
Definition: SkPathPriv.h:187
void set(float x, float y)
Definition: SkPoint_impl.h:200

◆ hasNextSegments()

bool SkContourMeasureIter::Impl::hasNextSegments ( ) const
inline

Definition at line 195 of file SkContourMeasure.cpp.

195{ return fIter != SkPathPriv::Iterate(fPath).end(); }

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