aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2015-09-14 08:52:12 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-14 08:52:12 -0700
commit74bd953719c97e048def312973fd51320e7a00f0 (patch)
tree71758a15963fdc5f65ae385bf7590c7bb53ff5c7 /tests
parent4c9281d1036606e52390f28dc964d53acf0c44b7 (diff)
discardable pixelrefs are gone, update tests accordingly
Diffstat (limited to 'tests')
-rw-r--r--tests/DrawBitmapRectTest.cpp15
-rw-r--r--tests/ImageDecodingTest.cpp131
-rw-r--r--tests/ImageTest.cpp48
-rw-r--r--tests/JpegTest.cpp16
4 files changed, 68 insertions, 142 deletions
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index 8836a7bd5c..2eb181960b 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -13,17 +13,18 @@
#include "SkMatrixUtils.h"
#include "SkPaint.h"
#include "SkPath.h"
+#include "SkPixelRef.h"
#include "SkRandom.h"
#include "SkShader.h"
#include "SkSurface.h"
#include "Test.h"
-// A BitmapFactory that always fails when asked to return pixels.
-class FailureImageGenerator : public SkImageGenerator {
+class FailurePixelRef : public SkPixelRef {
public:
- FailureImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(100, 100)) {}
+ FailurePixelRef(const SkImageInfo& info) : SkPixelRef(info) {}
protected:
- // default onGetPixels() returns kUnimplemented, which is what we want.
+ bool onNewLockPixels(LockRec*) override { return false; }
+ void onUnlockPixels() override {}
};
// crbug.com/295895
@@ -33,9 +34,11 @@ static void test_faulty_pixelref(skiatest::Reporter* reporter) {
// need a cache, but don't expect to use it, so the budget is not critical
SkAutoTUnref<SkDiscardableMemoryPool> pool(
SkDiscardableMemoryPool::Create(10 * 1000, nullptr));
+
SkBitmap bm;
- bool success = SkInstallDiscardablePixelRef(new FailureImageGenerator, nullptr, &bm, pool);
- REPORTER_ASSERT(reporter, success);
+ const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
+ bm.setInfo(info);
+ bm.setPixelRef(new FailurePixelRef(info), 0, 0)->unref();
// now our bitmap has a pixelref, but we know it will fail to lock
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(200, 200));
diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp
index 69ed7dedad..160260d9c8 100644
--- a/tests/ImageDecodingTest.cpp
+++ b/tests/ImageDecodingTest.cpp
@@ -361,6 +361,19 @@ static const SkColor kExpectedPixels[] = {
static_assert((kExpectedWidth * kExpectedHeight) == SK_ARRAY_COUNT(kExpectedPixels),
"array_size_mismatch");
+static bool decode_into_bitmap(skiatest::Reporter* r, SkBitmap* bm, SkData* encoded) {
+ SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(encoded));
+ if (!gen) {
+ REPORTER_ASSERT(r, false);
+ return false;
+ }
+ if (!gen->tryGenerateBitmap(bm)) {
+ REPORTER_ASSERT(r, false);
+ return false;
+ }
+ return true;
+}
+
DEF_TEST(WebP, reporter) {
const unsigned char encodedWebP[] = {
0x52, 0x49, 0x46, 0x46, 0x2c, 0x01, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50,
@@ -390,69 +403,45 @@ DEF_TEST(WebP, reporter) {
0xe3, 0xfe, 0x66, 0xa4, 0x7c, 0x1b, 0x6c, 0xd1, 0xa9, 0xd8, 0x14, 0xd0,
0xc5, 0xb5, 0x39, 0x71, 0x97, 0x19, 0x19, 0x1b
};
- SkAutoDataUnref encoded(SkData::NewWithCopy(encodedWebP,
- sizeof(encodedWebP)));
- SkBitmap bm;
- bool success = SkInstallDiscardablePixelRef(encoded, &bm);
-
- REPORTER_ASSERT(reporter, success);
- if (!success) {
+ SkBitmap bm;
+ SkAutoDataUnref encoded(SkData::NewWithoutCopy(encodedWebP, sizeof(encodedWebP)));
+ if (!decode_into_bitmap(reporter, &bm, encoded)) {
+ return;
+ }
+ if (kExpectedWidth != bm.width() || kExpectedHeight != bm.height()) {
+ REPORTER_ASSERT(reporter, false);
return;
}
- SkAutoLockPixels alp(bm);
- bool rightSize = ((kExpectedWidth == bm.width())
- && (kExpectedHeight == bm.height()));
- REPORTER_ASSERT(reporter, rightSize);
- if (rightSize) {
- bool error = false;
- const SkColor* correctPixel = kExpectedPixels;
- for (int y = 0; y < bm.height(); ++y) {
- for (int x = 0; x < bm.width(); ++x) {
- error |= (*correctPixel != bm.getColor(x, y));
- ++correctPixel;
- }
+ bool error = false;
+ const SkColor* correctPixel = kExpectedPixels;
+ for (int y = 0; y < bm.height(); ++y) {
+ for (int x = 0; x < bm.width(); ++x) {
+ error |= (*correctPixel != bm.getColor(x, y));
+ ++correctPixel;
}
- REPORTER_ASSERT(reporter, !error);
}
+ REPORTER_ASSERT(reporter, !error);
}
////////////////////////////////////////////////////////////////////////////////
-// example of how Android will do this inside their BitmapFactory
-static SkPixelRef* install_pixel_ref(SkBitmap* bitmap,
- SkStreamRewindable* stream,
- int sampleSize, bool ditherImage) {
- SkASSERT(bitmap != nullptr);
- SkASSERT(stream != nullptr);
- SkASSERT(stream->rewind());
- SkColorType colorType = bitmap->colorType();
- SkDecodingImageGenerator::Options opts(sampleSize, ditherImage, colorType);
- if (SkInstallDiscardablePixelRef(
- SkDecodingImageGenerator::Create(stream, opts), bitmap)) {
- return bitmap->pixelRef();
- }
- return nullptr;
-}
/**
- * A test for the SkDecodingImageGenerator::Create and
- * SkInstallDiscardablePixelRef functions.
+ * A test for the SkDecodingImageGenerator::Create
*/
DEF_TEST(ImprovedBitmapFactory, reporter) {
SkString pngFilename = GetResourcePath("randPixels.png");
SkAutoTDelete<SkStreamRewindable> stream(SkStream::NewFromFile(pngFilename.c_str()));
if (sk_exists(pngFilename.c_str())) {
+ // example of how Android will do this inside their BitmapFactory
+ SkDecodingImageGenerator::Options opts(1, true, kN32_SkColorType);
SkBitmap bm;
- SkAssertResult(bm.setInfo(SkImageInfo::MakeN32Premul(1, 1)));
- REPORTER_ASSERT(reporter,
- install_pixel_ref(&bm, stream.detach(), 1, true));
- SkAutoLockPixels alp(bm);
- REPORTER_ASSERT(reporter, bm.getPixels());
+ SkImageGenerator* gen = SkDecodingImageGenerator::Create(stream, opts);
+ REPORTER_ASSERT(reporter, gen->tryGenerateBitmap(&bm));
}
}
-
////////////////////////////////////////////////////////////////////////////////
#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
@@ -513,23 +502,21 @@ static void test_options(skiatest::Reporter* reporter,
bool useData,
const SkString& path) {
SkBitmap bm;
- bool success = false;
+ SkImageGenerator* gen;
+
if (useData) {
if (nullptr == encodedData) {
return;
}
- success = SkInstallDiscardablePixelRef(
- SkDecodingImageGenerator::Create(encodedData, opts), &bm);
+ gen = SkDecodingImageGenerator::Create(encodedData, opts);
} else {
if (nullptr == encodedStream) {
return;
}
- success = SkInstallDiscardablePixelRef(
- SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts), &bm);
+ gen = SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts);
}
- if (!success) {
- if (opts.fUseRequestedColorType
- && (kARGB_4444_SkColorType == opts.fRequestedColorType)) {
+ if (!gen) {
+ if (opts.fUseRequestedColorType && (kARGB_4444_SkColorType == opts.fRequestedColorType)) {
return; // Ignore known conversion inabilities.
}
// If we get here, it's a failure and we will need more
@@ -539,27 +526,22 @@ static void test_options(skiatest::Reporter* reporter,
options_colorType(opts), path.c_str());
return;
}
+ if (!gen->tryGenerateBitmap(&bm)) {
+ return;
+ }
+
#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
// Android is the only system that use Skia's image decoders in
// production. For now, we'll only verify that samplesize works
// on systems where it already is known to work.
- REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight,
- opts.fSampleSize));
- REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth,
- opts.fSampleSize));
+ REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight, opts.fSampleSize));
+ REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth, opts.fSampleSize));
// The ImageDecoder API doesn't guarantee that SampleSize does
// anything at all, but the decoders that this test excercises all
// produce an output size in the following range:
// (((sample_size * out_size) > (in_size - sample_size))
// && out_size <= SkNextPow2(((in_size - 1) / sample_size) + 1));
#endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
- SkAutoLockPixels alp(bm);
- if (bm.getPixels() == nullptr) {
- ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s "
- "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage),
- options_colorType(opts), path.c_str());
- return;
- }
SkColorType requestedColorType = opts.fRequestedColorType;
REPORTER_ASSERT(reporter,
@@ -661,7 +643,7 @@ DEF_TEST(ImageDecoderOptions, reporter) {
}
}
-DEF_TEST(DiscardablePixelRef_SecondLockColorTableCheck, r) {
+DEF_TEST(DecodingImageGenerator_ColorTableCheck, r) {
SkString resourceDir = GetResourcePath();
SkString path = SkOSPath::Join(resourceDir.c_str(), "randPixels.gif");
if (!sk_exists(path.c_str())) {
@@ -669,25 +651,20 @@ DEF_TEST(DiscardablePixelRef_SecondLockColorTableCheck, r) {
}
SkAutoDataUnref encoded(SkData::NewFromFileName(path.c_str()));
SkBitmap bitmap;
- if (!SkInstallDiscardablePixelRef(
- SkDecodingImageGenerator::Create(
- encoded, SkDecodingImageGenerator::Options()), &bitmap)) {
- #ifndef SK_BUILD_FOR_WIN
- ERRORF(r, "SkInstallDiscardablePixelRef [randPixels.gif] failed.");
- #endif
+ SkImageGenerator* gen = SkDecodingImageGenerator::Create(encoded,
+ SkDecodingImageGenerator::Options());
+ if (!gen) {
+ REPORTER_ASSERT(r, false);
return;
}
- if (kIndex_8_SkColorType != bitmap.colorType()) {
+ if (!gen->tryGenerateBitmap(&bitmap)) {
+ REPORTER_ASSERT(r, false);
return;
}
- {
- SkAutoLockPixels alp(bitmap);
- REPORTER_ASSERT(r, bitmap.getColorTable() && "first pass");
- }
- {
- SkAutoLockPixels alp(bitmap);
- REPORTER_ASSERT(r, bitmap.getColorTable() && "second pass");
+ if (kIndex_8_SkColorType != bitmap.colorType()) {
+ return;
}
+ REPORTER_ASSERT(r, bitmap.getColorTable());
}
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 30e477ab53..0b27af9780 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -245,53 +245,6 @@ DEF_TEST(Image_RetainSnapshot, reporter) {
}
/////////////////////////////////////////////////////////////////////////////////////////////////
-#include "SkImageGenerator.h"
-#include "SkData.h"
-
-const uint8_t tiny_png[] = {
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
- 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64,
- 0x08, 0x06, 0x00, 0x00, 0x00, 0x70, 0xe2, 0x95, 0x54, 0x00, 0x00, 0x00,
- 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
- 0x01, 0x6b, 0x49, 0x44, 0x41, 0x54, 0x78, 0x01, 0xed, 0xd3, 0x41, 0x11,
- 0x00, 0x20, 0x0c, 0xc4, 0x40, 0xc0, 0xbf, 0xe7, 0xc2, 0xa0, 0x22, 0x8f,
- 0xad, 0x82, 0x4c, 0xd2, 0xdb, 0xf3, 0x6e, 0xb9, 0x8c, 0x81, 0x93, 0x21,
- 0x01, 0xf2, 0x0d, 0x08, 0x12, 0x7b, 0x04, 0x41, 0x04, 0x89, 0x19, 0x88,
- 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24, 0x66,
- 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44, 0x90,
- 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1, 0x10,
- 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c, 0xc7,
- 0x42, 0x04, 0x89, 0x19, 0x88, 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31,
- 0x1c, 0x0b, 0x11, 0x24, 0x66, 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c,
- 0xc4, 0x70, 0x2c, 0x44, 0x90, 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12,
- 0x33, 0x10, 0xc3, 0xb1, 0x10, 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22,
- 0x48, 0xcc, 0x40, 0x0c, 0xc7, 0x42, 0x04, 0x89, 0x19, 0x88, 0xe1, 0x58,
- 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24, 0x66, 0x20, 0x86,
- 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44, 0x90, 0x98, 0x81,
- 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1, 0x10, 0x41, 0x62,
- 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c, 0xc7, 0x42, 0x04,
- 0x89, 0x19, 0x88, 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b,
- 0x11, 0x24, 0x66, 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70,
- 0x2c, 0x44, 0x90, 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10,
- 0xc3, 0xb1, 0x10, 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc,
- 0x40, 0x0c, 0xc7, 0x42, 0x04, 0x89, 0x19, 0x88, 0xe1, 0x58, 0x88, 0x20,
- 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24, 0x66, 0x20, 0x86, 0x63, 0x21,
- 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44, 0x90, 0x98, 0x81, 0x18, 0x8e,
- 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1, 0x10, 0x41, 0x62, 0x06, 0x62,
- 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c, 0xc7, 0x42, 0x04, 0x89, 0x19,
- 0x88, 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24,
- 0x66, 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44,
- 0x90, 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1,
- 0x10, 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c,
- 0xc7, 0x42, 0x62, 0x41, 0x2e, 0x08, 0x60, 0x04, 0xc4, 0x4c, 0x5d, 0x6e,
- 0xf2, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
- 0x82
-};
-
-static void make_bitmap_lazy(SkBitmap* bm) {
- SkAutoTUnref<SkData> data(SkData::NewWithoutCopy(tiny_png, sizeof(tiny_png)));
- SkInstallDiscardablePixelRef(data, bm);
-}
static void make_bitmap_mutable(SkBitmap* bm) {
bm->allocN32Pixels(10, 10);
@@ -309,7 +262,6 @@ DEF_TEST(image_newfrombitmap, reporter) {
bool fExpectSharedID;
bool fExpectLazy;
} rec[] = {
- { make_bitmap_lazy, false, true, true },
{ make_bitmap_mutable, true, false, false },
{ make_bitmap_immutable, true, true, false },
};
diff --git a/tests/JpegTest.cpp b/tests/JpegTest.cpp
index daa932c4c9..d61b0bd311 100644
--- a/tests/JpegTest.cpp
+++ b/tests/JpegTest.cpp
@@ -457,22 +457,16 @@ DEF_TEST(Jpeg, reporter) {
DEF_TEST(Jpeg_YUV, reporter) {
size_t len = sizeof(goodJpegImage);
SkMemoryStream* stream = new SkMemoryStream(goodJpegImage, len);
-
- SkBitmap bitmap;
SkDecodingImageGenerator::Options opts;
- bool pixelsInstalled = SkInstallDiscardablePixelRef(
- SkDecodingImageGenerator::Create(stream, opts), &bitmap);
- REPORTER_ASSERT(reporter, pixelsInstalled);
-
- if (!pixelsInstalled) {
+ SkAutoTDelete<SkImageGenerator> gen(SkDecodingImageGenerator::Create(stream, opts));
+ REPORTER_ASSERT(reporter, gen);
+ if (!gen) {
return;
}
- SkPixelRef* pixelRef = bitmap.pixelRef();
SkISize yuvSizes[3];
- bool sizesComputed = (nullptr != pixelRef) && pixelRef->getYUV8Planes(yuvSizes, nullptr, nullptr, nullptr);
+ bool sizesComputed = gen->getYUV8Planes(yuvSizes, nullptr, nullptr, nullptr);
REPORTER_ASSERT(reporter, sizesComputed);
-
if (!sizesComputed) {
return;
}
@@ -495,5 +489,5 @@ DEF_TEST(Jpeg_YUV, reporter) {
planes[2] = (uint8_t*)planes[1] + sizes[1];
// Get the YUV planes
- REPORTER_ASSERT(reporter, pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes, nullptr));
+ REPORTER_ASSERT(reporter, gen->getYUV8Planes(yuvSizes, planes, rowBytes, nullptr));
}