diff options
-rw-r--r-- | tests/EmptyPathTest.cpp | 5 | ||||
-rw-r--r-- | tests/FlatDataTest.cpp | 3 | ||||
-rw-r--r-- | tests/GradientTest.cpp | 6 | ||||
-rw-r--r-- | tests/ImageCacheTest.cpp | 9 | ||||
-rw-r--r-- | tests/ImageDecodingTest.cpp | 5 | ||||
-rw-r--r-- | tests/ImageFilterTest.cpp | 18 | ||||
-rw-r--r-- | tests/MipMapTest.cpp | 3 | ||||
-rw-r--r-- | tests/PDFPrimitivesTest.cpp | 3 | ||||
-rw-r--r-- | tests/PathOpsExtendedTest.cpp | 6 | ||||
-rwxr-xr-x | tests/PathOpsSkpClipTest.cpp | 6 | ||||
-rw-r--r-- | tests/PathUtilsTest.cpp | 6 | ||||
-rw-r--r-- | tests/PictureTest.cpp | 14 | ||||
-rw-r--r-- | tests/PipeTest.cpp | 8 | ||||
-rw-r--r-- | tests/PremulAlphaRoundTripTest.cpp | 9 | ||||
-rw-r--r-- | tests/QuickRejectTest.cpp | 6 | ||||
-rw-r--r-- | tests/ResourceCacheTest.cpp | 6 | ||||
-rw-r--r-- | tests/SerializationTest.cpp | 38 | ||||
-rw-r--r-- | tests/ShaderImageFilterTest.cpp | 6 | ||||
-rw-r--r-- | tests/ShaderOpacityTest.cpp | 6 | ||||
-rw-r--r-- | tests/SkpSkGrTest.cpp | 3 | ||||
-rw-r--r-- | tests/SurfaceTest.cpp | 3 | ||||
-rw-r--r-- | tests/TileGridTest.cpp | 60 |
22 files changed, 76 insertions, 153 deletions
diff --git a/tests/EmptyPathTest.cpp b/tests/EmptyPathTest.cpp index 09a1f5279c..c4f011a0dc 100644 --- a/tests/EmptyPathTest.cpp +++ b/tests/EmptyPathTest.cpp @@ -14,9 +14,8 @@ static void drawAndTest(skiatest::Reporter* reporter, const SkPath& path, const SkPaint& paint, bool shouldDraw) { SkBitmap bm; - // explicitly specify a trim rowbytes, so we have no padding on each row - bm.setConfig(SkBitmap::kARGB_8888_Config, DIMENSION, DIMENSION, DIMENSION*4); - bm.allocPixels(); + bm.allocN32Pixels(DIMENSION, DIMENSION); + SkASSERT(DIMENSION*4 == bm.rowBytes()); // ensure no padding on each row bm.eraseColor(SK_ColorTRANSPARENT); SkCanvas canvas(bm); diff --git a/tests/FlatDataTest.cpp b/tests/FlatDataTest.cpp index 36fecf9625..4b56fc06a0 100644 --- a/tests/FlatDataTest.cpp +++ b/tests/FlatDataTest.cpp @@ -68,8 +68,7 @@ DEF_TEST(FlatData, reporter) { // Test SkBitmap { SkBitmap bm; - bm.setConfig(SkBitmap::kARGB_8888_Config, 50, 50); - bm.allocPixels(); + bm.allocN32Pixels(50, 50); SkCanvas canvas(bm); SkPaint paint; paint.setShader(shader); diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp index 8a250fab79..3e400103fb 100644 --- a/tests/GradientTest.cpp +++ b/tests/GradientTest.cpp @@ -142,12 +142,10 @@ static void TestConstantGradient(skiatest::Reporter*) { 2, SkShader::kClamp_TileMode)); SkBitmap outBitmap; - outBitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 1); - outBitmap.allocPixels(); + outBitmap.allocN32Pixels(10, 1); SkPaint paint; paint.setShader(s.get()); - SkBitmapDevice device(outBitmap); - SkCanvas canvas(&device); + SkCanvas canvas(outBitmap); canvas.drawPaint(paint); SkAutoLockPixels alp(outBitmap); for (int i = 0; i < 10; i++) { diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp index 15b624aa87..65c9068853 100644 --- a/tests/ImageCacheTest.cpp +++ b/tests/ImageCacheTest.cpp @@ -10,8 +10,7 @@ #include "Test.h" static void make_bm(SkBitmap* bm, int w, int h) { - bm->setConfig(SkBitmap::kARGB_8888_Config, w, h); - bm->allocPixels(); + bm->allocN32Pixels(w, h); } static const int COUNT = 10; @@ -109,12 +108,10 @@ DEF_TEST(ImageCache_doubleAdd, r) { SkScaledImageCache cache(1024); SkBitmap original; - original.setConfig(SkBitmap::kARGB_8888_Config, 40, 40); - original.allocPixels(); + original.allocN32Pixels(40, 40); SkBitmap scaled; - scaled.setConfig(SkBitmap::kARGB_8888_Config, 20, 20); - scaled.allocPixels(); + scaled.allocN32Pixels(20, 20); SkScaledImageCache::ID* id1 = cache.addAndLock(original, 0.5f, 0.5f, scaled); SkScaledImageCache::ID* id2 = cache.addAndLock(original, 0.5f, 0.5f, scaled); diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp index 2e0225a261..7b2f988ffc 100644 --- a/tests/ImageDecodingTest.cpp +++ b/tests/ImageDecodingTest.cpp @@ -168,8 +168,7 @@ static void test_unpremul(skiatest::Reporter* reporter) { static SkMemoryStream* create_image_stream(SkImageEncoder::Type type) { SkBitmap bm; const int size = 50; - bm.setConfig(SkBitmap::kARGB_8888_Config, size, size); - bm.allocPixels(); + bm.allocN32Pixels(size, size); SkCanvas canvas(bm); SkPoint points[2] = { { SkIntToScalar(0), SkIntToScalar(0) }, @@ -363,7 +362,7 @@ DEF_TEST(ImprovedBitmapFactory, reporter) { SkStream::NewFromFile(path.c_str())); if (sk_exists(path.c_str())) { SkBitmap bm; - SkAssertResult(bm.setConfig(SkBitmap::kARGB_8888_Config, 1, 1)); + SkAssertResult(bm.setConfig(SkImageInfo::MakeN32Premul(1, 1))); REPORTER_ASSERT(reporter, NULL != install_pixel_ref(&bm, stream.detach(), 1, true)); SkAutoLockPixels alp(bm); diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 317a877d60..59504cf702 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -70,10 +70,8 @@ private: } static void make_small_bitmap(SkBitmap& bitmap) { - bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); - bitmap.allocPixels(); - SkBitmapDevice device(bitmap); - SkCanvas canvas(&device); + bitmap.allocN32Pixels(kBitmapSize, kBitmapSize); + SkCanvas canvas(bitmap); canvas.clear(0x00000000); SkPaint darkPaint; darkPaint.setColor(0xFF804020); @@ -159,8 +157,7 @@ DEF_TEST(ImageFilter, reporter) { // Tests pass by not asserting SkBitmap bitmap, result; make_small_bitmap(bitmap); - result.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); - result.allocPixels(); + result.allocN32Pixels(kBitmapSize, kBitmapSize); { // This tests for : @@ -204,8 +201,7 @@ static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter) // unaffected by the input crop rect. // Tests pass by not asserting. SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); - bitmap.allocPixels(); + bitmap.allocN32Pixels(100, 100); bitmap.eraseARGB(0, 0, 0, 0); SkDeviceImageFilterProxy proxy(device); @@ -260,16 +256,14 @@ static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter) DEF_TEST(ImageFilterCropRect, reporter) { SkBitmap temp; - temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); - temp.allocPixels(); + temp.allocN32Pixels(100, 100); SkBitmapDevice device(temp); test_crop_rects(&device, reporter); } DEF_TEST(ImageFilterMatrixTest, reporter) { SkBitmap temp; - temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); - temp.allocPixels(); + temp.allocN32Pixels(100, 100); SkBitmapDevice device(temp); SkCanvas canvas(&device); canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); diff --git a/tests/MipMapTest.cpp b/tests/MipMapTest.cpp index aca6973e19..33f467244b 100644 --- a/tests/MipMapTest.cpp +++ b/tests/MipMapTest.cpp @@ -15,8 +15,7 @@ static void make_bitmap(SkBitmap* bm, SkRandom& rand) { // should fix that to support 1 X N, where N > 1 to return non-null. int w = 2 + rand.nextU() % 1000; int h = 2 + rand.nextU() % 1000; - bm->setConfig(SkBitmap::kARGB_8888_Config, w, h); - bm->allocPixels(); + bm->allocN32Pixels(w, h); bm->eraseColor(SK_ColorWHITE); } diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index b05d4c84fe..b1d482ffa2 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -243,8 +243,7 @@ static void TestSubstitute(skiatest::Reporter* reporter) { // Create a bitmap that would be very eficiently compressed in a ZIP. static void setup_bitmap(SkBitmap* bitmap, int width, int height) { - bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); - bitmap->allocPixels(); + bitmap->allocN32Pixels(width, height); bitmap->eraseColor(SK_ColorWHITE); } diff --git a/tests/PathOpsExtendedTest.cpp b/tests/PathOpsExtendedTest.cpp index 1083a897e1..cee27e4588 100644 --- a/tests/PathOpsExtendedTest.cpp +++ b/tests/PathOpsExtendedTest.cpp @@ -289,8 +289,7 @@ static void scaleMatrix(const SkPath& one, const SkPath& two, SkMatrix& scale) { static int pathsDrawTheSame(SkBitmap& bits, const SkPath& scaledOne, const SkPath& scaledTwo, int& error2x2) { if (bits.width() == 0) { - bits.setConfig(SkBitmap::kARGB_8888_Config, bitWidth * 2, bitHeight); - bits.allocPixels(); + bits.allocN32Pixels(bitWidth * 2, bitHeight); } SkCanvas canvas(bits); canvas.drawColor(SK_ColorWHITE); @@ -355,8 +354,7 @@ bool drawAsciiPaths(const SkPath& one, const SkPath& two, bool drawPaths) { if (bitHeight >= (int) sizeof(out)) { return false; } - bits.setConfig(SkBitmap::kARGB_8888_Config, bitWidth * 2, bitHeight); - bits.allocPixels(); + bits.allocN32Pixels(bitWidth * 2, bitHeight); SkCanvas canvas(bits); canvas.drawColor(SK_ColorWHITE); SkPaint paint; diff --git a/tests/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp index e0f5e18f67..d80224f129 100755 --- a/tests/PathOpsSkpClipTest.cpp +++ b/tests/PathOpsSkpClipTest.cpp @@ -403,10 +403,8 @@ void TestResult::testOne() { do { int dimX = (width + scale - 1) / scale; int dimY = (height + scale - 1) / scale; - oldBitmap.setConfig(SkBitmap::kARGB_8888_Config, dimX, dimY); - opBitmap.setConfig(SkBitmap::kARGB_8888_Config, dimX, dimY); - bool success = oldBitmap.allocPixels() && opBitmap.allocPixels(); - if (success) { + if (oldBitmap.allocN32Pixels(dimX, dimY) && + opBitmap.allocN32Pixels(dimX, dimY)) { break; } SkDebugf("-%d-", scale); diff --git a/tests/PathUtilsTest.cpp b/tests/PathUtilsTest.cpp index 872af0b363..4dfeda467c 100644 --- a/tests/PathUtilsTest.cpp +++ b/tests/PathUtilsTest.cpp @@ -60,8 +60,7 @@ static void print_bmp( SkBitmap* bmp, int w, int h){ static void binary_to_skbitmap(const char* bin_bmp, SkBitmap* sk_bmp, int w, int h, int rowBytes){ //init the SkBitmap - sk_bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h); - sk_bmp->allocPixels(); + sk_bmp->allocN32Pixels(w, h); for (int y = 0; y < h; ++y) { // for every row @@ -98,8 +97,7 @@ static void test_path_eq(skiatest::Reporter* reporter, const SkPath* path, // make bmp SkBitmap bmp; - bmp.setConfig(SkBitmap::kARGB_8888_Config, w, h); - bmp.allocPixels(); + bmp.allocN32Pixels(w, h); SkCanvas canvas(bmp); canvas.clear(SK_ColorWHITE); canvas.drawPath(*path, bmpPaint); diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index 002fe8f441..e540181134 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -26,8 +26,7 @@ static const int gColorScale = 30; static const int gColorOffset = 60; static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { - bm->setConfig(SkBitmap::kARGB_8888_Config, w, h); - bm->allocPixels(); + bm->allocN32Pixels(w, h); bm->eraseColor(color); if (immutable) { bm->setImmutable(); @@ -37,8 +36,8 @@ static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { static void make_checkerboard(SkBitmap* bm, int w, int h, bool immutable) { SkASSERT(w % 2 == 0); SkASSERT(h % 2 == 0); - bm->setConfig(SkBitmap::kA8_Config, w, h); - bm->allocPixels(); + bm->allocPixels(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, + kPremul_SkAlphaType)); SkAutoLockPixels lock(*bm); for (int y = 0; y < h; y += 2) { uint8_t* s = bm->getAddr8(0, y); @@ -721,7 +720,7 @@ static void test_bad_bitmap() { // This bitmap has a width and height but no pixels. As a result, attempting to record it will // fail. SkBitmap bm; - bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); + bm.setConfig(SkImageInfo::MakeN32Premul(100, 100)); SkPicture picture; SkCanvas* recordingCanvas = picture.beginRecording(100, 100); recordingCanvas->drawBitmap(bm, 0, 0); @@ -1048,7 +1047,7 @@ static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { static void test_draw_bitmaps(SkCanvas* canvas) { SkBitmap empty; draw_bitmaps(empty, canvas); - empty.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); + empty.setConfig(SkImageInfo::MakeN32Premul(10, 10)); draw_bitmaps(empty, canvas); } @@ -1060,8 +1059,7 @@ DEF_TEST(Picture_EmptyBitmap, r) { DEF_TEST(Canvas_EmptyBitmap, r) { SkBitmap dst; - dst.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); - dst.allocPixels(); + dst.allocN32Pixels(10, 10); SkCanvas canvas(dst); test_draw_bitmaps(&canvas); diff --git a/tests/PipeTest.cpp b/tests/PipeTest.cpp index 6ab4d8eb4b..fd98fca7ef 100644 --- a/tests/PipeTest.cpp +++ b/tests/PipeTest.cpp @@ -16,7 +16,8 @@ // Ensures that the pipe gracefully handles drawing an invalid bitmap. static void testDrawingBadBitmap(SkCanvas* pipeCanvas) { SkBitmap badBitmap; - badBitmap.setConfig(SkBitmap::kNo_Config, 5, 5); + badBitmap.setConfig(SkImageInfo::Make(5, 5, kUnknown_SkColorType, + kPremul_SkAlphaType)); pipeCanvas->drawBitmap(badBitmap, 0, 0); } @@ -29,8 +30,7 @@ static void testDrawingAfterEndRecording(SkCanvas* canvas) { writer.endRecording(); SkBitmap bm; - bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); - bm.allocPixels(); + bm.allocN32Pixels(2, 2); bm.eraseColor(SK_ColorTRANSPARENT); SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, @@ -44,7 +44,7 @@ static void testDrawingAfterEndRecording(SkCanvas* canvas) { DEF_TEST(Pipe, reporter) { SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, 64, 64); + bitmap.setConfig(SkImageInfo::MakeN32Premul(64, 64)); SkCanvas canvas(bitmap); PipeController pipeController(&canvas); diff --git a/tests/PremulAlphaRoundTripTest.cpp b/tests/PremulAlphaRoundTripTest.cpp index 77f62dcecd..5e8e8bf1dd 100644 --- a/tests/PremulAlphaRoundTripTest.cpp +++ b/tests/PremulAlphaRoundTripTest.cpp @@ -17,8 +17,7 @@ static void fillCanvas(SkCanvas* canvas, SkCanvas::Config8888 unpremulConfig) { SkBitmap bmp; - bmp.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); - bmp.allocPixels(); + bmp.allocN32Pixels(256, 256); SkAutoLockPixels alp(bmp); uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); @@ -72,11 +71,9 @@ DEF_GPUTEST(PremulAlphaRoundTrip, reporter, factory) { SkCanvas canvas(device); SkBitmap readBmp1; - readBmp1.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); - readBmp1.allocPixels(); + readBmp1.allocN32Pixels(256, 256); SkBitmap readBmp2; - readBmp2.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); - readBmp2.allocPixels(); + readBmp2.allocN32Pixels(256, 256); for (size_t upmaIdx = 0; upmaIdx < SK_ARRAY_COUNT(gUnpremulConfigs); diff --git a/tests/QuickRejectTest.cpp b/tests/QuickRejectTest.cpp index 5c1b8776c2..2d367389bb 100644 --- a/tests/QuickRejectTest.cpp +++ b/tests/QuickRejectTest.cpp @@ -40,13 +40,11 @@ public: static void test_drawBitmap(skiatest::Reporter* reporter) { SkBitmap src; - src.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); - src.allocPixels(); + src.allocN32Pixels(10, 10); src.eraseColor(SK_ColorWHITE); SkBitmap dst; - dst.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); - dst.allocPixels(); + dst.allocN32Pixels(10, 10); dst.eraseColor(SK_ColorTRANSPARENT); SkCanvas canvas(dst); diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index b60cde97ba..6b324a7d84 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -22,8 +22,7 @@ static void test_cache(skiatest::Reporter* reporter, const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); SkBitmap src; - src.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); - src.allocPixels(); + src.allocN32Pixels(size.width(), size.height()); src.eraseColor(SK_ColorBLACK); size_t srcSize = src.getSize(); @@ -39,8 +38,7 @@ static void test_cache(skiatest::Reporter* reporter, context->setTextureCacheLimits(1000, maxCacheSize); SkBitmap readback; - readback.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); - readback.allocPixels(); + readback.allocN32Pixels(size.width(), size.height()); for (int i = 0; i < 100; ++i) { canvas->drawBitmap(src, 0, 0); diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index f35f568a64..95067298d0 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -218,10 +218,8 @@ static void TestBitmapSerialization(const SkBitmap& validBitmap, // to make sure we don't crash while trying to render it if (shouldSucceed) { SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, 24, 24); - bitmap.allocPixels(); - SkBitmapDevice device(bitmap); - SkCanvas canvas(&device); + bitmap.allocN32Pixels(24, 24); + SkCanvas canvas(bitmap); canvas.clear(0x00000000); SkPaint paint; paint.setImageFilter(deserializedFilter); @@ -293,40 +291,18 @@ DEF_TEST(Serialization, reporter) { // Test invalid deserializations { + SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256); + SkBitmap validBitmap; - validBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); + validBitmap.setConfig(info); // Create a bitmap with a really large height + info.fHeight = 1000000000; SkBitmap invalidBitmap; - invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000); + invalidBitmap.setConfig(info); // The deserialization should succeed, and the rendering shouldn't crash, // even when the device fails to initialize, due to its size TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); - - // we assert if the pixelref doesn't agree with the config, so skip this - // test (at least for now) -#if 0 - // Create a bitmap with a pixel ref too small - SkImageInfo info; - info.fWidth = 256; - info.fHeight = 256; - info.fColorType = kPMColor_SkColorType; - info.fAlphaType = kPremul_SkAlphaType; - - SkBitmap invalidBitmap2; - invalidBitmap2.setConfig(info); - - // Hack to force invalid, by making the pixelref smaller than its - // owning bitmap. - info.fWidth = 32; - info.fHeight = 1; - - invalidBitmap2.setPixelRef(SkMallocPixelRef::NewAllocate( - info, invalidBitmap2.rowBytes(), NULL))->unref(); - - // The deserialization should detect the pixel ref being too small and fail - TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter); -#endif } } diff --git a/tests/ShaderImageFilterTest.cpp b/tests/ShaderImageFilterTest.cpp index 96beed51a1..45fb5ca9a1 100644 --- a/tests/ShaderImageFilterTest.cpp +++ b/tests/ShaderImageFilterTest.cpp @@ -17,13 +17,11 @@ DEF_TEST(ShaderImageFilter, reporter) { SkBitmap filterResult, shaderResult; - filterResult.setConfig(SkBitmap::kARGB_8888_Config, w, h); - filterResult.allocPixels(); + filterResult.allocN32Pixels(w, h); SkCanvas canvasFilter(filterResult); canvasFilter.clear(0x00000000); - shaderResult.setConfig(SkBitmap::kARGB_8888_Config, w, h); - shaderResult.allocPixels(); + shaderResult.allocN32Pixels(w, h); SkCanvas canvasShader(shaderResult); canvasShader.clear(0x00000000); diff --git a/tests/ShaderOpacityTest.cpp b/tests/ShaderOpacityTest.cpp index 5230e4a0fa..e55560365a 100644 --- a/tests/ShaderOpacityTest.cpp +++ b/tests/ShaderOpacityTest.cpp @@ -11,8 +11,10 @@ #include "Test.h" static void test_bitmap(skiatest::Reporter* reporter) { + SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); + SkBitmap bmp; - bmp.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); + bmp.setConfig(info); // test 1: bitmap without pixel data SkShader* shader = SkShader::CreateBitmapShader(bmp, @@ -22,7 +24,7 @@ static void test_bitmap(skiatest::Reporter* reporter) { shader->unref(); // From this point on, we have pixels - bmp.allocPixels(); + bmp.allocPixels(info); // test 2: not opaque by default shader = SkShader::CreateBitmapShader(bmp, diff --git a/tests/SkpSkGrTest.cpp b/tests/SkpSkGrTest.cpp index 2c01a7e42a..02aabbe2af 100644 --- a/tests/SkpSkGrTest.cpp +++ b/tests/SkpSkGrTest.cpp @@ -425,8 +425,7 @@ void TestResult::testOne() { do { dim.fX = (pWidth + scale - 1) / scale; dim.fY = (pHeight + scale - 1) / scale; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, dim.fX, dim.fY); - bool success = bitmap.allocPixels(); + bool success = bitmap.allocN32Pixels(, dim.fX, dim.fY); if (success) { break; } diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 8075913dd7..aa457c7dcc 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -178,8 +178,7 @@ static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur const size_t testPointCount = 3; SkBitmap testBitmap; - testBitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); - testBitmap.allocPixels(); + testBitmap.allocN32Pixels(10, 10); testBitmap.eraseColor(0); SkRRect testRRect; diff --git a/tests/TileGridTest.cpp b/tests/TileGridTest.cpp index 37952b4ba0..f23324a69d 100644 --- a/tests/TileGridTest.cpp +++ b/tests/TileGridTest.cpp @@ -22,11 +22,9 @@ enum Tile { class MockCanvas : public SkCanvas { public: - MockCanvas(SkBaseDevice* device) : SkCanvas(device) - {} + MockCanvas(const SkBitmap& bm) : SkCanvas(bm) {} - virtual void drawRect(const SkRect& rect, const SkPaint&) - { + virtual void drawRect(const SkRect& rect, const SkPaint&) { // This capture occurs before quick reject. fRects.push(rect); } @@ -70,20 +68,17 @@ DEF_TEST(TileGrid_UnalignedQuery, reporter) { picture.endRecording(); SkBitmap store; - store.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); - store.allocPixels(); + store.allocN32Pixels(1, 1); // Test parts of top-left tile { - SkBitmapDevice device(store); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(store); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); } { - SkBitmapDevice device(store); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(store); mockCanvas.translate(-7.99f, -7.99f); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); @@ -91,8 +86,7 @@ DEF_TEST(TileGrid_UnalignedQuery, reporter) { } // Corner overlap { - SkBitmapDevice device(store); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(store); mockCanvas.translate(-9.5f, -9.5f); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); @@ -101,8 +95,7 @@ DEF_TEST(TileGrid_UnalignedQuery, reporter) { } // Intersect bottom right tile, but does not overlap rect 2 { - SkBitmapDevice device(store); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(store); mockCanvas.translate(-16.0f, -16.0f); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); @@ -110,32 +103,28 @@ DEF_TEST(TileGrid_UnalignedQuery, reporter) { } // Out of bounds queries, snap to border tiles { - SkBitmapDevice device(store); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(store); mockCanvas.translate(2.0f, 0.0f); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); } { - SkBitmapDevice device(store); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(store); mockCanvas.translate(0.0f, 2.0f); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); } { - SkBitmapDevice device(store); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(store); mockCanvas.translate(-22.0f, -16.0f); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); } { - SkBitmapDevice device(store); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(store); mockCanvas.translate(-16.0f, -22.0f); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); @@ -168,28 +157,23 @@ DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) { picture.endRecording(); SkBitmap tileBitmap; - tileBitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); - tileBitmap.allocPixels(); + tileBitmap.allocN32Pixels(10, 10); SkBitmap moreThanATileBitmap; - moreThanATileBitmap.setConfig(SkBitmap::kARGB_8888_Config, 11, 11); - moreThanATileBitmap.allocPixels(); + moreThanATileBitmap.allocN32Pixels(11, 11); SkBitmap tinyBitmap; - tinyBitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); - tinyBitmap.allocPixels(); + tinyBitmap.allocN32Pixels(2, 2); // Test parts of top-left tile { // The offset should cancel the top and left borders of the top left tile // So a look-up at interval 0-10 should be grid aligned, - SkBitmapDevice device(tileBitmap); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(tileBitmap); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); } { // Encroaching border by one pixel - SkBitmapDevice device(moreThanATileBitmap); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(moreThanATileBitmap); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); @@ -199,16 +183,14 @@ DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) { // Tile stride is 8 (tileWidth - 2 * border pixels // so translating by 8, should make query grid-aligned // with middle tile. - SkBitmapDevice device(tileBitmap); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(tileBitmap); mockCanvas.translate(SkIntToScalar(-8), SkIntToScalar(-8)); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); } { - SkBitmapDevice device(tileBitmap); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(tileBitmap); mockCanvas.translate(-7.9f, -7.9f); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); @@ -216,8 +198,7 @@ DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) { REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]); } { - SkBitmapDevice device(tileBitmap); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(tileBitmap); mockCanvas.translate(-8.1f, -8.1f); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); @@ -228,8 +209,7 @@ DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) { // Regression test for crbug.com/234688 // Once the 2x2 device region is inset by margin, it yields an empty // adjusted region, sitting right on top of the tile boundary. - SkBitmapDevice device(tinyBitmap); - MockCanvas mockCanvas(&device); + MockCanvas mockCanvas(tinyBitmap); mockCanvas.translate(-8.0f, -8.0f); picture.draw(&mockCanvas); // This test passes by not asserting. We do not validate the rects recorded |