Call rewindIfNeeded in SkCodec

Rather than calling it in each subclass, call it once in the base
class. Call it first, since other steps may modify internal structures
which would be replaced by a call to onRewind.

BUG=skia:4284

Review URL: https://codereview.chromium.org/1381483002
This commit is contained in:
scroggo 2015-09-30 09:15:14 -07:00 committed by Commit bot
parent 46c5747256
commit 3a7701c010
12 changed files with 17 additions and 52 deletions

View File

@ -402,9 +402,8 @@ protected:
* @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.
* This is called by getPixels() and start(). Subclasses may call if they
* need to rewind at another time.
*/
bool SK_WARN_UNUSED_RESULT rewindIfNeeded();

View File

@ -576,9 +576,6 @@ uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) {
SkCodec::Result SkBmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputColorCount) {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (options.fSubset) {
// Subsets are not supported.
return kUnimplemented;

View File

@ -30,9 +30,6 @@ SkCodec::Result SkBmpMaskCodec::onGetPixels(const SkImageInfo& dstInfo,
const Options& opts,
SkPMColor* inputColorPtr,
int* inputColorCount) {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (opts.fSubset) {
// Subsets are not supported.
return kUnimplemented;

View File

@ -39,9 +39,6 @@ SkCodec::Result SkBmpRLECodec::onGetPixels(const SkImageInfo& dstInfo,
const Options& opts,
SkPMColor* inputColorPtr,
int* inputColorCount) {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (opts.fSubset) {
// Subsets are not supported.
return kUnimplemented;

View File

@ -37,9 +37,6 @@ SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo,
const Options& opts,
SkPMColor* inputColorPtr,
int* inputColorCount) {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (opts.fSubset) {
// Subsets are not supported.
return kUnimplemented;

View File

@ -87,6 +87,12 @@ SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream)
SkCodec::~SkCodec() {}
bool SkCodec::rewindIfNeeded() {
if (!fStream) {
// Some codecs do not have a stream, but they hold others that do. They
// must handle rewinding themselves.
return true;
}
// Store the value of fNeedsRewind so we can update it. Next read will
// require a rewind.
const bool needsRewind = fNeedsRewind;
@ -138,6 +144,10 @@ SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
}
}
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
// Default options.
Options optsStorage;
if (nullptr == options) {
@ -172,6 +182,10 @@ SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
ctable = nullptr;
}
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
// Set options.
Options optsStorage;
if (nullptr == options) {

View File

@ -456,11 +456,6 @@ void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* inp
SkCodec::Result SkGifCodec::prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* inputColorPtr,
int* inputColorCount, const Options& opts) {
// Rewind if necessary
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
// Check for valid input parameters
if (opts.fSubset) {
// Subsets are not supported.

View File

@ -108,7 +108,7 @@ private:
int* inputColorCount);
/*
* Checks for invalid inputs and calls rewindIfNeeded(), setFramDimensions(), and
* Checks for invalid inputs and calls setFrameDimensions(), and
* initializeColorTable() in the proper sequence.
*/
Result prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* inputColorPtr,

View File

@ -477,9 +477,6 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void*
if (requestedInfo.dimensions() != this->getInfo().dimensions()) {
return kInvalidScale;
}
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
// Note that ctable and ctableCount may be modified if there is a color table
const Result result = this->initializeSwizzler(requestedInfo, options,
@ -592,10 +589,6 @@ public:
Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
SkPMColor ctable[], int* ctableCount) override {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (!conversion_possible(dstInfo, this->getInfo())) {
return kInvalidConversion;
}
@ -690,10 +683,6 @@ public:
Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
SkPMColor ctable[], int* ctableCount) override
{
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (!conversion_possible(dstInfo, this->getInfo())) {
return kInvalidConversion;
}

View File

@ -110,9 +110,6 @@ SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
const Options& options,
SkPMColor ctable[],
int* ctableCount) {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (options.fSubset) {
// Subsets are not supported.
return kUnimplemented;
@ -180,9 +177,6 @@ SkCodec::Result SkWbmpCodec::onGetScanlines(void* dst, int count, size_t dstRowB
SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
const Options& options, SkPMColor inputColorTable[], int* inputColorCount) {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (options.fSubset) {
// Subsets are not supported.
return kUnimplemented;

View File

@ -303,11 +303,6 @@ bool SkJpegCodec::nativelyScaleToDimensions(uint32_t dstWidth, uint32_t dstHeigh
SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
void* dst, size_t dstRowBytes,
const Options& options, SkPMColor*, int*) {
// Rewind the stream if needed
if (!this->rewindIfNeeded()) {
return fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRewind);
}
if (options.fSubset) {
// Subsets are not supported.
return kUnimplemented;
@ -412,11 +407,6 @@ SkCodec::Result SkJpegCodec::initializeSwizzler(const SkImageInfo& info, const O
SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
const Options& options, SkPMColor ctable[], int* ctableCount) {
// Rewind the stream if needed
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
// Set the jump location for libjpeg errors
if (setjmp(fDecoderMgr->getJmpBuf())) {
SkCodecPrintf("setjmp: Error from libjpeg\n");

View File

@ -152,10 +152,6 @@ bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const {
SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
const Options& options, SkPMColor*, int*) {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
if (!webp_conversion_possible(dstInfo, this->getInfo())) {
return kInvalidConversion;
}