discardable pixelrefs are gone, update tests accordingly

BUG=skia:4328

Review URL: https://codereview.chromium.org/1340803002
diff --git a/bench/ETCBitmapBench.cpp b/bench/ETCBitmapBench.cpp
index 5d72bf4..d2fc76f 100644
--- a/bench/ETCBitmapBench.cpp
+++ b/bench/ETCBitmapBench.cpp
@@ -150,26 +150,28 @@
             return;
         }
 
-        // Install pixel ref
-        if (!SkInstallDiscardablePixelRef(fPKMData, &(this->fBitmap))) {
-            SkDebugf("Could not install discardable pixel ref.\n");
-            return;
-        }
-
-        // Decompress it if necessary
-        if (this->fDecompress) {
-            this->fBitmap.lockPixels();
+        if (fDecompress) {
+            SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(fPKMData));
+            gen->generateBitmap(&fBitmap);
+        } else {
+            fImage.reset(SkImage::NewFromEncoded(fPKMData));
         }
     }
 
     void onDraw(const int loops, SkCanvas* canvas) override {
         for (int i = 0; i < loops; ++i) {
-            canvas->drawBitmap(this->fBitmap, 0, 0, nullptr);
+            if (fDecompress) {
+                canvas->drawBitmap(this->fBitmap, 0, 0, nullptr);
+            } else {
+                canvas->drawImage(fImage, 0, 0, nullptr);
+            }
         }
     }
 
 protected:
     SkBitmap fBitmap;
+    SkAutoTUnref<SkImage> fImage;
+
     bool decompress() const { return fDecompress; }
     Backend backend() const { return fBackend; }
 private:
diff --git a/gm/astcbitmap.cpp b/gm/astcbitmap.cpp
index d3191e25..211e8da 100644
--- a/gm/astcbitmap.cpp
+++ b/gm/astcbitmap.cpp
@@ -38,7 +38,6 @@
     if (idx < 0 || kNumASTCFilenames <= idx) {
         return "";
     }
-
     return kASTCFilenames[idx];
 }
 
@@ -48,28 +47,27 @@
 }  // namespace
 
 DEF_SIMPLE_GM(astcbitmap, canvas, kGMDimension, kGMDimension) {
-        for (int j = 0; j < 4; ++j) {
-            for (int i = 0; i < 4; ++i) {
-                SkString filename = GetResourcePath(get_astc_filename(j*4+i));
-                if (filename == GetResourcePath("")) {
-                    continue;
-                }
-
-                SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str()));
-                if (nullptr == fileData) {
-                    SkDebugf("Could not open the file. Did you forget to set the resourcePath?\n");
-                    return;
-                }
-
-                SkBitmap bm;
-                if (!SkInstallDiscardablePixelRef(fileData, &bm)) {
-                    SkDebugf("Could not install discardable pixel ref.\n");
-                    return;
-                }
-
+    for (int j = 0; j < 4; ++j) {
+        for (int i = 0; i < 4; ++i) {
+            SkBitmap bm;
+            if (GetResourceAsBitmap(get_astc_filename(j*4+i), &bm)) {
                 const SkScalar bmX = static_cast<SkScalar>(i*kBitmapDimension);
                 const SkScalar bmY = static_cast<SkScalar>(j*kBitmapDimension);
                 canvas->drawBitmap(bm, bmX, bmY);
             }
         }
+    }
+}
+
+DEF_SIMPLE_GM(astc_image, canvas, kGMDimension, kGMDimension) {
+    for (int j = 0; j < 4; ++j) {
+        for (int i = 0; i < 4; ++i) {
+            SkAutoTUnref<SkImage> image(GetResourceAsImage(get_astc_filename(j*4+i)));
+            if (image) {
+                const SkScalar bmX = static_cast<SkScalar>(i*kBitmapDimension);
+                const SkScalar bmY = static_cast<SkScalar>(j*kBitmapDimension);
+                canvas->drawImage(image, bmX, bmY);
+            }
+        }
+    }
 }
