blob: fd0744572d9bc256df276bc5feb1acc136b61a9d [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 SkOpEdgeBuilder_DEFINED
8#define SkOpEdgeBuilder_DEFINED
9
10#include "SkOpContour.h"
11#include "SkPathWriter.h"
12#include "SkTArray.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000013
14class SkOpEdgeBuilder {
15public:
16 SkOpEdgeBuilder(const SkPathWriter& path, SkTArray<SkOpContour>& contours)
17 : fPath(path.nativePath())
caryclark@google.com66560ca2013-04-26 19:51:16 +000018 , fContours(contours)
19 , fAllowOpenContours(true) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000020 init();
21 }
22
23 SkOpEdgeBuilder(const SkPath& path, SkTArray<SkOpContour>& contours)
24 : fPath(&path)
caryclark@google.com66560ca2013-04-26 19:51:16 +000025 , fContours(contours)
26 , fAllowOpenContours(false) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000027 init();
28 }
29
caryclarkd751ac02014-10-03 05:36:27 -070030 void addOperand(const SkPath& path);
31
caryclark@google.com07393ca2013-04-08 11:47:37 +000032 void complete() {
33 if (fCurrentContour && fCurrentContour->segments().count()) {
34 fCurrentContour->complete();
35 fCurrentContour = NULL;
36 }
37 }
38
caryclark@google.com66560ca2013-04-26 19:51:16 +000039 bool finish();
caryclark@google.com07393ca2013-04-08 11:47:37 +000040 void init();
caryclarkd751ac02014-10-03 05:36:27 -070041 bool unparseable() const { return fUnparseable; }
42 SkPathOpsMask xorMask() const { return fXorMask[fOperand]; }
caryclark@google.com07393ca2013-04-08 11:47:37 +000043
44private:
caryclark@google.com07e97fc2013-07-08 17:17:02 +000045 void closeContour(const SkPoint& curveEnd, const SkPoint& curveStart);
caryclark@google.com66560ca2013-04-26 19:51:16 +000046 bool close();
caryclark@google.com07393ca2013-04-08 11:47:37 +000047 int preFetch();
caryclark@google.com66560ca2013-04-26 19:51:16 +000048 bool walk();
caryclark@google.com07393ca2013-04-08 11:47:37 +000049
50 const SkPath* fPath;
caryclark@google.comd892bd82013-06-17 14:10:36 +000051 SkTArray<SkPoint, true> fPathPts;
52 SkTArray<uint8_t, true> fPathVerbs;
caryclark@google.com07393ca2013-04-08 11:47:37 +000053 SkOpContour* fCurrentContour;
54 SkTArray<SkOpContour>& fContours;
caryclark@google.com07393ca2013-04-08 11:47:37 +000055 SkPathOpsMask fXorMask[2];
56 int fSecondHalf;
57 bool fOperand;
caryclark@google.com66560ca2013-04-26 19:51:16 +000058 bool fAllowOpenContours;
59 bool fUnparseable;
caryclark@google.com07393ca2013-04-08 11:47:37 +000060};
61
62#endif