diff options
author | scroggo <scroggo@chromium.org> | 2015-08-12 07:24:13 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-12 07:24:13 -0700 |
commit | b427db1d457a083f2652756a453fbb91bc6a7447 (patch) | |
tree | 7f75aa76f1b488fb97a5fa4222c1a04a2906a5ae /include/codec | |
parent | 4b5472bdb05404681388b5c5a4962f24a76e088b (diff) |
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
Diffstat (limited to 'include/codec')
-rw-r--r-- | include/codec/SkCodec.h | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h index ce581632e1..a0bd18a8e5 100644 --- a/include/codec/SkCodec.h +++ b/include/codec/SkCodec.h @@ -233,26 +233,27 @@ protected: virtual bool onReallyHasAlpha() const { return false; } - enum RewindState { - kRewound_RewindState, - kNoRewindNecessary_RewindState, - kCouldNotRewind_RewindState - }; /** * If the stream was previously read, attempt to rewind. - * @returns: - * kRewound if the stream needed to be rewound, and the - * rewind succeeded. - * kNoRewindNecessary if the stream did not need to be - * rewound. - * kCouldNotRewind if the stream needed to be rewound, and - * rewind failed. + * + * If the stream needed to be rewound, call onRewind. + * @returns true if the codec is at the right position and can be used. + * false if there was a failure to rewind. * * Subclasses MUST call this function before reading the stream (e.g. in * onGetPixels). If it returns false, onGetPixels should return * kCouldNotRewind. */ - RewindState SK_WARN_UNUSED_RESULT rewindIfNeeded(); + bool SK_WARN_UNUSED_RESULT rewindIfNeeded(); + + /** + * Called by rewindIfNeeded, if the stream needed to be rewound. + * + * Subclasses should do any set up needed after a rewind. + */ + virtual bool onRewind() { + return true; + } /** * Get method for the input stream |