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

Side by Side Diff: src/core/SkPathRef.cpp

Issue 25754002: Move makeSpace and resetToSize from SkPathRef.cpp to .h (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkPathRef.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBuffer.h" 8 #include "SkBuffer.h"
9 #include "SkPath.h" 9 #include "SkPath.h"
10 #include "SkPathRef.h" 10 #include "SkPathRef.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // a copy then presumably we intend to make a modification immediately after wards. 229 // a copy then presumably we intend to make a modification immediately after wards.
230 fGenerationID = ref.fGenerationID; 230 fGenerationID = ref.fGenerationID;
231 fBoundsIsDirty = ref.fBoundsIsDirty; 231 fBoundsIsDirty = ref.fBoundsIsDirty;
232 if (!fBoundsIsDirty) { 232 if (!fBoundsIsDirty) {
233 fBounds = ref.fBounds; 233 fBounds = ref.fBounds;
234 fIsFinite = ref.fIsFinite; 234 fIsFinite = ref.fIsFinite;
235 } 235 }
236 SkDEBUGCODE(this->validate();) 236 SkDEBUGCODE(this->validate();)
237 } 237 }
238 238
239 void SkPathRef::resetToSize(int verbCount, int pointCount, int conicCount,
240 int reserveVerbs, int reservePoints) {
241 SkDEBUGCODE(this->validate();)
242 fBoundsIsDirty = true; // this also invalidates fIsFinite
243 fGenerationID = 0;
244
245 size_t newSize = sizeof(uint8_t) * verbCount + sizeof(SkPoint) * pointCount;
246 size_t newReserve = sizeof(uint8_t) * reserveVerbs + sizeof(SkPoint) * reser vePoints;
247 size_t minSize = newSize + newReserve;
248
249 ptrdiff_t sizeDelta = this->currSize() - minSize;
250
251 if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) {
252 sk_free(fPoints);
253 fPoints = NULL;
254 fVerbs = NULL;
255 fFreeSpace = 0;
256 fVerbCnt = 0;
257 fPointCnt = 0;
258 this->makeSpace(minSize);
259 fVerbCnt = verbCount;
260 fPointCnt = pointCount;
261 fFreeSpace -= newSize;
262 } else {
263 fPointCnt = pointCount;
264 fVerbCnt = verbCount;
265 fFreeSpace = this->currSize() - minSize;
266 }
267 fConicWeights.setCount(conicCount);
268 SkDEBUGCODE(this->validate();)
269 }
270
271 SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb) { 239 SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb) {
272 SkDEBUGCODE(this->validate();) 240 SkDEBUGCODE(this->validate();)
273 int pCnt; 241 int pCnt;
274 switch (verb) { 242 switch (verb) {
275 case SkPath::kMove_Verb: 243 case SkPath::kMove_Verb:
276 pCnt = 1; 244 pCnt = 1;
277 break; 245 break;
278 case SkPath::kLine_Verb: 246 case SkPath::kLine_Verb:
279 pCnt = 1; 247 pCnt = 1;
280 break; 248 break;
(...skipping 20 matching lines...) Expand all
301 this->fVerbs[~fVerbCnt] = verb; 269 this->fVerbs[~fVerbCnt] = verb;
302 SkPoint* ret = fPoints + fPointCnt; 270 SkPoint* ret = fPoints + fPointCnt;
303 fVerbCnt += 1; 271 fVerbCnt += 1;
304 fPointCnt += pCnt; 272 fPointCnt += pCnt;
305 fFreeSpace -= space; 273 fFreeSpace -= space;
306 fBoundsIsDirty = true; // this also invalidates fIsFinite 274 fBoundsIsDirty = true; // this also invalidates fIsFinite
307 SkDEBUGCODE(this->validate();) 275 SkDEBUGCODE(this->validate();)
308 return ret; 276 return ret;
309 } 277 }
310 278
311 void SkPathRef::makeSpace(size_t size) {
312 SkDEBUGCODE(this->validate();)
313 ptrdiff_t growSize = size - fFreeSpace;
314 if (growSize <= 0) {
315 return;
316 }
317 size_t oldSize = this->currSize();
318 // round to next multiple of 8 bytes
319 growSize = (growSize + 7) & ~static_cast<size_t>(7);
320 // we always at least double the allocation
321 if (static_cast<size_t>(growSize) < oldSize) {
322 growSize = oldSize;
323 }
324 if (growSize < kMinSize) {
325 growSize = kMinSize;
326 }
327 size_t newSize = oldSize + growSize;
328 // Note that realloc could memcpy more than we need. It seems to be a win an yway. TODO:
329 // encapsulate this.
330 fPoints = reinterpret_cast<SkPoint*>(sk_realloc_throw(fPoints, newSize));
331 size_t oldVerbSize = fVerbCnt * sizeof(uint8_t);
332 void* newVerbsDst = reinterpret_cast<void*>(
333 reinterpret_cast<intptr_t>(fPoints) + newSize - oldV erbSize);
334 void* oldVerbsSrc = reinterpret_cast<void*>(
335 reinterpret_cast<intptr_t>(fPoints) + oldSize - oldV erbSize);
336 memmove(newVerbsDst, oldVerbsSrc, oldVerbSize);
337 fVerbs = reinterpret_cast<uint8_t*>(reinterpret_cast<intptr_t>(fPoints) + ne wSize);
338 fFreeSpace += growSize;
339 SkDEBUGCODE(this->validate();)
340 }
341
342 int32_t SkPathRef::genID() const { 279 int32_t SkPathRef::genID() const {
343 SkASSERT(!fEditorsAttached); 280 SkASSERT(!fEditorsAttached);
344 if (!fGenerationID) { 281 if (!fGenerationID) {
345 if (0 == fPointCnt && 0 == fVerbCnt) { 282 if (0 == fPointCnt && 0 == fVerbCnt) {
346 fGenerationID = kEmptyGenID; 283 fGenerationID = kEmptyGenID;
347 } else { 284 } else {
348 static int32_t gPathRefGenerationID; 285 static int32_t gPathRefGenerationID;
349 // do a loop in case our global wraps around, as we never want to re turn a 0 or the 286 // do a loop in case our global wraps around, as we never want to re turn a 0 or the
350 // empty ID 287 // empty ID
351 do { 288 do {
(...skipping 25 matching lines...) Expand all
377 fPoints[i].fY >= fBounds.fTop && fPoints[i].fY <= fBound s.fBottom); 314 fPoints[i].fY >= fBounds.fTop && fPoints[i].fY <= fBound s.fBottom);
378 if (!fPoints[i].isFinite()) { 315 if (!fPoints[i].isFinite()) {
379 isFinite = false; 316 isFinite = false;
380 } 317 }
381 } 318 }
382 SkASSERT(SkToBool(fIsFinite) == isFinite); 319 SkASSERT(SkToBool(fIsFinite) == isFinite);
383 } 320 }
384 #endif 321 #endif
385 } 322 }
386 #endif 323 #endif
OLDNEW
« no previous file with comments | « include/core/SkPathRef.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698