diff options
author | reed <reed@google.com> | 2015-06-08 10:47:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-08 10:47:13 -0700 |
commit | c31af44336f5eb4a50e83e76e51962d46c3ed458 (patch) | |
tree | 244dcbfbeb638de8da65980dd59707ee323c5d24 /tests | |
parent | 77dcbdeb19d26e52428e392fca0ec9a72658b746 (diff) |
change SkDraw and all Blitters to use pixmap instead of bitmap
BUG=skia:
Review URL: https://codereview.chromium.org/1148793007
Diffstat (limited to 'tests')
-rw-r--r-- | tests/DeviceLooperTest.cpp | 23 | ||||
-rw-r--r-- | tests/TextureCompressionTest.cpp | 69 |
2 files changed, 31 insertions, 61 deletions
diff --git a/tests/DeviceLooperTest.cpp b/tests/DeviceLooperTest.cpp index 5735043074..1a51b58980 100644 --- a/tests/DeviceLooperTest.cpp +++ b/tests/DeviceLooperTest.cpp @@ -9,9 +9,8 @@ #include "SkRasterClip.h" #include "Test.h" -static void make_bm(SkBitmap* bm, int w, int h) { - bm->allocPixels(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, - kPremul_SkAlphaType)); +static void make_pm(SkAutoPixmapStorage* pixmap, int w, int h) { + pixmap->alloc(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, kPremul_SkAlphaType)); } static bool equal(const SkRasterClip& a, const SkRasterClip& b) { @@ -40,19 +39,19 @@ static const struct { static void test_simple(skiatest::Reporter* reporter) { for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { - SkBitmap bitmap; - make_bm(&bitmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height()); + SkAutoPixmapStorage pmap; + make_pm(&pmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height()); SkRasterClip rc(gRec[i].fRCBounds); for (int aa = 0; aa <= 1; ++aa) { - SkDeviceLooper looper(bitmap, rc, gRec[i].fRect, SkToBool(aa)); + SkDeviceLooper looper(pmap, rc, gRec[i].fRect, SkToBool(aa)); bool valid = looper.next(); REPORTER_ASSERT(reporter, valid); if (valid) { - REPORTER_ASSERT(reporter, looper.getBitmap().width() == bitmap.width()); - REPORTER_ASSERT(reporter, looper.getBitmap().height() == bitmap.height()); + REPORTER_ASSERT(reporter, looper.getPixmap().width() == pmap.width()); + REPORTER_ASSERT(reporter, looper.getPixmap().height() == pmap.height()); REPORTER_ASSERT(reporter, equal(looper.getRC(), rc)); REPORTER_ASSERT(reporter, !looper.next()); @@ -62,7 +61,7 @@ static void test_simple(skiatest::Reporter* reporter) { { SkIRect r = rc.getBounds(); r.offset(r.width(), 0); - SkDeviceLooper looper(bitmap, rc, r, false); + SkDeviceLooper looper(pmap, rc, r, false); REPORTER_ASSERT(reporter, !looper.next()); } } @@ -109,8 +108,8 @@ static void test_complex(skiatest::Reporter* reporter) { const int w = gRec[i].fSize.width(); const int h = gRec[i].fSize.height(); - SkBitmap bitmap; - make_bm(&bitmap, w, h); + SkAutoPixmapStorage pmap; + make_pm(&pmap, w, h); const SkIRect rect = SkIRect::MakeWH(w, h); @@ -125,7 +124,7 @@ static void test_complex(skiatest::Reporter* reporter) { SkRasterClip rc; rc.op(rgn, SkRegion::kReplace_Op); - SkDeviceLooper looper(bitmap, rc, rect, gRec[i].fAA); + SkDeviceLooper looper(pmap, rc, rect, gRec[i].fAA); while (looper.next()) { REPORTER_ASSERT(reporter, !looper.getRC().isEmpty()); } diff --git a/tests/TextureCompressionTest.cpp b/tests/TextureCompressionTest.cpp index 568d4d14b6..ca8da28858 100644 --- a/tests/TextureCompressionTest.cpp +++ b/tests/TextureCompressionTest.cpp @@ -42,10 +42,8 @@ static bool compresses_a8(SkTextureCompressor::Format fmt) { * Make sure that we properly fail when we don't have multiple of four image dimensions. */ DEF_TEST(CompressAlphaFailDimensions, reporter) { - SkBitmap bitmap; static const int kWidth = 17; static const int kHeight = 17; - SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); // R11_EAC and LATC are both dimensions of 4, so we need to make sure that we // are violating those assumptions. And if we are, then we're also violating the @@ -55,18 +53,16 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) { REPORTER_ASSERT(reporter, kWidth % 4 != 0); REPORTER_ASSERT(reporter, kHeight % 4 != 0); - bool setInfoSuccess = bitmap.setInfo(info); - REPORTER_ASSERT(reporter, setInfoSuccess); - - bitmap.allocPixels(info); - bitmap.unlockPixels(); + SkAutoPixmapStorage pixmap; + pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); + // leaving the pixels uninitialized, as they don't affect the test... for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor::Format>(i); if (!compresses_a8(fmt)) { continue; } - SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); + SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt)); REPORTER_ASSERT(reporter, NULL == data); } } @@ -76,10 +72,8 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) { * compressed textures can (currently) only be created from A8 bitmaps. */ DEF_TEST(CompressAlphaFailColorType, reporter) { - SkBitmap bitmap; static const int kWidth = 12; static const int kHeight = 12; - SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); // ASTC is at most 12x12, and any dimension divisible by 12 is also divisible // by 4, which is the dimensions of R11_EAC and LATC. In the future, we might @@ -88,18 +82,16 @@ DEF_TEST(CompressAlphaFailColorType, reporter) { REPORTER_ASSERT(reporter, kWidth % 12 == 0); REPORTER_ASSERT(reporter, kHeight % 12 == 0); - bool setInfoSuccess = bitmap.setInfo(info); - REPORTER_ASSERT(reporter, setInfoSuccess); - - bitmap.allocPixels(info); - bitmap.unlockPixels(); + SkAutoPixmapStorage pixmap; + pixmap.alloc(SkImageInfo::MakeN32Premul(kWidth, kHeight)); + // leaving the pixels uninitialized, as they don't affect the test... for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor::Format>(i); if (!compresses_a8(fmt)) { continue; } - SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); + SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt)); REPORTER_ASSERT(reporter, NULL == data); } } @@ -109,10 +101,8 @@ DEF_TEST(CompressAlphaFailColorType, reporter) { * then decompress it, you get what you started with. */ DEF_TEST(CompressCheckerboard, reporter) { - SkBitmap bitmap; static const int kWidth = 48; // We need the number to be divisible by both static const int kHeight = 48; // 12 (ASTC) and 16 (ARM NEON R11 EAC). - SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); // ASTC is at most 12x12, and any dimension divisible by 12 is also divisible // by 4, which is the dimensions of R11_EAC and LATC. In the future, we might @@ -123,17 +113,12 @@ DEF_TEST(CompressCheckerboard, reporter) { REPORTER_ASSERT(reporter, kWidth % 48 == 0); REPORTER_ASSERT(reporter, kHeight % 48 == 0); - bool setInfoSuccess = bitmap.setInfo(info); - REPORTER_ASSERT(reporter, setInfoSuccess); - - bitmap.allocPixels(info); - bitmap.unlockPixels(); + SkAutoPixmapStorage pixmap; + pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); - // Populate bitmap + // Populate the pixels { - SkAutoLockPixels alp(bitmap); - - uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); + uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); REPORTER_ASSERT(reporter, pixels); if (NULL == pixels) { return; @@ -147,7 +132,7 @@ DEF_TEST(CompressCheckerboard, reporter) { pixels[x] = 0; } } - pixels += bitmap.rowBytes(); + pixels += pixmap.rowBytes(); } } @@ -167,7 +152,7 @@ DEF_TEST(CompressCheckerboard, reporter) { continue; } - SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); + SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt)); REPORTER_ASSERT(reporter, data); if (NULL == data) { continue; @@ -180,8 +165,7 @@ DEF_TEST(CompressCheckerboard, reporter) { kWidth, kHeight, fmt); REPORTER_ASSERT(reporter, decompResult); - SkAutoLockPixels alp(bitmap); - uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); + const uint8_t* pixels = reinterpret_cast<const uint8_t*>(pixmap.addr()); REPORTER_ASSERT(reporter, pixels); if (NULL == pixels) { continue; @@ -189,7 +173,7 @@ DEF_TEST(CompressCheckerboard, reporter) { for (int y = 0; y < kHeight; ++y) { for (int x = 0; x < kWidth; ++x) { - bool ok = pixels[y*bitmap.rowBytes() + x] == decompBuffer[y*kWidth + x]; + bool ok = pixels[y*pixmap.rowBytes() + x] == decompBuffer[y*kWidth + x]; REPORTER_ASSERT(reporter, ok); } } @@ -204,16 +188,11 @@ DEF_TEST(CompressLATC, reporter) { const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_Format; static const int kLATCEncodedBlockSize = 8; - SkBitmap bitmap; static const int kWidth = 8; static const int kHeight = 8; - SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); - - bool setInfoSuccess = bitmap.setInfo(info); - REPORTER_ASSERT(reporter, setInfoSuccess); - bitmap.allocPixels(info); - bitmap.unlockPixels(); + SkAutoPixmapStorage pixmap; + pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); int latcDimX, latcDimY; SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY); @@ -226,21 +205,13 @@ DEF_TEST(CompressLATC, reporter) { REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0); for (int lum = 0; lum < 256; ++lum) { - bitmap.lockPixels(); - uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); - REPORTER_ASSERT(reporter, pixels); - if (NULL == pixels) { - bitmap.unlockPixels(); - continue; - } - + uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); for (int i = 0; i < kWidth*kHeight; ++i) { pixels[i] = lum; } - bitmap.unlockPixels(); SkAutoDataUnref latcData( - SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat)); + SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat)); REPORTER_ASSERT(reporter, latcData); if (NULL == latcData) { continue; |