caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | #ifndef SkPathWriter_DEFINED |
| 8 | #define SkPathWriter_DEFINED |
| 9 | |
| 10 | #include "SkPath.h" |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 11 | #include "SkTArray.h" |
| 12 | #include "SkTDArray.h" |
| 13 | |
| 14 | class SkOpPtT; |
| 15 | |
| 16 | // Construct the path one contour at a time. |
| 17 | // If the contour is closed, copy it to the final output. |
| 18 | // Otherwise, keep the partial contour for later assembly. |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 19 | |
| 20 | class SkPathWriter { |
| 21 | public: |
| 22 | SkPathWriter(SkPath& path); |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 23 | void assemble(); |
| 24 | void conicTo(const SkPoint& pt1, const SkOpPtT* pt2, SkScalar weight); |
| 25 | void cubicTo(const SkPoint& pt1, const SkPoint& pt2, const SkOpPtT* pt3); |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 26 | bool deferredLine(const SkOpPtT* pt); |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 27 | void deferredMove(const SkOpPtT* pt); |
| 28 | void finishContour(); |
| 29 | bool hasMove() const { return !fFirstPtT; } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 30 | void init(); |
| 31 | bool isClosed() const; |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 32 | const SkPath* nativePath() const { return fPathPtr; } |
| 33 | void quadTo(const SkPoint& pt1, const SkOpPtT* pt2); |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 34 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 35 | private: |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 36 | bool changedSlopes(const SkOpPtT* pt) const; |
| 37 | void close(); |
| 38 | const SkTDArray<const SkOpPtT*>& endPtTs() const { return fEndPtTs; } |
| 39 | void lineTo(); |
| 40 | bool matchedLast(const SkOpPtT*) const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 41 | void moveTo(); |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 42 | const SkTArray<SkPath>& partials() const { return fPartials; } |
| 43 | bool someAssemblyRequired(); |
Cary Clark | 98900b5 | 2018-08-17 12:38:22 -0400 | [diff] [blame] | 44 | SkPoint update(const SkOpPtT* pt); |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 45 | |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 46 | SkPath fCurrent; // contour under construction |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 47 | SkTArray<SkPath> fPartials; // contours with mismatched starts and ends |
| 48 | SkTDArray<const SkOpPtT*> fEndPtTs; // possible pt values for partial starts and ends |
| 49 | SkPath* fPathPtr; // closed contours are written here |
| 50 | const SkOpPtT* fDefer[2]; // [0] deferred move, [1] deferred line |
| 51 | const SkOpPtT* fFirstPtT; // first in current contour |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 54 | #endif /* defined(__PathOps__SkPathWriter__) */ |