Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: src/codec/SkCodec_libpng.cpp

Issue 1212593003: Destroy SkScanlineDecoder in the SkCodec subclass destructors (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Detachable SkScanlineDecoder Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/codec/SkCodec_libpng.cpp
diff --git a/src/codec/SkCodec_libpng.cpp b/src/codec/SkCodec_libpng.cpp
index 444e2ad87e0ae14a3bfd95746fd991f592c7ceca..32004366f839672ad8d932c3a81300834fc2305c 100644
--- a/src/codec/SkCodec_libpng.cpp
+++ b/src/codec/SkCodec_libpng.cpp
@@ -372,6 +372,12 @@ SkPngCodec::SkPngCodec(const SkImageInfo& info, SkStream* stream,
{}
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 @@ bool SkPngCodec::handleRewind() {
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 @@ public:
return SkImageGenerator::kSuccess;
}
- void onFinish() override {
- fCodec->finish();
- }
-
bool onReallyHasAlpha() const override { return fHasAlpha; }
private:
@@ -716,10 +724,6 @@ public:
return SkImageGenerator::kSuccess;
}
- void onFinish() override {
- fCodec->finish();
- }
-
bool onReallyHasAlpha() const override { return fHasAlpha; }
private:
@@ -734,7 +738,7 @@ private:
-
+
typedef SkScanlineDecoder INHERITED;
};

Powered by Google App Engine
This is Rietveld 408576698