From 8e3ad2d8099f68884701c7c7c278872299df861e Mon Sep 17 00:00:00 2001 From: Zan Dobersek Date: Tue, 30 Oct 2018 20:53:02 +0100 Subject: [PATCH] ScalableImageDecoder: avoid unnecessarily decoding image data. --- .../image-decoders/ScalableImageDecoder.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp b/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp index 6cbe7ad0c978d..d7d35aad86782 100644 --- a/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp +++ b/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp @@ -172,11 +172,10 @@ template int getScaledValue(const Vector& scaledValues, in bool ScalableImageDecoder::frameIsCompleteAtIndex(size_t index) const { - // FIXME(176089): asking whether enough data has been appended for a decode - // operation to succeed should not require decoding the entire frame. - // This function should be implementable in a way that allows const. - ImageFrame* buffer = const_cast(this)->frameBufferAtIndex(index); - return buffer && buffer->isComplete(); + if (index >= m_frameBufferCache.size()) + return false; + + return m_frameBufferCache[index].isComplete(); } bool ScalableImageDecoder::frameHasAlphaAtIndex(size_t index) const @@ -198,9 +197,13 @@ unsigned ScalableImageDecoder::frameBytesAtIndex(size_t index, SubsamplingLevel) Seconds ScalableImageDecoder::frameDurationAtIndex(size_t index) const { - // FIXME(176089): asking for the duration of a sub-image should not require decoding - // the entire frame. This function should be implementable in a way that - // allows const. + if (index >= m_frameBufferCache.size()) + return 0_s; + + auto& frame = m_frameBufferCache[index]; + if (!frame.isComplete()) + return 0_s; + ImageFrame* buffer = const_cast(this)->frameBufferAtIndex(index); if (!buffer || buffer->isInvalid()) return 0_s;