Changeset 238275 in webkit


Ignore:
Timestamp:
Nov 16, 2018 2:57:17 AM (5 years ago)
Author:
zandobersek@gmail.com
Message:

ScalableImageDecoder: don't forcefully decode image data when querying frame completeness, duration
https://bugs.webkit.org/show_bug.cgi?id=191354

Reviewed by Michael Catanzaro.

ScalableImageDecoder::frameIsCompleteAtIndex() should only check the
index validity and, if the index is valid, check for completeness of the
corresponding frame. ScalableImageDecoder::frameDurationAtIndex() should
also only retrieve duration for already-complete frames.

Both methods avoid calling ScalableImageDecoder::frameBufferAtIndex()
as that method goes on and decodes image data to determine specific
information. The ImageSource class that's querying this information
doesn't anticipate this, and doesn't handle the increased memory
consumption of the decoded data, leaving MemoryCache in the blind about
the image resource's actual amount of consumed memory. ImageSource can
instead gracefully handle any incomplete frame by marking the decoding
status for this frame as only partial.

  • platform/image-decoders/ScalableImageDecoder.cpp:

(WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const):
(WebCore::ScalableImageDecoder::frameHasAlphaAtIndex const):
(WebCore::ScalableImageDecoder::frameDurationAtIndex const):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r238274 r238275  
     12018-11-16  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        ScalableImageDecoder: don't forcefully decode image data when querying frame completeness, duration
     4        https://bugs.webkit.org/show_bug.cgi?id=191354
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        ScalableImageDecoder::frameIsCompleteAtIndex() should only check the
     9        index validity and, if the index is valid, check for completeness of the
     10        corresponding frame. ScalableImageDecoder::frameDurationAtIndex() should
     11        also only retrieve duration for already-complete frames.
     12
     13        Both methods avoid calling ScalableImageDecoder::frameBufferAtIndex()
     14        as that method goes on and decodes image data to determine specific
     15        information. The ImageSource class that's querying this information
     16        doesn't anticipate this, and doesn't handle the increased memory
     17        consumption of the decoded data, leaving MemoryCache in the blind about
     18        the image resource's actual amount of consumed memory. ImageSource can
     19        instead gracefully handle any incomplete frame by marking the decoding
     20        status for this frame as only partial.
     21
     22        * platform/image-decoders/ScalableImageDecoder.cpp:
     23        (WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const):
     24        (WebCore::ScalableImageDecoder::frameHasAlphaAtIndex const):
     25        (WebCore::ScalableImageDecoder::frameDurationAtIndex const):
     26
    1272018-11-16  Antoine Quint  <graouts@apple.com>
    228
  • trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp

    r230522 r238275  
    174174{
    175175    LockHolder lockHolder(m_mutex);
    176     // FIXME(176089): asking whether enough data has been appended for a decode
    177     // operation to succeed should not require decoding the entire frame.
    178     // This function should be implementable in a way that allows const.
    179     auto* buffer = const_cast<ScalableImageDecoder*>(this)->frameBufferAtIndex(index);
    180     return buffer && buffer->isComplete();
     176    if (index >= m_frameBufferCache.size())
     177        return false;
     178
     179    auto& frame = m_frameBufferCache[index];
     180    return frame.isComplete();
    181181}
    182182
     
    186186    if (m_frameBufferCache.size() <= index)
    187187        return true;
    188     if (m_frameBufferCache[index].isComplete())
    189         return m_frameBufferCache[index].hasAlpha();
    190     return true;
     188
     189    auto& frame = m_frameBufferCache[index];
     190    if (!frame.isComplete())
     191        return true;
     192    return frame.hasAlpha();
    191193}
    192194
     
    203205{
    204206    LockHolder lockHolder(m_mutex);
    205     // FIXME(176089): asking for the duration of a sub-image should not require decoding
    206     // the entire frame. This function should be implementable in a way that
    207     // allows const.
    208     auto* buffer = const_cast<ScalableImageDecoder*>(this)->frameBufferAtIndex(index);
    209     if (!buffer || buffer->isInvalid())
     207    if (index >= m_frameBufferCache.size())
    210208        return 0_s;
    211    
     209
     210    auto& frame = m_frameBufferCache[index];
     211    if (!frame.isComplete())
     212        return 0_s;
     213
    212214    // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
    213215    // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
    214216    // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
    215217    // for more information.
    216     if (buffer->duration() < 11_ms)
     218    auto duration = frame.duration();
     219    if (duration < 11_ms)
    217220        return 100_ms;
    218     return buffer->duration();
     221    return duration;
    219222}
    220223
Note: See TracChangeset for help on using the changeset viewer.