make allocPixels throw on failure

BUG=skia:
R=mtklein@google.com, fmalita@google.com, fmalita@chromium.org

Author: reed@google.com

Review URL: https://codereview.chromium.org/510423005
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index d83199d..928a4b7 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -268,7 +268,7 @@
     SkDEBUGCODE(this->validate();)
 }
 
-bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) {
+bool SkBitmap::tryAllocPixels(Allocator* allocator, SkColorTable* ctable) {
     HeapAllocator stdalloc;
 
     if (NULL == allocator) {
@@ -279,7 +279,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) {
+bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) {
     if (kIndex_8_SkColorType == requestedInfo.colorType()) {
         return reset_return_false(this);
     }
@@ -308,8 +308,8 @@
     return true;
 }
 
-bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory,
-                           SkColorTable* ctable) {
+bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory,
+                                SkColorTable* ctable) {
     if (kIndex_8_SkColorType == requestedInfo.fColorType && NULL == ctable) {
         return reset_return_false(this);
     }
@@ -950,7 +950,7 @@
         // TODO: can we just ref() the src colortable? Is it reentrant-safe?
         ctable.reset(SkNEW_ARGS(SkColorTable, (*src->getColorTable())));
     }
-    if (!tmpDst.allocPixels(alloc, ctable)) {
+    if (!tmpDst.tryAllocPixels(alloc, ctable)) {
         return false;
     }
 
@@ -1122,7 +1122,7 @@
     } else {
     NO_FILTER_CASE:
         tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), srcM.fRowBytes);
-        if (!tmpBitmap.allocPixels(allocator, NULL)) {
+        if (!tmpBitmap.tryAllocPixels(allocator, NULL)) {
             // Allocation of pixels for alpha bitmap failed.
             SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
                     tmpBitmap.width(), tmpBitmap.height());
@@ -1146,7 +1146,7 @@
 
     tmpBitmap.setInfo(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.height()),
                       dstM.fRowBytes);
