diff options
author | Mike Reed <reed@google.com> | 2016-10-25 09:57:13 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-10-25 14:19:07 +0000 |
commit | 7614794c9ad14d76abed6cf00890ad1a09c2cb8b (patch) | |
tree | fb79a90fe28039038d5d54e809f68e83399cb32a /tests/CachedDecodingPixelRefTest.cpp | |
parent | 67c7c81a82b6351e9fbbf235084d7120162d9268 (diff) |
remove discardablepixelref
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3883
Change-Id: Ica284be78563a4ccd6e0cb07404064fb5511ba57
Reviewed-on: https://skia-review.googlesource.com/3883
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'tests/CachedDecodingPixelRefTest.cpp')
-rw-r--r-- | tests/CachedDecodingPixelRefTest.cpp | 214 |
1 files changed, 1 insertions, 213 deletions
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp index b6253c73a2..b65765f96c 100644 --- a/tests/CachedDecodingPixelRefTest.cpp +++ b/tests/CachedDecodingPixelRefTest.cpp @@ -11,149 +11,13 @@ #include "SkDiscardableMemoryPool.h" #include "SkImage.h" #include "SkImageEncoder.h" -#include "SkImageGeneratorPriv.h" +#include "SkImageGenerator.h" #include "SkResourceCache.h" #include "SkStream.h" #include "SkUtils.h" #include "Test.h" -/** - * Fill this bitmap with some color. - */ -static void make_test_image(SkBitmap* bm) { - const int W = 50, H = 50; - bm->allocN32Pixels(W, H); - bm->eraseColor(SK_ColorBLACK); - SkCanvas canvas(*bm); - SkPaint paint; - paint.setColor(SK_ColorBLUE); - canvas.drawRectCoords(0, 0, SkIntToScalar(W/2), - SkIntToScalar(H/2), paint); - paint.setColor(SK_ColorWHITE); - canvas.drawRectCoords(SkIntToScalar(W/2), SkIntToScalar(H/2), - SkIntToScalar(W), SkIntToScalar(H), paint); -} - -/** - * encode this bitmap into some data via SkImageEncoder - */ -static sk_sp<SkData> create_data_from_bitmap(const SkBitmap& bm, SkImageEncoder::Type type) { - SkDynamicMemoryWStream stream; - if (SkImageEncoder::EncodeStream(&stream, bm, type, 100)) { - return stream.detachAsData(); - } - return nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// - -static void compare_bitmaps(skiatest::Reporter* reporter, - const SkBitmap& b1, const SkBitmap& b2, - bool pixelPerfect = true) { - REPORTER_ASSERT(reporter, b1.empty() == b2.empty()); - REPORTER_ASSERT(reporter, b1.width() == b2.width()); - REPORTER_ASSERT(reporter, b1.height() == b2.height()); - REPORTER_ASSERT(reporter, b1.isNull() == b2.isNull()); - SkAutoLockPixels autoLockPixels1(b1); - SkAutoLockPixels autoLockPixels2(b2); - REPORTER_ASSERT(reporter, b1.isNull() == b2.isNull()); - if (b1.isNull() || b1.empty()) { - return; - } - REPORTER_ASSERT(reporter, b1.getPixels()); - REPORTER_ASSERT(reporter, b2.getPixels()); - if ((!(b1.getPixels())) || (!(b2.getPixels()))) { - return; - } - if ((b1.width() != b2.width()) || - (b1.height() != b2.height())) { - return; - } - if (!pixelPerfect) { - return; - } - - int pixelErrors = 0; - for (int y = 0; y < b2.height(); ++y) { - for (int x = 0; x < b2.width(); ++x) { - if (b1.getColor(x, y) != b2.getColor(x, y)) { - ++pixelErrors; - } - } - } - REPORTER_ASSERT(reporter, 0 == pixelErrors); -} - -typedef bool (*InstallEncoded)(SkData* encoded, SkBitmap* dst); - -/** - This function tests three differently encoded images against the - original bitmap */ -static void test_three_encodings(skiatest::Reporter* reporter, - InstallEncoded install) { - SkBitmap original; - make_test_image(&original); - REPORTER_ASSERT(reporter, !original.empty()); - REPORTER_ASSERT(reporter, !original.isNull()); - if (original.empty() || original.isNull()) { - return; - } - static const SkImageEncoder::Type types[] = { - SkImageEncoder::kPNG_Type, - SkImageEncoder::kJPEG_Type, - SkImageEncoder::kWEBP_Type - }; - for (size_t i = 0; i < SK_ARRAY_COUNT(types); i++) { - SkImageEncoder::Type type = types[i]; - sk_sp<SkData> encoded = create_data_from_bitmap(original, type); - REPORTER_ASSERT(reporter, encoded.get() != nullptr); - if (nullptr == encoded.get()) { - continue; - } - SkBitmap lazy; - bool installSuccess = install(encoded.get(), &lazy); - REPORTER_ASSERT(reporter, installSuccess); - if (!installSuccess) { - continue; - } - REPORTER_ASSERT(reporter, nullptr == lazy.getPixels()); - { - SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. - REPORTER_ASSERT(reporter, lazy.getPixels()); - if (nullptr == lazy.getPixels()) { - continue; - } - } - // pixels should be gone! - REPORTER_ASSERT(reporter, nullptr == lazy.getPixels()); - { - SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. - REPORTER_ASSERT(reporter, lazy.getPixels()); - if (nullptr == lazy.getPixels()) { - continue; - } - } - bool comparePixels = (SkImageEncoder::kPNG_Type == type); - compare_bitmaps(reporter, original, lazy, comparePixels); - } -} - -//////////////////////////////////////////////////////////////////////////////// -static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { - // Use system-default discardable memory. - return SkDEPRECATED_InstallDiscardablePixelRef(encoded, dst); -} - -//////////////////////////////////////////////////////////////////////////////// -/** - * This checks to see that SkDiscardablePixelRef works as advertised with a - * SkDecodingImageGenerator. - */ -DEF_TEST(DecodingImageGenerator, reporter) { - test_three_encodings(reporter, install_skDiscardablePixelRef); -} - class TestImageGenerator : public SkImageGenerator { public: enum TestType { @@ -227,82 +91,6 @@ private: typedef SkImageGenerator INHERITED; }; -static void check_test_image_generator_bitmap(skiatest::Reporter* reporter, - const SkBitmap& bm) { - REPORTER_ASSERT(reporter, TestImageGenerator::Width() == bm.width()); - REPORTER_ASSERT(reporter, TestImageGenerator::Height() == bm.height()); - SkAutoLockPixels autoLockPixels(bm); - REPORTER_ASSERT(reporter, bm.getPixels()); - if (nullptr == bm.getPixels()) { - return; - } - int errors = 0; - for (int y = 0; y < bm.height(); ++y) { - for (int x = 0; x < bm.width(); ++x) { - if (TestImageGenerator::Color() != bm.getColor(x, y)) { - ++errors; - } - } - } - REPORTER_ASSERT(reporter, 0 == errors); -} - -static void check_pixelref(TestImageGenerator::TestType type, - skiatest::Reporter* reporter, - SkDiscardableMemory::Factory* factory, - SkColorType colorType) { - SkAutoTDelete<SkImageGenerator> gen(new TestImageGenerator(type, reporter, colorType)); - REPORTER_ASSERT(reporter, gen.get() != nullptr); - SkBitmap lazy; - bool success = SkDEPRECATED_InstallDiscardablePixelRef(gen.release(), nullptr, &lazy, factory); - - REPORTER_ASSERT(reporter, success); - if (TestImageGenerator::kSucceedGetPixels_TestType == type) { - check_test_image_generator_bitmap(reporter, lazy); - } else if (TestImageGenerator::kFailGetPixels_TestType == type) { - SkAutoLockPixels autoLockPixels(lazy); - REPORTER_ASSERT(reporter, nullptr == lazy.getPixels()); - } -} - -/** - * This tests the basic functionality of SkDiscardablePixelRef with a - * basic SkImageGenerator implementation and several - * SkDiscardableMemory::Factory choices. - */ -DEF_TEST(DiscardableAndCachingPixelRef, reporter) { - const SkColorType testColorTypes[] = { - kN32_SkColorType, - kIndex_8_SkColorType, - kRGB_565_SkColorType - }; - for (const SkColorType testColorType : testColorTypes) { - check_pixelref(TestImageGenerator::kFailGetPixels_TestType, reporter, nullptr, - testColorType); - check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, reporter, nullptr, - testColorType); - - SkAutoTUnref<SkDiscardableMemoryPool> pool( - SkDiscardableMemoryPool::Create(1, nullptr)); - REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); - check_pixelref(TestImageGenerator::kFailGetPixels_TestType, reporter, pool, - testColorType); - REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); - check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, reporter, pool, - testColorType); - REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); - - SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool(); - // Only acts differently from nullptr on a platform that has a - // default discardable memory implementation that differs from the - // global DM pool. - check_pixelref(TestImageGenerator::kFailGetPixels_TestType, reporter, globalPool, - testColorType); - check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, reporter, globalPool, - testColorType); - } -} - //////////////////////////////////////////////////////////////////////////////// DEF_TEST(Image_NewFromGenerator, r) { |