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_wbmp.cpp b/src/codec/SkCodec_wbmp.cpp
index 86dce5c..52535e1 100644
--- a/src/codec/SkCodec_wbmp.cpp
+++ b/src/codec/SkCodec_wbmp.cpp
@@ -66,16 +66,8 @@
return true;
}
-bool SkWbmpCodec::handleRewind() {
- SkCodec::RewindState rewindState = this->rewindIfNeeded();
- if (rewindState == kCouldNotRewind_RewindState) {
- return false;
- } else if (rewindState == kRewound_RewindState) {
- if (!read_header(this->stream(), NULL)) {
- return false;
- }
- }
- return true;
+bool SkWbmpCodec::onRewind() {
+ return read_header(this->stream(), NULL);
}
SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info,
@@ -117,7 +109,7 @@
const Options& options,
SkPMColor ctable[],
int* ctableCount) {
- if (!this->handleRewind()) {
+ if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (options.fSubset) {
@@ -197,7 +189,7 @@
SkCodec::Result onStart(const SkImageInfo& dstInfo,
const SkCodec::Options& options, SkPMColor inputColorTable[],
int* inputColorCount) {
- if (!fCodec->handleRewind()) {
+ if (!fCodec->rewindIfNeeded()) {
return SkCodec::kCouldNotRewind;
}
if (options.fSubset) {