Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: include/core/SkROPath.h

Issue 1126993003: experimental path-builder Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPathTypes.h ('k') | src/core/SkPath.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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
8 #ifndef SkROPath_DEFINED
9 #define SkROPath_DEFINED
10
11 #include "SkMatrix.h"
12 #include "SkTDArray.h"
13 #include "SkRefCnt.h"
14
15 class SkReader32;
16 class SkWriter32;
17 class SkString;
18 class SkRRect;
19 class SkWStream;
20
21 class SkROPath : public SkRefCnt {
22 public:
23 SkPathFillType fillType() const;
24 SkPathConvexityType convexityType() const;
25 SkPathSegmentMask segmentMask() const;
26
27 bool isEmpty() const { return 0 == this->segmentMask(); }
28 SkRect bounds() const { return fBounds; }
29 uint32_t uniqueID() const { return fUniqueID; }
30
31 /**
32 * Returns true if the path specifies a single line (i.e. it contains just
33 * a moveTo and a lineTo). If so, and line[] is not null, it sets the 2
34 * points in line[] to the end-points of the line. If the path is not a
35 * line, returns false and ignores line[].
36 */
37 bool isLine(SkPoint line[2]) const;
38
39 /**
40 * Does a conservative test to see whether a rectangle is inside a path. Cur rently it only
41 * will ever return true for single convex contour paths. The empty-status o f the rect is not
42 * considered (e.g. a rect that is a point can be inside a path). Points or line segments where
43 * the rect edge touches the path border are not considered containment viol ations.
44 */
45 bool conservativelyContainsRect(const SkRect& rect) const;
46
47 SkROPath* transform(const SkMatrix&) const;
48
49 /** Iterate through all of the segments (lines, quadratics, cubics) of
50 each contours in a path.
51
52 The iterator cleans up the segments along the way, removing degenerate
53 segments and adding close verbs where necessary. When the forceClose
54 argument is provided, each contour (as defined by a new starting
55 move command) will be completed with a close verb regardless of the
56 contour's contents.
57 */
58 class SK_API Iter {
59 public:
60 Iter(const SkPathRef&, bool forceClose);
61
62 /** Return the next verb in this iteration of the path. When all
63 segments have been visited, return kDone_Verb.
64
65 @param pts The points representing the current verb and/or segment
66 @param doConsumeDegerates If true, first scan for segments that are
67 deemed degenerate (too short) and skip those.
68 @return The verb for the current segment
69 */
70 SkPathVerb next(SkPoint pts[4], bool doConsumeDegerates = true) {
71 if (doConsumeDegerates) {
72 this->consumeDegenerateSegments();
73 }
74 return this->doNext(pts);
75 }
76
77 /**
78 * Return the weight for the current conic. Only valid if the current
79 * segment return by next() was a conic.
80 */
81 SkScalar conicWeight() const { return *fConicWeights; }
82
83 /** If next() returns kLine_Verb, then this query returns true if the
84 line was the result of a close() command (i.e. the end point is the
85 initial moveto for this contour). If next() returned a different
86 verb, this returns an undefined value.
87
88 @return If the last call to next() returned kLine_Verb, return true
89 if it was the result of an explicit close command.
90 */
91 bool isCloseLine() const { return SkToBool(fCloseLine); }
92
93 /** Returns true if the current contour is closed (has a kClose_Verb)
94 @return true if the current contour is closed (has a kClose_Verb)
95 */
96 bool isClosedContour() const;
97
98 private:
99 const SkPoint* fPts;
100 const uint8_t* fVerbs;
101 const uint8_t* fVerbStop;
102 const SkScalar* fConicWeights;
103 SkPoint fMoveTo;
104 SkPoint fLastPt;
105 SkBool8 fForceClose;
106 SkBool8 fNeedClose;
107 SkBool8 fCloseLine;
108 SkBool8 fSegmentState;
109
110 inline const SkPoint& cons_moveTo();
111 Verb autoClose(SkPoint pts[2]);
112 void consumeDegenerateSegments();
113 Verb doNext(SkPoint pts[4]);
114 };
115
116 /** Iterate through the verbs in the path, providing the associated points.
117 */
118 class SK_API RawIter {
119 public:
120 RawIter(const SkPathRef&);
121
122 /** Return the next verb in this iteration of the path. When all
123 segments have been visited, return kDone_Verb.
124
125 @param pts The points representing the current verb and/or segment
126 This must not be NULL.
127 @return The verb for the current segment
128 */
129 SkPathVerb next(SkPoint pts[4]);
130
131 SkScalar conicWeight() const { return *fConicWeights; }
132
133 private:
134 const SkPoint* fPts;
135 const uint8_t* fVerbs;
136 const uint8_t* fVerbStop;
137 const SkScalar* fConicWeights;
138 SkPoint fMoveTo;
139 SkPoint fLastPt;
140 };
141
142 /**
143 * Returns true if the point { x, y } is contained by the path, taking into
144 * account the FillType.
145 */
146 bool contains(SkScalar x, SkScalar y) const;
147
148 void dump(SkWStream* , bool forceClose, bool dumpAsHex) const;
149 void dump() const;
150 void dumpHex() const;
151
152 /**
153 * Write the path to the buffer, and return the number of bytes written.
154 * If buffer is NULL, it still returns the number of bytes.
155 */
156 size_t writeToMemory(void* buffer) const;
157 /**
158 * Initializes the path from the buffer
159 *
160 * @param buffer Memory to read from
161 * @param length Amount of memory available in the buffer
162 * @return number of bytes read (must be a multiple of 4) or
163 * 0 if there was not enough memory available
164 */
165 size_t readFromMemory(const void* buffer, size_t length);
166 };
167
168 #endif
OLDNEW
« no previous file with comments | « include/core/SkPathTypes.h ('k') | src/core/SkPath.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698