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

Unified Diff: src/core/SkMallocPixelRef.cpp

Issue 1430593007: For non-opaque SkBitmapDevices, replace malloc-then-zero with calloc. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkMallocPixelRef.cpp
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index 0196e046b17061505f63572e699c3552937791a3..fffc0448486cb26ad96d4b5a09da5f0a6724b2f6 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -48,9 +48,10 @@ SkMallocPixelRef* SkMallocPixelRef::NewDirect(const SkImageInfo& info,
}
-SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
- size_t requestedRowBytes,
- SkColorTable* ctable) {
+ SkMallocPixelRef* SkMallocPixelRef::NewUsing(void*(*alloc)(size_t),
+ const SkImageInfo& info,
+ size_t requestedRowBytes,
+ SkColorTable* ctable) {
if (!is_valid(info, ctable)) {
return nullptr;
}
@@ -78,7 +79,7 @@ SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
size_t size = sk_64_asS32(bigSize);
SkASSERT(size >= info.getSafeSize(rowBytes));
- void* addr = sk_malloc_flags(size, 0);
+ void* addr = alloc(size);
if (nullptr == addr) {
return nullptr;
}
@@ -86,6 +87,19 @@ SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
return new SkMallocPixelRef(info, addr, rowBytes, ctable, sk_free_releaseproc, nullptr);
}
+SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
+ size_t rowBytes,
+ SkColorTable* ctable) {
+ auto sk_malloc_nothrow = [](size_t size) { return sk_malloc_flags(size, 0); };
+ return NewUsing(sk_malloc_nothrow, info, rowBytes, ctable);
+}
+
+SkMallocPixelRef* SkMallocPixelRef::NewZeroed(const SkImageInfo& info,
+ size_t rowBytes,
+ SkColorTable* ctable) {
+ return NewUsing(sk_calloc, info, rowBytes, ctable);
+}
+
SkMallocPixelRef* SkMallocPixelRef::NewWithProc(const SkImageInfo& info,
size_t rowBytes,
SkColorTable* ctable,
@@ -201,3 +215,8 @@ SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, size_t
SkColorTable* ctable) {
return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable);
}
+
+SkPixelRef* SkMallocPixelRef::ZeroedPRFactory::create(const SkImageInfo& info, size_t rowBytes,
+ SkColorTable* ctable) {
+ return SkMallocPixelRef::NewZeroed(info, rowBytes, ctable);
+}
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698