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

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

Issue 1544983004: df generation: single allocation with calloc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: swap Created 4 years, 11 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 | « no previous file | 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 2014 Google Inc. 2 * Copyright 2014 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 "SkDistanceFieldGen.h" 8 #include "SkDistanceFieldGen.h"
9 #include "SkPoint.h" 9 #include "SkPoint.h"
10 10
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 SkASSERT(copyPtr); 336 SkASSERT(copyPtr);
337 337
338 // we expand our temp data by one more on each side to simplify 338 // we expand our temp data by one more on each side to simplify
339 // the scanning code -- will always be treated as infinitely far away 339 // the scanning code -- will always be treated as infinitely far away
340 int pad = SK_DistanceFieldPad + 1; 340 int pad = SK_DistanceFieldPad + 1;
341 341
342 // set params for distance field data 342 // set params for distance field data
343 int dataWidth = width + 2*pad; 343 int dataWidth = width + 2*pad;
344 int dataHeight = height + 2*pad; 344 int dataHeight = height + 2*pad;
345 345
346 // create temp data 346 // create zeroed temp DFData+edge storage
347 size_t dataSize = dataWidth*dataHeight*sizeof(DFData); 347 SkAutoFree storage(sk_calloc_throw(dataWidth*dataHeight*(sizeof(DFData) + 1) ));
348 SkAutoSMalloc<1024> dfStorage(dataSize); 348 DFData* dataPtr = (DFData*)storage.get();
349 DFData* dataPtr = (DFData*) dfStorage.get(); 349 unsigned char* edgePtr = (unsigned char*)storage.get() + dataWidth*dataHeigh t*sizeof(DFData);
350 sk_bzero(dataPtr, dataSize);
351
352 SkAutoSMalloc<1024> edgeStorage(dataWidth*dataHeight*sizeof(char));
353 unsigned char* edgePtr = (unsigned char*) edgeStorage.get();
354 sk_bzero(edgePtr, dataWidth*dataHeight*sizeof(char));
355 350
356 // copy glyph into distance field storage 351 // copy glyph into distance field storage
357 init_glyph_data(dataPtr, edgePtr, copyPtr, 352 init_glyph_data(dataPtr, edgePtr, copyPtr,
358 dataWidth, dataHeight, 353 dataWidth, dataHeight,
359 width+2, height+2, SK_DistanceFieldPad); 354 width+2, height+2, SK_DistanceFieldPad);
360 355
361 // create initial distance data, particularly at edges 356 // create initial distance data, particularly at edges
362 init_distances(dataPtr, edgePtr, dataWidth, dataHeight); 357 init_distances(dataPtr, edgePtr, dataWidth, dataHeight);
363 358
364 // now perform Euclidean distance transform to propagate distances 359 // now perform Euclidean distance transform to propagate distances
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 *currDestPtr++ = (mask & (1 << i)) ? 0xff : 0; 507 *currDestPtr++ = (mask & (1 << i)) ? 0xff : 0;
513 } 508 }
514 } 509 }
515 currSrcScanLine += rowBytes; 510 currSrcScanLine += rowBytes;
516 *currDestPtr++ = 0; 511 *currDestPtr++ = 0;
517 } 512 }
518 sk_bzero(currDestPtr, (width+2)*sizeof(char)); 513 sk_bzero(currDestPtr, (width+2)*sizeof(char));
519 514
520 return generate_distance_field_from_image(distanceField, copyPtr, width, hei ght); 515 return generate_distance_field_from_image(distanceField, copyPtr, width, hei ght);
521 } 516 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698