In the case of subset decodes, we will often not decode to
the bottom of the image.  In our code before this patch,
this would result in cleanup code in onFinish() never being
called.

We can allow subclasses to take ownership of the
SkScanlineDecoder in order to make sure that it is
finished/deleted before deleting the decode manager.

BUG=skia:

Review URL: https://codereview.chromium.org/1212593003
diff --git a/src/codec/SkCodec_libpng.cpp b/src/codec/SkCodec_libpng.cpp
index 444e2ad..3200436 100644
--- a/src/codec/SkCodec_libpng.cpp
+++ b/src/codec/SkCodec_libpng.cpp
@@ -372,6 +372,12 @@
 {}
 
 SkPngCodec::~SkPngCodec() {
+    // First, ensure that the scanline decoder is left in a finished state.
+    SkAutoTDelete<SkScanlineDecoder> decoder(this->detachScanlineDecoder());
+    if (NULL != decoder) {
+        this->finish();
+    }
+
     this->destroyReadStruct();
 }
 
@@ -514,6 +520,12 @@
 SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void* dst,
                                         size_t rowBytes, const Options& options,
                                         SkPMColor ctable[], int* ctableCount) {
+    // Do not allow a regular decode if the caller has asked for a scanline decoder
+    if (NULL != this->scanlineDecoder()) {
+        SkCodecPrintf("cannot getPixels() if a scanline decoder has been created\n");
+        return kInvalidParameters;
+    }
+
     if (!this->handleRewind()) {
         return kCouldNotRewind;
     }
@@ -633,10 +645,6 @@
         return SkImageGenerator::kSuccess;
     }
 
-    void onFinish() override {
-        fCodec->finish();
-    }
-
     bool onReallyHasAlpha() const override { return fHasAlpha; }
 
 private:
@@ -716,10 +724,6 @@
         return SkImageGenerator::kSuccess;
     }
 
-    void onFinish() override {
-        fCodec->finish();
-    }
-
     bool onReallyHasAlpha() const override { return fHasAlpha; }
 
 private:
@@ -734,7 +738,7 @@
     
     
     
-    
+
 
     typedef SkScanlineDecoder INHERITED;
 };