diff --git a/gm/etc1bitmap.cpp b/gm/etc1bitmap.cpp
index 11a700e..bbe7561 100644
--- a/gm/etc1bitmap.cpp
+++ b/gm/etc1bitmap.cpp
@@ -103,12 +103,8 @@
             return;
         }
 
-        if (!SkInstallDiscardablePixelRef(fileData, &bm)) {
-            SkDebugf("Could not install discardable pixel ref.\n");
-            return;
-        }
-
-        canvas->drawBitmap(bm, 0, 0);
+        SkAutoTUnref<SkImage> image(SkImage::NewFromEncoded(fileData));
+        canvas->drawImage(image, 0, 0);
     }
 
 private:
@@ -202,12 +198,8 @@
         size_t dataSz = etc1_get_encoded_data_size(width, height) + ETC_PKM_HEADER_SIZE;
         SkAutoDataUnref nonPOTData(SkData::NewWithCopy(am.get(), dataSz));
 
-        if (!SkInstallDiscardablePixelRef(nonPOTData, &bm)) {
-            SkDebugf("Could not install discardable pixel ref.\n");
-            return;
-        }
-
-        canvas->drawBitmap(bm, 0, 0);
+        SkAutoTUnref<SkImage> image(SkImage::NewFromEncoded(nonPOTData));
+        canvas->drawImage(image, 0, 0);
     }
 
 private:
diff --git a/gm/pictureimagegenerator.cpp b/gm/pictureimagegenerator.cpp
index 9149ec1..829006d 100644
--- a/gm/pictureimagegenerator.cpp
+++ b/gm/pictureimagegenerator.cpp
@@ -160,7 +160,7 @@
                 SkImageGenerator::NewFromPicture(configs[i].size, fPicture.get(), &m,
                                                  p.getAlpha() != 255 ? &p : nullptr));
             SkBitmap bm;
-            SkAssertResult(SkInstallDiscardablePixelRef(gen.detach(), &bm));
+            gen->generateBitmap(&bm);
 
             const SkScalar x = kDrawSize * (i % kDrawsPerRow);
             const SkScalar y = kDrawSize * (i / kDrawsPerRow);
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index 8836a7b..2eb1819 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 @@
     // 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 69ed7de..160260d 100644
--- a/tests/ImageDecodingTest.cpp
+++ b/tests/ImageDecodingTest.cpp
@@ -361,6 +361,19 @@
 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 @@
         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) {
+    SkAutoDataUnref encoded(SkData::NewWithoutCopy(encodedWebP, sizeof(encodedWebP)));
+    if (!decode_into_bitmap(reporter, &bm, encoded)) {
         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;
-            }
-        }
-        REPORTER_ASSERT(reporter, !error);
+    if (kExpectedWidth != bm.width() || kExpectedHeight != bm.height()) {
+        REPORTER_ASSERT(reporter, false);
+        return;
     }
+
+    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);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
-// 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 @@
                          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 @@
                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(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 @@
     }
     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 (!gen->tryGenerateBitmap(&bitmap)) {
+        REPORTER_ASSERT(r, false);
         return;
     }
     if (kIndex_8_SkColorType != bitmap.colorType()) {
         return;
     }
-    {
-        SkAutoLockPixels alp(bitmap);
-        REPORTER_ASSERT(r, bitmap.getColorTable() && "first pass");
-    }
-    {
-        SkAutoLockPixels alp(bitmap);
-        REPORTER_ASSERT(r, bitmap.getColorTable() && "second pass");
-    }
+    REPORTER_ASSERT(r, bitmap.getColorTable());
 }
 
 
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 30e477a..0b27af9 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -245,53 +245,6 @@
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
-#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 @@
         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 daa932c..d61b0bd 100644
--- a/tests/JpegTest.cpp
+++ b/tests/JpegTest.cpp
@@ -457,22 +457,16 @@
 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 @@
     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));
 }