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/tests/ARGBImageEncoderTest.cpp b/tests/ARGBImageEncoderTest.cpp
index 18f315f..4d16f4c 100644
--- a/tests/ARGBImageEncoderTest.cpp
+++ b/tests/ARGBImageEncoderTest.cpp
@@ -35,9 +35,8 @@
         // A bitmap that should generate the above bytes:
         SkBitmap bitmap;
         {
-            bool success = bitmap.allocPixels(SkImageInfo::Make(kWidth, kHeight,
-                                                        gColorTypes[ctIndex], kOpaque_SkAlphaType));
-            REPORTER_ASSERT(reporter, success);
+            bitmap.allocPixels(SkImageInfo::Make(kWidth, kHeight, gColorTypes[ctIndex],
+                                                 kOpaque_SkAlphaType));
             bitmap.eraseColor(SK_ColorBLUE);
             // Change rows [0,1] from blue to [red,green].
             SkCanvas canvas(bitmap);
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index 4a49a6b..6a20668 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -387,14 +387,16 @@
                 ct = init_ctable(kPremul_SkAlphaType);
             }
 
+            int localSubW;
             if (isExtracted[copyCase]) { // A larger image to extract from.
-                src.allocPixels(SkImageInfo::Make(2 * subW + 1, subH,
-                                                  gPairs[i].fColorType,
-                                                  kPremul_SkAlphaType));
+                localSubW = 2 * subW + 1;
             } else { // Tests expect a 2x2 bitmap, so make smaller.
-                src.allocPixels(SkImageInfo::Make(subW, subH,
-                                                  gPairs[i].fColorType,
-                                                  kPremul_SkAlphaType));
+                localSubW = subW;
+            }
+            // could fail if we pass kIndex_8 for the colortype
+            if (src.tryAllocPixels(SkImageInfo::Make(localSubW, subH, gPairs[i].fColorType,
+                                                     kPremul_SkAlphaType))) {
+                // failure is fine, as we will notice later on
             }
             SkSafeUnref(ct);
 
diff --git a/tests/BitmapHasherTest.cpp b/tests/BitmapHasherTest.cpp
index e39439a..3b51706 100644
--- a/tests/BitmapHasherTest.cpp
+++ b/tests/BitmapHasherTest.cpp
@@ -17,8 +17,7 @@
 // Fill in bitmap with test data.
 static void CreateTestBitmap(SkBitmap* bitmap, int width, int height,
                              SkColor color, skiatest::Reporter* reporter) {
-    SkImageInfo info = SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType);
-    REPORTER_ASSERT(reporter, bitmap->allocPixels(info));
+    bitmap->allocN32Pixels(width, height, kOpaque_SkAlphaType);
     bitmap->eraseColor(color);
 }
 
diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp
index 42ed884..4826b83 100644
--- a/tests/BitmapTest.cpp
+++ b/tests/BitmapTest.cpp
@@ -75,7 +75,7 @@
             bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height));
             REPORTER_ASSERT(reporter, setConf);
             if (setConf) {
-                REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
+                bm.allocPixels();
             }
             REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
         }
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp
index 65623d0..7c63a0e 100644
--- a/tests/CachedDecodingPixelRefTest.cpp
+++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -348,8 +348,7 @@
         REPORTER_ASSERT(r, TestImageGenerator::Height() == image->height());
 
         SkBitmap bitmap;
-        SkAssertResult(bitmap.allocN32Pixels(TestImageGenerator::Width(),
-                                             TestImageGenerator::Height()));
+        bitmap.allocN32Pixels(TestImageGenerator::Width(), TestImageGenerator::Height());
         SkCanvas canvas(bitmap);
         const SkColor kDefaultColor = 0xffabcdef;
         canvas.clear(kDefaultColor);
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index 6dca98b..720155c 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -190,7 +190,9 @@
     c.concat(matrix);
 
     SkBitmap bm;
