diff options
author | Mike Reed <reed@google.com> | 2018-01-22 13:34:53 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-22 20:50:47 +0000 |
commit | baafcdcd543571238654df87f060a9f5be0eb570 (patch) | |
tree | a66b87861c24de59e2148ad35ee8dcb763291ffb /src/core/SkMask.cpp | |
parent | ec97ac9be2b1d12620337da2b99c95e214170ded (diff) |
move zero-init to sk_malloc for masks
Bug: skia:
Change-Id: I75d557068bdcd9e9f7e380e4fa447f9d83dd1554
Reviewed-on: https://skia-review.googlesource.com/98200
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core/SkMask.cpp')
-rw-r--r-- | src/core/SkMask.cpp | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/src/core/SkMask.cpp b/src/core/SkMask.cpp index 7340d70f1a..ea196f9e45 100644 --- a/src/core/SkMask.cpp +++ b/src/core/SkMask.cpp @@ -6,10 +6,8 @@ */ #include "SkMask.h" - #include "SkMalloc.h" - -//#define TRACK_SKMASK_LIFETIME +#include "SkSafeMath.h" /** returns the product if it is positive and fits in 31 bits. Otherwise this returns 0. @@ -34,36 +32,22 @@ size_t SkMask::computeTotalImageSize() const { return size; } -#ifdef TRACK_SKMASK_LIFETIME - static int gCounter; -#endif - /** We explicitly use this allocator for SkBimap pixels, so that we can freely assign memory allocated by one class to the other. */ -uint8_t* SkMask::AllocImage(size_t size) { -#ifdef TRACK_SKMASK_LIFETIME - SkDebugf("SkMask::AllocImage %d\n", gCounter++); -#endif - size_t aligned_size = std::numeric_limits<size_t>::max(); - - // Expand size to next multiple of four. - size_t adjustment = 3; - if (size + adjustment > size) { - aligned_size = (size + adjustment) & ~adjustment; +uint8_t* SkMask::AllocImage(size_t size, AllocType at) { + size_t aligned_size = SkSafeMath::Align4(size); + unsigned flags = SK_MALLOC_THROW; + if (at == kZeroInit_Alloc) { + flags |= SK_MALLOC_ZERO_INITIALIZE; } - return static_cast<uint8_t*>(sk_malloc_throw(aligned_size)); + return static_cast<uint8_t*>(sk_malloc_flags(aligned_size, flags)); } /** We explicitly use this allocator for SkBimap pixels, so that we can freely assign memory allocated by one class to the other. */ void SkMask::FreeImage(void* image) { -#ifdef TRACK_SKMASK_LIFETIME - if (image) { - SkDebugf("SkMask::FreeImage %d\n", --gCounter); - } -#endif sk_free(image); } |