Consolidate SkCodec functions for handling rewind
Previously, many of our codec implementations followed the same
pattern (often in a function named handleRewind):
switch (this->rewindIfNeeded()) {
case CouldNotRewind:
return CouldNotRewind;
case NoRewindNecessary:
// keep going
break;
case Rewound:
<re-read header etc>
break;
}
In this CL, remove the enum, and put the piece that happens in the
Rewound case into a virtual function, onRewind. rewindIfNeeded now
contains the common pieces from various functions named handleRewind.
In SkBmpCodec, add a function that returns whether the BMP is in ICO,
so it can have a common implementation for onRewind.
BUG=skia:3257
Review URL: https://codereview.chromium.org/1288483002
diff --git a/src/codec/SkCodec_libpng.h b/src/codec/SkCodec_libpng.h
index 21bbdad..8904022 100644
--- a/src/codec/SkCodec_libpng.h
+++ b/src/codec/SkCodec_libpng.h
@@ -35,6 +35,7 @@
Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*)
override;
SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedFormat; }
+ bool onRewind() override;
bool onReallyHasAlpha() const override { return fReallyHasAlpha; }
private:
png_structp fPng_ptr;
@@ -56,8 +57,6 @@
Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&,
SkPMColor*, int* ctableCount);
- // Calls rewindIfNeeded and returns true if the decoder can continue.
- bool handleRewind();
bool decodePalette(bool premultiply, int* ctableCount);
void destroyReadStruct();