Changeset 222151 in webkit


Ignore:
Timestamp:
Sep 18, 2017 9:24:59 AM (7 years ago)
Author:
jer.noble@apple.com
Message:

Virtualize ImageDecoder
https://bugs.webkit.org/show_bug.cgi?id=176118

Reviewed by Eric Carlson.

Add an explicit, abstract base class ImageDecoder, and convert ImageDecoderCG to a true
subclass. This will allow multiple ImageDecoder subclasses to exist simultaneously at
runtime.

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/ImageDecoders.cmake:
  • platform/graphics/ImageDecoder.cpp: Added.

(WebCore::ImageDecoder::create):
(WebCore::ImageDecoder::bytesDecodedToDetermineProperties):

  • platform/graphics/ImageDecoder.h: Added.

(WebCore::ImageDecoder::isSizeAvailable):
(WebCore::ImageDecoder::isAllDataReceived const):

  • platform/graphics/cg/ImageDecoderCG.cpp:

(WebCore::ImageDecoderCG::ImageDecoderCG):
(WebCore::ImageDecoderCG::bytesDecodedToDetermineProperties):
(WebCore::ImageDecoderCG::uti const):
(WebCore::ImageDecoderCG::filenameExtension const):
(WebCore::ImageDecoderCG::encodedDataStatus const):
(WebCore::ImageDecoderCG::frameCount const):
(WebCore::ImageDecoderCG::repetitionCount const):
(WebCore::ImageDecoderCG::hotSpot const):
(WebCore::ImageDecoderCG::frameSizeAtIndex const):
(WebCore::ImageDecoderCG::frameIsCompleteAtIndex const):
(WebCore::ImageDecoderCG::frameOrientationAtIndex const):
(WebCore::ImageDecoderCG::frameDurationAtIndex const):
(WebCore::ImageDecoderCG::frameAllowSubsamplingAtIndex const):
(WebCore::ImageDecoderCG::frameHasAlphaAtIndex const):
(WebCore::ImageDecoderCG::frameBytesAtIndex const):
(WebCore::ImageDecoderCG::createFrameImageAtIndex const):
(WebCore::ImageDecoderCG::setData):
(WebCore::ImageDecoder::ImageDecoder): Deleted.
(WebCore::ImageDecoder::bytesDecodedToDetermineProperties): Deleted.
(WebCore::ImageDecoder::uti const): Deleted.
(WebCore::ImageDecoder::filenameExtension const): Deleted.
(WebCore::ImageDecoder::encodedDataStatus const): Deleted.
(WebCore::ImageDecoder::frameCount const): Deleted.
(WebCore::ImageDecoder::repetitionCount const): Deleted.
(WebCore::ImageDecoder::hotSpot const): Deleted.
(WebCore::ImageDecoder::frameSizeAtIndex const): Deleted.
(WebCore::ImageDecoder::frameIsCompleteAtIndex const): Deleted.
(WebCore::ImageDecoder::frameOrientationAtIndex const): Deleted.
(WebCore::ImageDecoder::frameDurationAtIndex const): Deleted.
(WebCore::ImageDecoder::frameAllowSubsamplingAtIndex const): Deleted.
(WebCore::ImageDecoder::frameHasAlphaAtIndex const): Deleted.
(WebCore::ImageDecoder::frameBytesAtIndex const): Deleted.
(WebCore::ImageDecoder::createFrameImageAtIndex const): Deleted.
(WebCore::ImageDecoder::setData): Deleted.

  • platform/graphics/cg/ImageDecoderCG.h:

(WebCore::ImageDecoderCG::create):
(WebCore::ImageDecoder::create): Deleted.
(WebCore::ImageDecoder::isSizeAvailable): Deleted.
(WebCore::ImageDecoder::isAllDataReceived const): Deleted.
(WebCore::ImageDecoder::clearFrameBufferCache): Deleted.

  • platform/graphics/win/ImageDecoderDirect2D.cpp:

(WebCore::ImageDecoderDirect2D::ImageDecoderDirect2D):
(WebCore::ImageDecoderDirect2D::systemImagingFactory):
(WebCore::ImageDecoderDirect2D::bytesDecodedToDetermineProperties):
(WebCore::ImageDecoderDirect2D::filenameExtension const):
(WebCore::ImageDecoderDirect2D::isSizeAvailable const):
(WebCore::ImageDecoderDirect2D::encodedDataStatus const):
(WebCore::ImageDecoderDirect2D::size const):
(WebCore::ImageDecoderDirect2D::frameCount const):
(WebCore::ImageDecoderDirect2D::repetitionCount const):
(WebCore::ImageDecoderDirect2D::hotSpot const):
(WebCore::ImageDecoderDirect2D::frameSizeAtIndex const):
(WebCore::ImageDecoderDirect2D::frameIsCompleteAtIndex const):
(WebCore::ImageDecoderDirect2D::frameOrientationAtIndex const):
(WebCore::ImageDecoderDirect2D::frameDurationAtIndex const):
(WebCore::ImageDecoderDirect2D::frameAllowSubsamplingAtIndex const):
(WebCore::ImageDecoderDirect2D::frameHasAlphaAtIndex const):
(WebCore::ImageDecoderDirect2D::frameBytesAtIndex const):
(WebCore::ImageDecoderDirect2D::setTargetContext):
(WebCore::ImageDecoderDirect2D::createFrameImageAtIndex const):
(WebCore::ImageDecoderDirect2D::setData):

  • platform/graphics/win/ImageDecoderDirect2D.h:

(WebCore::ImageDecoderDirect2D::create):
(WebCore::ImageDecoder::create): Deleted.
(WebCore::ImageDecoder::isAllDataReceived const): Deleted.
(WebCore::ImageDecoder::clearFrameBufferCache): Deleted.

  • platform/image-decoders/ScalableImageDecoder.cpp: Renamed from Source/WebCore/platform/image-decoders/ImageDecoder.cpp.

(WebCore::ScalableImageDecoder::create):
(WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const):
(WebCore::ScalableImageDecoder::frameHasAlphaAtIndex const):
(WebCore::ScalableImageDecoder::frameBytesAtIndex const):
(WebCore::ScalableImageDecoder::frameDurationAtIndex const):
(WebCore::ScalableImageDecoder::createFrameImageAtIndex):
(WebCore::ScalableImageDecoder::prepareScaleDataIfNecessary):
(WebCore::ScalableImageDecoder::upperBoundScaledX):
(WebCore::ScalableImageDecoder::lowerBoundScaledX):
(WebCore::ScalableImageDecoder::upperBoundScaledY):
(WebCore::ScalableImageDecoder::lowerBoundScaledY):
(WebCore::ScalableImageDecoder::scaledY):

  • platform/image-decoders/ScalableImageDecoder.h: Renamed from Source/WebCore/platform/image-decoders/ImageDecoder.h.

(WebCore::ScalableImageDecoder::ScalableImageDecoder):
(WebCore::ScalableImageDecoder::~ScalableImageDecoder):
(WebCore::ScalableImageDecoder::premultiplyAlpha const):
(WebCore::ScalableImageDecoder::isAllDataReceived const):
(WebCore::ScalableImageDecoder::size const):
(WebCore::ScalableImageDecoder::scaledSize):
(WebCore::ScalableImageDecoder::setSize):
(WebCore::ScalableImageDecoder::setIgnoreGammaAndColorProfile):
(WebCore::ScalableImageDecoder::ignoresGammaAndColorProfile const):
(WebCore::ScalableImageDecoder::rgbColorProfile):
(WebCore::ScalableImageDecoder::subsamplingLevelForScale):
(WebCore::ScalableImageDecoder::inputDeviceColorProfile):
(WebCore::ScalableImageDecoder::setFailed):
(WebCore::ScalableImageDecoder::failed const):

  • platform/image-decoders/bmp/BMPImageDecoder.cpp:

(WebCore::BMPImageDecoder::BMPImageDecoder):
(WebCore::BMPImageDecoder::setData):
(WebCore::BMPImageDecoder::setFailed):

  • platform/image-decoders/bmp/BMPImageDecoder.h:
  • platform/image-decoders/bmp/BMPImageReader.h:
  • platform/image-decoders/gif/GIFImageDecoder.cpp:

(WebCore::GIFImageDecoder::GIFImageDecoder):
(WebCore::GIFImageDecoder::setData):
(WebCore::GIFImageDecoder::setSize):
(WebCore::GIFImageDecoder::setFailed):

  • platform/image-decoders/gif/GIFImageDecoder.h:
  • platform/image-decoders/ico/ICOImageDecoder.cpp:

(WebCore::ICOImageDecoder::ICOImageDecoder):
(WebCore::ICOImageDecoder::setData):
(WebCore::ICOImageDecoder::size):
(WebCore::ICOImageDecoder::setSize):
(WebCore::ICOImageDecoder::setFailed):

  • platform/image-decoders/ico/ICOImageDecoder.h:
  • platform/image-decoders/jpeg/JPEGImageDecoder.cpp:

(WebCore::JPEGImageDecoder::JPEGImageDecoder):
(WebCore::JPEGImageDecoder::setSize):
(WebCore::JPEGImageDecoder::setFailed):

  • platform/image-decoders/jpeg/JPEGImageDecoder.h:
  • platform/image-decoders/png/PNGImageDecoder.cpp:

(WebCore::PNGImageReader::decode):
(WebCore::PNGImageDecoder::PNGImageDecoder):
(WebCore::PNGImageDecoder::setSize):
(WebCore::PNGImageDecoder::frameBufferAtIndex):
(WebCore::PNGImageDecoder::setFailed):

  • platform/image-decoders/png/PNGImageDecoder.h:
  • platform/image-decoders/webp/WEBPImageDecoder.cpp:

(WebCore::WEBPImageDecoder::WEBPImageDecoder):
(WebCore::WEBPImageDecoder::decode):

  • platform/image-decoders/webp/WEBPImageDecoder.h:
