aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBitmapDevice.cpp13
-rw-r--r--src/core/SkMallocPixelRef.cpp27
2 files changed, 33 insertions, 7 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index b7df9a4c25..ac3b9df082 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -8,6 +8,7 @@
#include "SkBitmapDevice.h"
#include "SkConfig8888.h"
#include "SkDraw.h"
+#include "SkMallocPixelRef.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkPath.h"
@@ -94,12 +95,18 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
if (!bitmap.setInfo(info)) {
return nullptr;
}
- } else {
+ } else if (bitmap.info().isOpaque()) {
+ // If this bitmap is opaque, we don't have any sensible default color,
+ // so we just return uninitialized pixels.
if (!bitmap.tryAllocPixels(info)) {
return nullptr;
}
- if (!bitmap.info().isOpaque()) {
- bitmap.eraseColor(SK_ColorTRANSPARENT);
+ } else {
+ // This bitmap has transparency, so we'll zero the pixels (to transparent).
+ // We use a ZeroedPRFactory as a faster alloc-then-eraseColor(SK_ColorTRANSPARENT).
+ SkMallocPixelRef::ZeroedPRFactory factory;
+ if (!bitmap.tryAllocPixels(info, &factory, nullptr/*color table*/)) {
+ return nullptr;
}
}
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index 0196e046b1..fffc044848 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);
+}