diff options
author | reed <reed@google.com> | 2014-09-02 12:50:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-02 12:50:45 -0700 |
commit | 848250415eddc54075f7eb8795e8db79e749c6ab (patch) | |
tree | eb60aea6e61c9b3a9e195ab3cfb01d571351f78b /tests | |
parent | 00f30bdc9e34b013da54b4406f36556c5be8d041 (diff) |
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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ARGBImageEncoderTest.cpp | 5 | ||||
-rw-r--r-- | tests/BitmapCopyTest.cpp | 14 | ||||
-rw-r--r-- | tests/BitmapHasherTest.cpp | 3 | ||||
-rw-r--r-- | tests/BitmapTest.cpp | 2 | ||||
-rw-r--r-- | tests/CachedDecodingPixelRefTest.cpp | 3 | ||||
-rw-r--r-- | tests/DrawBitmapRectTest.cpp | 4 | ||||
-rw-r--r-- | tests/ImageDecodingTest.cpp | 2 | ||||
-rw-r--r-- | tests/KtxTest.cpp | 3 | ||||
-rwxr-xr-x | tests/PathOpsSkpClipTest.cpp | 3 | ||||
-rw-r--r-- | tests/ReadPixelsTest.cpp | 4 | ||||
-rw-r--r-- | tests/SerializationTest.cpp | 25 | ||||
-rw-r--r-- | tests/SkResourceCacheTest.cpp | 2 | ||||
-rw-r--r-- | tests/TextureCompressionTest.cpp | 12 | ||||
-rw-r--r-- | tests/WritePixelsTest.cpp | 3 |
14 files changed, 35 insertions, 50 deletions
diff --git a/tests/ARGBImageEncoderTest.cpp b/tests/ARGBImageEncoderTest.cpp index 18f315fca9..4d16f4cc6d 100644 --- a/tests/ARGBImageEncoderTest.cpp +++ b/tests/ARGBImageEncoderTest.cpp @@ -35,9 +35,8 @@ DEF_TEST(ARGBImageEncoder, reporter) { // 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 4a49a6b487..6a20668cf6 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -387,14 +387,16 @@ DEF_TEST(BitmapCopy, reporter) { 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 e39439a11f..3b5170692d 100644 --- a/tests/BitmapHasherTest.cpp +++ b/tests/BitmapHasherTest.cpp @@ -17,8 +17,7 @@ typedef uint64_t checksum_result; // 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 42ed8841b4..4826b831fe 100644 --- a/tests/BitmapTest.cpp +++ b/tests/BitmapTest.cpp @@ -75,7 +75,7 @@ DEF_TEST(Bitmap, reporter) { 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 65623d0e4f..7c63a0e925 100644 --- a/tests/CachedDecodingPixelRefTest.cpp +++ b/tests/CachedDecodingPixelRefTest.cpp @@ -348,8 +348,7 @@ DEF_TEST(Image_NewFromGenerator, r) { 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 6dca98b527..720155ca0c 100644 --- a/tests/DrawBitmapRectTest.cpp +++ b/tests/DrawBitmapRectTest.cpp @@ -190,7 +190,9 @@ static void test_wacky_bitmapshader(skiatest::Reporter* reporter, 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 8838e75566..4d26167370 100644 --- a/tests/ImageDecodingTest.cpp +++ b/tests/ImageDecodingTest.cpp @@ -770,7 +770,7 @@ public: 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 bddd09abbf..32dacd5a0f 100644 --- a/tests/KtxTest.cpp +++ b/tests/KtxTest.cpp @@ -28,8 +28,7 @@ DEF_TEST(KtxReadWrite, reporter) { 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 d413a08a66..cdc3c1fcd9 100755 --- a/tests/PathOpsSkpClipTest.cpp +++ b/tests/PathOpsSkpClipTest.cpp @@ -482,8 +482,7 @@ void TestResult::testOne() { 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 d0bf9031f0..77aac1fdd5 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -96,9 +96,7 @@ static SkPMColor convertToPMColor(SkColorType ct, SkAlphaType at, const uint32_t 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 4e11f120db..450f94f47e 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -335,14 +335,12 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { 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 @@ static bool make_checkerboard_bitmap(SkBitmap& bitmap) { 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 @@ static bool draw_something(SkCanvas* canvas) { 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 @@ DEF_TEST(Serialization, reporter) { // 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 b71c7443e5..454f8c2042 100644 --- a/tests/SkResourceCacheTest.cpp +++ b/tests/SkResourceCacheTest.cpp @@ -27,7 +27,7 @@ static bool test_scaled_image_cache_useage() { 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 da7a87bd41..b93cabb4e0 100644 --- a/tests/TextureCompressionTest.cpp +++ b/tests/TextureCompressionTest.cpp @@ -58,8 +58,7 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) { 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 @@ DEF_TEST(CompressAlphaFailColorType, reporter) { 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 @@ DEF_TEST(CompressCheckerboard, reporter) { 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 @@ DEF_TEST(CompressLATC, reporter) { 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 2a8d0592bb..f47c67bd3b 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -115,8 +115,7 @@ static uint32_t getBitmapColor(int x, int y, int w, SkColorType ct, SkAlphaType 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); |