Decode using the last cached required frame (#7715)

`MultiFrameCodec` now uses whatever previously cached required frame is
available instead of panicking if it doesn't have the exact frame
requested by `SkCodec::FrameInfo#fRequiredFrame`.

`SkCodec::FrameInfo#fRequiredFrame` doesn't point to the one and only
frame that's required to decode the given frame. It points to the latest
frame that's disposal method none and filling a greater surface area
than the current frame. The last required frame `MultiFrameCodec` has
actually cached is also valid in these cases and can be supplied as
`fPriorFrame` instead. [flutter/flutter#26757](https://github.com/flutter/flutter/issues/26757#issuecomment-459522530)
has a more detailed explanation.

Fixes flutter/flutter#26757
This commit is contained in:
Michael Klimushyn 2019-02-07 14:47:23 -08:00 committed by GitHub
parent 4f3eb42dfd
commit b0370c13c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -408,11 +408,15 @@ sk_sp<SkImage> MultiFrameCodec::GetNextFrameImage(
options.fFrameIndex = nextFrameIndex_;
const int requiredFrameIndex = frameInfos_[nextFrameIndex_].fRequiredFrame;
if (requiredFrameIndex != SkCodec::kNoFrame) {
if (lastRequiredFrame_ == nullptr ||
lastRequiredFrameIndex_ != requiredFrameIndex) {
if (lastRequiredFrame_ == nullptr) {
FML_LOG(ERROR) << "Frame " << nextFrameIndex_ << " depends on frame "
<< requiredFrameIndex << " which has not been cached.";
<< requiredFrameIndex
<< " and no required frames are cached.";
return NULL;
} else if (lastRequiredFrameIndex_ != requiredFrameIndex) {
FML_DLOG(INFO) << "Required frame " << requiredFrameIndex
<< " is not cached. Using " << lastRequiredFrameIndex_
<< " instead";
}
if (lastRequiredFrame_->getPixels() &&