-    bm.allocN32Pixels(width, height);
+    if (bm.tryAllocN32Pixels(width, height)) {
+        // allow this to fail silently, to test the code downstream
+    }
     bm.eraseColor(SK_ColorRED);
 
     matrix.setAll(0.0078740157f,
diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp
index 8838e75..4d26167 100644
--- a/tests/ImageDecodingTest.cpp
+++ b/tests/ImageDecodingTest.cpp
@@ -770,7 +770,7 @@
             fSize = 0;
             return true;
         }
-        return bm->allocPixels(NULL, ct);
+        return bm->tryAllocPixels(NULL, ct);
     }
     bool ready() { return fPixels != NULL; }
 private:
diff --git a/tests/KtxTest.cpp b/tests/KtxTest.cpp
index bddd09a..32dacd5 100644
--- a/tests/KtxTest.cpp
+++ b/tests/KtxTest.cpp
@@ -28,8 +28,7 @@
     SkRandom rand(0x1005cbad);
 
     SkBitmap bm8888;
-    bool pixelsAllocated = bm8888.allocN32Pixels(128, 128);
-    REPORTER_ASSERT(reporter, pixelsAllocated);
+    bm8888.allocN32Pixels(128, 128);
 
     uint8_t *pixels = reinterpret_cast<uint8_t*>(bm8888.getPixels());
     REPORTER_ASSERT(reporter, NULL != pixels);
diff --git a/tests/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp
index d413a08..cdc3c1f 100755
--- a/tests/PathOpsSkpClipTest.cpp
+++ b/tests/PathOpsSkpClipTest.cpp
@@ -482,8 +482,7 @@
         do {
             int dimX = SkScalarCeilToInt(width / fScale);
             int dimY = SkScalarCeilToInt(height / fScale);
-            if (oldBitmap.allocN32Pixels(dimX, dimY) &&
-                opBitmap.allocN32Pixels(dimX, dimY)) {
+            if (oldBitmap.tryAllocN32Pixels(dimX, dimY) && opBitmap.tryAllocN32Pixels(dimX, dimY)) {
                 break;
             }
             SkDebugf("-%d-", fScale);
diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp
index d0bf903..77aac1f 100644
--- a/tests/ReadPixelsTest.cpp
+++ b/tests/ReadPixelsTest.cpp
@@ -96,9 +96,7 @@
 static void fillCanvas(SkCanvas* canvas) {
     static SkBitmap bmp;
     if (bmp.isNull()) {
-        SkDEBUGCODE(bool alloc =) bmp.allocN32Pixels(DEV_W, DEV_H);
-        SkASSERT(alloc);
-        SkAutoLockPixels alp(bmp);
+        bmp.allocN32Pixels(DEV_W, DEV_H);
         intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
         for (int y = 0; y < DEV_H; ++y) {
             for (int x = 0; x < DEV_W; ++x) {
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index 4e11f12..450f94f 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -335,14 +335,12 @@
     compare_bitmaps(reporter, origBitmap, destBitmap);
 }
 
-static bool setup_bitmap_for_canvas(SkBitmap* bitmap) {
-    SkImageInfo info = SkImageInfo::Make(
-        kBitmapSize, kBitmapSize, kN32_SkColorType, kPremul_SkAlphaType);
-    return bitmap->allocPixels(info);
+static void setup_bitmap_for_canvas(SkBitmap* bitmap) {
+    bitmap->allocN32Pixels(kBitmapSize, kBitmapSize);
 }
 
-static bool make_checkerboard_bitmap(SkBitmap& bitmap) {
-    bool success = setup_bitmap_for_canvas(&bitmap);
+static void make_checkerboard_bitmap(SkBitmap& bitmap) {
+    setup_bitmap_for_canvas(&bitmap);
 
     SkCanvas canvas(bitmap);
     canvas.clear(0x00000000);
@@ -363,14 +361,12 @@
             canvas.restore();
         }
     }
-
-    return success;
 }
 
-static bool draw_something(SkCanvas* canvas) {
+static void draw_something(SkCanvas* canvas) {
     SkPaint paint;
     SkBitmap bitmap;
-    bool success = make_checkerboard_bitmap(bitmap);
+    make_checkerboard_bitmap(bitmap);
 
     canvas->save();
     canvas->scale(0.5f, 0.5f);
@@ -389,8 +385,6 @@
     paint.setColor(SK_ColorBLACK);
     paint.setTextSize(SkIntToScalar(kBitmapSize/3));
     canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), paint);
-
-    return success;
 }
 
 DEF_TEST(Serialization, reporter) {
@@ -481,10 +475,9 @@
     // Test simple SkPicture serialization
     {
         SkPictureRecorder recorder;
-        bool didDraw = draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize), 
-                                                              SkIntToScalar(kBitmapSize), 
-                                                              NULL, 0));
-        REPORTER_ASSERT(reporter, didDraw);
+        draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize),
+                                               SkIntToScalar(kBitmapSize),
+                                               NULL, 0));
         SkAutoTUnref<SkPicture> pict(recorder.endRecording());
 
         // Serialize picture
diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp
index b71c744..454f8c2 100644
--- a/tests/SkResourceCacheTest.cpp
+++ b/tests/SkResourceCacheTest.cpp
@@ -27,7 +27,7 @@
     SkAutoTUnref<SkCanvas> canvas(
             SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize));
     SkBitmap bitmap;
-    SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize));
+    bitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
     bitmap.eraseColor(0xFFFFFFFF);
     SkScalar scale = SkIntToScalar(kScale);
     SkScalar scaledSize = SkIntToScalar(kBitmapSize) * scale;
diff --git a/tests/TextureCompressionTest.cpp b/tests/TextureCompressionTest.cpp
index da7a87b..b93cabb 100644
--- a/tests/TextureCompressionTest.cpp
+++ b/tests/TextureCompressionTest.cpp
@@ -58,8 +58,7 @@
     bool setInfoSuccess = bitmap.setInfo(info);
     REPORTER_ASSERT(reporter, setInfoSuccess);
 
-    bool allocPixelsSuccess = bitmap.allocPixels(info);
-    REPORTER_ASSERT(reporter, allocPixelsSuccess);
+    bitmap.allocPixels(info);
     bitmap.unlockPixels();
     
     for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
@@ -92,8 +91,7 @@
     bool setInfoSuccess = bitmap.setInfo(info);
     REPORTER_ASSERT(reporter, setInfoSuccess);
 
-    bool allocPixelsSuccess = bitmap.allocPixels(info);
-    REPORTER_ASSERT(reporter, allocPixelsSuccess);
+    bitmap.allocPixels(info);
     bitmap.unlockPixels();
 
     for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
@@ -128,8 +126,7 @@
     bool setInfoSuccess = bitmap.setInfo(info);
     REPORTER_ASSERT(reporter, setInfoSuccess);
 
-    bool allocPixelsSuccess = bitmap.allocPixels(info);
-    REPORTER_ASSERT(reporter, allocPixelsSuccess);
+    bitmap.allocPixels(info);
     bitmap.unlockPixels();
 
     // Populate bitmap
@@ -215,8 +212,7 @@
     bool setInfoSuccess = bitmap.setInfo(info);
     REPORTER_ASSERT(reporter, setInfoSuccess);
 
-    bool allocPixelsSuccess = bitmap.allocPixels(info);
-    REPORTER_ASSERT(reporter, allocPixelsSuccess);
+    bitmap.allocPixels(info);
     bitmap.unlockPixels();
 
     int latcDimX, latcDimY;
diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp
index 2a8d059..f47c67b 100644
--- a/tests/WritePixelsTest.cpp
+++ b/tests/WritePixelsTest.cpp
@@ -115,8 +115,7 @@
 static void fillCanvas(SkCanvas* canvas) {
     SkBitmap bmp;
     if (bmp.isNull()) {
-        SkDEBUGCODE(bool alloc = ) bmp.allocN32Pixels(DEV_W, DEV_H);
-        SkASSERT(alloc);
+        bmp.allocN32Pixels(DEV_W, DEV_H);
         for (int y = 0; y < DEV_H; ++y) {
             for (int x = 0; x < DEV_W; ++x) {
                 *bmp.getAddr32(x, y) = getCanvasColor(x, y);