Location:
trunk/Source/WebCore
Files:
2 added
22 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r222103 r222151  
    24492449    platform/graphics/Image.cpp
    24502450    platform/graphics/ImageBuffer.cpp
     2451    platform/graphics/ImageDecoder.cpp
    24512452    platform/graphics/ImageFrame.cpp
    24522453    platform/graphics/ImageFrameCache.cpp
  • trunk/Source/WebCore/ChangeLog

    r222150 r222151  
     12017-09-18  Jer Noble  <jer.noble@apple.com>
     2
     3        Virtualize ImageDecoder
     4        https://bugs.webkit.org/show_bug.cgi?id=176118
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add an explicit, abstract base class ImageDecoder, and convert ImageDecoderCG to a true
     9        subclass. This will allow multiple ImageDecoder subclasses to exist simultaneously at
     10        runtime.
     11
     12        * CMakeLists.txt:
     13        * WebCore.xcodeproj/project.pbxproj:
     14        * platform/ImageDecoders.cmake:
     15        * platform/graphics/ImageDecoder.cpp: Added.
     16        (WebCore::ImageDecoder::create):
     17        (WebCore::ImageDecoder::bytesDecodedToDetermineProperties):
     18        * platform/graphics/ImageDecoder.h: Added.
     19        (WebCore::ImageDecoder::isSizeAvailable):
     20        (WebCore::ImageDecoder::isAllDataReceived const):
     21        * platform/graphics/cg/ImageDecoderCG.cpp:
     22        (WebCore::ImageDecoderCG::ImageDecoderCG):
     23        (WebCore::ImageDecoderCG::bytesDecodedToDetermineProperties):
     24        (WebCore::ImageDecoderCG::uti const):
     25        (WebCore::ImageDecoderCG::filenameExtension const):
     26        (WebCore::ImageDecoderCG::encodedDataStatus const):
     27        (WebCore::ImageDecoderCG::frameCount const):
     28        (WebCore::ImageDecoderCG::repetitionCount const):
     29        (WebCore::ImageDecoderCG::hotSpot const):
     30        (WebCore::ImageDecoderCG::frameSizeAtIndex const):
     31        (WebCore::ImageDecoderCG::frameIsCompleteAtIndex const):
     32        (WebCore::ImageDecoderCG::frameOrientationAtIndex const):
     33        (WebCore::ImageDecoderCG::frameDurationAtIndex const):
     34        (WebCore::ImageDecoderCG::frameAllowSubsamplingAtIndex const):
     35        (WebCore::ImageDecoderCG::frameHasAlphaAtIndex const):
     36        (WebCore::ImageDecoderCG::frameBytesAtIndex const):
     37        (WebCore::ImageDecoderCG::createFrameImageAtIndex const):
     38        (WebCore::ImageDecoderCG::setData):
     39        (WebCore::ImageDecoder::ImageDecoder): Deleted.
     40        (WebCore::ImageDecoder::bytesDecodedToDetermineProperties): Deleted.
     41        (WebCore::ImageDecoder::uti const): Deleted.
     42        (WebCore::ImageDecoder::filenameExtension const): Deleted.
     43        (WebCore::ImageDecoder::encodedDataStatus const): Deleted.
     44        (WebCore::ImageDecoder::frameCount const): Deleted.
     45        (WebCore::ImageDecoder::repetitionCount const): Deleted.
     46        (WebCore::ImageDecoder::hotSpot const): Deleted.
     47        (WebCore::ImageDecoder::frameSizeAtIndex const): Deleted.
     48        (WebCore::ImageDecoder::frameIsCompleteAtIndex const): Deleted.
     49        (WebCore::ImageDecoder::frameOrientationAtIndex const): Deleted.
     50        (WebCore::ImageDecoder::frameDurationAtIndex const): Deleted.
     51        (WebCore::ImageDecoder::frameAllowSubsamplingAtIndex const): Deleted.
     52        (WebCore::ImageDecoder::frameHasAlphaAtIndex const): Deleted.
     53        (WebCore::ImageDecoder::frameBytesAtIndex const): Deleted.
     54        (WebCore::ImageDecoder::createFrameImageAtIndex const): Deleted.
     55        (WebCore::ImageDecoder::setData): Deleted.
     56        * platform/graphics/cg/ImageDecoderCG.h:
     57        (WebCore::ImageDecoderCG::create):
     58        (WebCore::ImageDecoder::create): Deleted.
     59        (WebCore::ImageDecoder::isSizeAvailable): Deleted.
     60        (WebCore::ImageDecoder::isAllDataReceived const): Deleted.
     61        (WebCore::ImageDecoder::clearFrameBufferCache): Deleted.
     62        * platform/graphics/win/ImageDecoderDirect2D.cpp:
     63        (WebCore::ImageDecoderDirect2D::ImageDecoderDirect2D):
     64        (WebCore::ImageDecoderDirect2D::systemImagingFactory):
     65        (WebCore::ImageDecoderDirect2D::bytesDecodedToDetermineProperties):
     66        (WebCore::ImageDecoderDirect2D::filenameExtension const):
     67        (WebCore::ImageDecoderDirect2D::isSizeAvailable const):
     68        (WebCore::ImageDecoderDirect2D::encodedDataStatus const):
     69        (WebCore::ImageDecoderDirect2D::size const):
     70        (WebCore::ImageDecoderDirect2D::frameCount const):
     71        (WebCore::ImageDecoderDirect2D::repetitionCount const):
     72        (WebCore::ImageDecoderDirect2D::hotSpot const):
     73        (WebCore::ImageDecoderDirect2D::frameSizeAtIndex const):
     74        (WebCore::ImageDecoderDirect2D::frameIsCompleteAtIndex const):
     75        (WebCore::ImageDecoderDirect2D::frameOrientationAtIndex const):
     76        (WebCore::ImageDecoderDirect2D::frameDurationAtIndex const):
     77        (WebCore::ImageDecoderDirect2D::frameAllowSubsamplingAtIndex const):
     78        (WebCore::ImageDecoderDirect2D::frameHasAlphaAtIndex const):
     79        (WebCore::ImageDecoderDirect2D::frameBytesAtIndex const):
     80        (WebCore::ImageDecoderDirect2D::setTargetContext):
     81        (WebCore::ImageDecoderDirect2D::createFrameImageAtIndex const):
     82        (WebCore::ImageDecoderDirect2D::setData):
     83        * platform/graphics/win/ImageDecoderDirect2D.h:
     84        (WebCore::ImageDecoderDirect2D::create):
     85        (WebCore::ImageDecoder::create): Deleted.
     86        (WebCore::ImageDecoder::isAllDataReceived const): Deleted.
     87        (WebCore::ImageDecoder::clearFrameBufferCache): Deleted.
     88        * platform/image-decoders/ScalableImageDecoder.cpp: Renamed from Source/WebCore/platform/image-decoders/ImageDecoder.cpp.
     89        (WebCore::ScalableImageDecoder::create):
     90        (WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const):
     91        (WebCore::ScalableImageDecoder::frameHasAlphaAtIndex const):
     92        (WebCore::ScalableImageDecoder::frameBytesAtIndex const):
     93        (WebCore::ScalableImageDecoder::frameDurationAtIndex const):
     94        (WebCore::ScalableImageDecoder::createFrameImageAtIndex):
     95        (WebCore::ScalableImageDecoder::prepareScaleDataIfNecessary):
     96        (WebCore::ScalableImageDecoder::upperBoundScaledX):
     97        (WebCore::ScalableImageDecoder::lowerBoundScaledX):
     98        (WebCore::ScalableImageDecoder::upperBoundScaledY):
     99        (WebCore::ScalableImageDecoder::lowerBoundScaledY):
     100        (WebCore::ScalableImageDecoder::scaledY):
     101        * platform/image-decoders/ScalableImageDecoder.h: Renamed from Source/WebCore/platform/image-decoders/ImageDecoder.h.
     102        (WebCore::ScalableImageDecoder::ScalableImageDecoder):
     103        (WebCore::ScalableImageDecoder::~ScalableImageDecoder):
     104        (WebCore::ScalableImageDecoder::premultiplyAlpha const):
     105        (WebCore::ScalableImageDecoder::isAllDataReceived const):
     106        (WebCore::ScalableImageDecoder::size const):
     107        (WebCore::ScalableImageDecoder::scaledSize):
     108        (WebCore::ScalableImageDecoder::setSize):
     109        (WebCore::ScalableImageDecoder::setIgnoreGammaAndColorProfile):
     110        (WebCore::ScalableImageDecoder::ignoresGammaAndColorProfile const):
     111        (WebCore::ScalableImageDecoder::rgbColorProfile):
     112        (WebCore::ScalableImageDecoder::subsamplingLevelForScale):
     113        (WebCore::ScalableImageDecoder::inputDeviceColorProfile):
     114        (WebCore::ScalableImageDecoder::setFailed):
     115        (WebCore::ScalableImageDecoder::failed const):
     116        * platform/image-decoders/bmp/BMPImageDecoder.cpp:
     117        (WebCore::BMPImageDecoder::BMPImageDecoder):
     118        (WebCore::BMPImageDecoder::setData):
     119        (WebCore::BMPImageDecoder::setFailed):
     120        * platform/image-decoders/bmp/BMPImageDecoder.h:
     121        * platform/image-decoders/bmp/BMPImageReader.h:
     122        * platform/image-decoders/gif/GIFImageDecoder.cpp:
     123        (WebCore::GIFImageDecoder::GIFImageDecoder):
     124        (WebCore::GIFImageDecoder::setData):
     125        (WebCore::GIFImageDecoder::setSize):
     126        (WebCore::GIFImageDecoder::setFailed):
     127        * platform/image-decoders/gif/GIFImageDecoder.h:
     128        * platform/image-decoders/ico/ICOImageDecoder.cpp:
     129        (WebCore::ICOImageDecoder::ICOImageDecoder):
     130        (WebCore::ICOImageDecoder::setData):
     131        (WebCore::ICOImageDecoder::size):
     132        (WebCore::ICOImageDecoder::setSize):
     133        (WebCore::ICOImageDecoder::setFailed):
     134        * platform/image-decoders/ico/ICOImageDecoder.h:
     135        * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
     136        (WebCore::JPEGImageDecoder::JPEGImageDecoder):
     137        (WebCore::JPEGImageDecoder::setSize):
     138        (WebCore::JPEGImageDecoder::setFailed):
     139        * platform/image-decoders/jpeg/JPEGImageDecoder.h:
     140        * platform/image-decoders/png/PNGImageDecoder.cpp:
     141        (WebCore::PNGImageReader::decode):
     142        (WebCore::PNGImageDecoder::PNGImageDecoder):
     143        (WebCore::PNGImageDecoder::setSize):
     144        (WebCore::PNGImageDecoder::frameBufferAtIndex):
     145        (WebCore::PNGImageDecoder::setFailed):
     146        * platform/image-decoders/png/PNGImageDecoder.h:
     147        * platform/image-decoders/webp/WEBPImageDecoder.cpp:
     148        (WebCore::WEBPImageDecoder::WEBPImageDecoder):
     149        (WebCore::WEBPImageDecoder::decode):
     150        * platform/image-decoders/webp/WEBPImageDecoder.h:
     151
    11522017-09-18  Andy Estes  <aestes@apple.com>
    2153
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r222091 r222151  
    62816281                CD127DEE14F3098400E84779 /* WebCoreFullScreenWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
    62826282                CD19A2681A13E700008D650E /* DiagnosticLoggingClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CD19A2671A13E700008D650E /* DiagnosticLoggingClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
     6283                CD19FEA81F573972000C42FB /* ImageDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = CD19FEA61F573972000C42FB /* ImageDecoder.h */; };
     6284                CD19FEA91F573972000C42FB /* ImageDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD19FEA71F573972000C42FB /* ImageDecoder.cpp */; };
    62836285                CD1E7347167BC78E009A885D /* TextTrackRepresentation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD1E7346167BC78E009A885D /* TextTrackRepresentation.cpp */; };
    62846286                CD225C0B1C46FBF400140761 /* WebCoreNSURLSession.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD225C091C46FBF400140761 /* WebCoreNSURLSession.mm */; };
     
    1502515027                CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreFullScreenWindow.mm; sourceTree = "<group>"; };
    1502615028                CD19A2671A13E700008D650E /* DiagnosticLoggingClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiagnosticLoggingClient.h; sourceTree = "<group>"; };
     15029                CD19FEA61F573972000C42FB /* ImageDecoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageDecoder.h; sourceTree = "<group>"; };
     15030                CD19FEA71F573972000C42FB /* ImageDecoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ImageDecoder.cpp; sourceTree = "<group>"; };
    1502715031                CD1E7346167BC78E009A885D /* TextTrackRepresentation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextTrackRepresentation.cpp; sourceTree = "<group>"; };
    1502815032                CD225C091C46FBF400140761 /* WebCoreNSURLSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSURLSession.mm; sourceTree = "<group>"; };
     
    2384423848                                B2A10B910B3818BD00099AA4 /* ImageBuffer.h */,
    2384523849                                22BD9F7D1353625C009BD102 /* ImageBufferData.h */,
     23850                                CD19FEA61F573972000C42FB /* ImageDecoder.h */,
     23851                                CD19FEA71F573972000C42FB /* ImageDecoder.cpp */,
    2384623852                                5576A5621D88A70800CCC04C /* ImageFrame.cpp */,
    2384723853                                5576A5631D88A70800CCC04C /* ImageFrame.h */,
     
    2848028486                                9479493A1E0459FA00018D85 /* JSDeprecatedCSSOMValueList.h in Headers */,
    2848128487                                31FB1A66120A5D3F00DC02A0 /* JSDeviceMotionEvent.h in Headers */,
     28488                                CD19FEA81F573972000C42FB /* ImageDecoder.h in Headers */,
    2848228489                                59A86008119DAFA100DEF1EF /* JSDeviceOrientationEvent.h in Headers */,
    2848328490                                659DDC8309E198BA001BF3C6 /* JSDocument.h in Headers */,
     
    3145631463                                E1B533471717D0A100F205F9 /* CachedSVGDocumentReference.cpp in Sources */,
    3145731464                                1C0939EA1A13E12900B788E5 /* CachedSVGFont.cpp in Sources */,
     31465                                CD19FEA91F573972000C42FB /* ImageDecoder.cpp in Sources */,
    3145831466                                0753860214489E9800B78452 /* CachedTextTrack.cpp in Sources */,
    3145931467                                BCB16C270979C3BD00467741 /* CachedXSLStyleSheet.cpp in Sources */,
  • trunk/Source/WebCore/platform/ImageDecoders.cmake

    r221387 r222151  
    1010
    1111list(APPEND WebCore_SOURCES
    12     platform/image-decoders/ImageDecoder.cpp
     12    platform/image-decoders/ScalableImageDecoder.cpp
    1313
    1414    platform/image-decoders/bmp/BMPImageDecoder.cpp
  • trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp

    r220506 r222151  
    148148#endif
    149149
    150 ImageDecoder::ImageDecoder(SharedBuffer& data, AlphaOption, GammaAndColorProfileOption)
     150ImageDecoderCG::ImageDecoderCG(SharedBuffer& data, AlphaOption, GammaAndColorProfileOption)
    151151{
    152152    RetainPtr<CFStringRef> utiHint;
     
    163163}
    164164
    165 size_t ImageDecoder::bytesDecodedToDetermineProperties()
     165size_t ImageDecoderCG::bytesDecodedToDetermineProperties() const
    166166{
    167167    // Measured by tracing malloc/calloc calls on Mac OS 10.6.6, x86_64.
     
    174174}
    175175   
    176 String ImageDecoder::uti() const
     176String ImageDecoderCG::uti() const
    177177{
    178178    return CGImageSourceGetType(m_nativeDecoder.get());
    179179}
    180180
    181 String ImageDecoder::filenameExtension() const
     181String ImageDecoderCG::filenameExtension() const
    182182{
    183183    return WebCore::preferredExtensionForImageSourceType(uti());
    184184}
    185185
    186 EncodedDataStatus ImageDecoder::encodedDataStatus() const
     186EncodedDataStatus ImageDecoderCG::encodedDataStatus() const
    187187{
    188188    String uti = this->uti();
     
    228228}
    229229
    230 size_t ImageDecoder::frameCount() const
     230size_t ImageDecoderCG::frameCount() const
    231231{
    232232    return CGImageSourceGetCount(m_nativeDecoder.get());
    233233}
    234234
    235 RepetitionCount ImageDecoder::repetitionCount() const
     235RepetitionCount ImageDecoderCG::repetitionCount() const
    236236{
    237237    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyProperties(m_nativeDecoder.get(), imageSourceOptions().get()));
     
    269269}
    270270
    271 std::optional<IntPoint> ImageDecoder::hotSpot() const
     271std::optional<IntPoint> ImageDecoderCG::hotSpot() const
    272272{
    273273    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), 0, imageSourceOptions().get()));
     
    290290}
    291291
    292 IntSize ImageDecoder::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
     292IntSize ImageDecoderCG::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
    293293{
    294294    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), index, imageSourceOptions(subsamplingLevel).get()));
     
    310310}
    311311
    312 bool ImageDecoder::frameIsCompleteAtIndex(size_t index) const
     312bool ImageDecoderCG::frameIsCompleteAtIndex(size_t index) const
    313313{
    314314    ASSERT(frameCount());
     
    322322}
    323323
    324 ImageOrientation ImageDecoder::frameOrientationAtIndex(size_t index) const
     324ImageOrientation ImageDecoderCG::frameOrientationAtIndex(size_t index) const
    325325{
    326326    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), index, imageSourceOptions().get()));
     
    331331}
    332332
    333 float ImageDecoder::frameDurationAtIndex(size_t index) const
     333float ImageDecoderCG::frameDurationAtIndex(size_t index) const
    334334{
    335335    float duration = 0;
     
    365365}
    366366
    367 bool ImageDecoder::frameAllowSubsamplingAtIndex(size_t) const
     367bool ImageDecoderCG::frameAllowSubsamplingAtIndex(size_t) const
    368368{
    369369    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), 0, imageSourceOptions().get()));
     
    387387}
    388388
    389 bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const
     389bool ImageDecoderCG::frameHasAlphaAtIndex(size_t index) const
    390390{
    391391    if (!frameIsCompleteAtIndex(index))
     
    405405}
    406406
    407 unsigned ImageDecoder::frameBytesAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
     407unsigned ImageDecoderCG::frameBytesAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
    408408{
    409409    IntSize frameSize = frameSizeAtIndex(index, subsamplingLevel);
     
    411411}
    412412
    413 NativeImagePtr ImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel, const DecodingOptions& decodingOptions) const
     413NativeImagePtr ImageDecoderCG::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel, const DecodingOptions& decodingOptions)
    414414{
    415415    LOG(Images, "ImageDecoder %p createFrameImageAtIndex %lu", this, index);
     
    461461}
    462462
    463 void ImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
     463void ImageDecoderCG::setData(SharedBuffer& data, bool allDataReceived)
    464464{
    465465    m_isAllDataReceived = allDataReceived;
  • trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h

    r217246 r222151  
    2626#pragma once
    2727
    28 #include "DecodingOptions.h"
    29 #include "ImageOrientation.h"
    30 #include "ImageTypes.h"
    31 #include "IntPoint.h"
    32 #include "IntSize.h"
    33 #include "NativeImage.h"
    34 #include <wtf/Optional.h>
    35 #include <wtf/ThreadSafeRefCounted.h>
     28#include "ImageDecoder.h"
    3629
    3730namespace WebCore {
    38    
    39 class SharedBuffer;
    40    
    41 class ImageDecoder : public ThreadSafeRefCounted<ImageDecoder> {
     31
     32class ImageDecoderCG final : public ImageDecoder {
    4233    WTF_MAKE_FAST_ALLOCATED;
    4334public:
    44     ImageDecoder(SharedBuffer& data, AlphaOption, GammaAndColorProfileOption);
     35    ImageDecoderCG(SharedBuffer& data, AlphaOption, GammaAndColorProfileOption);
    4536
    46     static Ref<ImageDecoder> create(SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     37    static Ref<ImageDecoderCG> create(SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    4738    {
    48         return adoptRef(*new ImageDecoder(data, alphaOption, gammaAndColorProfileOption));
     39        return adoptRef(*new ImageDecoderCG(data, alphaOption, gammaAndColorProfileOption));
    4940    }
    5041   
    51     static size_t bytesDecodedToDetermineProperties();
     42    size_t bytesDecodedToDetermineProperties() const final;
    5243
    53     EncodedDataStatus encodedDataStatus() const;
    54     bool isSizeAvailable() { return encodedDataStatus() >= EncodedDataStatus::SizeAvailable; }
    55     size_t frameCount() const;
    56     RepetitionCount repetitionCount() const;
    57     String uti() const;
    58     String filenameExtension() const;
    59     std::optional<IntPoint> hotSpot() const;
     44    EncodedDataStatus encodedDataStatus() const final;
     45    IntSize size() const final { return IntSize(); }
     46    size_t frameCount() const final;
     47    RepetitionCount repetitionCount() const final;
     48    String uti() const final;
     49    String filenameExtension() const final;
     50    std::optional<IntPoint> hotSpot() const final;
    6051
    61     IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const;
    62     bool frameIsCompleteAtIndex(size_t) const;
    63     ImageOrientation frameOrientationAtIndex(size_t) const;
    64    
    65     float frameDurationAtIndex(size_t) const;
    66     bool frameHasAlphaAtIndex(size_t) const;
    67     bool frameAllowSubsamplingAtIndex(size_t) const;
    68     unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const;
    69    
    70     NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default, const DecodingOptions& = DecodingMode::Synchronous) const;
    71    
    72     void setData(SharedBuffer&, bool allDataReceived);
    73     bool isAllDataReceived() const { return m_isAllDataReceived; }
    74     void clearFrameBufferCache(size_t) { }
    75    
     52    IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const final;
     53    bool frameIsCompleteAtIndex(size_t) const final;
     54    ImageOrientation frameOrientationAtIndex(size_t) const final;
     55
     56    float frameDurationAtIndex(size_t) const final;
     57    bool frameHasAlphaAtIndex(size_t) const final;
     58    bool frameAllowSubsamplingAtIndex(size_t) const final;
     59    unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const final;
     60
     61    NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default, const DecodingOptions& = DecodingMode::Synchronous) final;
     62
     63    void setData(SharedBuffer&, bool allDataReceived) final;
     64    bool isAllDataReceived() const final { return m_isAllDataReceived; }
     65    void clearFrameBufferCache(size_t) final { }
     66
    7667protected:
    7768    bool m_isAllDataReceived { false };
  • trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.cpp

    r215710 r222151  
    4242namespace WebCore {
    4343
    44 ImageDecoder::ImageDecoder()
    45 {
    46 }
    47 
    48 IWICImagingFactory* ImageDecoder::systemImagingFactory()
     44ImageDecoderDirect2D::ImageDecoderDirect2D()
     45{
     46}
     47
     48IWICImagingFactory* ImageDecoderDirect2D::systemImagingFactory()
    4949{
    5050    static IWICImagingFactory* wicImagingFactory = nullptr;
     
    5757}
    5858
    59 size_t ImageDecoder::bytesDecodedToDetermineProperties()
     59size_t ImageDecoderDirect2D::bytesDecodedToDetermineProperties()
    6060{
    6161    // Set to match value used for CoreGraphics.
     
    6363}
    6464
    65 String ImageDecoder::filenameExtension() const
     65String ImageDecoderDirect2D::filenameExtension() const
    6666{
    6767    notImplemented();
     
    6969}
    7070
    71 bool ImageDecoder::isSizeAvailable() const
     71bool ImageDecoderDirect2D::isSizeAvailable() const
    7272{
    7373    return m_nativeDecoder ? true : false;
    7474}
    7575
    76 EncodedDataStatus ImageDecoder::encodedDataStatus() const
     76EncodedDataStatus ImageDecoderDirect2D::encodedDataStatus() const
    7777{
    7878    notImplemented();
     
    8080}
    8181
    82 IntSize ImageDecoder::size() const
     82IntSize ImageDecoderDirect2D::size() const
    8383{
    8484    if (!m_nativeDecoder)
     
    9898}
    9999
    100 size_t ImageDecoder::frameCount() const
     100size_t ImageDecoderDirect2D::frameCount() const
    101101{
    102102    if (!m_nativeDecoder)
     
    111111}
    112112
    113 RepetitionCount ImageDecoder::repetitionCount() const
     113RepetitionCount ImageDecoderDirect2D::repetitionCount() const
    114114{
    115115    return RepetitionCountNone;
    116116}
    117117
    118 std::optional<IntPoint> ImageDecoder::hotSpot() const
     118std::optional<IntPoint> ImageDecoderDirect2D::hotSpot() const
    119119{
    120120    return IntPoint();
    121121}
    122122
    123 IntSize ImageDecoder::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
     123IntSize ImageDecoderDirect2D::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
    124124{
    125125    if (!m_nativeDecoder)
     
    139139}
    140140
    141 bool ImageDecoder::frameIsCompleteAtIndex(size_t index) const
     141bool ImageDecoderDirect2D::frameIsCompleteAtIndex(size_t index) const
    142142{
    143143    if (!m_nativeDecoder)
     
    149149}
    150150
    151 ImageOrientation ImageDecoder::frameOrientationAtIndex(size_t index) const
     151ImageOrientation ImageDecoderDirect2D::frameOrientationAtIndex(size_t index) const
    152152{
    153153    notImplemented();
     
    155155}
    156156
    157 float ImageDecoder::frameDurationAtIndex(size_t index) const
     157float ImageDecoderDirect2D::frameDurationAtIndex(size_t index) const
    158158{
    159159    notImplemented();
     
    161161}
    162162
    163 bool ImageDecoder::frameAllowSubsamplingAtIndex(size_t) const
     163bool ImageDecoderDirect2D::frameAllowSubsamplingAtIndex(size_t) const
    164164{
    165165    notImplemented();
     
    167167}
    168168
    169 bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const
     169bool ImageDecoderDirect2D::frameHasAlphaAtIndex(size_t index) const
    170170{
    171171    notImplemented();
     
    173173}
    174174
    175 unsigned ImageDecoder::frameBytesAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
     175unsigned ImageDecoderDirect2D::frameBytesAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
    176176{
    177177    if (!m_nativeDecoder)
     
    182182}
    183183
    184 void ImageDecoder::setTargetContext(ID2D1RenderTarget* renderTarget)
     184void ImageDecoderDirect2D::setTargetContext(ID2D1RenderTarget* renderTarget)
    185185{
    186186    m_renderTarget = renderTarget;
    187187}
    188188
    189 NativeImagePtr ImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel, const DecodingOptions&) const
     189NativeImagePtr ImageDecoderDirect2D::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel, const DecodingOptions&) const
    190190{
    191191    if (!m_nativeDecoder || !m_renderTarget)
     
    214214}
    215215
    216 void ImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
     216void ImageDecoderDirect2D::setData(SharedBuffer& data, bool allDataReceived)
    217217{
    218218    if (!allDataReceived)
  • trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.h

    r217246 r222151  
    2626#pragma once
    2727
     28#if USE(DIRECT2D)
     29
    2830#include "COMPtr.h"
    29 #include "ImageSource.h"
    30 #include "IntSize.h"
     31#include "ImageDecoder.h"
    3132#include <wtf/Optional.h>
    3233
     
    3738namespace WebCore {
    3839
    39 class ImageDecoder : public ThreadSafeRefCounted<ImageDecoder> {
     40class ImageDecoderDirect2D final : public ImageDecoder {
    4041    WTF_MAKE_FAST_ALLOCATED;
    4142public:
    42     ImageDecoder();
    43    
    44     static Ref<ImageDecoder> create(SharedBuffer&, AlphaOption, GammaAndColorProfileOption)
     43    ImageDecoderDirect2D();
     44
     45    static Ref<ImageDecoderDirect2D> create(SharedBuffer&, AlphaOption, GammaAndColorProfileOption)
    4546    {
    46         return adoptRef(*new ImageDecoder());
     47        return adoptRef(*new ImageDecoderDirect2D());
    4748    }
    48    
     49
    4950    static size_t bytesDecodedToDetermineProperties();
    50    
    51     String filenameExtension() const;
    52     EncodedDataStatus encodedDataStatus() const;
    53     bool isSizeAvailable() const;
    54    
     51
     52    String filenameExtension() const final;
     53    EncodedDataStatus encodedDataStatus() const final;
     54    bool isSizeAvailable() const final;
     55
    5556    // Always original size, without subsampling.
    56     IntSize size() const;
    57     size_t frameCount() const;
     57    IntSize size() const final;
     58    size_t frameCount() const final;
    5859
    59     RepetitionCount repetitionCount() const;
    60     std::optional<IntPoint> hotSpot() const;
    61    
    62     IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const;
    63     bool frameIsCompleteAtIndex(size_t) const;
    64     ImageOrientation frameOrientationAtIndex(size_t) const;
    65    
    66     float frameDurationAtIndex(size_t) const;
    67     bool frameHasAlphaAtIndex(size_t) const;
    68     bool frameAllowSubsamplingAtIndex(size_t) const;
    69     unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const;
    70    
    71     NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default, const DecodingOptions& = DecodingMode::Synchronous) const;
    72    
    73     void setData(SharedBuffer&, bool allDataReceived);
    74     bool isAllDataReceived() const { return m_isAllDataReceived; }
    75     void clearFrameBufferCache(size_t) { }
     60    RepetitionCount repetitionCount() const final;
     61    std::optional<IntPoint> hotSpot() const final;
     62
     63    IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const final;
     64    bool frameIsCompleteAtIndex(size_t) const final;
     65    ImageOrientation frameOrientationAtIndex(size_t) const final;
     66
     67    float frameDurationAtIndex(size_t) const final;
     68    bool frameHasAlphaAtIndex(size_t) const final;
     69    bool frameAllowSubsamplingAtIndex(size_t) const final;
     70    unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const final;
     71
     72    NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default, const DecodingOptions& = DecodingMode::Synchronous) const final;
     73
     74    void setData(SharedBuffer&, bool allDataReceived) final;
     75    bool isAllDataReceived() const final { return m_isAllDataReceived; }
     76    void clearFrameBufferCache(size_t) final { }
    7677
    7778    void setTargetContext(ID2D1RenderTarget*);
     
    8788
    8889}
     90
     91#endif
  • trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp

    r222150 r222151  
    2222
    2323#include "config.h"
    24 #include "ImageDecoder.h"
     24#include "ScalableImageDecoder.h"
    2525
    2626#include "BMPImageDecoder.h"
     
    9999}
    100100
    101 RefPtr<ImageDecoder> ImageDecoder::create(SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     101RefPtr<ScalableImageDecoder> ScalableImageDecoder::create(SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    102102{
    103103    static const unsigned lengthOfLongestSignature = 14; // To wit: "RIFF????WEBPVP"
     
    171171}
    172172
    173 bool ImageDecoder::frameIsCompleteAtIndex(size_t index)
    174 {
    175     ImageFrame* buffer = frameBufferAtIndex(index);
     173bool ScalableImageDecoder::frameIsCompleteAtIndex(size_t index) const
     174{
     175    // FIXME(176089): asking whether enough data has been appended for a decode
     176    // operation to succeed should not require decoding the entire frame.
     177    // This function should be implementable in a way that allows const.
     178    ImageFrame* buffer = const_cast<ScalableImageDecoder*>(this)->frameBufferAtIndex(index);
    176179    return buffer && buffer->isComplete();
    177180}
    178181
    179 bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const
     182bool ScalableImageDecoder::frameHasAlphaAtIndex(size_t index) const
    180183{
    181184    if (m_frameBufferCache.size() <= index)
     
    186189}
    187190
    188 unsigned ImageDecoder::frameBytesAtIndex(size_t index) const
     191unsigned ScalableImageDecoder::frameBytesAtIndex(size_t index, SubsamplingLevel) const
    189192{
    190193    if (m_frameBufferCache.size() <= index)
     
    194197}
    195198
    196 float ImageDecoder::frameDurationAtIndex(size_t index)
    197 {
    198     ImageFrame* buffer = frameBufferAtIndex(index);
     199float ScalableImageDecoder::frameDurationAtIndex(size_t index) const
     200{
     201    // FIXME(176089): asking for the duration of a sub-image should not require decoding
     202    // the entire frame. This function should be implementable in a way that
     203    // allows const.
     204    ImageFrame* buffer = const_cast<ScalableImageDecoder*>(this)->frameBufferAtIndex(index);
    199205    if (!buffer || buffer->isInvalid())
    200206        return 0;
     
    210216}
    211217
    212 NativeImagePtr ImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel, const DecodingOptions&)
     218NativeImagePtr ScalableImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel, const DecodingOptions&)
    213219{
    214220    // Zero-height images can cause problems for some ports. If we have an empty image dimension, just bail.
     
    225231}
    226232
    227 void ImageDecoder::prepareScaleDataIfNecessary()
     233void ScalableImageDecoder::prepareScaleDataIfNecessary()
    228234{
    229235    m_scaled = false;
     
    243249}
    244250
    245 int ImageDecoder::upperBoundScaledX(int origX, int searchStart)
     251int ScalableImageDecoder::upperBoundScaledX(int origX, int searchStart)
    246252{
    247253    return getScaledValue<UpperBound>(m_scaledColumns, origX, searchStart);
    248254}
    249255
    250 int ImageDecoder::lowerBoundScaledX(int origX, int searchStart)
     256int ScalableImageDecoder::lowerBoundScaledX(int origX, int searchStart)
    251257{
    252258    return getScaledValue<LowerBound>(m_scaledColumns, origX, searchStart);
    253259}
    254260
    255 int ImageDecoder::upperBoundScaledY(int origY, int searchStart)
     261int ScalableImageDecoder::upperBoundScaledY(int origY, int searchStart)
    256262{
    257263    return getScaledValue<UpperBound>(m_scaledRows, origY, searchStart);
    258264}
    259265
    260 int ImageDecoder::lowerBoundScaledY(int origY, int searchStart)
     266int ScalableImageDecoder::lowerBoundScaledY(int origY, int searchStart)
    261267{
    262268    return getScaledValue<LowerBound>(m_scaledRows, origY, searchStart);
    263269}
    264270
    265 int ImageDecoder::scaledY(int origY, int searchStart)
     271int ScalableImageDecoder::scaledY(int origY, int searchStart)
    266272{
    267273    return getScaledValue<Exact>(m_scaledRows, origY, searchStart);
  • trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h

    r222150 r222151  
    2929#pragma once
    3030
     31#include "ImageDecoder.h"
    3132#include "ImageFrame.h"
    3233#include "IntRect.h"
    33 #include "IntSize.h"
    3434#include "SharedBuffer.h"
    3535#include <wtf/Assertions.h>
    36 #include <wtf/Optional.h>
    3736#include <wtf/RefPtr.h>
    3837#include <wtf/Vector.h>
     
    4140namespace WebCore {
    4241
    43 // ImageDecoder is a base for all format-specific decoders
     42// ScalableImageDecoder is a base for all format-specific decoders
    4443// (e.g. JPEGImageDecoder). This base manages the ImageFrame cache.
    4544//
     
    4746// at decode time. Image decoders will downsample any images larger than
    4847// |m_maxNumPixels|. FIXME: Not yet supported by all decoders.
    49 class ImageDecoder : public ThreadSafeRefCounted<ImageDecoder> {
    50     WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED;
     48class ScalableImageDecoder : public ImageDecoder {
     49    WTF_MAKE_NONCOPYABLE(ScalableImageDecoder); WTF_MAKE_FAST_ALLOCATED;
    5150public:
    52     ImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     51    ScalableImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    5352        : m_premultiplyAlpha(alphaOption == AlphaOption::Premultiplied)
    5453        , m_ignoreGammaAndColorProfile(gammaAndColorProfileOption == GammaAndColorProfileOption::Ignored)
     
    5655    }
    5756
    58     virtual ~ImageDecoder()
     57    virtual ~ScalableImageDecoder()
    5958    {
    6059    }
     
    6261    // Returns nullptr if we can't sniff a supported type from the provided data (possibly
    6362    // because there isn't enough data yet).
    64     static RefPtr<ImageDecoder> create(SharedBuffer& data, AlphaOption, GammaAndColorProfileOption);
    65 
    66     virtual String filenameExtension() const = 0;
     63    static RefPtr<ScalableImageDecoder> create(SharedBuffer& data, AlphaOption, GammaAndColorProfileOption);
    6764
    6865    bool premultiplyAlpha() const { return m_premultiplyAlpha; }
    6966
    70     bool isAllDataReceived() const
     67    bool isAllDataReceived() const override
    7168    {
    7269        ASSERT(!m_decodingSizeFromSetData);
     
    7471    }
    7572
    76     virtual void setData(SharedBuffer& data, bool allDataReceived)
     73    void setData(SharedBuffer& data, bool allDataReceived) override
    7774    {
    7875        if (m_encodedDataStatus == EncodedDataStatus::Error)
     
    9592    }
    9693
    97     EncodedDataStatus encodedDataStatus() const { return m_encodedDataStatus; }
    98 
    99     bool isSizeAvailable() { return m_encodedDataStatus >= EncodedDataStatus::SizeAvailable; }
    100 
    101     virtual IntSize size() { return isSizeAvailable() ? m_size : IntSize(); }
     94    EncodedDataStatus encodedDataStatus() const override { return m_encodedDataStatus; }
     95
     96    bool isSizeAvailable() const override { return m_encodedDataStatus >= EncodedDataStatus::SizeAvailable; }
     97
     98    IntSize size() const override { return isSizeAvailable() ? m_size : IntSize(); }
    10299
    103100    IntSize scaledSize()
     
    111108    // composites any smaller frames against previous frames to create full-
    112109    // size frames.
    113     virtual IntSize frameSizeAtIndex(size_t, SubsamplingLevel)
     110    IntSize frameSizeAtIndex(size_t, SubsamplingLevel) const override
    114111    {
    115112        return size();
     
    131128    // FIXME: Right now that has to be done by each subclass; factor the
    132129    // decode call out and use it here.
    133     virtual size_t frameCount() const { return 1; }
    134 
    135     virtual RepetitionCount repetitionCount() const { return RepetitionCountNone; }
     130    size_t frameCount() const override { return 1; }
     131
     132    RepetitionCount repetitionCount() const override { return RepetitionCountNone; }
    136133
    137134    // Decodes as much of the requested frame as possible, and returns an
    138     // ImageDecoder-owned pointer.
     135    // ScalableImageDecoder-owned pointer.
    139136    virtual ImageFrame* frameBufferAtIndex(size_t) = 0;
    140137
    141     bool frameIsCompleteAtIndex(size_t);
     138    bool frameIsCompleteAtIndex(size_t) const override;
    142139
    143140    // Make the best effort guess to check if the requested frame has alpha channel.
    144     bool frameHasAlphaAtIndex(size_t) const;
     141    bool frameHasAlphaAtIndex(size_t) const override;
    145142
    146143    // Number of bytes in the decoded frame requested. Return 0 if not yet decoded.
    147     unsigned frameBytesAtIndex(size_t) const;
    148    
    149     float frameDurationAtIndex(size_t);
    150    
    151     NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default, const DecodingOptions& = DecodingMode::Synchronous);
     144    unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const override;
     145
     146    float frameDurationAtIndex(size_t) const override;
     147
     148    NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default, const DecodingOptions& = DecodingMode::Synchronous) override;
    152149
    153150    void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile = flag; }
    154151    bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfile; }
    155152
    156     ImageOrientation frameOrientationAtIndex(size_t) const { return m_orientation; }
    157    
    158     bool frameAllowSubsamplingAtIndex(size_t) const { return false; }
     153    ImageOrientation frameOrientationAtIndex(size_t) const override { return m_orientation; }
     154
     155    bool frameAllowSubsamplingAtIndex(size_t) const override { return false; }
    159156
    160157    enum { ICCColorProfileHeaderLength = 128 };
     
    167164    }
    168165
    169     static size_t bytesDecodedToDetermineProperties() { return 0; }
    170    
     166    size_t bytesDecodedToDetermineProperties() const final { return 0; }
     167
    171168    static SubsamplingLevel subsamplingLevelForScale(float, SubsamplingLevel) { return SubsamplingLevel::Default; }
    172169
     
    193190    // data may be needed to decode future frames (e.g. due to GIF frame
    194191    // compositing).
    195     virtual void clearFrameBufferCache(size_t) { }
     192    void clearFrameBufferCache(size_t) override { }
    196193
    197194    // If the image has a cursor hot-spot, stores it in the argument
    198195    // and returns true. Otherwise returns false.
    199     virtual std::optional<IntPoint> hotSpot() const { return std::nullopt; }
     196    std::optional<IntPoint> hotSpot() const override { return std::nullopt; }
    200197
    201198protected:
  • trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp

    r219702 r222151  
    4242
    4343BMPImageDecoder::BMPImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    44     : ImageDecoder(alphaOption, gammaAndColorProfileOption)
     44    : ScalableImageDecoder(alphaOption, gammaAndColorProfileOption)
    4545    , m_decodedOffset(0)
    4646{
     
    5252        return;
    5353
    54     ImageDecoder::setData(data, allDataReceived);
     54    ScalableImageDecoder::setData(data, allDataReceived);
    5555    if (m_reader)
    5656        m_reader->setData(&data);
     
    7474{
    7575    m_reader = nullptr;
    76     return ImageDecoder::setFailed();
     76    return ScalableImageDecoder::setFailed();
    7777}
    7878
  • trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h

    r215924 r222151  
    3535namespace WebCore {
    3636
    37     // This class decodes the BMP image format.
    38     class BMPImageDecoder final : public ImageDecoder {
    39     public:
    40         static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    41         {
    42             return adoptRef(*new BMPImageDecoder(alphaOption, gammaAndColorProfileOption));
    43         }
     37// This class decodes the BMP image format.
     38class BMPImageDecoder final : public ScalableImageDecoder {
     39public:
     40    static Ref<ScalableImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     41    {
     42        return adoptRef(*new BMPImageDecoder(alphaOption, gammaAndColorProfileOption));
     43    }
    4444
    45         // ImageDecoder
    46         String filenameExtension() const override { return ASCIILiteral("bmp"); }
    47         void setData(SharedBuffer&, bool allDataReceived) override;
    48         ImageFrame* frameBufferAtIndex(size_t index) override;
    49         // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
    50         // accessing deleted memory, especially when calling this from inside
    51         // BMPImageReader!
    52         bool setFailed() override;
     45    // ScalableImageDecoder
     46    String filenameExtension() const final { return ASCIILiteral("bmp"); }
     47    void setData(SharedBuffer&, bool allDataReceived) final;
     48    ImageFrame* frameBufferAtIndex(size_t index) final;
     49    // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
     50    // accessing deleted memory, especially when calling this from inside
     51    // BMPImageReader!
     52    bool setFailed() final;
    5353
    54     private:
    55         BMPImageDecoder(AlphaOption, GammaAndColorProfileOption);
    56         void tryDecodeSize(bool allDataReceived) override { decode(true, allDataReceived); }
     54private:
     55    BMPImageDecoder(AlphaOption, GammaAndColorProfileOption);
     56    void tryDecodeSize(bool allDataReceived) final { decode(true, allDataReceived); }
    5757
    58         inline uint32_t readUint32(int offset) const
    59         {
    60             return BMPImageReader::readUint32(m_data.get(), m_decodedOffset + offset);
    61         }
     58    inline uint32_t readUint32(int offset) const
     59    {
     60        return BMPImageReader::readUint32(m_data.get(), m_decodedOffset + offset);
     61    }
    6262
    63         // Decodes the image. If |onlySize| is true, stops decoding after
    64         // calculating the image size. If decoding fails but there is no more
    65         // data coming, sets the "decode failure" flag.
    66         void decode(bool onlySize, bool allDataReceived);
     63    // Decodes the image. If |onlySize| is true, stops decoding after
     64    // calculating the image size. If decoding fails but there is no more
     65    // data coming, sets the "decode failure" flag.
     66    void decode(bool onlySize, bool allDataReceived);
    6767
    68         // Decodes the image. If |onlySize| is true, stops decoding after
    69         // calculating the image size. Returns whether decoding succeeded.
    70         bool decodeHelper(bool onlySize);
     68    // Decodes the image. If |onlySize| is true, stops decoding after
     69    // calculating the image size. Returns whether decoding succeeded.
     70    bool decodeHelper(bool onlySize);
    7171
    72         // Processes the file header at the beginning of the data. Sets
    73         // |*imgDataOffset| based on the header contents. Returns true if the
    74         // file header could be decoded.
    75         bool processFileHeader(size_t* imgDataOffset);
     72    // Processes the file header at the beginning of the data. Sets
     73    // |*imgDataOffset| based on the header contents. Returns true if the
     74    // file header could be decoded.
     75    bool processFileHeader(size_t* imgDataOffset);
    7676
    77         // An index into |m_data| representing how much we've already decoded.
    78         // Note that this only tracks data _this_ class decodes; once the
    79         // BMPImageReader takes over this will not be updated further.
    80         size_t m_decodedOffset;
     77    // An index into |m_data| representing how much we've already decoded.
     78    // Note that this only tracks data _this_ class decodes; once the
     79    // BMPImageReader takes over this will not be updated further.
     80    size_t m_decodedOffset;
    8181
    82         // The reader used to do most of the BMP decoding.
    83         std::unique_ptr<BMPImageReader> m_reader;
    84     };
     82    // The reader used to do most of the BMP decoding.
     83    std::unique_ptr<BMPImageReader> m_reader;
     84};
    8585
    8686} // namespace WebCore
  • trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageReader.cpp

    r219762 r222151  
    3434namespace WebCore {
    3535
    36 BMPImageReader::BMPImageReader(ImageDecoder* parent, size_t decodedAndHeaderOffset, size_t imgDataOffset, bool usesAndMask)
     36BMPImageReader::BMPImageReader(ScalableImageDecoder* parent, size_t decodedAndHeaderOffset, size_t imgDataOffset, bool usesAndMask)
    3737    : m_parent(parent)
    3838    , m_buffer(0)
  • trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageReader.h

    r206156 r222151  
    2929 */
    3030
    31 #ifndef BMPImageReader_h
    32 #define BMPImageReader_h
    33 
     31#pragma once
     32
     33#include "ScalableImageDecoder.h"
    3434#include <stdint.h>
    35 #include "ImageDecoder.h"
    3635
    3736namespace WebCore {
    3837
    39     // This class decodes a BMP image.  It is used in the BMP and ICO decoders,
    40     // which wrap it in the appropriate code to read file headers, etc.
    41     class BMPImageReader {
    42         WTF_MAKE_FAST_ALLOCATED;
    43     public:
    44         // Read a value from |data[offset]|, converting from little to native
    45         // endianness.
    46         static inline uint16_t readUint16(SharedBuffer* data, int offset)
    47         {
    48             uint16_t result;
    49             memcpy(&result, &data->data()[offset], 2);
    50         #if CPU(BIG_ENDIAN)
    51             result = ((result & 0xff) << 8) | ((result & 0xff00) >> 8);
    52         #endif
    53             return result;
     38// This class decodes a BMP image. It is used in the BMP and ICO decoders,
     39// which wrap it in the appropriate code to read file headers, etc.
     40class BMPImageReader {
     41    WTF_MAKE_FAST_ALLOCATED;
     42public:
     43    // Read a value from |data[offset]|, converting from little to native
     44    // endianness.
     45    static inline uint16_t readUint16(SharedBuffer* data, int offset)
     46    {
     47        uint16_t result;
     48        memcpy(&result, &data->data()[offset], 2);
     49#if CPU(BIG_ENDIAN)
     50        result = ((result & 0xff) << 8) | ((result & 0xff00) >> 8);
     51#endif
     52        return result;
     53    }
     54
     55    static inline uint32_t readUint32(SharedBuffer* data, int offset)
     56    {
     57        uint32_t result;
     58        memcpy(&result, &data->data()[offset], 4);
     59#if CPU(BIG_ENDIAN)
     60        result = ((result & 0xff) << 24) | ((result & 0xff00) << 8) | ((result & 0xff0000) >> 8) | ((result & 0xff000000) >> 24);
     61#endif
     62        return result;
     63    }
     64
     65    // |parent| is the decoder that owns us.
     66    // |startOffset| points to the start of the BMP within the file.
     67    // |buffer| points at an empty ImageFrame that we'll initialize and
     68    // fill with decoded data.
     69    BMPImageReader(ScalableImageDecoder* parent, size_t decodedAndHeaderOffset, size_t imgDataOffset, bool usesAndMask);
     70
     71    void setBuffer(ImageFrame* buffer) { m_buffer = buffer; }
     72    void setData(SharedBuffer* data) { m_data = data; }
     73
     74    // Does the actual decoding. If |onlySize| is true, decoding only
     75    // progresses as far as necessary to get the image size. Returns
     76    // whether decoding succeeded.
     77    bool decodeBMP(bool onlySize);
     78
     79private:
     80    // The various BMP compression types. We don't currently decode all
     81    // these.
     82    enum CompressionType {
     83        // Universal types
     84        RGB = 0,
     85        RLE8 = 1,
     86        RLE4 = 2,
     87        // Windows V3+ only
     88        BITFIELDS = 3,
     89        JPEG = 4,
     90        PNG = 5,
     91        // OS/2 2.x-only
     92        HUFFMAN1D, // Stored in file as 3
     93        RLE24, // Stored in file as 4
     94    };
     95    enum AndMaskState {
     96        None,
     97        NotYetDecoded,
     98        Decoding,
     99    };
     100    enum ProcessingResult {
     101        Success,
     102        Failure,
     103        InsufficientData,
     104    };
     105
     106    // These are based on the Windows BITMAPINFOHEADER and RGBTRIPLE
     107    // structs, but with unnecessary entries removed.
     108    struct BitmapInfoHeader {
     109        uint32_t biSize;
     110        int32_t biWidth;
     111        int32_t biHeight;
     112        uint16_t biBitCount;
     113        CompressionType biCompression;
     114        uint32_t biClrUsed;
     115    };
     116    struct RGBTriple {
     117        uint8_t rgbBlue;
     118        uint8_t rgbGreen;
     119        uint8_t rgbRed;
     120    };
     121
     122    inline uint16_t readUint16(int offset) const
     123    {
     124        return readUint16(m_data.get(), m_decodedOffset + offset);
     125    }
     126
     127    inline uint32_t readUint32(int offset) const
     128    {
     129        return readUint32(m_data.get(), m_decodedOffset + offset);
     130    }
     131
     132    // Determines the size of the BMP info header. Returns true if the size
     133    // is valid.
     134    bool readInfoHeaderSize();
     135
     136    // Processes the BMP info header. Returns true if the info header could
     137    // be decoded.
     138    bool processInfoHeader();
     139
     140    // Helper function for processInfoHeader() which does the actual reading
     141    // of header values from the byte stream. Returns false on error.
     142    bool readInfoHeader();
     143
     144    // Returns true if this is a Windows V4+ BMP.
     145    inline bool isWindowsV4Plus() const
     146    {
     147        // Windows V4 info header is 108 bytes. V5 is 124 bytes.
     148        return (m_infoHeader.biSize == 108) || (m_infoHeader.biSize == 124);
     149    }
     150
     151    // Returns false if consistency errors are found in the info header.
     152    bool isInfoHeaderValid() const;
     153
     154    // For BI_BITFIELDS images, initializes the m_bitMasks[] and
     155    // m_bitOffsets[] arrays. processInfoHeader() will initialize these for
     156    // other compression types where needed.
     157    bool processBitmasks();
     158
     159    // For paletted images, allocates and initializes the m_colorTable[]
     160    // array.
     161    bool processColorTable();
     162
     163    // Processes an RLE-encoded image. Returns true if the entire image was
     164    // decoded.
     165    bool processRLEData();
     166
     167    // Processes a set of non-RLE-compressed pixels. Two cases:
     168    //   * inRLE = true: the data is inside an RLE-encoded bitmap. Tries to
     169    //     process |numPixels| pixels on the current row.
     170    //   * inRLE = false: the data is inside a non-RLE-encoded bitmap.
     171    //     |numPixels| is ignored. Expects |m_coord| to point at the
     172    //     beginning of the next row to be decoded. Tries to process as
     173    //     many complete rows as possible. Returns InsufficientData if
     174    //     there wasn't enough data to decode the whole image.
     175    //
     176    // This function returns a ProcessingResult instead of a bool so that it
     177    // can avoid calling m_parent->setFailed(), which could lead to memory
     178    // corruption since that will delete |this| but some callers still want
     179    // to access member variables after this returns.
     180    ProcessingResult processNonRLEData(bool inRLE, int numPixels);
     181
     182    // Returns true if the current y-coordinate plus |numRows| would be past
     183    // the end of the image. Here "plus" means "toward the end of the
     184    // image", so downwards for m_isTopDown images and upwards otherwise.
     185    inline bool pastEndOfImage(int numRows)
     186    {
     187        return m_isTopDown ? ((m_coord.y() + numRows) >= m_parent->size().height()) : ((m_coord.y() - numRows) < 0);
     188    }
     189
     190    // Returns the pixel data for the current X coordinate in a uint32_t.
     191    // Assumes m_decodedOffset has been set to the beginning of the current
     192    // row.
     193    // NOTE: Only as many bytes of the return value as are needed to hold
     194    // the pixel data will actually be set.
     195    inline uint32_t readCurrentPixel(int bytesPerPixel) const
     196    {
     197        const int offset = m_coord.x() * bytesPerPixel;
     198        switch (bytesPerPixel) {
     199        case 2:
     200            return readUint16(offset);
     201
     202        case 3: {
     203            // It doesn't matter that we never set the most significant byte
     204            // of the return value here in little-endian mode, the caller
     205            // won't read it.
     206            uint32_t pixel;
     207            memcpy(&pixel, &m_data->data()[m_decodedOffset + offset], 3);
     208#if CPU(BIG_ENDIAN)
     209            pixel = ((pixel & 0xff00) << 8) | ((pixel & 0xff0000) >> 8) | ((pixel & 0xff000000) >> 24);
     210#endif
     211            return pixel;
    54212        }
    55213
    56         static inline uint32_t readUint32(SharedBuffer* data, int offset)
    57         {
    58             uint32_t result;
    59             memcpy(&result, &data->data()[offset], 4);
    60         #if CPU(BIG_ENDIAN)
    61             result = ((result & 0xff) << 24) | ((result & 0xff00) << 8) | ((result & 0xff0000) >> 8) | ((result & 0xff000000) >> 24);
    62         #endif
    63             return result;
     214        case 4:
     215            return readUint32(offset);
     216
     217        default:
     218            ASSERT_NOT_REACHED();
     219            return 0;
    64220        }
    65 
    66         // |parent| is the decoder that owns us.
    67         // |startOffset| points to the start of the BMP within the file.
    68         // |buffer| points at an empty ImageFrame that we'll initialize and
    69         // fill with decoded data.
    70         BMPImageReader(ImageDecoder* parent, size_t decodedAndHeaderOffset, size_t imgDataOffset, bool usesAndMask);
    71 
    72         void setBuffer(ImageFrame* buffer) { m_buffer = buffer; }
    73         void setData(SharedBuffer* data) { m_data = data; }
    74 
    75         // Does the actual decoding.  If |onlySize| is true, decoding only
    76         // progresses as far as necessary to get the image size.  Returns
    77         // whether decoding succeeded.
    78         bool decodeBMP(bool onlySize);
    79 
    80     private:
    81         // The various BMP compression types.  We don't currently decode all
    82         // these.
    83         enum CompressionType {
    84             // Universal types
    85             RGB = 0,
    86             RLE8 = 1,
    87             RLE4 = 2,
    88             // Windows V3+ only
    89             BITFIELDS = 3,
    90             JPEG = 4,
    91             PNG = 5,
    92             // OS/2 2.x-only
    93             HUFFMAN1D,  // Stored in file as 3
    94             RLE24,      // Stored in file as 4
    95         };
    96         enum AndMaskState {
    97             None,
    98             NotYetDecoded,
    99             Decoding,
    100         };
    101         enum ProcessingResult {
    102             Success,
    103             Failure,
    104             InsufficientData,
    105         };
    106 
    107         // These are based on the Windows BITMAPINFOHEADER and RGBTRIPLE
    108         // structs, but with unnecessary entries removed.
    109         struct BitmapInfoHeader {
    110             uint32_t biSize;
    111             int32_t biWidth;
    112             int32_t biHeight;
    113             uint16_t biBitCount;
    114             CompressionType biCompression;
    115             uint32_t biClrUsed;
    116         };
    117         struct RGBTriple {
    118             uint8_t rgbBlue;
    119             uint8_t rgbGreen;
    120             uint8_t rgbRed;
    121         };
    122 
    123         inline uint16_t readUint16(int offset) const
    124         {
    125             return readUint16(m_data.get(), m_decodedOffset + offset);
    126         }
    127 
    128         inline uint32_t readUint32(int offset) const
    129         {
    130             return readUint32(m_data.get(), m_decodedOffset + offset);
    131         }
    132 
    133         // Determines the size of the BMP info header.  Returns true if the size
    134         // is valid.
    135         bool readInfoHeaderSize();
    136 
    137         // Processes the BMP info header.  Returns true if the info header could
    138         // be decoded.
    139         bool processInfoHeader();
    140 
    141         // Helper function for processInfoHeader() which does the actual reading
    142         // of header values from the byte stream.  Returns false on error.
    143         bool readInfoHeader();
    144 
    145         // Returns true if this is a Windows V4+ BMP.
    146         inline bool isWindowsV4Plus() const
    147         {
    148             // Windows V4 info header is 108 bytes.  V5 is 124 bytes.
    149             return (m_infoHeader.biSize == 108) || (m_infoHeader.biSize == 124);
    150         }
    151 
    152         // Returns false if consistency errors are found in the info header.
    153         bool isInfoHeaderValid() const;
    154 
    155         // For BI_BITFIELDS images, initializes the m_bitMasks[] and
    156         // m_bitOffsets[] arrays.  processInfoHeader() will initialize these for
    157         // other compression types where needed.
    158         bool processBitmasks();
    159 
    160         // For paletted images, allocates and initializes the m_colorTable[]
    161         // array.
    162         bool processColorTable();
    163 
    164         // Processes an RLE-encoded image.  Returns true if the entire image was
    165         // decoded.
    166         bool processRLEData();
    167 
    168         // Processes a set of non-RLE-compressed pixels.  Two cases:
    169         //   * inRLE = true: the data is inside an RLE-encoded bitmap.  Tries to
    170         //     process |numPixels| pixels on the current row.
    171         //   * inRLE = false: the data is inside a non-RLE-encoded bitmap.
    172         //     |numPixels| is ignored.  Expects |m_coord| to point at the
    173         //     beginning of the next row to be decoded.  Tries to process as
    174         //     many complete rows as possible.  Returns InsufficientData if
    175         //     there wasn't enough data to decode the whole image.
    176         //
    177         // This function returns a ProcessingResult instead of a bool so that it
    178         // can avoid calling m_parent->setFailed(), which could lead to memory
    179         // corruption since that will delete |this| but some callers still want
    180         // to access member variables after this returns.
    181         ProcessingResult processNonRLEData(bool inRLE, int numPixels);
    182 
    183         // Returns true if the current y-coordinate plus |numRows| would be past
    184         // the end of the image.  Here "plus" means "toward the end of the
    185         // image", so downwards for m_isTopDown images and upwards otherwise.
    186         inline bool pastEndOfImage(int numRows)
    187         {
    188             return m_isTopDown ? ((m_coord.y() + numRows) >= m_parent->size().height()) : ((m_coord.y() - numRows) < 0);
    189         }
    190 
    191         // Returns the pixel data for the current X coordinate in a uint32_t.
    192         // Assumes m_decodedOffset has been set to the beginning of the current
    193         // row.
    194         // NOTE: Only as many bytes of the return value as are needed to hold
    195         // the pixel data will actually be set.
    196         inline uint32_t readCurrentPixel(int bytesPerPixel) const
    197         {
    198             const int offset = m_coord.x() * bytesPerPixel;
    199             switch (bytesPerPixel) {
    200             case 2:
    201                 return readUint16(offset);
    202 
    203             case 3: {
    204                 // It doesn't matter that we never set the most significant byte
    205                 // of the return value here in little-endian mode, the caller
    206                 // won't read it.
    207                 uint32_t pixel;
    208                 memcpy(&pixel, &m_data->data()[m_decodedOffset + offset], 3);
    209         #if CPU(BIG_ENDIAN)
    210                 pixel = ((pixel & 0xff00) << 8) | ((pixel & 0xff0000) >> 8) | ((pixel & 0xff000000) >> 24);
    211         #endif
    212                 return pixel;
    213             }
    214 
    215             case 4:
    216                 return readUint32(offset);
    217 
    218             default:
    219                 ASSERT_NOT_REACHED();
    220                 return 0;
    221             }
    222         }
    223 
    224         // Returns the value of the desired component (0, 1, 2, 3 == R, G, B, A)
    225         // in the given pixel data.
    226         inline unsigned getComponent(uint32_t pixel, int component) const
    227         {
    228             return ((pixel & m_bitMasks[component]) >> m_bitShiftsRight[component]) << m_bitShiftsLeft[component];
    229         }
    230 
    231         inline unsigned getAlpha(uint32_t pixel) const
    232         {
    233             // For images without alpha, return alpha of 0xff.
    234             return m_bitMasks[3] ? getComponent(pixel, 3) : 0xff;
    235         }
    236 
    237         // Sets the current pixel to the color given by |colorIndex|.  This also
    238         // increments the relevant local variables to move the current pixel
    239         // right by one.
    240         inline void setI(size_t colorIndex)
    241         {
    242             setPixel(m_colorTable[colorIndex].rgbRed, m_colorTable[colorIndex].rgbGreen, m_colorTable[colorIndex].rgbBlue, 0xff);
    243         }
    244 
    245         // Like setI(), but with the individual component values specified.
    246         inline void setPixel(unsigned red,
    247                             unsigned green,
    248                             unsigned blue,
    249                             unsigned alpha)
    250         {
    251             m_buffer->backingStore()->setPixel(m_coord.x(), m_coord.y(), red, green, blue, alpha);
    252             m_coord.move(1, 0);
    253         }
    254 
    255         // Fills pixels from the current X-coordinate up to, but not including,
    256         // |endCoord| with the color given by the individual components.  This
    257         // also increments the relevant local variables to move the current
    258         // pixel right to |endCoord|.
    259         inline void fillRGBA(int endCoord,
    260                              unsigned red,
    261                              unsigned green,
    262                              unsigned blue,
    263                              unsigned alpha)
    264         {
    265             if (endCoord <= m_coord.x())
    266                 return;
    267             m_buffer->backingStore()->fillRect(IntRect(m_coord.x(), m_coord.y(), endCoord - m_coord.x(), 1), red, green, blue, alpha);
    268             m_coord.setX(endCoord);
    269         }
    270 
    271         // Resets the relevant local variables to start drawing at the left edge
    272         // of the "next" row, where "next" is above or below the current row
    273         // depending on the value of |m_isTopDown|.
    274         void moveBufferToNextRow();
    275 
    276         // The decoder that owns us.
    277         ImageDecoder* m_parent;
    278 
    279         // The destination for the pixel data.
    280         ImageFrame* m_buffer;
    281 
    282         // The file to decode.
    283         RefPtr<SharedBuffer> m_data;
    284 
    285         // An index into |m_data| representing how much we've already decoded.
    286         size_t m_decodedOffset;
    287 
    288         // The file offset at which the BMP info header starts.
    289         size_t m_headerOffset;
    290 
    291         // The file offset at which the actual image bits start.  When decoding
    292         // ICO files, this is set to 0, since it's not stored anywhere in a
    293         // header; the reader functions expect the image data to start
    294         // immediately after the header and (if necessary) color table.
    295         size_t m_imgDataOffset;
    296 
    297         // The BMP info header.
    298         BitmapInfoHeader m_infoHeader;
    299 
    300         // True if this is an OS/2 1.x (aka Windows 2.x) BMP.  The struct
    301         // layouts for this type of BMP are slightly different from the later,
    302         // more common formats.
    303         bool m_isOS21x;
    304 
    305         // True if this is an OS/2 2.x BMP.  The meanings of compression types 3
    306         // and 4 for this type of BMP differ from Windows V3+ BMPs.
    307         //
    308         // This will be falsely negative in some cases, but only ones where the
    309         // way we misinterpret the data is irrelevant.
    310         bool m_isOS22x;
    311 
    312         // True if the BMP is not vertically flipped, that is, the first line of
    313         // raster data in the file is the top line of the image.
    314         bool m_isTopDown;
    315 
    316         // These flags get set to false as we finish each processing stage.
    317         bool m_needToProcessBitmasks;
    318         bool m_needToProcessColorTable;
    319 
    320         // Masks/offsets for the color values for non-palette formats.  These
    321         // are bitwise, with array entries 0, 1, 2, 3 corresponding to R, G, B,
    322         // A.
    323         //
    324         // The right/left shift values are meant to be applied after the masks.
    325         // We need to right shift to compensate for the bitfields' offsets into
    326         // the 32 bits of pixel data, and left shift to scale the color values
    327         // up for fields with less than 8 bits of precision.  Sadly, we can't
    328         // just combine these into one shift value because the net shift amount
    329         // could go either direction.  (If only "<< -x" were equivalent to
    330         // ">> x"...)
    331         uint32_t m_bitMasks[4];
    332         int m_bitShiftsRight[4];
    333         int m_bitShiftsLeft[4];
    334 
    335         // The color palette, for paletted formats.
    336         size_t m_tableSizeInBytes;
    337         Vector<RGBTriple> m_colorTable;
    338 
    339         // The coordinate to which we've decoded the image.
    340         IntPoint m_coord;
    341 
    342         // Variables that track whether we've seen pixels with alpha values != 0
    343         // and == 0, respectively.  See comments in processNonRLEData() on how
    344         // these are used.
    345         bool m_seenNonZeroAlphaPixel;
    346         bool m_seenZeroAlphaPixel;
    347 
    348         // ICOs store a 1bpp "mask" immediately after the main bitmap image data
    349         // (and, confusingly, add its height to the biHeight value in the info
    350         // header, thus doubling it).  This variable tracks whether we have such
    351         // a mask and if we've started decoding it yet.
    352         AndMaskState m_andMaskState;
    353     };
     221    }
     222
     223    // Returns the value of the desired component (0, 1, 2, 3 == R, G, B, A)
     224    // in the given pixel data.
     225    inline unsigned getComponent(uint32_t pixel, int component) const
     226    {
     227        return ((pixel & m_bitMasks[component]) >> m_bitShiftsRight[component]) << m_bitShiftsLeft[component];
     228    }
     229
     230    inline unsigned getAlpha(uint32_t pixel) const
     231    {
     232        // For images without alpha, return alpha of 0xff.
     233        return m_bitMasks[3] ? getComponent(pixel, 3) : 0xff;
     234    }
     235
     236    // Sets the current pixel to the color given by |colorIndex|. This also
     237    // increments the relevant local variables to move the current pixel
     238    // right by one.
     239    inline void setI(size_t colorIndex)
     240    {
     241        setPixel(m_colorTable[colorIndex].rgbRed, m_colorTable[colorIndex].rgbGreen, m_colorTable[colorIndex].rgbBlue, 0xff);
     242    }
     243
     244    // Like setI(), but with the individual component values specified.
     245    inline void setPixel(unsigned red, unsigned green, unsigned blue, unsigned alpha)
     246    {
     247        m_buffer->backingStore()->setPixel(m_coord.x(), m_coord.y(), red, green, blue, alpha);
     248        m_coord.move(1, 0);
     249    }
     250
     251    // Fills pixels from the current X-coordinate up to, but not including,
     252    // |endCoord| with the color given by the individual components. This
     253    // also increments the relevant local variables to move the current
     254    // pixel right to |endCoord|.
     255    inline void fillRGBA(int endCoord, unsigned red, unsigned green, unsigned blue, unsigned alpha)
     256    {
     257        if (endCoord <= m_coord.x())
     258            return;
     259        m_buffer->backingStore()->fillRect(IntRect(m_coord.x(), m_coord.y(), endCoord - m_coord.x(), 1), red, green, blue, alpha);
     260        m_coord.setX(endCoord);
     261    }
     262
     263    // Resets the relevant local variables to start drawing at the left edge
     264    // of the "next" row, where "next" is above or below the current row
     265    // depending on the value of |m_isTopDown|.
     266    void moveBufferToNextRow();
     267
     268    // The decoder that owns us.
     269    ScalableImageDecoder* m_parent;
     270
     271    // The destination for the pixel data.
     272    ImageFrame* m_buffer;
     273
     274    // The file to decode.
     275    RefPtr<SharedBuffer> m_data;
     276
     277    // An index into |m_data| representing how much we've already decoded.
     278    size_t m_decodedOffset;
     279
     280    // The file offset at which the BMP info header starts.
     281    size_t m_headerOffset;
     282
     283    // The file offset at which the actual image bits start. When decoding
     284    // ICO files, this is set to 0, since it's not stored anywhere in a
     285    // header; the reader functions expect the image data to start
     286    // immediately after the header and (if necessary) color table.
     287    size_t m_imgDataOffset;
     288
     289    // The BMP info header.
     290    BitmapInfoHeader m_infoHeader;
     291
     292    // True if this is an OS/2 1.x (aka Windows 2.x) BMP. The struct
     293    // layouts for this type of BMP are slightly different from the later,
     294    // more common formats.
     295    bool m_isOS21x;
     296
     297    // True if this is an OS/2 2.x BMP. The meanings of compression types 3
     298    // and 4 for this type of BMP differ from Windows V3+ BMPs.
     299    //
     300    // This will be falsely negative in some cases, but only ones where the
     301    // way we misinterpret the data is irrelevant.
     302    bool m_isOS22x;
     303
     304    // True if the BMP is not vertically flipped, that is, the first line of
     305    // raster data in the file is the top line of the image.
     306    bool m_isTopDown;
     307
     308    // These flags get set to false as we finish each processing stage.
     309    bool m_needToProcessBitmasks;
     310    bool m_needToProcessColorTable;
     311
     312    // Masks/offsets for the color values for non-palette formats. These
     313    // are bitwise, with array entries 0, 1, 2, 3 corresponding to R, G, B,
     314    // A.
     315    //
     316    // The right/left shift values are meant to be applied after the masks.
     317    // We need to right shift to compensate for the bitfields' offsets into
     318    // the 32 bits of pixel data, and left shift to scale the color values
     319    // up for fields with less than 8 bits of precision. Sadly, we can't
     320    // just combine these into one shift value because the net shift amount
     321    // could go either direction. (If only "<< -x" were equivalent to
     322    // ">> x"...)
     323    uint32_t m_bitMasks[4];
     324    int m_bitShiftsRight[4];
     325    int m_bitShiftsLeft[4];
     326
     327    // The color palette, for paletted formats.
     328    size_t m_tableSizeInBytes;
     329    Vector<RGBTriple> m_colorTable;
     330
     331    // The coordinate to which we've decoded the image.
     332    IntPoint m_coord;
     333
     334    // Variables that track whether we've seen pixels with alpha values != 0
     335    // and == 0, respectively. See comments in processNonRLEData() on how
     336    // these are used.
     337    bool m_seenNonZeroAlphaPixel;
     338    bool m_seenZeroAlphaPixel;
     339
     340    // ICOs store a 1bpp "mask" immediately after the main bitmap image data
     341    // (and, confusingly, add its height to the biHeight value in the info
     342    // header, thus doubling it). This variable tracks whether we have such
     343    // a mask and if we've started decoding it yet.
     344    AndMaskState m_andMaskState;
     345};
    354346
    355347} // namespace WebCore
    356 
    357 #endif
  • trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp

    r219762 r222151  
    3333
    3434GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    35     : ImageDecoder(alphaOption, gammaAndColorProfileOption)
     35    : ScalableImageDecoder(alphaOption, gammaAndColorProfileOption)
    3636{
    3737}
     
    4646        return;
    4747
    48     ImageDecoder::setData(data, allDataReceived);
     48    ScalableImageDecoder::setData(data, allDataReceived);
    4949    if (m_reader)
    5050        m_reader->setData(&data);
     
    5353bool GIFImageDecoder::setSize(const IntSize& size)
    5454{
    55     if (ImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable && this->size() == size)
     55    if (ScalableImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable && this->size() == size)
    5656        return true;
    5757
    58     if (!ImageDecoder::setSize(size))
     58    if (!ScalableImageDecoder::setSize(size))
    5959        return false;
    6060
     
    116116{
    117117    m_reader = nullptr;
    118     return ImageDecoder::setFailed();
     118    return ScalableImageDecoder::setFailed();
    119119}
    120120
  • trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h

    r215924 r222151  
    2626#pragma once
    2727
    28 #include "ImageDecoder.h"
     28#include "ScalableImageDecoder.h"
    2929#include <wtf/Lock.h>
    3030
     
    3333namespace WebCore {
    3434
    35     // This class decodes the GIF image format.
    36     class GIFImageDecoder final : public ImageDecoder {
    37     public:
    38         static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    39         {
    40             return adoptRef(*new GIFImageDecoder(alphaOption, gammaAndColorProfileOption));
    41         }
     35// This class decodes the GIF image format.
     36class GIFImageDecoder final : public ScalableImageDecoder {
     37public:
     38    static Ref<ScalableImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     39    {
     40        return adoptRef(*new GIFImageDecoder(alphaOption, gammaAndColorProfileOption));
     41    }
    4242
    43         virtual ~GIFImageDecoder();
     43    virtual ~GIFImageDecoder();
    4444
    45         enum GIFQuery { GIFFullQuery, GIFSizeQuery, GIFFrameCountQuery };
     45    enum GIFQuery { GIFFullQuery, GIFSizeQuery, GIFFrameCountQuery };
    4646
    47         // ImageDecoder
    48         String filenameExtension() const override { return ASCIILiteral("gif"); }
    49         void setData(SharedBuffer& data, bool allDataReceived) override;
    50         bool setSize(const IntSize&) override;
    51         size_t frameCount() const override;
    52         RepetitionCount repetitionCount() const override;
    53         ImageFrame* frameBufferAtIndex(size_t index) override;
    54         // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
    55         // accessing deleted memory, especially when calling this from inside
    56         // GIFImageReader!
    57         bool setFailed() override;
    58         void clearFrameBufferCache(size_t clearBeforeFrame) override;
     47    // ScalableImageDecoder
     48    String filenameExtension() const final { return ASCIILiteral("gif"); }
     49    void setData(SharedBuffer& data, bool allDataReceived) final;
     50    bool setSize(const IntSize&) final;
     51    size_t frameCount() const final;
     52    RepetitionCount repetitionCount() const final;
     53    ImageFrame* frameBufferAtIndex(size_t index) final;
     54    // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
     55    // accessing deleted memory, especially when calling this from inside
     56    // GIFImageReader!
     57    bool setFailed() final;
     58    void clearFrameBufferCache(size_t clearBeforeFrame) final;
    5959
    60         // Callbacks from the GIF reader.
    61         bool haveDecodedRow(unsigned frameIndex, const Vector<unsigned char>& rowBuffer, size_t width, size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels);
    62         bool frameComplete(unsigned frameIndex, unsigned frameDuration, ImageFrame::DisposalMethod);
    63         void gifComplete();
     60    // Callbacks from the GIF reader.
     61    bool haveDecodedRow(unsigned frameIndex, const Vector<unsigned char>& rowBuffer, size_t width, size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels);
     62    bool frameComplete(unsigned frameIndex, unsigned frameDuration, ImageFrame::DisposalMethod);
     63    void gifComplete();
    6464
    65     private:
    66         GIFImageDecoder(AlphaOption, GammaAndColorProfileOption);
    67         void tryDecodeSize(bool allDataReceived) override { decode(0, GIFSizeQuery, allDataReceived); }
     65private:
     66    GIFImageDecoder(AlphaOption, GammaAndColorProfileOption);
     67    void tryDecodeSize(bool allDataReceived) final { decode(0, GIFSizeQuery, allDataReceived); }
    6868
    69         // If the query is GIFFullQuery, decodes the image up to (but not
    70         // including) |haltAtFrame|. Otherwise, decodes as much as is needed to
    71         // answer the query, ignoring bitmap data. If decoding fails but there
    72         // is no more data coming, sets the "decode failure" flag.
    73         void decode(unsigned haltAtFrame, GIFQuery, bool allDataReceived);
     69    // If the query is GIFFullQuery, decodes the image up to (but not
     70    // including) |haltAtFrame|. Otherwise, decodes as much as is needed to
     71    // answer the query, ignoring bitmap data. If decoding fails but there
     72    // is no more data coming, sets the "decode failure" flag.
     73    void decode(unsigned haltAtFrame, GIFQuery, bool allDataReceived);
    7474
    75         // Called to initialize the frame buffer with the given index, based on
    76         // the previous frame's disposal method. Returns true on success. On
    77         // failure, this will mark the image as failed.
    78         bool initFrameBuffer(unsigned frameIndex);
     75    // Called to initialize the frame buffer with the given index, based on
     76    // the previous frame's disposal method. Returns true on success. On
     77    // failure, this will mark the image as failed.
     78    bool initFrameBuffer(unsigned frameIndex);
    7979
    80         bool m_currentBufferSawAlpha;
    81         mutable RepetitionCount m_repetitionCount { RepetitionCountOnce };
    82         std::unique_ptr<GIFImageReader> m_reader;
    83         Lock m_decodeLock;
    84     };
     80    bool m_currentBufferSawAlpha;
     81    mutable RepetitionCount m_repetitionCount { RepetitionCountOnce };
     82    std::unique_ptr<GIFImageReader> m_reader;
     83    Lock m_decodeLock;
     84};
    8585
    8686} // namespace WebCore
  • trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp

    r219702 r222151  
    4646
    4747ICOImageDecoder::ICOImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    48     : ImageDecoder(alphaOption, gammaAndColorProfileOption)
     48    : ScalableImageDecoder(alphaOption, gammaAndColorProfileOption)
    4949    , m_decodedOffset(0)
    5050{
     
    6060        return;
    6161
    62     ImageDecoder::setData(data, allDataReceived);
     62    ScalableImageDecoder::setData(data, allDataReceived);
    6363
    6464    for (BMPReaders::iterator i(m_bmpReaders.begin()); i != m_bmpReaders.end(); ++i) {
     
    7070}
    7171
    72 IntSize ICOImageDecoder::size()
    73 {
    74     return m_frameSize.isEmpty() ? ImageDecoder::size() : m_frameSize;
    75 }
    76 
    77 IntSize ICOImageDecoder::frameSizeAtIndex(size_t index, SubsamplingLevel)
     72IntSize ICOImageDecoder::size() const
     73{
     74    return m_frameSize.isEmpty() ? ScalableImageDecoder::size() : m_frameSize;
     75}
     76
     77IntSize ICOImageDecoder::frameSizeAtIndex(size_t index, SubsamplingLevel) const
    7878{
    7979    return (index && (index < m_dirEntries.size())) ? m_dirEntries[index].m_size : size();
     
    8484    // The size calculated inside the BMPImageReader had better match the one in
    8585    // the icon directory.
    86     return m_frameSize.isEmpty() ? ImageDecoder::setSize(size) : ((size == m_frameSize) || setFailed());
     86    return m_frameSize.isEmpty() ? ScalableImageDecoder::setSize(size) : ((size == m_frameSize) || setFailed());
    8787}
    8888
     
    109109    m_bmpReaders.clear();
    110110    m_pngDecoders.clear();
    111     return ImageDecoder::setFailed();
     111    return ScalableImageDecoder::setFailed();
    112112}
    113113
  • trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h

    r215924 r222151  
    3434
    3535namespace WebCore {
    36     // This class decodes the ICO and CUR image formats.
    37     class ICOImageDecoder final : public ImageDecoder {
    38     public:
    39         static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    40         {
    41             return adoptRef(*new ICOImageDecoder(alphaOption, gammaAndColorProfileOption));
    42         }
    4336
    44         virtual ~ICOImageDecoder();
     37// This class decodes the ICO and CUR image formats.
     38class ICOImageDecoder final : public ScalableImageDecoder {
     39public:
     40    static Ref<ScalableImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     41    {
     42        return adoptRef(*new ICOImageDecoder(alphaOption, gammaAndColorProfileOption));
     43    }
    4544
    46         // ImageDecoder
    47         String filenameExtension() const override { return ASCIILiteral("ico"); }
    48         void setData(SharedBuffer&, bool allDataReceived) override;
    49         IntSize size() override;
    50         IntSize frameSizeAtIndex(size_t, SubsamplingLevel) override;
    51         bool setSize(const IntSize&) override;
    52         size_t frameCount() const override;
    53         ImageFrame* frameBufferAtIndex(size_t) override;
    54         // CAUTION: setFailed() deletes all readers and decoders.  Be careful to
    55         // avoid accessing deleted memory, especially when calling this from
    56         // inside BMPImageReader!
    57         bool setFailed() override;
    58         std::optional<IntPoint> hotSpot() const override;
     45    virtual ~ICOImageDecoder();
    5946
    60     private:
    61         enum ImageType {
    62             Unknown,
    63             BMP,
    64             PNG,
    65         };
     47    // ScalableImageDecoder
     48    String filenameExtension() const final { return ASCIILiteral("ico"); }
     49    void setData(SharedBuffer&, bool allDataReceived) final;
     50    IntSize size() const final;
     51    IntSize frameSizeAtIndex(size_t, SubsamplingLevel) const final;
     52    bool setSize(const IntSize&) final;
     53    size_t frameCount() const final;
     54    ImageFrame* frameBufferAtIndex(size_t) final;
     55    // CAUTION: setFailed() deletes all readers and decoders. Be careful to
     56    // avoid accessing deleted memory, especially when calling this from
     57    // inside BMPImageReader!
     58    bool setFailed() final;
     59    std::optional<IntPoint> hotSpot() const final;
    6660
    67         enum FileType {
    68             ICON = 1,
    69             CURSOR = 2,
    70         };
    71 
    72         struct IconDirectoryEntry {
    73             IntSize m_size;
    74             uint16_t m_bitCount;
    75             IntPoint m_hotSpot;
    76             uint32_t m_imageOffset;
    77         };
    78 
    79         ICOImageDecoder(AlphaOption, GammaAndColorProfileOption);
    80         void tryDecodeSize(bool allDataReceived) override { decode(0, true, allDataReceived); }
    81 
    82         // Returns true if |a| is a preferable icon entry to |b|.
    83         // Larger sizes, or greater bitdepths at the same size, are preferable.
    84         static bool compareEntries(const IconDirectoryEntry& a, const IconDirectoryEntry& b);
    85 
    86         inline uint16_t readUint16(int offset) const
    87         {
    88             return BMPImageReader::readUint16(m_data.get(), m_decodedOffset + offset);
    89         }
    90 
    91         inline uint32_t readUint32(int offset) const
    92         {
    93             return BMPImageReader::readUint32(m_data.get(), m_decodedOffset + offset);
    94         }
    95 
    96         // If the desired PNGImageDecoder exists, gives it the appropriate data.
    97         void setDataForPNGDecoderAtIndex(size_t);
    98 
    99         // Decodes the entry at |index|.  If |onlySize| is true, stops decoding
    100         // after calculating the image size.  If decoding fails but there is no
    101         // more data coming, sets the "decode failure" flag.
    102         void decode(size_t index, bool onlySize, bool allDataReceived);
    103 
    104         // Decodes the directory and directory entries at the beginning of the
    105         // data, and initializes members.  Returns true if all decoding
    106         // succeeded.  Once this returns true, all entries' sizes are known.
    107         bool decodeDirectory();
    108 
    109         // Decodes the specified entry.
    110         bool decodeAtIndex(size_t);
    111 
    112         // Processes the ICONDIR at the beginning of the data.  Returns true if
    113         // the directory could be decoded.
    114         bool processDirectory();
    115 
    116         // Processes the ICONDIRENTRY records after the directory.  Keeps the
    117         // "best" entry as the one we'll decode.  Returns true if the entries
    118         // could be decoded.
    119         bool processDirectoryEntries();
    120 
    121         // Returns the hot-spot for |index|, returns std::nullopt if there is none.
    122         std::optional<IntPoint> hotSpotAtIndex(size_t) const;
    123 
    124         // Reads and returns a directory entry from the current offset into
    125         // |data|.
    126         IconDirectoryEntry readDirectoryEntry();
    127 
    128         // Determines whether the desired entry is a BMP or PNG.  Returns true
    129         // if the type could be determined.
    130         ImageType imageTypeAtIndex(size_t);
    131 
    132         // An index into |m_data| representing how much we've already decoded.
    133         // Note that this only tracks data _this_ class decodes; once the
    134         // BMPImageReader takes over this will not be updated further.
    135         size_t m_decodedOffset;
    136 
    137         // Which type of file (ICO/CUR) this is.
    138         FileType m_fileType;
    139 
    140         // The headers for the ICO.
    141         typedef Vector<IconDirectoryEntry> IconDirectoryEntries;
    142         IconDirectoryEntries m_dirEntries;
    143 
    144         // The image decoders for the various frames.
    145         typedef Vector<std::unique_ptr<BMPImageReader>> BMPReaders;
    146         BMPReaders m_bmpReaders;
    147         typedef Vector<RefPtr<ImageDecoder>> PNGDecoders;
    148         PNGDecoders m_pngDecoders;
    149 
    150         // Valid only while a BMPImageReader is decoding, this holds the size
    151         // for the particular entry being decoded.
    152         IntSize m_frameSize;
     61private:
     62    enum ImageType {
     63        Unknown,
     64        BMP,
     65        PNG,
    15366    };
    15467
     68    enum FileType {
     69        ICON = 1,
     70        CURSOR = 2,
     71    };
     72
     73    struct IconDirectoryEntry {
     74        IntSize m_size;
     75        uint16_t m_bitCount;
     76        IntPoint m_hotSpot;
     77        uint32_t m_imageOffset;
     78    };
     79
     80    ICOImageDecoder(AlphaOption, GammaAndColorProfileOption);
     81    void tryDecodeSize(bool allDataReceived) final { decode(0, true, allDataReceived); }
     82
     83    // Returns true if |a| is a preferable icon entry to |b|.
     84    // Larger sizes, or greater bitdepths at the same size, are preferable.
     85    static bool compareEntries(const IconDirectoryEntry& a, const IconDirectoryEntry& b);
     86
     87    inline uint16_t readUint16(int offset) const
     88    {
     89        return BMPImageReader::readUint16(m_data.get(), m_decodedOffset + offset);
     90    }
     91
     92    inline uint32_t readUint32(int offset) const
     93    {
     94        return BMPImageReader::readUint32(m_data.get(), m_decodedOffset + offset);
     95    }
     96
     97    // If the desired PNGImageDecoder exists, gives it the appropriate data.
     98    void setDataForPNGDecoderAtIndex(size_t);
     99
     100    // Decodes the entry at |index|. If |onlySize| is true, stops decoding
     101    // after calculating the image size. If decoding fails but there is no
     102    // more data coming, sets the "decode failure" flag.
     103    void decode(size_t index, bool onlySize, bool allDataReceived);
     104
     105    // Decodes the directory and directory entries at the beginning of the
     106    // data, and initializes members. Returns true if all decoding
     107    // succeeded. Once this returns true, all entries' sizes are known.
     108    bool decodeDirectory();
     109
     110    // Decodes the specified entry.
     111    bool decodeAtIndex(size_t);
     112
     113    // Processes the ICONDIR at the beginning of the data. Returns true if
     114    // the directory could be decoded.
     115    bool processDirectory();
     116
     117    // Processes the ICONDIRENTRY records after the directory. Keeps the
     118    // "best" entry as the one we'll decode. Returns true if the entries
     119    // could be decoded.
     120    bool processDirectoryEntries();
     121
     122    // Returns the hot-spot for |index|, returns std::nullopt if there is none.
     123    std::optional<IntPoint> hotSpotAtIndex(size_t) const;
     124
     125    // Reads and returns a directory entry from the current offset into
     126    // |data|.
     127    IconDirectoryEntry readDirectoryEntry();
     128
     129    // Determines whether the desired entry is a BMP or PNG. Returns true
     130    // if the type could be determined.
     131    ImageType imageTypeAtIndex(size_t);
     132
     133    // An index into |m_data| representing how much we've already decoded.
     134    // Note that this only tracks data _this_ class decodes; once the
     135    // BMPImageReader takes over this will not be updated further.
     136    size_t m_decodedOffset;
     137
     138    // Which type of file (ICO/CUR) this is.
     139    FileType m_fileType;
     140
     141    // The headers for the ICO.
     142    typedef Vector<IconDirectoryEntry> IconDirectoryEntries;
     143    IconDirectoryEntries m_dirEntries;
     144
     145    // The image decoders for the various frames.
     146    typedef Vector<std::unique_ptr<BMPImageReader>> BMPReaders;
     147    BMPReaders m_bmpReaders;
     148    typedef Vector<RefPtr<ScalableImageDecoder>> PNGDecoders;
     149    PNGDecoders m_pngDecoders;
     150
     151    // Valid only while a BMPImageReader is decoding, this holds the size
     152    // for the particular entry being decoded.
     153    IntSize m_frameSize;
     154};
     155
    155156} // namespace WebCore
  • trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp

    r219762 r222151  
    503503
    504504JPEGImageDecoder::JPEGImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    505     : ImageDecoder(alphaOption, gammaAndColorProfileOption)
     505    : ScalableImageDecoder(alphaOption, gammaAndColorProfileOption)
    506506{
    507507}
     
    513513bool JPEGImageDecoder::setSize(const IntSize& size)
    514514{
    515     if (!ImageDecoder::setSize(size))
     515    if (!ScalableImageDecoder::setSize(size))
    516516        return false;
    517517
     
    537537{
    538538    m_reader = nullptr;
    539     return ImageDecoder::setFailed();
     539    return ScalableImageDecoder::setFailed();
    540540}
    541541
  • trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h

    r215924 r222151  
    2727#pragma once
    2828
    29 #include "ImageDecoder.h"
     29#include "ScalableImageDecoder.h"
    3030#include <stdio.h> // Needed by jpeglib.h for FILE.
    3131
     
    4242
    4343    // This class decodes the JPEG image format.
    44     class JPEGImageDecoder final : public ImageDecoder {
     44    class JPEGImageDecoder final : public ScalableImageDecoder {
    4545    public:
    46         static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     46        static Ref<ScalableImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    4747        {
    4848            return adoptRef(*new JPEGImageDecoder(alphaOption, gammaAndColorProfileOption));
     
    5151        virtual ~JPEGImageDecoder();
    5252
    53         // ImageDecoder
     53        // ScalableImageDecoder
    5454        String filenameExtension() const override { return ASCIILiteral("jpg"); }
    5555        bool setSize(const IntSize&) override;
     
    6262        bool willDownSample()
    6363        {
    64             ASSERT(ImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable);
     64            ASSERT(ScalableImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable);
    6565            return m_scaled;
    6666        }
  • trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp

    r219762 r222151  
    174174            // merely want to check if we've managed to set the size, not
    175175            // (recursively) trigger additional decoding if we haven't.
    176             if (sizeOnly ? decoder->ImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable : decoder->isCompleteAtIndex(haltAtFrame))
     176            if (sizeOnly ? decoder->ScalableImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable : decoder->isCompleteAtIndex(haltAtFrame))
    177177                return true;
    178178        }
     
    203203
    204204PNGImageDecoder::PNGImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    205     : ImageDecoder(alphaOption, gammaAndColorProfileOption)
     205    : ScalableImageDecoder(alphaOption, gammaAndColorProfileOption)
    206206    , m_doNothingOnFailure(false)
    207207    , m_currentFrame(0)
     
    250250bool PNGImageDecoder::setSize(const IntSize& size)
    251251{
    252     if (!ImageDecoder::setSize(size))
     252    if (!ScalableImageDecoder::setSize(size))
    253253        return false;
    254254
     
    260260{
    261261#if ENABLE(APNG)
    262     if (ImageDecoder::encodedDataStatus() < EncodedDataStatus::SizeAvailable)
     262    if (ScalableImageDecoder::encodedDataStatus() < EncodedDataStatus::SizeAvailable)
    263263        return nullptr;
    264264
     
    284284        return false;
    285285    m_reader = nullptr;
    286     return ImageDecoder::setFailed();
     286    return ScalableImageDecoder::setFailed();
    287287}
    288288
  • trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h

    r215924 r222151  
    2626#pragma once
    2727
    28 #include "ImageDecoder.h"
     28#include "ScalableImageDecoder.h"
    2929#if ENABLE(APNG)
    3030#include <png.h>
     
    3636
    3737    // This class decodes the PNG image format.
    38     class PNGImageDecoder final : public ImageDecoder {
     38    class PNGImageDecoder final : public ScalableImageDecoder {
    3939    public:
    40         static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     40        static Ref<ScalableImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    4141        {
    4242            return adoptRef(*new PNGImageDecoder(alphaOption, gammaAndColorProfileOption));
     
    4545        virtual ~PNGImageDecoder();
    4646
    47         // ImageDecoder
     47        // ScalableImageDecoder
    4848        String filenameExtension() const override { return ASCIILiteral("png"); }
    4949#if ENABLE(APNG)
  • trunk/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp

    r219762 r222151  
    4747
    4848WEBPImageDecoder::WEBPImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    49     : ImageDecoder(alphaOption, gammaAndColorProfileOption)
     49    : ScalableImageDecoder(alphaOption, gammaAndColorProfileOption)
    5050    , m_decoder(0)
    5151    , m_hasAlpha(false)
     
    8787    const size_t dataSize = m_data->size();
    8888
    89     if (ImageDecoder::encodedDataStatus() < EncodedDataStatus::SizeAvailable) {
     89    if (ScalableImageDecoder::encodedDataStatus() < EncodedDataStatus::SizeAvailable) {
    9090        static const size_t imageHeaderSize = 30;
    9191        if (dataSize < imageHeaderSize)
     
    109109    }
    110110
    111     ASSERT(ImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable);
     111    ASSERT(ScalableImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable);
    112112    if (onlySize)
    113113        return true;
  • trunk/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.h

    r215924 r222151  
    2929#pragma once
    3030
    31 #include "ImageDecoder.h"
     31#include "ScalableImageDecoder.h"
    3232
    3333#if USE(WEBP)
     
    3737namespace WebCore {
    3838
    39 class WEBPImageDecoder final : public ImageDecoder {
     39class WEBPImageDecoder final : public ScalableImageDecoder {
    4040public:
    41     static Ref<ImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     41    static Ref<ScalableImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    4242    {
    4343        return adoptRef(*new WEBPImageDecoder(alphaOption, gammaAndColorProfileOption));
Note: See TracChangeset for help on using the changeset viewer.