| Index: tests/DrawBitmapRectTest.cpp
|
| diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
|
| index ab667fdfae1635f784cead108074fbf1e8e1a700..fc98c21481cdcfab3e6a676a835c96559cbdb861 100644
|
| --- a/tests/DrawBitmapRectTest.cpp
|
| +++ b/tests/DrawBitmapRectTest.cpp
|
| @@ -18,18 +18,26 @@
|
| #include "SkLazyPixelRef.h"
|
| #include "SkLruImageCache.h"
|
|
|
| -// A BitmapFactory that always fails when asked to return pixels.
|
| -static bool FailureDecoder(const void* data, size_t length, SkImageInfo* info,
|
| - const SkBitmapFactory::Target* target) {
|
| - if (info) {
|
| - info->fWidth = info->fHeight = 100;
|
| - info->fColorType = kRGBA_8888_SkColorType;
|
| - info->fAlphaType = kPremul_SkAlphaType;
|
| +
|
| +namespace {
|
| +// A SkImageGenerator that always fails when asked to return pixels.
|
| +class FailureImageGenerator : public SkImageGenerator {
|
| +public:
|
| + FailureImageGenerator() { }
|
| + virtual ~FailureImageGenerator() { }
|
| + virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE {
|
| + if (info) {
|
| + info->fWidth = info->fHeight = 100;
|
| + info->fColorType = kRGBA_8888_SkColorType;
|
| + info->fAlphaType = kPremul_SkAlphaType;
|
| + }
|
| + return true;
|
| }
|
| - // this will deliberately return false if they are asking us to decode
|
| - // into pixels.
|
| - return NULL == target;
|
| -}
|
| + virtual bool getPixels(const SkImageInfo&, void*, size_t) SK_OVERRIDE {
|
| + return false;
|
| + }
|
| +};
|
| +} // namespace
|
|
|
| // crbug.com/295895
|
| // Crashing in skia when a pixelref fails in lockPixels
|
| @@ -39,11 +47,11 @@ static void test_faulty_pixelref(skiatest::Reporter* reporter) {
|
| SkLruImageCache cache(10 * 1000);
|
| // construct a garbage data represent "bad" encoded data.
|
| SkAutoDataUnref data(SkData::NewFromMalloc(malloc(1000), 1000));
|
| - SkAutoTUnref<SkPixelRef> pr(new SkLazyPixelRef(data, FailureDecoder, &cache));
|
|
|
| + FailureImageGenerator* gen(SkNEW(FailureImageGenerator));
|
| SkBitmap bm;
|
| - bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
|
| - bm.setPixelRef(pr);
|
| + bool lazyPixelRefSuccess = SkLazyPixelRef::Install(gen, &cache, &bm);
|
| + REPORTER_ASSERT(reporter, lazyPixelRefSuccess);
|
| // now our bitmap has a pixelref, but we know it will fail to lock
|
|
|
| SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200));
|
| @@ -66,25 +74,25 @@ static void test_faulty_pixelref(skiatest::Reporter* reporter) {
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| -static void rand_matrix(SkMatrix* mat, SkRandom& rand, unsigned mask) {
|
| +static void rand_matrix(SkMatrix* mat, SkRandom* rand, unsigned mask) {
|
| mat->setIdentity();
|
| if (mask & SkMatrix::kTranslate_Mask) {
|
| - mat->postTranslate(rand.nextSScalar1(), rand.nextSScalar1());
|
| + mat->postTranslate(rand->nextSScalar1(), rand->nextSScalar1());
|
| }
|
| if (mask & SkMatrix::kScale_Mask) {
|
| - mat->postScale(rand.nextSScalar1(), rand.nextSScalar1());
|
| + mat->postScale(rand->nextSScalar1(), rand->nextSScalar1());
|
| }
|
| if (mask & SkMatrix::kAffine_Mask) {
|
| - mat->postRotate(rand.nextSScalar1() * 360);
|
| + mat->postRotate(rand->nextSScalar1() * 360);
|
| }
|
| if (mask & SkMatrix::kPerspective_Mask) {
|
| - mat->setPerspX(rand.nextSScalar1());
|
| - mat->setPerspY(rand.nextSScalar1());
|
| + mat->setPerspX(rand->nextSScalar1());
|
| + mat->setPerspY(rand->nextSScalar1());
|
| }
|
| }
|
|
|
| -static void rand_size(SkISize* size, SkRandom& rand) {
|
| - size->set(rand.nextU() & 0xFFFF, rand.nextU() & 0xFFFF);
|
| +static void rand_size(SkISize* size, SkRandom* rand) {
|
| + size->set(rand->nextU() & 0xFFFF, rand->nextU() & 0xFFFF);
|
| }
|
|
|
| static bool treat_as_sprite(const SkMatrix& mat, const SkISize& size,
|
| @@ -101,18 +109,18 @@ static void test_treatAsSprite(skiatest::Reporter* reporter) {
|
|
|
| // assert: translate-only no-filter can always be treated as sprite
|
| for (int i = 0; i < 1000; ++i) {
|
| - rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask);
|
| + rand_matrix(&mat, &rand, SkMatrix::kTranslate_Mask);
|
| for (int j = 0; j < 1000; ++j) {
|
| - rand_size(&size, rand);
|
| + rand_size(&size, &rand);
|
| REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, 0));
|
| }
|
| }
|
|
|
| // assert: rotate/perspect is never treated as sprite
|
| for (int i = 0; i < 1000; ++i) {
|
| - rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask);
|
| + rand_matrix(&mat, &rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask);
|
| for (int j = 0; j < 1000; ++j) {
|
| - rand_size(&size, rand);
|
| + rand_size(&size, &rand);
|
| REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, 0));
|
| REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
|
| }
|
|
|