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

Unified Diff: src/codec/SkCodec_libpng.cpp

Issue 1050893002: SkCodec::onGetScanlineDecoder must call rewind. (Closed) Base URL: https://skia.googlesource.com/skia.git@pngRewind
Patch Set: All codecs can now rewind. Remove code to support unrewindable codecs. Created 5 years, 9 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
« no previous file with comments | « src/codec/SkCodec_libpng.h ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodec_libpng.cpp
diff --git a/src/codec/SkCodec_libpng.cpp b/src/codec/SkCodec_libpng.cpp
index 18574f70be705ae15a2ae959006d6399b86b2cea..33111cee67841938335fd6f7b0862d5f9ec0a9c6 100644
--- a/src/codec/SkCodec_libpng.cpp
+++ b/src/codec/SkCodec_libpng.cpp
@@ -450,27 +450,39 @@ SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
return kSuccess;
}
+bool SkPngCodec::handleRewind() {
+ switch (this->rewindIfNeeded()) {
+ case kNoRewindNecessary_RewindState:
+ return true;
+ case kCouldNotRewind_RewindState:
+ return false;
+ case kRewound_RewindState: {
+ // This sets fPng_ptr and fInfo_ptr to NULL. If read_header
+ // succeeds, they will be repopulated, and if it fails, they will
+ // remain NULL. Any future accesses to fPng_ptr and fInfo_ptr will
+ // come through this function which will rewind and again attempt
+ // to reinitialize them.
+ this->destroyReadStruct();
+ png_structp png_ptr;
+ png_infop info_ptr;
+ if (read_header(this->stream(), &png_ptr, &info_ptr, NULL)) {
+ fPng_ptr = png_ptr;
+ fInfo_ptr = info_ptr;
+ return true;
+ }
+ return false;
+ }
+ default:
+ SkASSERT(false);
+ return false;
+ }
+}
+
SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void* dst,
size_t rowBytes, const Options& options,
SkPMColor ctable[], int* ctableCount) {
- SkCodec::RewindState rewindState = this->rewindIfNeeded();
- if (rewindState == kCouldNotRewind_RewindState) {
+ if (!this->handleRewind()) {
return kCouldNotRewind;
- } else if (rewindState == kRewound_RewindState) {
- // This sets fPng_ptr and fInfo_ptr to NULL. If read_header succeeds,
- // they will be repopulated, and if it fails, they will remain NULL.
- // Any future accesses to fPng_ptr and fInfo_ptr will come through this
- // function which will rewind and again attempt to reinitialize them.
- this->destroyReadStruct();
- png_structp png_ptr;
- png_infop info_ptr;
- if (read_header(this->stream(), &png_ptr, &info_ptr, NULL)) {
- fPng_ptr = png_ptr;
- fInfo_ptr = info_ptr;
- } else {
- return kCouldNotRewind;
- }
-
}
if (requestedInfo.dimensions() != this->getInfo().dimensions()) {
return kInvalidScale;
@@ -598,6 +610,10 @@ private:
};
SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo) {
+ if (!this->handleRewind()) {
+ return NULL;
+ }
+
// Check to see if scaling was requested.
if (dstInfo.dimensions() != this->getInfo().dimensions()) {
return NULL;
« no previous file with comments | « src/codec/SkCodec_libpng.h ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698