Changeset 267016 in webkit


Ignore:
Timestamp:
Sep 14, 2020 9:22:29 AM (4 years ago)
Author:
commit-queue@webkit.org
Message:

[CG] Cache the last status of the image encoded data
https://bugs.webkit.org/show_bug.cgi?id=216104

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2020-09-14
Reviewed by Youenn Fablet.

Cache the last status of the image encoded data such that early decisions
can be made without calling system functions.

  • platform/graphics/cg/ImageDecoderCG.cpp:

(WebCore::ImageDecoderCG::encodedDataStatus const):

  • platform/graphics/cg/ImageDecoderCG.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r267014 r267016  
     12020-09-14  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        [CG] Cache the last status of the image encoded data
     4        https://bugs.webkit.org/show_bug.cgi?id=216104
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Cache the last status of the image encoded data such that early decisions
     9        can be made without calling system functions.
     10
     11        * platform/graphics/cg/ImageDecoderCG.cpp:
     12        (WebCore::ImageDecoderCG::encodedDataStatus const):
     13        * platform/graphics/cg/ImageDecoderCG.h:
     14
    1152020-09-14  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp

    r266827 r267016  
    226226EncodedDataStatus ImageDecoderCG::encodedDataStatus() const
    227227{
     228    if (m_encodedDataStatus == EncodedDataStatus::Error || m_encodedDataStatus == EncodedDataStatus::Complete)
     229        return m_encodedDataStatus;
     230
     231    // The image source UTI can be changed while receiving more encoded data.
    228232    String uti = this->uti();
    229233    if (uti.isEmpty())
    230234        return EncodedDataStatus::Unknown;
    231235
     236    if (!isSupportedImageType(uti)) {
     237        m_encodedDataStatus = EncodedDataStatus::Error;
     238        return m_encodedDataStatus;
     239    }
     240
    232241    switch (CGImageSourceGetStatus(m_nativeDecoder.get())) {
    233242    case kCGImageStatusUnknownType:
    234         return EncodedDataStatus::Error;
     243        m_encodedDataStatus = EncodedDataStatus::Error;
     244        break;
    235245
    236246    case kCGImageStatusUnexpectedEOF:
     
    239249        // Ragnaros yells: TOO SOON! You have awakened me TOO SOON, Executus!
    240250        if (!m_isAllDataReceived)
    241             return EncodedDataStatus::Unknown;
    242 
    243         return EncodedDataStatus::Error;
     251            m_encodedDataStatus = EncodedDataStatus::Unknown;
     252        else
     253            m_encodedDataStatus = EncodedDataStatus::Error;
     254        break;
    244255
    245256    case kCGImageStatusIncomplete: {
    246         if (!isSupportedImageType(uti))
    247             return EncodedDataStatus::Error;
    248 
    249         RetainPtr<CFDictionaryRef> image0Properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), 0, imageSourceOptions().get()));
    250         if (!image0Properties)
    251             return EncodedDataStatus::TypeAvailable;
    252        
    253         if (!CFDictionaryContainsKey(image0Properties.get(), kCGImagePropertyPixelWidth) || !CFDictionaryContainsKey(image0Properties.get(), kCGImagePropertyPixelHeight))
    254             return EncodedDataStatus::TypeAvailable;
    255        
    256         return EncodedDataStatus::SizeAvailable;
     257        if (m_encodedDataStatus == EncodedDataStatus::SizeAvailable)
     258            break;
     259
     260        auto image0Properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), 0, imageSourceOptions().get()));
     261        if (!image0Properties || !CFDictionaryContainsKey(image0Properties.get(), kCGImagePropertyPixelWidth) || !CFDictionaryContainsKey(image0Properties.get(), kCGImagePropertyPixelHeight)) {
     262            m_encodedDataStatus = EncodedDataStatus::TypeAvailable;
     263            break;
     264        }
     265
     266        m_encodedDataStatus = EncodedDataStatus::SizeAvailable;
     267        break;
    257268    }
    258269
    259270    case kCGImageStatusComplete:
    260         if (!isSupportedImageType(uti))
    261             return EncodedDataStatus::Error;
    262 
    263         return EncodedDataStatus::Complete;
     271        m_encodedDataStatus = EncodedDataStatus::Complete;
     272        break;
    264273    }
    265274
    266     ASSERT_NOT_REACHED();
    267     return EncodedDataStatus::Unknown;
     275    return m_encodedDataStatus;
    268276}
    269277
  • trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h

    r260415 r267016  
    7070private:
    7171    bool m_isAllDataReceived { false };
     72    mutable EncodedDataStatus m_encodedDataStatus { EncodedDataStatus::Unknown };
    7273    RetainPtr<CGImageSourceRef> m_nativeDecoder;
    7374};
Note: See TracChangeset for help on using the changeset viewer.