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

Unified Diff: src/core/SkBitmapDevice.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 | « include/core/SkMallocPixelRef.h ('k') | src/core/SkMallocPixelRef.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmapDevice.cpp
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index b7df9a4c25890c3a3c3fde7e544817bdff226d21..ac3b9df0827ed51aedfb5f5520c7457ced5e7a8a 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;
}
}
« no previous file with comments | « include/core/SkMallocPixelRef.h ('k') | src/core/SkMallocPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698