ImageFrame type used by non-Cocoa image decoder should not be the same as that used...
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Apr 2018 13:47:26 +0000 (13:47 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Apr 2018 13:47:26 +0000 (13:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184418

Reviewed by Said Abou-Hallawa.

ScalableImageDecoder uses ImageFrame class which is meant to be an implementation detail of ImageSource.
There are bunch of fields and methods in the type that are only used by one or the other client. For hackability
there should be an unrelated frame type for ScalableImageDecoder.

This patch adds ScalableImageDecoderFrame type used in ScalableImageDecoder only. It then cleans up
unneeded things from both ImageFrame and ScalableImageDecoderFrame.

* platform/ImageDecoders.cmake:
* platform/graphics/ImageFrame.cpp:
(WebCore::ImageFrame::operator=):
(WebCore::ImageFrame::clearImage):
(WebCore::ImageFrame::size const):
(WebCore::ImageFrame::initialize): Deleted.
* platform/graphics/ImageFrame.h:
(WebCore::ImageFrame::setDisposalMethod): Deleted.
(WebCore::ImageFrame::disposalMethod const): Deleted.
(WebCore::ImageFrame::backingStore const): Deleted.
(WebCore::ImageFrame::hasBackingStore const): Deleted.
* platform/image-decoders/ScalableImageDecoder.cpp:
(WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const):
(WebCore::ScalableImageDecoder::frameDurationAtIndex const):
(WebCore::ScalableImageDecoder::createFrameImageAtIndex):
* platform/image-decoders/ScalableImageDecoder.h:
* platform/image-decoders/ScalableImageDecoderFrame.cpp: Copied from Source/WebCore/platform/graphics/ImageFrame.cpp.
(WebCore::ScalableImageDecoderFrame::ScalableImageDecoderFrame):
(WebCore::ScalableImageDecoderFrame::~ScalableImageDecoderFrame):
(WebCore::ScalableImageDecoderFrame::operator=):
(WebCore::ScalableImageDecoderFrame::setDecodingStatus):
(WebCore::ScalableImageDecoderFrame::decodingStatus const):
(WebCore::ScalableImageDecoderFrame::clearImage):
(WebCore::ScalableImageDecoderFrame::clear):
(WebCore::ScalableImageDecoderFrame::initialize):
(WebCore::ScalableImageDecoderFrame::size const):
(WebCore::ImageFrame::ImageFrame): Deleted.
(WebCore::ImageFrame::~ImageFrame): Deleted.
(WebCore::ImageFrame::defaultFrame): Deleted.
(WebCore::ImageFrame::operator=): Deleted.
(WebCore::ImageFrame::setDecodingStatus): Deleted.
(WebCore::ImageFrame::decodingStatus const): Deleted.
(WebCore::ImageFrame::clearImage): Deleted.
(WebCore::ImageFrame::clear): Deleted.
(WebCore::ImageFrame::initialize): Deleted.
(WebCore::ImageFrame::size const): Deleted.
(WebCore::ImageFrame::hasNativeImage const): Deleted.
(WebCore::ImageFrame::hasFullSizeNativeImage const): Deleted.
(WebCore::ImageFrame::hasDecodedNativeImageCompatibleWithOptions const): Deleted.
(WebCore::ImageFrame::singlePixelSolidColor const): Deleted.
* platform/image-decoders/ScalableImageDecoderFrame.h: Copied from Source/WebCore/platform/graphics/ImageFrame.h.
(WebCore::ScalableImageDecoderFrame::ScalableImageDecoderFrame):
(WebCore::ScalableImageDecoderFrame::disposalMethod const):
(WebCore::ScalableImageDecoderFrame::hasAlpha const):
(WebCore::ScalableImageDecoderFrame::hasBackingStore const):
(WebCore::ImageFrame::ImageFrame): Deleted.
(WebCore::ImageFrame::isInvalid const): Deleted.
(WebCore::ImageFrame::isPartial const): Deleted.
(WebCore::ImageFrame::isComplete const): Deleted.
(WebCore::ImageFrame::sizeRespectingOrientation const): Deleted.
(WebCore::ImageFrame::frameBytes const): Deleted.
(WebCore::ImageFrame::subsamplingLevel const): Deleted.
(WebCore::ImageFrame::setDisposalMethod): Deleted.
(WebCore::ImageFrame::disposalMethod const): Deleted.
(WebCore::ImageFrame::nativeImage const): Deleted.
(WebCore::ImageFrame::setOrientation): Deleted.
(WebCore::ImageFrame::orientation const): Deleted.
(WebCore::ImageFrame::setDuration): Deleted.
(WebCore::ImageFrame::duration const): Deleted.
(WebCore::ImageFrame::setHasAlpha): Deleted.
(WebCore::ImageFrame::hasAlpha const): Deleted.
(WebCore::ImageFrame::hasNativeImage): Deleted.
(WebCore::ImageFrame::hasFullSizeNativeImage): Deleted.
(WebCore::ImageFrame::hasMetadata const): Deleted.
(WebCore::ImageFrame::backingStore const): Deleted.
(WebCore::ImageFrame::hasBackingStore const): Deleted.
* platform/image-decoders/bmp/BMPImageDecoder.cpp:
(WebCore::BMPImageDecoder::frameBufferAtIndex):
* platform/image-decoders/bmp/BMPImageDecoder.h:
* platform/image-decoders/bmp/BMPImageReader.h:
(WebCore::BMPImageReader::setBuffer):
* platform/image-decoders/gif/GIFImageDecoder.cpp:
(WebCore::GIFImageDecoder::findFirstRequiredFrameToDecode):
(WebCore::GIFImageDecoder::frameBufferAtIndex):
(WebCore::GIFImageDecoder::clearFrameBufferCache):
(WebCore::GIFImageDecoder::haveDecodedRow):
(WebCore::GIFImageDecoder::frameComplete):
(WebCore::GIFImageDecoder::initFrameBuffer):
* platform/image-decoders/gif/GIFImageDecoder.h:
* platform/image-decoders/gif/GIFImageReader.cpp:
(GIFImageReader::parse):
* platform/image-decoders/gif/GIFImageReader.h:
(GIFFrameContext::GIFFrameContext):
* platform/image-decoders/ico/ICOImageDecoder.cpp:
(WebCore::ICOImageDecoder::frameBufferAtIndex):
* platform/image-decoders/ico/ICOImageDecoder.h:
* platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
(WebCore::JPEGImageDecoder::frameBufferAtIndex):
(WebCore::setPixel):
(WebCore::JPEGImageDecoder::outputScanlines):
(WebCore::JPEGImageDecoder::jpegComplete):
* platform/image-decoders/jpeg/JPEGImageDecoder.h:
* platform/image-decoders/png/PNGImageDecoder.cpp:
(WebCore::PNGImageDecoder::frameBufferAtIndex):
(WebCore::PNGImageDecoder::rowAvailable):
(WebCore::PNGImageDecoder::readChunks):
(WebCore::PNGImageDecoder::clearFrameBufferCache):
(WebCore::PNGImageDecoder::initFrameBuffer):
(WebCore::PNGImageDecoder::frameComplete):
* platform/image-decoders/png/PNGImageDecoder.h:
* platform/image-decoders/webp/WEBPImageDecoder.cpp:
(WebCore::WEBPImageDecoder::frameBufferAtIndex):
(WebCore::WEBPImageDecoder::findFirstRequiredFrameToDecode):
(WebCore::WEBPImageDecoder::decodeFrame):
(WebCore::WEBPImageDecoder::initFrameBuffer):
(WebCore::WEBPImageDecoder::applyPostProcessing):
(WebCore::WEBPImageDecoder::clearFrameBufferCache):
* platform/image-decoders/webp/WEBPImageDecoder.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230522 268f45cc-cd09-0410-ab3c-d52691b4dbfc

23 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/ImageDecoders.cmake
Source/WebCore/platform/graphics/ImageFrame.cpp
Source/WebCore/platform/graphics/ImageFrame.h
Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp
Source/WebCore/platform/image-decoders/ScalableImageDecoder.h
Source/WebCore/platform/image-decoders/ScalableImageDecoderFrame.cpp [new file with mode: 0644]
Source/WebCore/platform/image-decoders/ScalableImageDecoderFrame.h [new file with mode: 0644]
Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp
Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h
Source/WebCore/platform/image-decoders/bmp/BMPImageReader.h
Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h
Source/WebCore/platform/image-decoders/gif/GIFImageReader.cpp
Source/WebCore/platform/image-decoders/gif/GIFImageReader.h
Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h
Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h
Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h
Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp
Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.h

index e9a5a7b..ed4313f 100644 (file)
@@ -1,3 +1,126 @@
+2018-04-11  Antti Koivisto  <antti@apple.com>
+
+        ImageFrame type used by non-Cocoa image decoder should not be the same as that used by ImageSource
+        https://bugs.webkit.org/show_bug.cgi?id=184418
+
+        Reviewed by Said Abou-Hallawa.
+
+        ScalableImageDecoder uses ImageFrame class which is meant to be an implementation detail of ImageSource.
+        There are bunch of fields and methods in the type that are only used by one or the other client. For hackability
+        there should be an unrelated frame type for ScalableImageDecoder.
+
+        This patch adds ScalableImageDecoderFrame type used in ScalableImageDecoder only. It then cleans up
+        unneeded things from both ImageFrame and ScalableImageDecoderFrame.
+
+        * platform/ImageDecoders.cmake:
+        * platform/graphics/ImageFrame.cpp:
+        (WebCore::ImageFrame::operator=):
+        (WebCore::ImageFrame::clearImage):
+        (WebCore::ImageFrame::size const):
+        (WebCore::ImageFrame::initialize): Deleted.
+        * platform/graphics/ImageFrame.h:
+        (WebCore::ImageFrame::setDisposalMethod): Deleted.
+        (WebCore::ImageFrame::disposalMethod const): Deleted.
+        (WebCore::ImageFrame::backingStore const): Deleted.
+        (WebCore::ImageFrame::hasBackingStore const): Deleted.
+        * platform/image-decoders/ScalableImageDecoder.cpp:
+        (WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const):
+        (WebCore::ScalableImageDecoder::frameDurationAtIndex const):
+        (WebCore::ScalableImageDecoder::createFrameImageAtIndex):
+        * platform/image-decoders/ScalableImageDecoder.h:
+        * platform/image-decoders/ScalableImageDecoderFrame.cpp: Copied from Source/WebCore/platform/graphics/ImageFrame.cpp.
+        (WebCore::ScalableImageDecoderFrame::ScalableImageDecoderFrame):
+        (WebCore::ScalableImageDecoderFrame::~ScalableImageDecoderFrame):
+        (WebCore::ScalableImageDecoderFrame::operator=):
+        (WebCore::ScalableImageDecoderFrame::setDecodingStatus):
+        (WebCore::ScalableImageDecoderFrame::decodingStatus const):
+        (WebCore::ScalableImageDecoderFrame::clearImage):
+        (WebCore::ScalableImageDecoderFrame::clear):
+        (WebCore::ScalableImageDecoderFrame::initialize):
+        (WebCore::ScalableImageDecoderFrame::size const):
+        (WebCore::ImageFrame::ImageFrame): Deleted.
+        (WebCore::ImageFrame::~ImageFrame): Deleted.
+        (WebCore::ImageFrame::defaultFrame): Deleted.
+        (WebCore::ImageFrame::operator=): Deleted.
+        (WebCore::ImageFrame::setDecodingStatus): Deleted.
+        (WebCore::ImageFrame::decodingStatus const): Deleted.
+        (WebCore::ImageFrame::clearImage): Deleted.
+        (WebCore::ImageFrame::clear): Deleted.
+        (WebCore::ImageFrame::initialize): Deleted.
+        (WebCore::ImageFrame::size const): Deleted.
+        (WebCore::ImageFrame::hasNativeImage const): Deleted.
+        (WebCore::ImageFrame::hasFullSizeNativeImage const): Deleted.
+        (WebCore::ImageFrame::hasDecodedNativeImageCompatibleWithOptions const): Deleted.
+        (WebCore::ImageFrame::singlePixelSolidColor const): Deleted.
+        * platform/image-decoders/ScalableImageDecoderFrame.h: Copied from Source/WebCore/platform/graphics/ImageFrame.h.
+        (WebCore::ScalableImageDecoderFrame::ScalableImageDecoderFrame):
+        (WebCore::ScalableImageDecoderFrame::disposalMethod const):
+        (WebCore::ScalableImageDecoderFrame::hasAlpha const):
+        (WebCore::ScalableImageDecoderFrame::hasBackingStore const):
+        (WebCore::ImageFrame::ImageFrame): Deleted.
+        (WebCore::ImageFrame::isInvalid const): Deleted.
+        (WebCore::ImageFrame::isPartial const): Deleted.
+        (WebCore::ImageFrame::isComplete const): Deleted.
+        (WebCore::ImageFrame::sizeRespectingOrientation const): Deleted.
+        (WebCore::ImageFrame::frameBytes const): Deleted.
+        (WebCore::ImageFrame::subsamplingLevel const): Deleted.
+        (WebCore::ImageFrame::setDisposalMethod): Deleted.
+        (WebCore::ImageFrame::disposalMethod const): Deleted.
+        (WebCore::ImageFrame::nativeImage const): Deleted.
+        (WebCore::ImageFrame::setOrientation): Deleted.
+        (WebCore::ImageFrame::orientation const): Deleted.
+        (WebCore::ImageFrame::setDuration): Deleted.
+        (WebCore::ImageFrame::duration const): Deleted.
+        (WebCore::ImageFrame::setHasAlpha): Deleted.
+        (WebCore::ImageFrame::hasAlpha const): Deleted.
+        (WebCore::ImageFrame::hasNativeImage): Deleted.
+        (WebCore::ImageFrame::hasFullSizeNativeImage): Deleted.
+        (WebCore::ImageFrame::hasMetadata const): Deleted.
+        (WebCore::ImageFrame::backingStore const): Deleted.
+        (WebCore::ImageFrame::hasBackingStore const): Deleted.
+        * platform/image-decoders/bmp/BMPImageDecoder.cpp:
+        (WebCore::BMPImageDecoder::frameBufferAtIndex):
+        * platform/image-decoders/bmp/BMPImageDecoder.h:
+        * platform/image-decoders/bmp/BMPImageReader.h:
+        (WebCore::BMPImageReader::setBuffer):
+        * platform/image-decoders/gif/GIFImageDecoder.cpp:
+        (WebCore::GIFImageDecoder::findFirstRequiredFrameToDecode):
+        (WebCore::GIFImageDecoder::frameBufferAtIndex):
+        (WebCore::GIFImageDecoder::clearFrameBufferCache):
+        (WebCore::GIFImageDecoder::haveDecodedRow):
+        (WebCore::GIFImageDecoder::frameComplete):
+        (WebCore::GIFImageDecoder::initFrameBuffer):
+        * platform/image-decoders/gif/GIFImageDecoder.h:
+        * platform/image-decoders/gif/GIFImageReader.cpp:
+        (GIFImageReader::parse):
+        * platform/image-decoders/gif/GIFImageReader.h:
+        (GIFFrameContext::GIFFrameContext):
+        * platform/image-decoders/ico/ICOImageDecoder.cpp:
+        (WebCore::ICOImageDecoder::frameBufferAtIndex):
+        * platform/image-decoders/ico/ICOImageDecoder.h:
+        * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
+        (WebCore::JPEGImageDecoder::frameBufferAtIndex):
+        (WebCore::setPixel):
+        (WebCore::JPEGImageDecoder::outputScanlines):
+        (WebCore::JPEGImageDecoder::jpegComplete):
+        * platform/image-decoders/jpeg/JPEGImageDecoder.h:
+        * platform/image-decoders/png/PNGImageDecoder.cpp:
+        (WebCore::PNGImageDecoder::frameBufferAtIndex):
+        (WebCore::PNGImageDecoder::rowAvailable):
+        (WebCore::PNGImageDecoder::readChunks):
+        (WebCore::PNGImageDecoder::clearFrameBufferCache):
+        (WebCore::PNGImageDecoder::initFrameBuffer):
+        (WebCore::PNGImageDecoder::frameComplete):
+        * platform/image-decoders/png/PNGImageDecoder.h:
+        * platform/image-decoders/webp/WEBPImageDecoder.cpp:
+        (WebCore::WEBPImageDecoder::frameBufferAtIndex):
+        (WebCore::WEBPImageDecoder::findFirstRequiredFrameToDecode):
+        (WebCore::WEBPImageDecoder::decodeFrame):
+        (WebCore::WEBPImageDecoder::initFrameBuffer):
+        (WebCore::WEBPImageDecoder::applyPostProcessing):
+        (WebCore::WEBPImageDecoder::clearFrameBufferCache):
+        * platform/image-decoders/webp/WEBPImageDecoder.h:
+
 2018-04-11  Antoine Quint  <graouts@apple.com>
 
         [Web Animations] Turn Web Animations on by default
index 440cc2f..58d3305 100644 (file)
@@ -10,6 +10,7 @@ list(APPEND WebCore_INCLUDE_DIRECTORIES
 
 list(APPEND WebCore_SOURCES
     platform/image-decoders/ScalableImageDecoder.cpp
+    platform/image-decoders/ScalableImageDecoderFrame.cpp
 
     platform/image-decoders/bmp/BMPImageDecoder.cpp
     platform/image-decoders/bmp/BMPImageReader.cpp
index f628be2..a10a069 100644 (file)
@@ -53,14 +53,6 @@ ImageFrame& ImageFrame::operator=(const ImageFrame& other)
     m_decodingStatus = other.m_decodingStatus;
     m_size = other.m_size;
 
-#if !USE(CG)
-    if (other.backingStore())
-        initialize(*other.backingStore());
-    else
-        m_backingStore = nullptr;
-    m_disposalMethod = other.m_disposalMethod;
-#endif
-
     m_nativeImage = other.m_nativeImage;
     m_subsamplingLevel = other.m_subsamplingLevel;
     m_decodingOptions = other.m_decodingOptions;
@@ -85,11 +77,6 @@ DecodingStatus ImageFrame::decodingStatus() const
 
 unsigned ImageFrame::clearImage()
 {
-#if !USE(CG)
-    if (hasBackingStore())
-        m_backingStore = nullptr;
-#endif
-
     if (!hasNativeImage())
         return 0;
 
@@ -109,32 +96,8 @@ unsigned ImageFrame::clear()
     return frameBytes;
 }
 
-#if !USE(CG)
-bool ImageFrame::initialize(const ImageBackingStore& backingStore)
-{
-    if (&backingStore == this->backingStore())
-        return true;
-
-    m_backingStore = ImageBackingStore::create(backingStore);
-    return m_backingStore != nullptr;
-}
-
-bool ImageFrame::initialize(const IntSize& size, bool premultiplyAlpha)
-{
-    if (size.isEmpty())
-        return false;
-
-    m_backingStore = ImageBackingStore::create(size, premultiplyAlpha);
-    return m_backingStore != nullptr;
-}
-#endif
-
 IntSize ImageFrame::size() const
 {
-#if !USE(CG)
-    if (hasBackingStore())
-        return backingStore()->size();
-#endif
     return m_size;
 }
     
index c01c68a..da7e6ea 100644 (file)
@@ -53,11 +53,6 @@ public:
     unsigned clearImage();
     unsigned clear();
 
-#if !USE(CG)
-    bool initialize(const ImageBackingStore&);
-    bool initialize(const IntSize&, bool premultiplyAlpha);
-#endif
-
     void setDecodingStatus(DecodingStatus);
     DecodingStatus decodingStatus() const;
 
@@ -70,12 +65,6 @@ public:
     unsigned frameBytes() const { return hasNativeImage() ? (size().area() * sizeof(uint32_t)).unsafeGet() : 0; }
     SubsamplingLevel subsamplingLevel() const { return m_subsamplingLevel; }
 
-#if !USE(CG)
-    enum class DisposalMethod { Unspecified, DoNotDispose, RestoreToBackground, RestoreToPrevious };
-    void setDisposalMethod(DisposalMethod method) { m_disposalMethod = method; }
-    DisposalMethod disposalMethod() const { return m_disposalMethod; }
-#endif
-
     NativeImagePtr nativeImage() const { return m_nativeImage; }
 
     void setOrientation(ImageOrientation orientation) { m_orientation = orientation; };
@@ -92,22 +81,12 @@ public:
     bool hasDecodedNativeImageCompatibleWithOptions(const std::optional<SubsamplingLevel>&, const DecodingOptions&) const;
     bool hasMetadata() const { return !size().isEmpty(); }
 
-#if !USE(CG)
-    ImageBackingStore* backingStore() const { return m_backingStore ? m_backingStore.get() : nullptr; }
-    bool hasBackingStore() const { return backingStore(); }
-#endif
-
     Color singlePixelSolidColor() const;
 
 private:
     DecodingStatus m_decodingStatus { DecodingStatus::Invalid };
     IntSize m_size;
 
-#if !USE(CG)
-    std::unique_ptr<ImageBackingStore> m_backingStore;
-    DisposalMethod m_disposalMethod { DisposalMethod::Unspecified };
-#endif
-
     NativeImagePtr m_nativeImage;
     SubsamplingLevel m_subsamplingLevel { SubsamplingLevel::Default };
     DecodingOptions m_decodingOptions;
index cf8ddad..1ccc8ef 100644 (file)
@@ -176,7 +176,7 @@ bool ScalableImageDecoder::frameIsCompleteAtIndex(size_t index) const
     // FIXME(176089): asking whether enough data has been appended for a decode
     // operation to succeed should not require decoding the entire frame.
     // This function should be implementable in a way that allows const.
-    ImageFrame* buffer = const_cast<ScalableImageDecoder*>(this)->frameBufferAtIndex(index);
+    auto* buffer = const_cast<ScalableImageDecoder*>(this)->frameBufferAtIndex(index);
     return buffer && buffer->isComplete();
 }
 
@@ -205,7 +205,7 @@ Seconds ScalableImageDecoder::frameDurationAtIndex(size_t index) const
     // FIXME(176089): asking for the duration of a sub-image should not require decoding
     // the entire frame. This function should be implementable in a way that
     // allows const.
-    ImageFrame* buffer = const_cast<ScalableImageDecoder*>(this)->frameBufferAtIndex(index);
+    auto* buffer = const_cast<ScalableImageDecoder*>(this)->frameBufferAtIndex(index);
     if (!buffer || buffer->isInvalid())
         return 0_s;
     
@@ -225,7 +225,7 @@ NativeImagePtr ScalableImageDecoder::createFrameImageAtIndex(size_t index, Subsa
     if (size().isEmpty())
         return nullptr;
 
-    ImageFrame* buffer = frameBufferAtIndex(index);
+    auto* buffer = frameBufferAtIndex(index);
     if (!buffer || buffer->isInvalid() || !buffer->hasBackingStore())
         return nullptr;
 
index b7279a7..24e6665 100644 (file)
@@ -29,8 +29,8 @@
 #pragma once
 
 #include "ImageDecoder.h"
-#include "ImageFrame.h"
 #include "IntRect.h"
+#include "ScalableImageDecoderFrame.h"
 #include "SharedBuffer.h"
 #include <wtf/Assertions.h>
 #include <wtf/Lock.h>
@@ -41,7 +41,7 @@
 namespace WebCore {
 
 // ScalableImageDecoder is a base for all format-specific decoders
-// (e.g. JPEGImageDecoder). This base manages the ImageFrame cache.
+// (e.g. JPEGImageDecoder). This base manages the ScalableImageDecoderFrame cache.
 
 class ScalableImageDecoder : public ImageDecoder {
     WTF_MAKE_NONCOPYABLE(ScalableImageDecoder); WTF_MAKE_FAST_ALLOCATED;
@@ -134,7 +134,7 @@ public:
 
     // Decodes as much of the requested frame as possible, and returns an
     // ScalableImageDecoder-owned pointer.
-    virtual ImageFrame* frameBufferAtIndex(size_t) = 0;
+    virtual ScalableImageDecoderFrame* frameBufferAtIndex(size_t) = 0;
 
     bool frameIsCompleteAtIndex(size_t) const override;
 
@@ -205,7 +205,7 @@ protected:
     int scaledY(int origY, int searchStart = 0);
 
     RefPtr<SharedBuffer> m_data; // The encoded data.
-    Vector<ImageFrame, 1> m_frameBufferCache;
+    Vector<ScalableImageDecoderFrame, 1> m_frameBufferCache;
     mutable Lock m_mutex;
     bool m_scaled { false };
     Vector<int> m_scaledColumns;
diff --git a/Source/WebCore/platform/image-decoders/ScalableImageDecoderFrame.cpp b/Source/WebCore/platform/image-decoders/ScalableImageDecoderFrame.cpp
new file mode 100644 (file)
index 0000000..1d38df6
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2016 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ScalableImageDecoderFrame.h"
+
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+ScalableImageDecoderFrame::ScalableImageDecoderFrame()
+{
+}
+
+ScalableImageDecoderFrame::~ScalableImageDecoderFrame()
+{
+}
+
+ScalableImageDecoderFrame& ScalableImageDecoderFrame::operator=(const ScalableImageDecoderFrame& other)
+{
+    if (this == &other)
+        return *this;
+
+    m_decodingStatus = other.m_decodingStatus;
+
+    if (other.backingStore())
+        initialize(*other.backingStore());
+    else
+        m_backingStore = nullptr;
+    m_disposalMethod = other.m_disposalMethod;
+
+    m_orientation = other.m_orientation;
+    m_duration = other.m_duration;
+    m_hasAlpha = other.m_hasAlpha;
+    return *this;
+}
+
+void ScalableImageDecoderFrame::setDecodingStatus(DecodingStatus decodingStatus)
+{
+    ASSERT(decodingStatus != DecodingStatus::Decoding);
+    m_decodingStatus = decodingStatus;
+}
+
+DecodingStatus ScalableImageDecoderFrame::decodingStatus() const
+{
+    ASSERT(m_decodingStatus != DecodingStatus::Decoding);
+    return m_decodingStatus;
+}
+
+void ScalableImageDecoderFrame::clear()
+{
+    *this = ScalableImageDecoderFrame();
+}
+
+bool ScalableImageDecoderFrame::initialize(const ImageBackingStore& backingStore)
+{
+    if (&backingStore == this->backingStore())
+        return true;
+
+    m_backingStore = ImageBackingStore::create(backingStore);
+    return m_backingStore != nullptr;
+}
+
+bool ScalableImageDecoderFrame::initialize(const IntSize& size, bool premultiplyAlpha)
+{
+    if (size.isEmpty())
+        return false;
+
+    m_backingStore = ImageBackingStore::create(size, premultiplyAlpha);
+    return m_backingStore != nullptr;
+}
+
+IntSize ScalableImageDecoderFrame::size() const
+{
+    if (hasBackingStore())
+        return backingStore()->size();
+    return { };
+}
+
+}
diff --git a/Source/WebCore/platform/image-decoders/ScalableImageDecoderFrame.h b/Source/WebCore/platform/image-decoders/ScalableImageDecoderFrame.h
new file mode 100644 (file)
index 0000000..d843a06
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2016 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "Color.h"
+#include "DecodingOptions.h"
+#include "ImageBackingStore.h"
+#include "ImageOrientation.h"
+#include "ImageTypes.h"
+#include "IntSize.h"
+#include "NativeImage.h"
+#include <wtf/Seconds.h>
+
+namespace WebCore {
+
+class ScalableImageDecoderFrame {
+public:
+    ScalableImageDecoderFrame();
+    ScalableImageDecoderFrame(const ScalableImageDecoderFrame& other) { operator=(other); }
+
+    ~ScalableImageDecoderFrame();
+
+    ScalableImageDecoderFrame& operator=(const ScalableImageDecoderFrame& other);
+
+    void clear();
+
+    bool initialize(const ImageBackingStore&);
+    bool initialize(const IntSize&, bool premultiplyAlpha);
+
+    void setDecodingStatus(DecodingStatus);
+    DecodingStatus decodingStatus() const;
+
+    bool isInvalid() const { return m_decodingStatus == DecodingStatus::Invalid; }
+    bool isPartial() const { return m_decodingStatus == DecodingStatus::Partial; }
+    bool isComplete() const { return m_decodingStatus == DecodingStatus::Complete; }
+
+    IntSize size() const;
+
+    enum class DisposalMethod { Unspecified, DoNotDispose, RestoreToBackground, RestoreToPrevious };
+    void setDisposalMethod(DisposalMethod method) { m_disposalMethod = method; }
+    DisposalMethod disposalMethod() const { return m_disposalMethod; }
+
+    void setOrientation(ImageOrientation orientation) { m_orientation = orientation; };
+    ImageOrientation orientation() const { return m_orientation; }
+
+    void setDuration(const Seconds& duration) { m_duration = duration; }
+    Seconds duration() const { return m_duration; }
+
+    void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; }
+    bool hasAlpha() const { return !hasMetadata() || m_hasAlpha; }
+    bool hasMetadata() const { return !size().isEmpty(); }
+
+    ImageBackingStore* backingStore() const { return m_backingStore ? m_backingStore.get() : nullptr; }
+    bool hasBackingStore() const { return backingStore(); }
+
+private:
+    DecodingStatus m_decodingStatus { DecodingStatus::Invalid };
+
+    std::unique_ptr<ImageBackingStore> m_backingStore;
+    DisposalMethod m_disposalMethod { DisposalMethod::Unspecified };
+
+    ImageOrientation m_orientation { DefaultImageOrientation };
+    Seconds m_duration;
+    bool m_hasAlpha { true };
+};
+
+}
index e675be8..8407c11 100644 (file)
@@ -56,7 +56,7 @@ void BMPImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
         m_reader->setData(&data);
 }
 
-ImageFrame* BMPImageDecoder::frameBufferAtIndex(size_t index)
+ScalableImageDecoderFrame* BMPImageDecoder::frameBufferAtIndex(size_t index)
 {
     if (index)
         return 0;
@@ -64,7 +64,7 @@ ImageFrame* BMPImageDecoder::frameBufferAtIndex(size_t index)
     if (m_frameBufferCache.isEmpty())
         m_frameBufferCache.grow(1);
 
-    ImageFrame* buffer = &m_frameBufferCache.first();
+    auto* buffer = &m_frameBufferCache.first();
     if (!buffer->isComplete())
         decode(false, isAllDataReceived());
     return buffer;
index 595f1ca..72da3e2 100644 (file)
@@ -45,7 +45,7 @@ public:
     // ScalableImageDecoder
     String filenameExtension() const final { return ASCIILiteral("bmp"); }
     void setData(SharedBuffer&, bool allDataReceived) final;
-    ImageFrame* frameBufferAtIndex(size_t index) final;
+    ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) final;
     // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
     // accessing deleted memory, especially when calling this from inside
     // BMPImageReader!
index 0986db7..923c6d9 100644 (file)
@@ -64,11 +64,11 @@ public:
 
     // |parent| is the decoder that owns us.
     // |startOffset| points to the start of the BMP within the file.
-    // |buffer| points at an empty ImageFrame that we'll initialize and
+    // |buffer| points at an empty ScalableImageDecoderFrame that we'll initialize and
     // fill with decoded data.
     BMPImageReader(ScalableImageDecoder* parent, size_t decodedAndHeaderOffset, size_t imgDataOffset, bool usesAndMask);
 
-    void setBuffer(ImageFrame* buffer) { m_buffer = buffer; }
+    void setBuffer(ScalableImageDecoderFrame* buffer) { m_buffer = buffer; }
     void setData(SharedBuffer* data) { m_data = data; }
 
     // Does the actual decoding. If |onlySize| is true, decoding only
@@ -269,7 +269,7 @@ private:
     ScalableImageDecoder* m_parent;
 
     // The destination for the pixel data.
-    ImageFrame* m_buffer;
+    ScalableImageDecoderFrame* m_buffer;
 
     // The file to decode.
     RefPtr<SharedBuffer> m_data;
index 5190705..2b6d1d4 100644 (file)
@@ -106,10 +106,10 @@ size_t GIFImageDecoder::findFirstRequiredFrameToDecode(size_t frameIndex)
         return 0;
 
     for (size_t i = frameIndex; i > 0; --i) {
-        ImageFrame& frame = m_frameBufferCache[i - 1];
+        auto& frame = m_frameBufferCache[i - 1];
 
         // Frames with disposal method RestoreToPrevious are useless, skip them.
-        if (frame.disposalMethod() == ImageFrame::DisposalMethod::RestoreToPrevious)
+        if (frame.disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToPrevious)
             continue;
 
         // At this point the disposal method can be Unspecified, DoNotDispose or RestoreToBackground.
@@ -119,7 +119,7 @@ size_t GIFImageDecoder::findFirstRequiredFrameToDecode(size_t frameIndex)
 
         // If the disposal method of this frame is RestoreToBackground and it fills the whole area,
         // the next frame's backing store is initialized to transparent, so we start decoding with it.
-        if (frame.disposalMethod() == ImageFrame::DisposalMethod::RestoreToBackground) {
+        if (frame.disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToBackground) {
             // We cannot use frame.backingStore()->frameRect() here, because it has been cleared
             // when the frame was removed from the cache. We need to get the values from the
             // reader context.
@@ -137,12 +137,12 @@ size_t GIFImageDecoder::findFirstRequiredFrameToDecode(size_t frameIndex)
     return 0;
 }
 
-ImageFrame* GIFImageDecoder::frameBufferAtIndex(size_t index)
+ScalableImageDecoderFrame* GIFImageDecoder::frameBufferAtIndex(size_t index)
 {
     if (index >= frameCount())
         return 0;
 
-    ImageFrame& frame = m_frameBufferCache[index];
+    auto& frame = m_frameBufferCache[index];
     if (!frame.isComplete()) {
         for (auto i = findFirstRequiredFrameToDecode(index); i <= index; i++)
             decode(i + 1, GIFFullQuery, isAllDataReceived());
@@ -173,7 +173,7 @@ void GIFImageDecoder::clearFrameBufferCache(size_t clearBeforeFrame)
     // always use ImageSource::clear(true, ...) to completely free the memory in
     // this case.
     clearBeforeFrame = std::min(clearBeforeFrame, m_frameBufferCache.size() - 1);
-    const Vector<ImageFrame>::iterator end(m_frameBufferCache.begin() + clearBeforeFrame);
+    const Vector<ScalableImageDecoderFrame>::iterator end(m_frameBufferCache.begin() + clearBeforeFrame);
 
     // We need to preserve frames such that:
     //   * We don't clear |end|
@@ -193,14 +193,14 @@ void GIFImageDecoder::clearFrameBufferCache(size_t clearBeforeFrame)
     //   * If the frame is partial, we're decoding it, so don't clear it; if it
     //     has a disposal method other than DisposalMethod::RestoreToPrevious, stop
     //     scanning, as we'll only need this frame when decoding the next one.
-    Vector<ImageFrame>::iterator i(end);
-    for (; (i != m_frameBufferCache.begin()) && (i->isInvalid() || (i->disposalMethod() == ImageFrame::DisposalMethod::RestoreToPrevious)); --i) {
+    Vector<ScalableImageDecoderFrame>::iterator i(end);
+    for (; (i != m_frameBufferCache.begin()) && (i->isInvalid() || (i->disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToPrevious)); --i) {
         if (i->isComplete() && (i != end))
             i->clear();
     }
 
     // Now |i| holds the last frame we need to preserve; clear prior frames.
-    for (Vector<ImageFrame>::iterator j(m_frameBufferCache.begin()); j != i; ++j) {
+    for (Vector<ScalableImageDecoderFrame>::iterator j(m_frameBufferCache.begin()); j != i; ++j) {
         ASSERT(!j->isPartial());
         if (!j->isInvalid())
             j->clear();
@@ -237,7 +237,7 @@ bool GIFImageDecoder::haveDecodedRow(unsigned frameIndex, const Vector<unsigned
         return true;
 
     // Initialize the frame if necessary.
-    ImageFrame& buffer = m_frameBufferCache[frameIndex];
+    auto& buffer = m_frameBufferCache[frameIndex];
     if ((buffer.isInvalid() && !initFrameBuffer(frameIndex)) || !buffer.hasBackingStore())
         return false;
 
@@ -270,11 +270,11 @@ bool GIFImageDecoder::haveDecodedRow(unsigned frameIndex, const Vector<unsigned
     return true;
 }
 
-bool GIFImageDecoder::frameComplete(unsigned frameIndex, unsigned frameDuration, ImageFrame::DisposalMethod disposalMethod)
+bool GIFImageDecoder::frameComplete(unsigned frameIndex, unsigned frameDuration, ScalableImageDecoderFrame::DisposalMethod disposalMethod)
 {
     // Initialize the frame if necessary.  Some GIFs insert do-nothing frames,
     // in which case we never reach haveDecodedRow() before getting here.
-    ImageFrame& buffer = m_frameBufferCache[frameIndex];
+    auto& buffer = m_frameBufferCache[frameIndex];
     if (buffer.isInvalid() && !initFrameBuffer(frameIndex))
         return false; // initFrameBuffer() has already called setFailed().
 
@@ -298,8 +298,8 @@ bool GIFImageDecoder::frameComplete(unsigned frameIndex, unsigned frameDuration,
             // First skip over prior DisposalMethod::RestoreToPrevious frames (since they
             // don't affect the start state of this frame) the same way we do in
             // initFrameBuffer().
-            const ImageFrame* prevBuffer = &m_frameBufferCache[--frameIndex];
-            while (frameIndex && (prevBuffer->disposalMethod() == ImageFrame::DisposalMethod::RestoreToPrevious))
+            const auto* prevBuffer = &m_frameBufferCache[--frameIndex];
+            while (frameIndex && (prevBuffer->disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToPrevious))
                 prevBuffer = &m_frameBufferCache[--frameIndex];
 
             // Now, if we're at a DisposalMethod::Unspecified or DisposalMethod::DoNotDispose frame, then
@@ -311,7 +311,7 @@ bool GIFImageDecoder::frameComplete(unsigned frameIndex, unsigned frameDuration,
             // it had no alpha, and its rect is contained in the current frame's
             // rect, we know the current frame has no alpha.
             IntRect prevRect = prevBuffer->backingStore()->frameRect();
-            if ((prevBuffer->disposalMethod() == ImageFrame::DisposalMethod::RestoreToBackground) && !prevBuffer->hasAlpha() && rect.contains(prevRect))
+            if ((prevBuffer->disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToBackground) && !prevBuffer->hasAlpha() && rect.contains(prevRect))
                 buffer.setHasAlpha(false);
         }
     }
@@ -370,7 +370,7 @@ bool GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
     // Initialize the frame rect in our buffer.
     const GIFFrameContext* frameContext = m_reader->frameContext();
     IntRect frameRect(frameContext->xOffset, frameContext->yOffset, frameContext->width, frameContext->height);
-    ImageFrame* const buffer = &m_frameBufferCache[frameIndex];
+    auto* const buffer = &m_frameBufferCache[frameIndex];
 
     if (!frameIndex) {
         // This is the first frame, so we're not relying on any previous data.
@@ -385,16 +385,16 @@ bool GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
         // the starting state of the previous frame, so skip over them.  (If the
         // first frame specifies this method, it will get treated like
         // DisposalMethod::RestoreToBackground below and reset to a completely empty image.)
-        const ImageFrame* prevBuffer = &m_frameBufferCache[--frameIndex];
-        ImageFrame::DisposalMethod prevMethod = prevBuffer->disposalMethod();
-        while (frameIndex && (prevMethod == ImageFrame::DisposalMethod::RestoreToPrevious)) {
+        const auto* prevBuffer = &m_frameBufferCache[--frameIndex];
+        auto prevMethod = prevBuffer->disposalMethod();
+        while (frameIndex && (prevMethod == ScalableImageDecoderFrame::DisposalMethod::RestoreToPrevious)) {
             prevBuffer = &m_frameBufferCache[--frameIndex];
             prevMethod = prevBuffer->disposalMethod();
         }
 
         ASSERT(prevBuffer->isComplete());
 
-        if ((prevMethod == ImageFrame::DisposalMethod::Unspecified) || (prevMethod == ImageFrame::DisposalMethod::DoNotDispose)) {
+        if ((prevMethod == ScalableImageDecoderFrame::DisposalMethod::Unspecified) || (prevMethod == ScalableImageDecoderFrame::DisposalMethod::DoNotDispose)) {
             // Preserve the last frame as the starting state for this frame.
             if (!prevBuffer->backingStore() || !buffer->initialize(*prevBuffer->backingStore()))
                 return setFailed();
index 68715ae..0b17643 100644 (file)
@@ -50,7 +50,7 @@ public:
     bool setSize(const IntSize&) final;
     size_t frameCount() const final;
     RepetitionCount repetitionCount() const final;
-    ImageFrame* frameBufferAtIndex(size_t index) final;
+    ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) final;
     // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
     // accessing deleted memory, especially when calling this from inside
     // GIFImageReader!
@@ -59,7 +59,7 @@ public:
 
     // Callbacks from the GIF reader.
     bool haveDecodedRow(unsigned frameIndex, const Vector<unsigned char>& rowBuffer, size_t width, size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels);
-    bool frameComplete(unsigned frameIndex, unsigned frameDuration, ImageFrame::DisposalMethod);
+    bool frameComplete(unsigned frameIndex, unsigned frameDuration, ScalableImageDecoderFrame::DisposalMethod);
     void gifComplete();
 
 private:
index c1db8a6..1cca5e5 100644 (file)
@@ -576,11 +576,11 @@ bool GIFImageReader::parse(size_t dataPosition, size_t len, bool parseSizeOnly)
             // NOTE: This relies on the values in the DisposalMethod enum
             // matching those in the GIF spec!
             int disposalMethod = ((*currentComponent) >> 2) & 0x7;
-            currentFrame->disposalMethod = static_cast<WebCore::ImageFrame::DisposalMethod>(disposalMethod);
+            currentFrame->disposalMethod = static_cast<WebCore::ScalableImageDecoderFrame::DisposalMethod>(disposalMethod);
             // Some specs say that disposal method 3 is "overwrite previous", others that setting
             // the third bit of the field (i.e. method 4) is. We map both to the same value.
             if (disposalMethod == 4)
-                currentFrame->disposalMethod = WebCore::ImageFrame::DisposalMethod::RestoreToPrevious;
+                currentFrame->disposalMethod = WebCore::ScalableImageDecoderFrame::DisposalMethod::RestoreToPrevious;
             currentFrame->delayTime = GETINT16(currentComponent + 1) * 10;
             GETN(1, GIFConsumeBlock);
             break;
index 4b70e54..d0fc58a 100644 (file)
@@ -154,7 +154,7 @@ public:
     unsigned width;
     unsigned height;
     int tpixel; // Index of transparent pixel.
-    WebCore::ImageFrame::DisposalMethod disposalMethod; // Restore to background, leave in place, etc.
+    WebCore::ScalableImageDecoderFrame::DisposalMethod disposalMethod; // Restore to background, leave in place, etc.
     size_t localColormapPosition; // Per-image colormap.
     int localColormapSize; // Size of local colormap array.
     int datasize;
@@ -173,7 +173,7 @@ public:
         , width(0)
         , height(0)
         , tpixel(0)
-        , disposalMethod(WebCore::ImageFrame::DisposalMethod::Unspecified)
+        , disposalMethod(WebCore::ScalableImageDecoderFrame::DisposalMethod::Unspecified)
         , localColormapPosition(0)
         , localColormapSize(0)
         , datasize(0)
index fa68f2b..860da38 100644 (file)
@@ -90,13 +90,13 @@ size_t ICOImageDecoder::frameCount() const
     return m_frameBufferCache.size();
 }
 
-ImageFrame* ICOImageDecoder::frameBufferAtIndex(size_t index)
+ScalableImageDecoderFrame* ICOImageDecoder::frameBufferAtIndex(size_t index)
 {
     // Ensure |index| is valid.
     if (index >= frameCount())
         return 0;
 
-    ImageFrame* buffer = &m_frameBufferCache[index];
+    auto* buffer = &m_frameBufferCache[index];
     if (!buffer->isComplete())
         decode(index, false, isAllDataReceived());
     return buffer;
index 2d37692..c0f4232 100644 (file)
@@ -51,7 +51,7 @@ public:
     IntSize frameSizeAtIndex(size_t, SubsamplingLevel) const final;
     bool setSize(const IntSize&) final;
     size_t frameCount() const final;
-    ImageFrame* frameBufferAtIndex(size_t) final;
+    ScalableImageDecoderFrame* frameBufferAtIndex(size_t) final;
     // CAUTION: setFailed() deletes all readers and decoders. Be careful to
     // avoid accessing deleted memory, especially when calling this from
     // inside BMPImageReader!
index 416819a..b72c55a 100644 (file)
@@ -511,7 +511,7 @@ bool JPEGImageDecoder::setSize(const IntSize& size)
     return true;
 }
 
-ImageFrame* JPEGImageDecoder::frameBufferAtIndex(size_t index)
+ScalableImageDecoderFrame* JPEGImageDecoder::frameBufferAtIndex(size_t index)
 {
     if (index)
         return 0;
@@ -519,7 +519,7 @@ ImageFrame* JPEGImageDecoder::frameBufferAtIndex(size_t index)
     if (m_frameBufferCache.isEmpty())
         m_frameBufferCache.grow(1);
 
-    ImageFrame& frame = m_frameBufferCache[0];
+    auto& frame = m_frameBufferCache[0];
     if (!frame.isComplete())
         decode(false, isAllDataReceived());
     return &frame;
@@ -532,7 +532,7 @@ bool JPEGImageDecoder::setFailed()
 }
 
 template <J_COLOR_SPACE colorSpace>
-void setPixel(ImageFrame& buffer, uint32_t* currentAddress, JSAMPARRAY samples, int column)
+void setPixel(ScalableImageDecoderFrame& buffer, uint32_t* currentAddress, JSAMPARRAY samples, int column)
 {
     JSAMPLE* jsample = *samples + column * (colorSpace == JCS_RGB ? 3 : 4);
 
@@ -557,7 +557,7 @@ void setPixel(ImageFrame& buffer, uint32_t* currentAddress, JSAMPARRAY samples,
 }
 
 template <J_COLOR_SPACE colorSpace, bool isScaled>
-bool JPEGImageDecoder::outputScanlines(ImageFrame& buffer)
+bool JPEGImageDecoder::outputScanlines(ScalableImageDecoderFrame& buffer)
 {
     JSAMPARRAY samples = m_reader->samples();
     jpeg_decompress_struct* info = m_reader->info();
@@ -585,7 +585,7 @@ bool JPEGImageDecoder::outputScanlines(ImageFrame& buffer)
 }
 
 template <J_COLOR_SPACE colorSpace>
-bool JPEGImageDecoder::outputScanlines(ImageFrame& buffer)
+bool JPEGImageDecoder::outputScanlines(ScalableImageDecoderFrame& buffer)
 {
     return m_scaled ? outputScanlines<colorSpace, true>(buffer) : outputScanlines<colorSpace, false>(buffer);
 }
@@ -596,7 +596,7 @@ bool JPEGImageDecoder::outputScanlines()
         return false;
 
     // Initialize the framebuffer if needed.
-    ImageFrame& buffer = m_frameBufferCache[0];
+    auto& buffer = m_frameBufferCache[0];
     if (buffer.isInvalid()) {
         if (!buffer.initialize(scaledSize(), m_premultiplyAlpha))
             return setFailed();
@@ -642,7 +642,7 @@ void JPEGImageDecoder::jpegComplete()
 
     // Hand back an appropriately sized buffer, even if the image ended up being
     // empty.
-    ImageFrame& buffer = m_frameBufferCache[0];
+    auto& buffer = m_frameBufferCache[0];
     buffer.setHasAlpha(false);
     buffer.setDecodingStatus(DecodingStatus::Complete);
 }
index d56cf23..284e3c2 100644 (file)
@@ -53,7 +53,7 @@ namespace WebCore {
         // ScalableImageDecoder
         String filenameExtension() const override { return ASCIILiteral("jpg"); }
         bool setSize(const IntSize&) override;
-        ImageFrame* frameBufferAtIndex(size_t index) override;
+        ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) override;
         // CAUTION: setFailed() deletes |m_reader|.  Be careful to avoid
         // accessing deleted memory, especially when calling this from inside
         // JPEGImageReader!
@@ -80,10 +80,10 @@ namespace WebCore {
         void decode(bool onlySize, bool allDataReceived);
 
         template <J_COLOR_SPACE colorSpace>
-        bool outputScanlines(ImageFrame& buffer);
+        bool outputScanlines(ScalableImageDecoderFrame& buffer);
 
         template <J_COLOR_SPACE colorSpace, bool isScaled>
-        bool outputScanlines(ImageFrame& buffer);
+        bool outputScanlines(ScalableImageDecoderFrame& buffer);
 
         std::unique_ptr<JPEGImageReader> m_reader;
     };
index a9f3736..fd86f2b 100644 (file)
@@ -253,7 +253,7 @@ bool PNGImageDecoder::setSize(const IntSize& size)
     return true;
 }
 
-ImageFrame* PNGImageDecoder::frameBufferAtIndex(size_t index)
+ScalableImageDecoderFrame* PNGImageDecoder::frameBufferAtIndex(size_t index)
 {
 #if ENABLE(APNG)
     if (ScalableImageDecoder::encodedDataStatus() < EncodedDataStatus::SizeAvailable)
@@ -269,7 +269,7 @@ ImageFrame* PNGImageDecoder::frameBufferAtIndex(size_t index)
     if (m_frameBufferCache.isEmpty())
         m_frameBufferCache.grow(1);
 
-    ImageFrame& frame = m_frameBufferCache[index];
+    auto& frame = m_frameBufferCache[index];
     if (!frame.isComplete())
         decode(false, index, isAllDataReceived());
     return &frame;
@@ -428,7 +428,7 @@ void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
     if (m_currentFrame >= frameCount())
         return;
 #endif
-    ImageFrame& buffer = m_frameBufferCache[m_currentFrame];
+    auto& buffer = m_frameBufferCache[m_currentFrame];
     if (buffer.isInvalid()) {
         png_structp png = m_reader->pngPtr();
         if (!buffer.initialize(scaledSize(), m_premultiplyAlpha)) {
@@ -632,7 +632,7 @@ void PNGImageDecoder::readChunks(png_unknown_chunkp chunk)
             m_frameBufferCache.grow(1);
 
         if (m_currentFrame < m_frameBufferCache.size()) {
-            ImageFrame& buffer = m_frameBufferCache[m_currentFrame];
+            auto& buffer = m_frameBufferCache[m_currentFrame];
 
             if (!m_delayDenominator)
                 buffer.setDuration(Seconds::fromMilliseconds(m_delayNumerator * 10));
@@ -640,11 +640,11 @@ void PNGImageDecoder::readChunks(png_unknown_chunkp chunk)
                 buffer.setDuration(Seconds::fromMilliseconds(m_delayNumerator * 1000 / m_delayDenominator));
 
             if (m_dispose == 2)
-                buffer.setDisposalMethod(ImageFrame::DisposalMethod::RestoreToPrevious);
+                buffer.setDisposalMethod(ScalableImageDecoderFrame::DisposalMethod::RestoreToPrevious);
             else if (m_dispose == 1)
-                buffer.setDisposalMethod(ImageFrame::DisposalMethod::RestoreToBackground);
+                buffer.setDisposalMethod(ScalableImageDecoderFrame::DisposalMethod::RestoreToBackground);
             else
-                buffer.setDisposalMethod(ImageFrame::DisposalMethod::DoNotDispose);
+                buffer.setDisposalMethod(ScalableImageDecoderFrame::DisposalMethod::DoNotDispose);
         }
 
         m_frameInfo = true;
@@ -724,16 +724,16 @@ void PNGImageDecoder::clearFrameBufferCache(size_t clearBeforeFrame)
 
     // See GIFImageDecoder for full explanation.
     clearBeforeFrame = std::min(clearBeforeFrame, m_frameBufferCache.size() - 1);
-    const Vector<ImageFrame>::iterator end(m_frameBufferCache.begin() + clearBeforeFrame);
+    const Vector<ScalableImageDecoderFrame>::iterator end(m_frameBufferCache.begin() + clearBeforeFrame);
 
-    Vector<ImageFrame>::iterator i(end);
-    for (; (i != m_frameBufferCache.begin()) && (i->isInvalid() || (i->disposalMethod() == ImageFrame::DisposalMethod::RestoreToPrevious)); --i) {
+    Vector<ScalableImageDecoderFrame>::iterator i(end);
+    for (; (i != m_frameBufferCache.begin()) && (i->isInvalid() || (i->disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToPrevious)); --i) {
         if (i->isComplete() && (i != end))
             i->clear();
     }
 
     // Now |i| holds the last frame we need to preserve; clear prior frames.
-    for (Vector<ImageFrame>::iterator j(m_frameBufferCache.begin()); j != i; ++j) {
+    for (Vector<ScalableImageDecoderFrame>::iterator j(m_frameBufferCache.begin()); j != i; ++j) {
         ASSERT(!j->isPartial());
         if (j->isInvalid())
             j->clear();
@@ -745,7 +745,7 @@ void PNGImageDecoder::initFrameBuffer(size_t frameIndex)
     if (frameIndex >= frameCount())
         return;
 
-    ImageFrame& buffer = m_frameBufferCache[frameIndex];
+    auto& buffer = m_frameBufferCache[frameIndex];
 
     // The starting state for this frame depends on the previous frame's
     // disposal method.
@@ -755,9 +755,9 @@ void PNGImageDecoder::initFrameBuffer(size_t frameIndex)
     // the starting state of the previous frame, so skip over them.  (If the
     // first frame specifies this method, it will get treated like
     // DisposeOverwriteBgcolor below and reset to a completely empty image.)
-    const ImageFrame* prevBuffer = &m_frameBufferCache[--frameIndex];
-    ImageFrame::DisposalMethod prevMethod = prevBuffer->disposalMethod();
-    while (frameIndex && (prevMethod == ImageFrame::DisposalMethod::RestoreToPrevious)) {
+    const auto* prevBuffer = &m_frameBufferCache[--frameIndex];
+    auto prevMethod = prevBuffer->disposalMethod();
+    while (frameIndex && (prevMethod == ScalableImageDecoderFrame::DisposalMethod::RestoreToPrevious)) {
         prevBuffer = &m_frameBufferCache[--frameIndex];
         prevMethod = prevBuffer->disposalMethod();
     }
@@ -765,7 +765,7 @@ void PNGImageDecoder::initFrameBuffer(size_t frameIndex)
     png_structp png = m_reader->pngPtr();
     ASSERT(prevBuffer->isComplete());
 
-    if (prevMethod == ImageFrame::DisposalMethod::DoNotDispose) {
+    if (prevMethod == ScalableImageDecoderFrame::DisposalMethod::DoNotDispose) {
         // Preserve the last frame as the starting state for this frame.
         if (!prevBuffer->backingStore() || !buffer.initialize(*prevBuffer->backingStore()))
             longjmp(JMPBUF(png), 1);
@@ -809,7 +809,7 @@ void PNGImageDecoder::frameComplete()
     if (m_frameIsHidden || m_currentFrame >= frameCount())
         return;
 
-    ImageFrame& buffer = m_frameBufferCache[m_currentFrame];
+    auto& buffer = m_frameBufferCache[m_currentFrame];
     buffer.setDecodingStatus(DecodingStatus::Complete);
 
     png_bytep interlaceBuffer = m_reader->interlaceBuffer();
@@ -843,12 +843,12 @@ void PNGImageDecoder::frameComplete()
                 buffer.setHasAlpha(false);
             else {
                 size_t frameIndex = m_currentFrame;
-                const ImageFrame* prevBuffer = &m_frameBufferCache[--frameIndex];
-                while (frameIndex && (prevBuffer->disposalMethod() == ImageFrame::DisposalMethod::RestoreToPrevious))
+                const auto* prevBuffer = &m_frameBufferCache[--frameIndex];
+                while (frameIndex && (prevBuffer->disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToPrevious))
                     prevBuffer = &m_frameBufferCache[--frameIndex];
 
                 IntRect prevRect = prevBuffer->backingStore()->frameRect();
-                if ((prevBuffer->disposalMethod() == ImageFrame::DisposalMethod::RestoreToBackground) && !prevBuffer->hasAlpha() && rect.contains(prevRect))
+                if ((prevBuffer->disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToBackground) && !prevBuffer->hasAlpha() && rect.contains(prevRect))
                     buffer.setHasAlpha(false);
             }
         } else if (!m_blend && !buffer.hasAlpha())
index 6c74741..0b9ca7c 100644 (file)
@@ -51,7 +51,7 @@ namespace WebCore {
         RepetitionCount repetitionCount() const override;
 #endif
         bool setSize(const IntSize&) override;
-        ImageFrame* frameBufferAtIndex(size_t index) override;
+        ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) override;
         // CAUTION: setFailed() deletes |m_reader|.  Be careful to avoid
         // accessing deleted memory, especially when calling this from inside
         // PNGImageReader!
index 92677b9..5698189 100644 (file)
@@ -70,7 +70,7 @@ RepetitionCount WEBPImageDecoder::repetitionCount() const
     return m_repetitionCount ? m_repetitionCount : RepetitionCountInfinite;
 }
 
-ImageFrame* WEBPImageDecoder::frameBufferAtIndex(size_t index)
+ScalableImageDecoderFrame* WEBPImageDecoder::frameBufferAtIndex(size_t index)
 {
     if (index >= frameCount())
         return 0;
@@ -117,7 +117,7 @@ size_t WEBPImageDecoder::findFirstRequiredFrameToDecode(size_t frameIndex, WebPD
         // This frame covers the whole area and its disposalMethod is RestoreToBackground, which means
         // that the next frame will be rendered on top of a transparent background, and can be decoded
         // without dependencies. This can only be checked for frames prior to frameIndex.
-        if (firstIndependentFrame < frameIndex && m_frameBufferCache[firstIndependentFrame].disposalMethod() == ImageFrame::DisposalMethod::RestoreToBackground)
+        if (firstIndependentFrame < frameIndex && m_frameBufferCache[firstIndependentFrame].disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToBackground)
             return firstIndependentFrame + 1;
     }
 
@@ -170,9 +170,9 @@ void WEBPImageDecoder::decodeFrame(size_t frameIndex, WebPDemuxer* demuxer)
     bool blend = webpFrame.blend_method == WEBP_MUX_BLEND ? true : false;
 
     ASSERT(m_frameBufferCache.size() > frameIndex);
-    ImageFrame& buffer = m_frameBufferCache[frameIndex];
+    auto& buffer = m_frameBufferCache[frameIndex];
     buffer.setDuration(Seconds::fromMilliseconds(webpFrame.duration));
-    buffer.setDisposalMethod(webpFrame.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ? ImageFrame::DisposalMethod::RestoreToBackground : ImageFrame::DisposalMethod::DoNotDispose);
+    buffer.setDisposalMethod(webpFrame.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ? ScalableImageDecoderFrame::DisposalMethod::RestoreToBackground : ScalableImageDecoderFrame::DisposalMethod::DoNotDispose);
     ASSERT(!buffer.isComplete());
 
     if (buffer.isInvalid() && !initFrameBuffer(frameIndex, &webpFrame)) {
@@ -223,7 +223,7 @@ bool WEBPImageDecoder::initFrameBuffer(size_t frameIndex, const WebPIterator* we
     if (frameIndex >= frameCount())
         return false;
 
-    ImageFrame& buffer = m_frameBufferCache[frameIndex];
+    auto& buffer = m_frameBufferCache[frameIndex];
 
     // Initialize the frame rect in our buffer.
     IntRect frameRect(webpFrame->x_offset, webpFrame->y_offset, webpFrame->width, webpFrame->height);
@@ -236,14 +236,14 @@ bool WEBPImageDecoder::initFrameBuffer(size_t frameIndex, const WebPIterator* we
         if (!buffer.initialize(size(), m_premultiplyAlpha))
             return false;
     } else {
-        const ImageFrame& prevBuffer = m_frameBufferCache[frameIndex - 1];
+        const auto& prevBuffer = m_frameBufferCache[frameIndex - 1];
         ASSERT(prevBuffer.isComplete());
 
         // Preserve the last frame as the starting state for this frame.
         if (!prevBuffer.backingStore() || !buffer.initialize(*prevBuffer.backingStore()))
             return false;
 
-        if (prevBuffer.disposalMethod() == ImageFrame::DisposalMethod::RestoreToBackground) {
+        if (prevBuffer.disposalMethod() == ScalableImageDecoderFrame::DisposalMethod::RestoreToBackground) {
             // We want to clear the previous frame to transparent, without
             // affecting pixels in the image outside of the frame.
             const IntRect& prevRect = prevBuffer.backingStore()->frameRect();
@@ -259,7 +259,7 @@ bool WEBPImageDecoder::initFrameBuffer(size_t frameIndex, const WebPIterator* we
 
 void WEBPImageDecoder::applyPostProcessing(size_t frameIndex, WebPIDecoder* decoder, WebPDecBuffer& decoderBuffer, bool blend)
 {
-    ImageFrame& buffer = m_frameBufferCache[frameIndex];
+    auto& buffer = m_frameBufferCache[frameIndex];
     int decodedWidth = 0;
     int decodedHeight = 0;
     if (!WebPIDecGetRGB(decoder, &decodedHeight, &decodedWidth, 0, 0))
@@ -352,7 +352,7 @@ void WEBPImageDecoder::clearFrameBufferCache(size_t clearBeforeFrame)
     // In WEBP every frame depends on the previous one or none. That means that frames after clearBeforeFrame
     // won't need any frame before them to render, so we can clear them all.
     for (int i = clearBeforeFrame - 1; i >= 0; i--) {
-        ImageFrame& buffer = m_frameBufferCache[i];
+        auto& buffer = m_frameBufferCache[i];
         if (!buffer.isInvalid())
             buffer.clear();
     }
index b1e340b..e4808a5 100644 (file)
@@ -48,7 +48,7 @@ public:
 
     String filenameExtension() const override { return ASCIILiteral("webp"); }
     void setData(SharedBuffer&, bool) final;
-    ImageFrame* frameBufferAtIndex(size_t index) override;
+    ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) override;
     RepetitionCount repetitionCount() const override;
     size_t frameCount() const override { return m_frameCount; }
     void clearFrameBufferCache(size_t) override;