blob: 64f6fb86da465b300a727029c597d2212f08487d [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"
mtklein78358bf2014-06-02 08:44:27 -07009#include "SkLazyPtr.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.org709ca752014-01-24 22:38:39 +000031
mtklein78358bf2014-06-02 08:44:27 -070032SkPathRef* SkPathRef::CreateEmptyImpl() {
mtklein0b544ae2014-07-08 19:37:47 -070033 return SkNEW(SkPathRef);
commit-bot@chromium.org1f81fd62013-10-23 14:44:08 +000034}
35
36SkPathRef* SkPathRef::CreateEmpty() {
mtklein78358bf2014-06-02 08:44:27 -070037 SK_DECLARE_STATIC_LAZY_PTR(SkPathRef, empty, CreateEmptyImpl);
38 return SkRef(empty.get());
commit-bot@chromium.org1f81fd62013-10-23 14:44:08 +000039}
40
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000041void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
42 const SkPathRef& src,
43 const SkMatrix& matrix) {
robertphillips@google.com03087072013-10-02 16:42:21 +000044 SkDEBUGCODE(src.validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000045 if (matrix.isIdentity()) {
46 if (*dst != &src) {
47 src.ref();
48 dst->reset(const_cast<SkPathRef*>(&src));
robertphillips@google.com03087072013-10-02 16:42:21 +000049 SkDEBUGCODE((*dst)->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000050 }
51 return;
52 }
53
robertphillips@google.comb06e88d2013-12-03 17:15:36 +000054 if (!(*dst)->unique()) {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000055 dst->reset(SkNEW(SkPathRef));
robertphillips@google.comb06e88d2013-12-03 17:15:36 +000056 }
57
58 if (*dst != &src) {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000059 (*dst)->resetToSize(src.fVerbCnt, src.fPointCnt, src.fConicWeights.count());
60 memcpy((*dst)->verbsMemWritable(), src.verbsMemBegin(), src.fVerbCnt * sizeof(uint8_t));
61 (*dst)->fConicWeights = src.fConicWeights;
62 }
63
robertphillips@google.comb06e88d2013-12-03 17:15:36 +000064 SkASSERT((*dst)->countPoints() == src.countPoints());
65 SkASSERT((*dst)->countVerbs() == src.countVerbs());
66 SkASSERT((*dst)->fConicWeights.count() == src.fConicWeights.count());
67
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000068 // Need to check this here in case (&src == dst)
69 bool canXformBounds = !src.fBoundsIsDirty && matrix.rectStaysRect() && src.countPoints() > 1;
70
71 matrix.mapPoints((*dst)->fPoints, src.points(), src.fPointCnt);
72
73 /*
74 * Here we optimize the bounds computation, by noting if the bounds are
75 * already known, and if so, we just transform those as well and mark
76 * them as "known", rather than force the transformed path to have to
77 * recompute them.
78 *
79 * Special gotchas if the path is effectively empty (<= 1 point) or
80 * if it is non-finite. In those cases bounds need to stay empty,
81 * regardless of the matrix.
82 */
83 if (canXformBounds) {
84 (*dst)->fBoundsIsDirty = false;
85 if (src.fIsFinite) {
mtklein0b544ae2014-07-08 19:37:47 -070086 matrix.mapRect((*dst)->fBounds.get(), src.fBounds);
87 if (!((*dst)->fIsFinite = (*dst)->fBounds->isFinite())) {
88 (*dst)->fBounds->setEmpty();
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000089 }
90 } else {
91 (*dst)->fIsFinite = false;
mtklein0b544ae2014-07-08 19:37:47 -070092 (*dst)->fBounds->setEmpty();
robertphillips@google.com3e292aa2013-09-27 17:48:49 +000093 }
94 } else {
95 (*dst)->fBoundsIsDirty = true;
96 }
97
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +000098 (*dst)->fSegmentMask = src.fSegmentMask;
99
robertphillips@google.com466310d2013-12-03 16:43:54 +0000100 // It's an oval only if it stays a rect.
101 (*dst)->fIsOval = src.fIsOval && matrix.rectStaysRect();
102
robertphillips@google.com03087072013-10-02 16:42:21 +0000103 SkDEBUGCODE((*dst)->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000104}
105
commit-bot@chromium.orgfed2ab62014-01-23 15:16:05 +0000106SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer) {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000107 SkPathRef* ref = SkNEW(SkPathRef);
robertphillips@google.com466310d2013-12-03 16:43:54 +0000108 bool isOval;
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000109 uint8_t segmentMask;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000110
111 int32_t packed;
112 if (!buffer->readS32(&packed)) {
113 SkDELETE(ref);
114 return NULL;
115 }
116
117 ref->fIsFinite = (packed >> kIsFinite_SerializationShift) & 1;
commit-bot@chromium.orgfed2ab62014-01-23 15:16:05 +0000118 segmentMask = (packed >> kSegmentMask_SerializationShift) & 0xF;
119 isOval = (packed >> kIsOval_SerializationShift) & 1;
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000120
commit-bot@chromium.org8f457e32013-11-08 19:22:57 +0000121 int32_t verbCount, pointCount, conicCount;
122 if (!buffer->readU32(&(ref->fGenerationID)) ||
123 !buffer->readS32(&verbCount) ||
124 !buffer->readS32(&pointCount) ||
125 !buffer->readS32(&conicCount)) {
126 SkDELETE(ref);
127 return NULL;
128 }
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000129
commit-bot@chromium.org8f457e32013-11-08 19:22:57 +0000130 ref->resetToSize(verbCount, pointCount, conicCount);
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000131 SkASSERT(verbCount == ref->countVerbs());
132 SkASSERT(pointCount == ref->countPoints());
133 SkASSERT(conicCount == ref->fConicWeights.count());
commit-bot@chromium.org8f457e32013-11-08 19:22:57 +0000134
135 if (!buffer->read(ref->verbsMemWritable(), verbCount * sizeof(uint8_t)) ||
136 !buffer->read(ref->fPoints, pointCount * sizeof(SkPoint)) ||
137 !buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar)) ||
138 !buffer->read(&ref->fBounds, sizeof(SkRect))) {
139 SkDELETE(ref);
140 return NULL;
141 }
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000142 ref->fBoundsIsDirty = false;
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000143
144 // resetToSize clears fSegmentMask and fIsOval
145 ref->fSegmentMask = segmentMask;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000146 ref->fIsOval = isOval;
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000147 return ref;
148}
149
150void SkPathRef::Rewind(SkAutoTUnref<SkPathRef>* pathRef) {
151 if ((*pathRef)->unique()) {
robertphillips@google.com03087072013-10-02 16:42:21 +0000152 SkDEBUGCODE((*pathRef)->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000153 (*pathRef)->fBoundsIsDirty = true; // this also invalidates fIsFinite
154 (*pathRef)->fVerbCnt = 0;
155 (*pathRef)->fPointCnt = 0;
156 (*pathRef)->fFreeSpace = (*pathRef)->currSize();
157 (*pathRef)->fGenerationID = 0;
158 (*pathRef)->fConicWeights.rewind();
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000159 (*pathRef)->fSegmentMask = 0;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000160 (*pathRef)->fIsOval = false;
robertphillips@google.com03087072013-10-02 16:42:21 +0000161 SkDEBUGCODE((*pathRef)->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000162 } else {
163 int oldVCnt = (*pathRef)->countVerbs();
164 int oldPCnt = (*pathRef)->countPoints();
165 pathRef->reset(SkNEW(SkPathRef));
166 (*pathRef)->resetToSize(0, 0, 0, oldVCnt, oldPCnt);
167 }
168}
169
170bool SkPathRef::operator== (const SkPathRef& ref) const {
robertphillips@google.com03087072013-10-02 16:42:21 +0000171 SkDEBUGCODE(this->validate();)
172 SkDEBUGCODE(ref.validate();)
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000173
174 // We explicitly check fSegmentMask as a quick-reject. We could skip it,
175 // since it is only a cache of info in the fVerbs, but its a fast way to
176 // notice a difference
177 if (fSegmentMask != ref.fSegmentMask) {
178 return false;
179 }
180
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000181 bool genIDMatch = fGenerationID && fGenerationID == ref.fGenerationID;
182#ifdef SK_RELEASE
183 if (genIDMatch) {
184 return true;
185 }
186#endif
187 if (fPointCnt != ref.fPointCnt ||
188 fVerbCnt != ref.fVerbCnt) {
189 SkASSERT(!genIDMatch);
190 return false;
191 }
192 if (0 != memcmp(this->verbsMemBegin(),
193 ref.verbsMemBegin(),
194 ref.fVerbCnt * sizeof(uint8_t))) {
195 SkASSERT(!genIDMatch);
196 return false;
197 }
198 if (0 != memcmp(this->points(),
199 ref.points(),
200 ref.fPointCnt * sizeof(SkPoint))) {
201 SkASSERT(!genIDMatch);
202 return false;
203 }
204 if (fConicWeights != ref.fConicWeights) {
205 SkASSERT(!genIDMatch);
206 return false;
207 }
208 // We've done the work to determine that these are equal. If either has a zero genID, copy
209 // the other's. If both are 0 then genID() will compute the next ID.
210 if (0 == fGenerationID) {
211 fGenerationID = ref.genID();
212 } else if (0 == ref.fGenerationID) {
213 ref.fGenerationID = this->genID();
214 }
215 return true;
216}
217
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000218void SkPathRef::writeToBuffer(SkWBuffer* buffer) const {
robertphillips@google.com03087072013-10-02 16:42:21 +0000219 SkDEBUGCODE(this->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000220 SkDEBUGCODE(size_t beforePos = buffer->pos();)
221
222 // Call getBounds() to ensure (as a side-effect) that fBounds
223 // and fIsFinite are computed.
224 const SkRect& bounds = this->getBounds();
225
robertphillips@google.com466310d2013-12-03 16:43:54 +0000226 int32_t packed = ((fIsFinite & 1) << kIsFinite_SerializationShift) |
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000227 ((fIsOval & 1) << kIsOval_SerializationShift) |
228 (fSegmentMask << kSegmentMask_SerializationShift);
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000229 buffer->write32(packed);
230
231 // TODO: write gen ID here. Problem: We don't know if we're cross process or not from
232 // SkWBuffer. Until this is fixed we write 0.
233 buffer->write32(0);
234 buffer->write32(fVerbCnt);
235 buffer->write32(fPointCnt);
236 buffer->write32(fConicWeights.count());
237 buffer->write(verbsMemBegin(), fVerbCnt * sizeof(uint8_t));
238 buffer->write(fPoints, fPointCnt * sizeof(SkPoint));
239 buffer->write(fConicWeights.begin(), fConicWeights.bytes());
240 buffer->write(&bounds, sizeof(bounds));
241
242 SkASSERT(buffer->pos() - beforePos == (size_t) this->writeSize());
243}
244
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000245uint32_t SkPathRef::writeSize() const {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000246 return uint32_t(5 * sizeof(uint32_t) +
247 fVerbCnt * sizeof(uint8_t) +
248 fPointCnt * sizeof(SkPoint) +
249 fConicWeights.bytes() +
250 sizeof(SkRect));
251}
252
skia.committer@gmail.com50df4d02013-09-28 07:01:33 +0000253void SkPathRef::copy(const SkPathRef& ref,
254 int additionalReserveVerbs,
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000255 int additionalReservePoints) {
robertphillips@google.com03087072013-10-02 16:42:21 +0000256 SkDEBUGCODE(this->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000257 this->resetToSize(ref.fVerbCnt, ref.fPointCnt, ref.fConicWeights.count(),
258 additionalReserveVerbs, additionalReservePoints);
259 memcpy(this->verbsMemWritable(), ref.verbsMemBegin(), ref.fVerbCnt * sizeof(uint8_t));
260 memcpy(this->fPoints, ref.fPoints, ref.fPointCnt * sizeof(SkPoint));
261 fConicWeights = ref.fConicWeights;
262 // We could call genID() here to force a real ID (instead of 0). However, if we're making
263 // a copy then presumably we intend to make a modification immediately afterwards.
264 fGenerationID = ref.fGenerationID;
265 fBoundsIsDirty = ref.fBoundsIsDirty;
266 if (!fBoundsIsDirty) {
267 fBounds = ref.fBounds;
268 fIsFinite = ref.fIsFinite;
269 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000270 fSegmentMask = ref.fSegmentMask;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000271 fIsOval = ref.fIsOval;
robertphillips@google.com03087072013-10-02 16:42:21 +0000272 SkDEBUGCODE(this->validate();)
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000273}
274
skia.committer@gmail.com96f5fa02013-12-16 07:01:40 +0000275SkPoint* SkPathRef::growForRepeatedVerb(int /*SkPath::Verb*/ verb,
276 int numVbs,
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000277 SkScalar** weights) {
278 // This value is just made-up for now. When count is 4, calling memset was much
279 // slower than just writing the loop. This seems odd, and hopefully in the
280 // future this will appear to have been a fluke...
281 static const unsigned int kMIN_COUNT_FOR_MEMSET_TO_BE_FAST = 16;
282
283 SkDEBUGCODE(this->validate();)
284 int pCnt;
285 bool dirtyAfterEdit = true;
286 switch (verb) {
287 case SkPath::kMove_Verb:
288 pCnt = numVbs;
289 dirtyAfterEdit = false;
290 break;
291 case SkPath::kLine_Verb:
292 fSegmentMask |= SkPath::kLine_SegmentMask;
293 pCnt = numVbs;
294 break;
295 case SkPath::kQuad_Verb:
296 fSegmentMask |= SkPath::kQuad_SegmentMask;
297 pCnt = 2 * numVbs;
298 break;
299 case SkPath::kConic_Verb:
300 fSegmentMask |= SkPath::kConic_SegmentMask;
301 pCnt = 2 * numVbs;
302 break;
303 case SkPath::kCubic_Verb:
304 fSegmentMask |= SkPath::kCubic_SegmentMask;
305 pCnt = 3 * numVbs;
306 break;
307 case SkPath::kClose_Verb:
308 SkDEBUGFAIL("growForRepeatedVerb called for kClose_Verb");
309 pCnt = 0;
310 dirtyAfterEdit = false;
311 break;
312 case SkPath::kDone_Verb:
313 SkDEBUGFAIL("growForRepeatedVerb called for kDone");
314 // fall through
315 default:
316 SkDEBUGFAIL("default should not be reached");
317 pCnt = 0;
318 dirtyAfterEdit = false;
319 }
320
321 size_t space = numVbs * sizeof(uint8_t) + pCnt * sizeof (SkPoint);
322 this->makeSpace(space);
323
324 SkPoint* ret = fPoints + fPointCnt;
325 uint8_t* vb = fVerbs - fVerbCnt;
326
327 // cast to unsigned, so if kMIN_COUNT_FOR_MEMSET_TO_BE_FAST is defined to
328 // be 0, the compiler will remove the test/branch entirely.
329 if ((unsigned)numVbs >= kMIN_COUNT_FOR_MEMSET_TO_BE_FAST) {
330 memset(vb - numVbs, verb, numVbs);
331 } else {
332 for (int i = 0; i < numVbs; ++i) {
333 vb[~i] = verb;
334 }
335 }
336
337 fVerbCnt += numVbs;
338 fPointCnt += pCnt;
339 fFreeSpace -= space;
340 fBoundsIsDirty = true; // this also invalidates fIsFinite
341 if (dirtyAfterEdit) {
342 fIsOval = false;
343 }
344
345 if (SkPath::kConic_Verb == verb) {
bsalomon49f085d2014-09-05 13:34:00 -0700346 SkASSERT(weights);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000347 *weights = fConicWeights.append(numVbs);
348 }
349
350 SkDEBUGCODE(this->validate();)
351 return ret;
352}
353
354SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb, SkScalar weight) {
robertphillips@google.com03087072013-10-02 16:42:21 +0000355 SkDEBUGCODE(this->validate();)
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000356 int pCnt;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000357 bool dirtyAfterEdit = true;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000358 switch (verb) {
359 case SkPath::kMove_Verb:
360 pCnt = 1;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000361 dirtyAfterEdit = false;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000362 break;
363 case SkPath::kLine_Verb:
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000364 fSegmentMask |= SkPath::kLine_SegmentMask;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000365 pCnt = 1;
366 break;
367 case SkPath::kQuad_Verb:
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000368 fSegmentMask |= SkPath::kQuad_SegmentMask;
369 pCnt = 2;
370 break;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000371 case SkPath::kConic_Verb:
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000372 fSegmentMask |= SkPath::kConic_SegmentMask;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000373 pCnt = 2;
374 break;
375 case SkPath::kCubic_Verb:
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000376 fSegmentMask |= SkPath::kCubic_SegmentMask;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000377 pCnt = 3;
378 break;
379 case SkPath::kClose_Verb:
380 pCnt = 0;
robertphillips@google.com466310d2013-12-03 16:43:54 +0000381 dirtyAfterEdit = false;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000382 break;
383 case SkPath::kDone_Verb:
384 SkDEBUGFAIL("growForVerb called for kDone");
385 // fall through
386 default:
387 SkDEBUGFAIL("default is not reached");
robertphillips@google.com466310d2013-12-03 16:43:54 +0000388 dirtyAfterEdit = false;
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000389 pCnt = 0;
390 }
391 size_t space = sizeof(uint8_t) + pCnt * sizeof (SkPoint);
392 this->makeSpace(space);
393 this->fVerbs[~fVerbCnt] = verb;
394 SkPoint* ret = fPoints + fPointCnt;
395 fVerbCnt += 1;
396 fPointCnt += pCnt;
397 fFreeSpace -= space;
398 fBoundsIsDirty = true; // this also invalidates fIsFinite
robertphillips@google.com466310d2013-12-03 16:43:54 +0000399 if (dirtyAfterEdit) {
400 fIsOval = false;
401 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000402
403 if (SkPath::kConic_Verb == verb) {
404 *fConicWeights.append() = weight;
405 }
406
robertphillips@google.com03087072013-10-02 16:42:21 +0000407 SkDEBUGCODE(this->validate();)
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000408 return ret;
409}
410
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000411uint32_t SkPathRef::genID() const {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000412 SkASSERT(!fEditorsAttached);
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000413 static const uint32_t kMask = (static_cast<int64_t>(1) << SkPath::kPathRefGenIDBitCnt) - 1;
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000414 if (!fGenerationID) {
415 if (0 == fPointCnt && 0 == fVerbCnt) {
416 fGenerationID = kEmptyGenID;
417 } else {
418 static int32_t gPathRefGenerationID;
419 // do a loop in case our global wraps around, as we never want to return a 0 or the
420 // empty ID
421 do {
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000422 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMask;
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000423 } while (fGenerationID <= kEmptyGenID);
424 }
425 }
426 return fGenerationID;
427}
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000428
robertphillips@google.com03087072013-10-02 16:42:21 +0000429#ifdef SK_DEBUG
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000430void SkPathRef::validate() const {
robertphillips@google.com03087072013-10-02 16:42:21 +0000431 this->INHERITED::validate();
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000432 SkASSERT(static_cast<ptrdiff_t>(fFreeSpace) >= 0);
433 SkASSERT(reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(fPoints) >= 0);
434 SkASSERT((NULL == fPoints) == (NULL == fVerbs));
435 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace));
436 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace));
437 SkASSERT(!(NULL == fPoints && fPointCnt));
438 SkASSERT(!(NULL == fVerbs && fVerbCnt));
439 SkASSERT(this->currSize() ==
440 fFreeSpace + sizeof(SkPoint) * fPointCnt + sizeof(uint8_t) * fVerbCnt);
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000441
mtklein0b544ae2014-07-08 19:37:47 -0700442 if (!fBoundsIsDirty && !fBounds->isEmpty()) {
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000443 bool isFinite = true;
444 for (int i = 0; i < fPointCnt; ++i) {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000445 SkASSERT(!fPoints[i].isFinite() || (
mtklein0b544ae2014-07-08 19:37:47 -0700446 fBounds->fLeft - fPoints[i].fX < SK_ScalarNearlyZero &&
447 fPoints[i].fX - fBounds->fRight < SK_ScalarNearlyZero &&
448 fBounds->fTop - fPoints[i].fY < SK_ScalarNearlyZero &&
449 fPoints[i].fY - fBounds->fBottom < SK_ScalarNearlyZero));
robertphillips@google.com3e292aa2013-09-27 17:48:49 +0000450 if (!fPoints[i].isFinite()) {
451 isFinite = false;
452 }
453 }
454 SkASSERT(SkToBool(fIsFinite) == isFinite);
455 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +0000456
457#ifdef SK_DEBUG_PATH
458 uint32_t mask = 0;
459 for (int i = 0; i < fVerbCnt; ++i) {
460 switch (fVerbs[~i]) {
461 case SkPath::kMove_Verb:
462 break;
463 case SkPath::kLine_Verb:
464 mask |= SkPath::kLine_SegmentMask;
465 break;
466 case SkPath::kQuad_Verb:
467 mask |= SkPath::kQuad_SegmentMask;
468 break;
469 case SkPath::kConic_Verb:
470 mask |= SkPath::kConic_SegmentMask;
471 break;
472 case SkPath::kCubic_Verb:
473 mask |= SkPath::kCubic_SegmentMask;
474 break;
475 case SkPath::kClose_Verb:
476 break;
477 case SkPath::kDone_Verb:
478 SkDEBUGFAIL("Done verb shouldn't be recorded.");
479 break;
480 default:
481 SkDEBUGFAIL("Unknown Verb");
482 break;
483 }
484 }
485 SkASSERT(mask == fSegmentMask);
486#endif // SK_DEBUG_PATH
robertphillips@google.comca0c8382013-09-26 12:18:23 +0000487}
robertphillips@google.com03087072013-10-02 16:42:21 +0000488#endif