OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef SkPathRef_DEFINED | 9 #ifndef SkPathRef_DEFINED |
10 #define SkPathRef_DEFINED | 10 #define SkPathRef_DEFINED |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 void incReserve(int additionalVerbs, int additionalPoints) { | 276 void incReserve(int additionalVerbs, int additionalPoints) { |
277 SkDEBUGCODE(this->validate();) | 277 SkDEBUGCODE(this->validate();) |
278 size_t space = additionalVerbs * sizeof(uint8_t) + additionalPoints * si
zeof (SkPoint); | 278 size_t space = additionalVerbs * sizeof(uint8_t) + additionalPoints * si
zeof (SkPoint); |
279 this->makeSpace(space); | 279 this->makeSpace(space); |
280 SkDEBUGCODE(this->validate();) | 280 SkDEBUGCODE(this->validate();) |
281 } | 281 } |
282 | 282 |
283 /** Resets the path ref with verbCount verbs and pointCount points, all unin
itialized. Also | 283 /** Resets the path ref with verbCount verbs and pointCount points, all unin
itialized. Also |
284 * allocates space for reserveVerb additional verbs and reservePoints addit
ional points.*/ | 284 * allocates space for reserveVerb additional verbs and reservePoints addit
ional points.*/ |
285 void resetToSize(int verbCount, int pointCount, int conicCount, | 285 void resetToSize(int verbCount, int pointCount, int conicCount, |
286 int reserveVerbs = 0, int reservePoints = 0); | 286 int reserveVerbs = 0, int reservePoints = 0) { |
| 287 SkDEBUGCODE(this->validate();) |
| 288 fBoundsIsDirty = true; // this also invalidates fIsFinite |
| 289 fGenerationID = 0; |
| 290 |
| 291 size_t newSize = sizeof(uint8_t) * verbCount + sizeof(SkPoint) * pointCo
unt; |
| 292 size_t newReserve = sizeof(uint8_t) * reserveVerbs + sizeof(SkPoint) * r
eservePoints; |
| 293 size_t minSize = newSize + newReserve; |
| 294 |
| 295 ptrdiff_t sizeDelta = this->currSize() - minSize; |
| 296 |
| 297 if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) { |
| 298 sk_free(fPoints); |
| 299 fPoints = NULL; |
| 300 fVerbs = NULL; |
| 301 fFreeSpace = 0; |
| 302 fVerbCnt = 0; |
| 303 fPointCnt = 0; |
| 304 this->makeSpace(minSize); |
| 305 fVerbCnt = verbCount; |
| 306 fPointCnt = pointCount; |
| 307 fFreeSpace -= newSize; |
| 308 } else { |
| 309 fPointCnt = pointCount; |
| 310 fVerbCnt = verbCount; |
| 311 fFreeSpace = this->currSize() - minSize; |
| 312 } |
| 313 fConicWeights.setCount(conicCount); |
| 314 SkDEBUGCODE(this->validate();) |
| 315 } |
287 | 316 |
288 /** | 317 /** |
289 * Increases the verb count by newVerbs and the point count be newPoints. Ne
w verbs and points | 318 * Increases the verb count by newVerbs and the point count be newPoints. Ne
w verbs and points |
290 * are uninitialized. | 319 * are uninitialized. |
291 */ | 320 */ |
292 void grow(int newVerbs, int newPoints) { | 321 void grow(int newVerbs, int newPoints) { |
293 SkDEBUGCODE(this->validate();) | 322 SkDEBUGCODE(this->validate();) |
294 size_t space = newVerbs * sizeof(uint8_t) + newPoints * sizeof (SkPoint)
; | 323 size_t space = newVerbs * sizeof(uint8_t) + newPoints * sizeof (SkPoint)
; |
295 this->makeSpace(space); | 324 this->makeSpace(space); |
296 fVerbCnt += newVerbs; | 325 fVerbCnt += newVerbs; |
297 fPointCnt += newPoints; | 326 fPointCnt += newPoints; |
298 fFreeSpace -= space; | 327 fFreeSpace -= space; |
299 fBoundsIsDirty = true; // this also invalidates fIsFinite | 328 fBoundsIsDirty = true; // this also invalidates fIsFinite |
300 SkDEBUGCODE(this->validate();) | 329 SkDEBUGCODE(this->validate();) |
301 } | 330 } |
302 | 331 |
303 /** | 332 /** |
304 * Increases the verb count 1, records the new verb, and creates room for th
e requisite number | 333 * Increases the verb count 1, records the new verb, and creates room for th
e requisite number |
305 * of additional points. A pointer to the first point is returned. Any new p
oints are | 334 * of additional points. A pointer to the first point is returned. Any new p
oints are |
306 * uninitialized. | 335 * uninitialized. |
307 */ | 336 */ |
308 SkPoint* growForVerb(int /*SkPath::Verb*/ verb); | 337 SkPoint* growForVerb(int /*SkPath::Verb*/ verb); |
309 | 338 |
310 /** | 339 /** |
311 * Ensures that the free space available in the path ref is >= size. The ver
b and point counts | 340 * Ensures that the free space available in the path ref is >= size. The ver
b and point counts |
312 * are not changed. | 341 * are not changed. |
313 */ | 342 */ |
314 void makeSpace(size_t size); | 343 void makeSpace(size_t size) { |
| 344 SkDEBUGCODE(this->validate();) |
| 345 ptrdiff_t growSize = size - fFreeSpace; |
| 346 if (growSize <= 0) { |
| 347 return; |
| 348 } |
| 349 size_t oldSize = this->currSize(); |
| 350 // round to next multiple of 8 bytes |
| 351 growSize = (growSize + 7) & ~static_cast<size_t>(7); |
| 352 // we always at least double the allocation |
| 353 if (static_cast<size_t>(growSize) < oldSize) { |
| 354 growSize = oldSize; |
| 355 } |
| 356 if (growSize < kMinSize) { |
| 357 growSize = kMinSize; |
| 358 } |
| 359 size_t newSize = oldSize + growSize; |
| 360 // Note that realloc could memcpy more than we need. It seems to be a wi
n anyway. TODO: |
| 361 // encapsulate this. |
| 362 fPoints = reinterpret_cast<SkPoint*>(sk_realloc_throw(fPoints, newSize))
; |
| 363 size_t oldVerbSize = fVerbCnt * sizeof(uint8_t); |
| 364 void* newVerbsDst = reinterpret_cast<void*>( |
| 365 reinterpret_cast<intptr_t>(fPoints) + newSize -
oldVerbSize); |
| 366 void* oldVerbsSrc = reinterpret_cast<void*>( |
| 367 reinterpret_cast<intptr_t>(fPoints) + oldSize -
oldVerbSize); |
| 368 memmove(newVerbsDst, oldVerbsSrc, oldVerbSize); |
| 369 fVerbs = reinterpret_cast<uint8_t*>(reinterpret_cast<intptr_t>(fPoints)
+ newSize); |
| 370 fFreeSpace += growSize; |
| 371 SkDEBUGCODE(this->validate();) |
| 372 } |
315 | 373 |
316 /** | 374 /** |
317 * Private, non-const-ptr version of the public function verbsMemBegin(). | 375 * Private, non-const-ptr version of the public function verbsMemBegin(). |
318 */ | 376 */ |
319 uint8_t* verbsMemWritable() { | 377 uint8_t* verbsMemWritable() { |
320 SkDEBUGCODE(this->validate();) | 378 SkDEBUGCODE(this->validate();) |
321 return fVerbs - fVerbCnt; | 379 return fVerbs - fVerbCnt; |
322 } | 380 } |
323 | 381 |
324 /** | 382 /** |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 enum { | 414 enum { |
357 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer
o verbs. | 415 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer
o verbs. |
358 }; | 416 }; |
359 mutable int32_t fGenerationID; | 417 mutable int32_t fGenerationID; |
360 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use
at any time. | 418 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use
at any time. |
361 | 419 |
362 typedef SkRefCnt INHERITED; | 420 typedef SkRefCnt INHERITED; |
363 }; | 421 }; |
364 | 422 |
365 #endif | 423 #endif |
OLD | NEW |