diff options
author | mtklein <mtklein@chromium.org> | 2016-01-04 18:40:07 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-04 18:40:07 -0800 |
commit | 12204d90337656542a42fa0fcccb7bec13af0cce (patch) | |
tree | c9840ce6af3ecfd84d947e91755c1fa6baeaf530 /src | |
parent | e735f163035c4df79024d3bfee8adbe4e4409e1e (diff) |
df generation: single allocation with calloc
The dfStorage DFData allocation can never fit in its stack space: 5px padding on each side always implies at least a 10x10 DFData allocation, but the stack space only fits 64 DFData.
So we've always been spilling to the heap.
If we're going to spill to the heap, we might as well allocate/free all our temporary memory in one block, and since we want it zeroed, might as well calloc.
So in practice this replaces 1-2 malloc, 1-2 free, and 2 bzeros with 1 calloc and 1 free.
BUG=skia:4729
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1544983004
Review URL: https://codereview.chromium.org/1544983004
Diffstat (limited to 'src')
-rwxr-xr-x | src/core/SkDistanceFieldGen.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/core/SkDistanceFieldGen.cpp b/src/core/SkDistanceFieldGen.cpp index 30354e09f8..4f4de56a46 100755 --- a/src/core/SkDistanceFieldGen.cpp +++ b/src/core/SkDistanceFieldGen.cpp @@ -343,15 +343,10 @@ static bool generate_distance_field_from_image(unsigned char* distanceField, int dataWidth = width + 2*pad; int dataHeight = height + 2*pad; - // create temp data - size_t dataSize = dataWidth*dataHeight*sizeof(DFData); - SkAutoSMalloc<1024> dfStorage(dataSize); - DFData* dataPtr = (DFData*) dfStorage.get(); - sk_bzero(dataPtr, dataSize); - - SkAutoSMalloc<1024> edgeStorage(dataWidth*dataHeight*sizeof(char)); - unsigned char* edgePtr = (unsigned char*) edgeStorage.get(); - sk_bzero(edgePtr, dataWidth*dataHeight*sizeof(char)); + // create zeroed temp edge+DFData storage + SkAutoFree storage(sk_calloc_throw(dataWidth*dataHeight*(1 + sizeof(DFData)))); + unsigned char* edgePtr = (unsigned char*)storage.get(); + DFData* dataPtr = (DFData*)(edgePtr + dataWidth*dataHeight); // copy glyph into distance field storage init_glyph_data(dataPtr, edgePtr, copyPtr, |