blob: bd13c718a90f3c2808b95d037c02832b17aff4c5 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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"
caryclarkeed356d2016-09-14 07:18:20 -070011#include "SkTArray.h"
12#include "SkTDArray.h"
13
14class 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.com07393ca2013-04-08 11:47:37 +000019
20class SkPathWriter {
21public:
22 SkPathWriter(SkPath& path);
caryclarkeed356d2016-09-14 07:18:20 -070023 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);
26 void deferredLine(const SkOpPtT* pt);
27 void deferredMove(const SkOpPtT* pt);
28 void finishContour();
29 bool hasMove() const { return !fFirstPtT; }
caryclark@google.com07393ca2013-04-08 11:47:37 +000030 void init();
31 bool isClosed() const;
caryclarkeed356d2016-09-14 07:18:20 -070032 const SkPath* nativePath() const { return fPathPtr; }
33 void quadTo(const SkPoint& pt1, const SkOpPtT* pt2);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000034
caryclark@google.com07393ca2013-04-08 11:47:37 +000035private:
caryclarkeed356d2016-09-14 07:18:20 -070036 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.com07393ca2013-04-08 11:47:37 +000041 void moveTo();
caryclarkeed356d2016-09-14 07:18:20 -070042 const SkTArray<SkPath>& partials() const { return fPartials; }
43 bool someAssemblyRequired();
44 void update(const SkOpPtT* pt);
skia.committer@gmail.com32840172013-04-09 07:01:27 +000045
caryclarkeed356d2016-09-14 07:18:20 -070046 SkPath fCurrent; // contour under construction
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.com07393ca2013-04-08 11:47:37 +000052};
53
caryclark@google.com07393ca2013-04-08 11:47:37 +000054#endif /* defined(__PathOps__SkPathWriter__) */