From c64ef3563dc8badac3d64544513b03df826cf8c3 Mon Sep 17 00:00:00 2001 From: lsalzman Date: Wed, 12 Oct 2016 16:50:16 -0700 Subject: [PATCH] leave pixel memory uninitialized for opaque alpha type in SkSurface::MakeRaster BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2412633002 Review-Url: https://codereview.chromium.org/2412633002 --- include/core/SkSurface.h | 12 ++++++++---- src/image/SkSurface_Raster.cpp | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index bb3f719754..8e7e148cb9 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -51,10 +51,14 @@ public: void* context, const SkSurfaceProps* = nullptr); /** - * Return a new surface, with the memory for the pixels automatically allocated and - * zero-initialized, but respecting the specified rowBytes. If rowBytes==0, then a default - * value will be chosen. If a non-zero rowBytes is specified, then any images snapped off of - * this surface (via makeImageSnapshot()) are guaranteed to have the same rowBytes. + * Return a new surface, with the memory for the pixels automatically allocated but respecting + * the specified rowBytes. If rowBytes==0, then a default value will be chosen. If a non-zero + * rowBytes is specified, then any images snapped off of this surface (via makeImageSnapshot()) + * are guaranteed to have the same rowBytes. + * + * If the requested alpha type is not opaque, then the surface's pixel memory will be + * zero-initialized. If it is opaque, then it will be left uninitialized, and the caller is + * responsible for initially clearing the surface. * * If the requested surface cannot be created, or the request is not a * supported configuration, NULL will be returned. diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index f2cb94a04f..2b2bf64526 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp @@ -208,7 +208,11 @@ sk_sp SkSurface::MakeRaster(const SkImageInfo& info, size_t rowBytes, return nullptr; } - SkAutoTUnref pr(SkMallocPixelRef::NewZeroed(info, rowBytes, nullptr)); + // If the requested alpha type is opaque, then leave the pixels uninitialized. + // Alpha formats can be safely initialiezd to zero. + SkAutoTUnref pr(info.isOpaque() + ? SkMallocPixelRef::NewAllocate(info, rowBytes, nullptr) + : SkMallocPixelRef::NewZeroed(info, rowBytes, nullptr)); if (nullptr == pr.get()) { return nullptr; }