Two malloc+bzero -> calloc.
authormtklein <mtklein@chromium.org>
Tue, 5 Jan 2016 02:56:57 +0000 (18:56 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 5 Jan 2016 02:56:57 +0000 (18:56 -0800)
I was profiling DM and noticed a couple spots where we malloc then bzero.
These might as well call calloc instead:
   - any time DM itself allocates bitmaps for raster drawing;
   - any time Skia allocates memory for a raster SkSurface.

We could use malloc for opaque surfaces, but it seems simpler to always calloc.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1557713003

Review URL: https://codereview.chromium.org/1557713003

dm/DMSrcSink.cpp
src/image/SkSurface_Raster.cpp

index 5bc5e5a30d6494f44892ee5e53182ad6a9d18f16..fa600ff4eb33bc07ba22c6d0eebe46e435085b52 100644 (file)
@@ -14,6 +14,7 @@
 #include "SkDocument.h"
 #include "SkError.h"
 #include "SkImageGenerator.h"
+#include "SkMallocPixelRef.h"
 #include "SkMultiPictureDraw.h"
 #include "SkNullCanvas.h"
 #include "SkOSFile.h"
@@ -973,8 +974,10 @@ Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) con
     SkAlphaType alphaType = kPremul_SkAlphaType;
     (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType);
 
-    dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType));
-    dst->eraseColor(SK_ColorTRANSPARENT);
+    SkMallocPixelRef::ZeroedPRFactory factory;
+    dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType),
+                     &factory,
+                     nullptr/*colortable*/);
     SkCanvas canvas(*dst);
     return src.draw(&canvas);
 }
index d5593eb1d7dd1e72872df0ab3c0707fe6108371d..a606656709457699ee998b7ec9a311a755fd7579 100644 (file)
@@ -99,10 +99,6 @@ SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr, const SkSurfaceProps* props)
     fBitmap.setInfo(info, info.minRowBytes());
     fBitmap.setPixelRef(pr);
     fWeOwnThePixels = true;
-
-    if (!info.isOpaque()) {
-        fBitmap.eraseColor(SK_ColorTRANSPARENT);
-    }
 }
 
 SkCanvas* SkSurface_Raster::onNewCanvas() { return new SkCanvas(fBitmap, this->props()); }
@@ -185,7 +181,7 @@ SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const SkSurfaceProps* p
         return nullptr;
     }
 
-    SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, nullptr));
+    SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr));
     if (nullptr == pr.get()) {
         return nullptr;
     }