blob: b83a4513765d84eba44a644bf65ee0f71939c1cf [file] [log] [blame]
robertphillips@google.comca0c8382013-09-26 12:18:23 +00001/*
2 * Copyright 2013 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#include "SkBuffer.h"
commit-bot@chromium.org1f81fd62013-10-23 14:44:08 +00009#include "SkOnce.h"
robertphillips@google.comca0c8382013-09-26 12:18:23 +000010#include "SkPath.h"
11#include "SkPathRef.h"
12
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000013//////////////////////////////////////////////////////////////////////////////
14SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef,
15 int incReserveVerbs,
16 int incReservePoints)
17{
18 if ((*pathRef)->unique()) {
19 (*pathRef)->incReserve(incReserveVerbs, incReservePoints);
20 } else {
21 SkPathRef* copy = SkNEW(SkPathRef);
22 copy->copy(**pathRef, incReserveVerbs, incReservePoints);
23 pathRef->reset(copy);
24 }
25 fPathRef = *pathRef;
26 fPathRef->fGenerationID = 0;
27 SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);)
robertphillips@google.comca0c8382013-09-26 12:18:23 +000028}
29
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000030//////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.org1f81fd62013-10-23 14:44:08 +000031void SkPathRef::CreateEmptyImpl(SkPathRef** empty) {
32 *empty = SkNEW(SkPathRef);
33 (*empty)->computeBounds(); // Preemptively avoid a race to clear fBoundsIsDirty.
34}
35
36SkPathRef* SkPathRef::CreateEmpty() {
37 static SkPathRef* gEmptyPathRef;
38 SK_DECLARE_STATIC_ONCE(once);
39 SkOnce(&once, SkPathRef::CreateEmptyImpl, &gEmptyPathRef);
40 return SkRef(gEmptyPathRef);
41}
42
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000043void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
44 const SkPathRef& src,
45 const SkMatrix& matrix) {
robertphillips@google.com03087072013-10-02 16:42:21 +000046 SkDEBUGCODE(src.validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000047 if (matrix.isIdentity()) {
48 if (*dst != &src) {
49 src.ref();
50 dst->reset(const_cast<SkPathRef*>(&src));
robertphillips@google.com03087072013-10-02 16:42:21 +000051 SkDEBUGCODE((*dst)->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000052 }
53 return;
54 }
55
robertphillips@google.comb06e88d2013-12-03 17:15:36 +000056 if (!(*dst)->unique()) {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000057 dst->reset(SkNEW(SkPathRef));
robertphillips@google.comb06e88d2013-12-03 17:15:36 +000058 }
59
60 if (*dst != &src) {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000061 (*dst)->resetToSize(src.fVerbCnt, src.fPointCnt, src.fConicWeights.count());
62 memcpy((*dst)->verbsMemWritable(), src.verbsMemBegin(), src.fVerbCnt * sizeof(uint8_t));
63 (*dst)->fConicWeights = src.fConicWeights;
64 }
65
robertphillips@google.comb06e88d2013-12-03 17:15:36 +000066 SkASSERT((*dst)->countPoints() == src.countPoints());
67 SkASSERT((*dst)->countVerbs() == src.countVerbs());
68 SkASSERT((*dst)->fConicWeights.count() == src.fConicWeights.count());
69
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000070 // Need to check this here in case (&src == dst)
71 bool canXformBounds = !src.fBoundsIsDirty && matrix.rectStaysRect() && src.countPoints() > 1;
72
73 matrix.mapPoints((*dst)->fPoints, src.points(), src.fPointCnt);
74
75 /*
76 * Here we optimize the bounds computation, by noting if the bounds are
77 * already known, and if so, we just transform those as well and mark
78 * them as "known", rather than force the transformed path to have to
79 * recompute them.
80 *
81 * Special gotchas if the path is effectively empty (<= 1 point) or
82 * if it is non-finite. In those cases bounds need to stay empty,
83 * regardless of the matrix.
84 */
85 if (canXformBounds) {
86 (*dst)->fBoundsIsDirty = false;
87 if (src.fIsFinite) {
88 matrix.mapRect(&(*dst)->fBounds, src.fBounds);
89 if (!((*dst)->fIsFinite = (*dst)->fBounds.isFinite())) {
90 (*dst)->fBounds.setEmpty();
91 }
92 } else {
93 (*dst)->fIsFinite = false;
94 (*dst)->fBounds.setEmpty();
95 }
96 } else {
97 (*dst)->fBoundsIsDirty = true;
98 }
99
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000100 (*dst)->fSegmentMask = src.fSegmentMask;
101
robertphillips@google.com466310d2013-12-03 16:43:54 +0000102 // It's an oval only if it stays a rect.
103 (*dst)->fIsOval = src.fIsOval && matrix.rectStaysRect();
104
robertphillips@google.com03087072013-10-02 16:42:21 +0000105 SkDEBUGCODE((*dst)->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000106}
107
commit-bot@chromium.orgfed2ab62014-01-23 15:16:05 +0000108SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer) {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000109 SkPathRef* ref = SkNEW(SkPathRef);
robertphillips@google.com466310d2013-12-03 16:43:54 +0000110 bool isOval;
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000111 uint8_t segmentMask;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000112
113 int32_t packed;
114 if (!buffer->readS32(&packed)) {
115 SkDELETE(ref);
116 return NULL;
117 }
118
119 ref->fIsFinite = (packed >> kIsFinite_SerializationShift) & 1;
commit-bot@chromium.orgfed2ab62014-01-23 15:16:05 +0000120 segmentMask = (packed >> kSegmentMask_SerializationShift) & 0xF;
121 isOval = (packed >> kIsOval_SerializationShift) & 1;
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000122
commit-bot@chromium.org8f457e32013-11-08 19:22:57 +0000123 int32_t verbCount, pointCount, conicCount;
124 if (!buffer->readU32(&(ref->fGenerationID)) ||
125 !buffer->readS32(&verbCount) ||
126 !buffer->readS32(&pointCount) ||
127 !buffer->readS32(&conicCount)) {
128 SkDELETE(ref);
129 return NULL;
130 }
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000131
commit-bot@chromium.org8f457e32013-11-08 19:22:57 +0000132 ref->resetToSize(verbCount, pointCount, conicCount);
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000133 SkASSERT(verbCount == ref->countVerbs());
134 SkASSERT(pointCount == ref->countPoints());
135 SkASSERT(conicCount == ref->fConicWeights.count());
commit-bot@chromium.org8f457e32013-11-08 19:22:57 +0000136
137 if (!buffer->read(ref->verbsMemWritable(), verbCount * sizeof(uint8_t)) ||
138 !buffer->read(ref->fPoints, pointCount * sizeof(SkPoint)) ||
139 !buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar)) ||
140 !buffer->read(&ref->fBounds, sizeof(SkRect))) {
141 SkDELETE(ref);
142 return NULL;
143 }
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000144 ref->fBoundsIsDirty = false;
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000145
146 // resetToSize clears fSegmentMask and fIsOval
147 ref->fSegmentMask = segmentMask;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000148 ref->fIsOval = isOval;
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000149 return ref;
150}
151
152void SkPathRef::Rewind(SkAutoTUnref<SkPathRef>* pathRef) {
153 if ((*pathRef)->unique()) {
robertphillips@google.com03087072013-10-02 16:42:21 +0000154 SkDEBUGCODE((*pathRef)->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000155 (*pathRef)->fBoundsIsDirty = true; // this also invalidates fIsFinite
156 (*pathRef)->fVerbCnt = 0;
157 (*pathRef)->fPointCnt = 0;
158 (*pathRef)->fFreeSpace = (*pathRef)->currSize();
159 (*pathRef)->fGenerationID = 0;
160 (*pathRef)->fConicWeights.rewind();
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000161 (*pathRef)->fSegmentMask = 0;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000162 (*pathRef)->fIsOval = false;
robertphillips@google.com03087072013-10-02 16:42:21 +0000163 SkDEBUGCODE((*pathRef)->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000164 } else {
165 int oldVCnt = (*pathRef)->countVerbs();
166 int oldPCnt = (*pathRef)->countPoints();
167 pathRef->reset(SkNEW(SkPathRef));
168 (*pathRef)->resetToSize(0, 0, 0, oldVCnt, oldPCnt);
169 }
170}
171
172bool SkPathRef::operator== (const SkPathRef& ref) const {
robertphillips@google.com03087072013-10-02 16:42:21 +0000173 SkDEBUGCODE(this->validate();)
174 SkDEBUGCODE(ref.validate();)
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000175
176 // We explicitly check fSegmentMask as a quick-reject. We could skip it,
177 // since it is only a cache of info in the fVerbs, but its a fast way to
178 // notice a difference
179 if (fSegmentMask != ref.fSegmentMask) {
180 return false;
181 }
182
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000183 bool genIDMatch = fGenerationID && fGenerationID == ref.fGenerationID;
184#ifdef SK_RELEASE
185 if (genIDMatch) {
186 return true;
187 }
188#endif
189 if (fPointCnt != ref.fPointCnt ||
190 fVerbCnt != ref.fVerbCnt) {
191 SkASSERT(!genIDMatch);
192 return false;
193 }
194 if (0 != memcmp(this->verbsMemBegin(),
195 ref.verbsMemBegin(),
196 ref.fVerbCnt * sizeof(uint8_t))) {
197 SkASSERT(!genIDMatch);
198 return false;
199 }
200 if (0 != memcmp(this->points(),
201 ref.points(),
202 ref.fPointCnt * sizeof(SkPoint))) {
203 SkASSERT(!genIDMatch);
204 return false;
205 }
206 if (fConicWeights != ref.fConicWeights) {
207 SkASSERT(!genIDMatch);
208 return false;
209 }
210 // We've done the work to determine that these are equal. If either has a zero genID, copy
211 // the other's. If both are 0 then genID() will compute the next ID.
212 if (0 == fGenerationID) {
213 fGenerationID = ref.genID();
214 } else if (0 == ref.fGenerationID) {
215 ref.fGenerationID = this->genID();
216 }
217 return true;
218}
219
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000220void SkPathRef::writeToBuffer(SkWBuffer* buffer) const {
robertphillips@google.com03087072013-10-02 16:42:21 +0000221 SkDEBUGCODE(this->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000222 SkDEBUGCODE(size_t beforePos = buffer->pos();)
223
224 // Call getBounds() to ensure (as a side-effect) that fBounds
225 // and fIsFinite are computed.
226 const SkRect& bounds = this->getBounds();
227
robertphillips@google.com466310d2013-12-03 16:43:54 +0000228 int32_t packed = ((fIsFinite & 1) << kIsFinite_SerializationShift) |
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000229 ((fIsOval & 1) << kIsOval_SerializationShift) |
230 (fSegmentMask << kSegmentMask_SerializationShift);
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000231 buffer->write32(packed);
232
233 // TODO: write gen ID here. Problem: We don't know if we're cross process or not from
234 // SkWBuffer. Until this is fixed we write 0.
235 buffer->write32(0);
236 buffer->write32(fVerbCnt);
237 buffer->write32(fPointCnt);
238 buffer->write32(fConicWeights.count());
239 buffer->write(verbsMemBegin(), fVerbCnt * sizeof(uint8_t));
240 buffer->write(fPoints, fPointCnt * sizeof(SkPoint));
241 buffer->write(fConicWeights.begin(), fConicWeights.bytes());
242 buffer->write(&bounds, sizeof(bounds));
243
244 SkASSERT(buffer->pos() - beforePos == (size_t) this->writeSize());
245}
246
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000247uint32_t SkPathRef::writeSize() const {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000248 return uint32_t(5 * sizeof(uint32_t) +
249 fVerbCnt * sizeof(uint8_t) +
250 fPointCnt * sizeof(SkPoint) +
251 fConicWeights.bytes() +
252 sizeof(SkRect));
253}
254
skia.committer@gmail.com50df4d02013-09-28 07:01:33 +0000255void SkPathRef::copy(const SkPathRef& ref,
256 int additionalReserveVerbs,
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000257 int additionalReservePoints) {
robertphillips@google.com03087072013-10-02 16:42:21 +0000258 SkDEBUGCODE(this->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000259 this->resetToSize(ref.fVerbCnt, ref.fPointCnt, ref.fConicWeights.count(),
260 additionalReserveVerbs, additionalReservePoints);
261 memcpy(this->verbsMemWritable(), ref.verbsMemBegin(), ref.fVerbCnt * sizeof(uint8_t));
262 memcpy(this->fPoints, ref.fPoints, ref.fPointCnt * sizeof(SkPoint));
263 fConicWeights = ref.fConicWeights;
264 // We could call genID() here to force a real ID (instead of 0). However, if we're making
265 // a copy then presumably we intend to make a modification immediately afterwards.
266 fGenerationID = ref.fGenerationID;
267 fBoundsIsDirty = ref.fBoundsIsDirty;
268 if (!fBoundsIsDirty) {
269 fBounds = ref.fBounds;
270 fIsFinite = ref.fIsFinite;
271 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000272 fSegmentMask = ref.fSegmentMask;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000273 fIsOval = ref.fIsOval;
robertphillips@google.com03087072013-10-02 16:42:21 +0000274 SkDEBUGCODE(this->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000275}
276
skia.committer@gmail.com96f5fa02013-12-16 07:01:40 +0000277SkPoint* SkPathRef::growForRepeatedVerb(int /*SkPath::Verb*/ verb,
278 int numVbs,
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000279 SkScalar** weights) {
280 // This value is just made-up for now. When count is 4, calling memset was much
281 // slower than just writing the loop. This seems odd, and hopefully in the
282 // future this will appear to have been a fluke...
283 static const unsigned int kMIN_COUNT_FOR_MEMSET_TO_BE_FAST = 16;
284
285 SkDEBUGCODE(this->validate();)
286 int pCnt;
287 bool dirtyAfterEdit = true;
288 switch (verb) {
289 case SkPath::kMove_Verb:
290 pCnt = numVbs;
291 dirtyAfterEdit = false;
292 break;
293 case SkPath::kLine_Verb:
294 fSegmentMask |= SkPath::kLine_SegmentMask;
295 pCnt = numVbs;
296 break;
297 case SkPath::kQuad_Verb:
298 fSegmentMask |= SkPath::kQuad_SegmentMask;
299 pCnt = 2 * numVbs;
300 break;
301 case SkPath::kConic_Verb:
302 fSegmentMask |= SkPath::kConic_SegmentMask;
303 pCnt = 2 * numVbs;
304 break;
305 case SkPath::kCubic_Verb:
306 fSegmentMask |= SkPath::kCubic_SegmentMask;
307 pCnt = 3 * numVbs;
308 break;
309 case SkPath::kClose_Verb:
310 SkDEBUGFAIL("growForRepeatedVerb called for kClose_Verb");
311 pCnt = 0;
312 dirtyAfterEdit = false;
313 break;
314 case SkPath::kDone_Verb:
315 SkDEBUGFAIL("growForRepeatedVerb called for kDone");
316 // fall through
317 default:
318 SkDEBUGFAIL("default should not be reached");
319 pCnt = 0;
320 dirtyAfterEdit = false;
321 }
322
323 size_t space = numVbs * sizeof(uint8_t) + pCnt * sizeof (SkPoint);
324 this->makeSpace(space);
325
326 SkPoint* ret = fPoints + fPointCnt;
327 uint8_t* vb = fVerbs - fVerbCnt;
328
329 // cast to unsigned, so if kMIN_COUNT_FOR_MEMSET_TO_BE_FAST is defined to
330 // be 0, the compiler will remove the test/branch entirely.
331 if ((unsigned)numVbs >= kMIN_COUNT_FOR_MEMSET_TO_BE_FAST) {
332 memset(vb - numVbs, verb, numVbs);
333 } else {
334 for (int i = 0; i < numVbs; ++i) {
335 vb[~i] = verb;
336 }
337 }
338
339 fVerbCnt += numVbs;
340 fPointCnt += pCnt;
341 fFreeSpace -= space;
342 fBoundsIsDirty = true; // this also invalidates fIsFinite
343 if (dirtyAfterEdit) {
344 fIsOval = false;
345 }
346
347 if (SkPath::kConic_Verb == verb) {
348 SkASSERT(NULL != weights);
349 *weights = fConicWeights.append(numVbs);
350 }
351
352 SkDEBUGCODE(this->validate();)
353 return ret;
354}
355
356SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb, SkScalar weight) {
robertphillips@google.com03087072013-10-02 16:42:21 +0000357 SkDEBUGCODE(this->validate();)
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000358 int pCnt;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000359 bool dirtyAfterEdit = true;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000360 switch (verb) {
361 case SkPath::kMove_Verb:
362 pCnt = 1;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000363 dirtyAfterEdit = false;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000364 break;
365 case SkPath::kLine_Verb:
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000366 fSegmentMask |= SkPath::kLine_SegmentMask;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000367 pCnt = 1;
368 break;
369 case SkPath::kQuad_Verb:
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000370 fSegmentMask |= SkPath::kQuad_SegmentMask;
371 pCnt = 2;
372 break;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000373 case SkPath::kConic_Verb:
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000374 fSegmentMask |= SkPath::kConic_SegmentMask;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000375 pCnt = 2;
376 break;
377 case SkPath::kCubic_Verb:
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000378 fSegmentMask |= SkPath::kCubic_SegmentMask;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000379 pCnt = 3;
380 break;
381 case SkPath::kClose_Verb:
382 pCnt = 0;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000383 dirtyAfterEdit = false;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000384 break;
385 case SkPath::kDone_Verb:
386 SkDEBUGFAIL("growForVerb called for kDone");
387 // fall through
388 default:
389 SkDEBUGFAIL("default is not reached");
robertphillips@google.com466310d2013-12-03 16:43:54 +0000390 dirtyAfterEdit = false;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000391 pCnt = 0;
392 }
393 size_t space = sizeof(uint8_t) + pCnt * sizeof (SkPoint);
394 this->makeSpace(space);
395 this->fVerbs[~fVerbCnt] = verb;
396 SkPoint* ret = fPoints + fPointCnt;
397 fVerbCnt += 1;
398 fPointCnt += pCnt;
399 fFreeSpace -= space;
400 fBoundsIsDirty = true; // this also invalidates fIsFinite
robertphillips@google.com466310d2013-12-03 16:43:54 +0000401 if (dirtyAfterEdit) {
402 fIsOval = false;
403 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000404
405 if (SkPath::kConic_Verb == verb) {
406 *fConicWeights.append() = weight;
407 }
408
robertphillips@google.com03087072013-10-02 16:42:21 +0000409 SkDEBUGCODE(this->validate();)
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000410 return ret;
411}
412
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000413uint32_t SkPathRef::genID() const {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000414 SkASSERT(!fEditorsAttached);
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000415 static const uint32_t kMask = (static_cast<int64_t>(1) << SkPath::kPathRefGenIDBitCnt) - 1;
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000416 if (!fGenerationID) {
417 if (0 == fPointCnt && 0 == fVerbCnt) {
418 fGenerationID = kEmptyGenID;
419 } else {
420 static int32_t gPathRefGenerationID;
421 // do a loop in case our global wraps around, as we never want to return a 0 or the
422 // empty ID
423 do {
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000424 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMask;
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000425 } while (fGenerationID <= kEmptyGenID);
426 }
427 }
428 return fGenerationID;
429}
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000430
robertphillips@google.com03087072013-10-02 16:42:21 +0000431#ifdef SK_DEBUG
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000432void SkPathRef::validate() const {
robertphillips@google.com03087072013-10-02 16:42:21 +0000433 this->INHERITED::validate();
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000434 SkASSERT(static_cast<ptrdiff_t>(fFreeSpace) >= 0);
435 SkASSERT(reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(fPoints) >= 0);
436 SkASSERT((NULL == fPoints) == (NULL == fVerbs));
437 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace));
438 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace));
439 SkASSERT(!(NULL == fPoints && fPointCnt));
440 SkASSERT(!(NULL == fVerbs && fVerbCnt));
441 SkASSERT(this->currSize() ==
442 fFreeSpace + sizeof(SkPoint) * fPointCnt + sizeof(uint8_t) * fVerbCnt);
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000443
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000444 if (!fBoundsIsDirty && !fBounds.isEmpty()) {
445 bool isFinite = true;
446 for (int i = 0; i < fPointCnt; ++i) {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000447 SkASSERT(!fPoints[i].isFinite() || (
448 fBounds.fLeft - fPoints[i].fX < SK_ScalarNearlyZero &&
robertphillips@google.com1cc385b2013-10-17 12:17:27 +0000449 fPoints[i].fX - fBounds.fRight < SK_ScalarNearlyZero &&
skia.committer@gmail.comf84ad8f2013-10-18 07:01:59 +0000450 fBounds.fTop - fPoints[i].fY < SK_ScalarNearlyZero &&
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000451 fPoints[i].fY - fBounds.fBottom < SK_ScalarNearlyZero));
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000452 if (!fPoints[i].isFinite()) {
453 isFinite = false;
454 }
455 }
456 SkASSERT(SkToBool(fIsFinite) == isFinite);
457 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000458
459#ifdef SK_DEBUG_PATH
460 uint32_t mask = 0;
461 for (int i = 0; i < fVerbCnt; ++i) {
462 switch (fVerbs[~i]) {
463 case SkPath::kMove_Verb:
464 break;
465 case SkPath::kLine_Verb:
466 mask |= SkPath::kLine_SegmentMask;
467 break;
468 case SkPath::kQuad_Verb:
469 mask |= SkPath::kQuad_SegmentMask;
470 break;
471 case SkPath::kConic_Verb:
472 mask |= SkPath::kConic_SegmentMask;
473 break;
474 case SkPath::kCubic_Verb:
475 mask |= SkPath::kCubic_SegmentMask;
476 break;
477 case SkPath::kClose_Verb:
478 break;
479 case SkPath::kDone_Verb:
480 SkDEBUGFAIL("Done verb shouldn't be recorded.");
481 break;
482 default:
483 SkDEBUGFAIL("Unknown Verb");
484 break;
485 }
486 }
487 SkASSERT(mask == fSegmentMask);
488#endif // SK_DEBUG_PATH
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000489}
robertphillips@google.com03087072013-10-02 16:42:21 +0000490#endif