-    if (!tmpBitmap.allocPixels(allocator, NULL)) {
+    if (!tmpBitmap.tryAllocPixels(allocator, NULL)) {
         // Allocation of pixels for alpha bitmap failed.
         SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
                 tmpBitmap.width(), tmpBitmap.height());
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 5f205ce..2287864 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -82,7 +82,7 @@
             return NULL;
         }
     } else {
-        if (!bitmap.allocPixels(info)) {
+        if (!bitmap.tryAllocPixels(info)) {
             return NULL;
         }
         if (!bitmap.info().isOpaque()) {
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 717878c..f071fc9 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -568,7 +568,7 @@
 
     bool weAllocated = false;
     if (NULL == bitmap->pixelRef()) {
-        if (!bitmap->allocPixels()) {
+        if (!bitmap->tryAllocPixels()) {
             return false;
         }
         weAllocated = true;
@@ -594,7 +594,7 @@
         return false;
     }
 
-    if (!bitmap->allocN32Pixels(r.width(), r.height())) {
+    if (!bitmap->tryAllocN32Pixels(r.width(), r.height())) {
         // bitmap will already be reset.
         return false;
     }
@@ -1006,7 +1006,7 @@
     fAddr = canvas->peekPixels(&fInfo, &fRowBytes);
     if (NULL == fAddr) {
         fInfo = canvas->imageInfo();
-        if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.allocPixels(fInfo)) {
+        if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.tryAllocPixels(fInfo)) {
             return; // failure, fAddr is NULL
         }
         if (!canvas->readPixels(&fBitmap, 0, 0)) {
@@ -2535,7 +2535,7 @@
     }
 
     SkBitmap bitmap;
-    if (!bitmap.allocPixels(info)) {
+    if (!bitmap.tryAllocPixels(info)) {
         return NULL;
     }
 
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index 73ab170..a7b5412 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -107,7 +107,7 @@
 
     if (!fCachedBitmapShader || tileScale != fCachedTileScale) {
         SkBitmap bm;
-        if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) {
+        if (!bm.tryAllocN32Pixels(tileSize.width(), tileSize.height())) {
             return NULL;
         }
         bm.eraseColor(SK_ColorTRANSPARENT);
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index db3c0fb..4d7f362 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -437,7 +437,7 @@
     SkBitmap bm;
 
     if (0 == dstRB) {
-        if (!bm.allocPixels(info)) {
+        if (!bm.tryAllocPixels(info)) {
             // can't allocate offscreen, so empty the mask and return
             sk_bzero(mask.fImage, mask.computeImageSize());
             return;
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index ce35ba2..261640f 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -343,7 +343,7 @@
         return false;
     }
 
-    if (!dst->allocPixels(src.info())) {
+    if (!dst->tryAllocPixels(src.info())) {
         return false;
     }
 
diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp
index d082098..8590400 100644
--- a/src/effects/SkBlurImageFilter.cpp
+++ b/src/effects/SkBlurImageFilter.cpp
@@ -172,7 +172,7 @@
         return false;
     }
 
-    if (!dst->allocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) {
+    if (!dst->tryAllocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) {
         return false;
     }
     dst->getBounds(&dstBounds);
@@ -199,7 +199,7 @@
     }
 
     SkBitmap temp;
-    if (!temp.allocPixels(dst->info())) {
+    if (!temp.tryAllocPixels(dst->info())) {
         return false;
     }
 
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index 5d15b4f..bb71aa1 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -254,7 +254,7 @@
         return false;
     }
 
-    if (!dst->allocPixels(color.info().makeWH(bounds.width(), bounds.height()))) {
+    if (!dst->tryAllocPixels(color.info().makeWH(bounds.width(), bounds.height()))) {
         return false;
     }
 
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 69e2760..1eb2a36 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -1016,7 +1016,7 @@
         return false;
     }
 
-    if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
+    if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
         return false;
     }
 
@@ -1134,7 +1134,7 @@
         return false;
     }
 
-    if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
+    if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
         return false;
     }
 
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 70e95f6..9293f7f 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -321,7 +321,7 @@
       return false;
     }
 
-    if (!dst->allocPixels(src.info())) {
+    if (!dst->tryAllocPixels(src.info())) {
         return false;
     }
 
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index aa8b804..c8959ee 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -265,7 +265,7 @@
         return SkBitmap();
     }
     SkBitmap result;
-    if (!result.allocPixels(src.info())) {
+    if (!result.tryAllocPixels(src.info())) {
         return SkBitmap();
     }
     for (int y = 0; y < src.height(); ++y) {
@@ -307,7 +307,7 @@
         return false;
     }
 
-    if (!result->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
+    if (!result->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
         return false;
     }
 
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 2b9c91e..c6c470c 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -166,7 +166,7 @@
         return false;
     }
 
-    if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
+    if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
         return false;
     }
 
@@ -191,7 +191,7 @@
     }
 
     SkBitmap temp;
-    if (!temp.allocPixels(dst->info())) {
+    if (!temp.tryAllocPixels(dst->info())) {
         return false;
     }
 
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index b7b2d1a..b51bae4 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -205,7 +205,7 @@
     // allocate the pixels for a bitmap
     const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight);
     if (kBlitter_CompressionMode != fCompressionMode) {
-        if (!fBM.allocPixels(bmImageInfo)) {
+        if (!fBM.tryAllocPixels(bmImageInfo)) {
             return false;
         }
 
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index a07fe67..54497fe 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -25,8 +25,7 @@
 
 bool GrSurface::savePixels(const char* filename) {
     SkBitmap bm;
-    if (!bm.allocPixels(SkImageInfo::MakeN32Premul(this->width(),
-                                                   this->height()))) {
+    if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->height()))) {
         return false;
     }
 
diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp
index d378032..2371ea7 100644
--- a/src/gpu/SkGrPixelRef.cpp
+++ b/src/gpu/SkGrPixelRef.cpp
@@ -170,7 +170,7 @@
         top = 0;
         height = this->info().fHeight;
     }
-    if (!dst->allocPixels(SkImageInfo::MakeN32Premul(width, height))) {
+    if (!dst->tryAllocN32Pixels(width, height)) {
         SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\n");
         return false;
     }
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 795b842..a606384 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -117,9 +117,8 @@
             return false;
         }
     } else {
-        const SkImageInfo info = SkImageInfo::MakeN32Premul(subset.width(), subset.height());
         SkBitmap tmp;
-        if (!tmp.allocPixels(info)) {
+        if (!tmp.tryAllocN32Pixels(subset.width(), subset.height())) {
             return false;
         }
         *bitmap = tmp;
diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp
index dfa093b..5c66c94 100644
--- a/src/images/SkDecodingImageGenerator.cpp
+++ b/src/images/SkDecodingImageGenerator.cpp
@@ -69,7 +69,7 @@
     virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) {
         if (NULL == fTarget || !equal_modulo_alpha(fInfo, bm->info())) {
             // Call default allocator.
-            return bm->allocPixels(NULL, ct);
+            return bm->tryAllocPixels(NULL, ct);
         }
 
         // TODO(halcanary): verify that all callers of this function
diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp
index ed2ad16..4a5e734 100644
--- a/src/images/SkImageDecoder.cpp
+++ b/src/images/SkImageDecoder.cpp
@@ -133,7 +133,7 @@
 
 bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap,
                                    SkColorTable* ctable) const {
-    return bitmap->allocPixels(fAllocator, ctable);
+    return bitmap->tryAllocPixels(fAllocator, ctable);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index 9b93716..99401e6 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -852,7 +852,7 @@
             return return_false(*cinfo, bitmap, "allocPixelRef");
         }
     } else {
-        if (!bitmap.allocPixels()) {
+        if (!bitmap.tryAllocPixels()) {
             return return_false(*cinfo, bitmap, "allocPixels");
         }
     }
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index 01b7c69..b69f879 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -823,7 +823,7 @@
             return false;
         }
     } else {
-        if (!decodedBitmap.allocPixels(NULL, needColorTable ? colorTable : NULL)) {
+        if (!decodedBitmap.tryAllocPixels(NULL, needColorTable ? colorTable : NULL)) {
             return false;
         }
     }
diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp
index f7cfa8b..f32587d 100644
--- a/src/images/SkImageDecoder_libwebp.cpp
+++ b/src/images/SkImageDecoder_libwebp.cpp
@@ -375,7 +375,7 @@
         // alloc from native heap if it is a temp bitmap. (prevent GC)
         bool allocResult = (bitmap == decodedBitmap)
                                ? allocPixelRef(bitmap, NULL)
-                               : bitmap->allocPixels();
+                               : bitmap->tryAllocPixels();
         if (!allocResult) {
             return return_false(*decodedBitmap, "allocPixelRef");
         }
diff --git a/src/images/SkMovie_gif.cpp b/src/images/SkMovie_gif.cpp
index decefd5..3810db5 100644
--- a/src/images/SkMovie_gif.cpp
+++ b/src/images/SkMovie_gif.cpp
@@ -364,11 +364,11 @@
         startIndex = 0;
 
         // create bitmap
-        if (!bm->allocPixels(SkImageInfo::MakeN32Premul(width, height))) {
+        if (!bm->tryAllocN32Pixels(width, height)) {
             return false;
         }
         // create bitmap for backup
-        if (!fBackup.allocPixels(SkImageInfo::MakeN32Premul(width, height))) {
+        if (!fBackup.tryAllocN32Pixels(width, height)) {
             return false;
         }
     } else if (startIndex > fCurrIndex) {
diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp
index 5643188..bd67532 100644
--- a/src/lazy/SkCachingPixelRef.cpp
+++ b/src/lazy/SkCachingPixelRef.cpp
@@ -46,7 +46,7 @@
     const SkImageInfo& info = this->info();
     if (!SkBitmapCache::Find(this->getGenerationID(), info.fWidth, info.fHeight, &fLockedBitmap)) {
         // Cache has been purged, must re-decode.
-        if (!fLockedBitmap.allocPixels(info, fRowBytes)) {
+        if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) {
             fErrorInDecoding = true;
             return false;
         }
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp
index a86c3de..ec8d5ea 100644
--- a/src/lazy/SkDiscardablePixelRef.cpp
+++ b/src/lazy/SkDiscardablePixelRef.cpp
@@ -110,7 +110,7 @@
 
     SkASSERT(info.colorType() != kUnknown_SkColorType);
     if (dst->empty()) {  // Use a normal pixelref.
-        return dst->allocPixels();
+        return dst->tryAllocPixels();
     }
     SkAutoTUnref<SkDiscardablePixelRef> ref(
         SkNEW_ARGS(SkDiscardablePixelRef,
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index ec07a8f..f4ea694 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -2120,7 +2120,7 @@
 
         const int w = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().width());
         const int h = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().height());
-        if (!perspectiveBitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) {
+        if (!perspectiveBitmap.tryAllocN32Pixels(w, h)) {
             return;
         }
         perspectiveBitmap.eraseColor(SK_ColorTRANSPARENT);
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index 4946051..0c9b741 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -375,8 +375,7 @@
 static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap,
                                      const SkIRect& srcRect) {
     SkBitmap outBitmap;
-    SkAssertResult(outBitmap.allocPixels(
-            bitmap.info().makeWH(srcRect.width(), srcRect.height())));
+    outBitmap.allocPixels(bitmap.info().makeWH(srcRect.width(), srcRect.height()));
     int dstRow = 0;
 
     SkAutoLockPixels outBitmapPixelLock(outBitmap);
diff --git a/src/utils/SkPDFRasterizer.cpp b/src/utils/SkPDFRasterizer.cpp
index 6663480..1cb792f 100644
--- a/src/utils/SkPDFRasterizer.cpp
+++ b/src/utils/SkPDFRasterizer.cpp
@@ -50,7 +50,7 @@
   char *imgData = image.data();
 
   SkBitmap bitmap;
-  if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height))) {
+  if (!bitmap.tryAllocN32Pixels(width, height)) {
     return false;
   }
   bitmap.eraseColor(SK_ColorWHITE);
diff --git a/src/utils/mac/SkCreateCGImageRef.cpp b/src/utils/mac/SkCreateCGImageRef.cpp
index 01b774d..14a24d8 100644
--- a/src/utils/mac/SkCreateCGImageRef.cpp
+++ b/src/utils/mac/SkCreateCGImageRef.cpp
@@ -221,7 +221,7 @@
     int h = (int)CGRectGetHeight(bounds);
 
     SkBitmap bitmap;
-    if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) {
+    if (!bitmap.tryAllocN32Pixels(w, h)) {
         return false;
     }
     bitmap.eraseColor(SK_ColorWHITE);
@@ -287,7 +287,7 @@
     SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
 
     SkBitmap tmp;
-    if (!tmp.allocPixels(info)) {
+    if (!tmp.tryAllocPixels(info)) {
         return false;
     }