Title: [199294] trunk
Revision
199294
Author
[email protected]
Date
2016-04-11 05:46:30 -0700 (Mon, 11 Apr 2016)

Log Message

Unreviewed, rolling out r199290.
https://bugs.webkit.org/show_bug.cgi?id=156465

broke 300 tests (Requested by mcatanzaro on #webkit).

Reverted changeset:

"Merge CG ImageSource and non CG ImageSource implementation in
one file"
https://bugs.webkit.org/show_bug.cgi?id=155456
http://trac.webkit.org/changeset/199290

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (199293 => 199294)


--- trunk/LayoutTests/ChangeLog	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/LayoutTests/ChangeLog	2016-04-11 12:46:30 UTC (rev 199294)
@@ -1,3 +1,17 @@
+2016-04-11  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r199290.
+        https://bugs.webkit.org/show_bug.cgi?id=156465
+
+        broke 300 tests (Requested by mcatanzaro on #webkit).
+
+        Reverted changeset:
+
+        "Merge CG ImageSource and non CG ImageSource implementation in
+        one file"
+        https://bugs.webkit.org/show_bug.cgi?id=155456
+        http://trac.webkit.org/changeset/199290
+
 2016-04-11  Frederic Wang  <[email protected]>
 
         Refactor RenderMathMLUnderOver layout functions to avoid using flexbox

Deleted: trunk/LayoutTests/fast/images/image-subsampling-expected.html (199293 => 199294)


--- trunk/LayoutTests/fast/images/image-subsampling-expected.html	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/LayoutTests/fast/images/image-subsampling-expected.html	2016-04-11 12:46:30 UTC (rev 199294)
@@ -1,26 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-    <style>
-        div {
-            width: 100px;
-            height: 100px;
-            margin: 10px;
-            display: inline-block;
-        }
-    </style>
-<head>
-<body>
-<script>
-    function createDiv(color) {
-        var divElement = document.createElement("div");
-        divElement.style.backgroundColor = color;
-        document.body.appendChild(divElement);
-    }
-
-    createDiv("red");
-    createDiv("green");
-    createDiv("blue");
-</script>
-</body>
-</html>

Deleted: trunk/LayoutTests/fast/images/image-subsampling.html (199293 => 199294)


--- trunk/LayoutTests/fast/images/image-subsampling.html	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/LayoutTests/fast/images/image-subsampling.html	2016-04-11 12:46:30 UTC (rev 199294)
@@ -1,43 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-    <style>
-        div {
-            width: 100px;
-            height: 100px;
-            margin: 10px;
-            display: inline-block;
-        }
-        img {
-            width: 100px;
-            height: 100px;
-        }
-    </style>
-<head>
-<body>
-<script>
-    if (window.internals)
-        window.internals.settings.setImageSubsamplingEnabled(true);
-
-    function createImage(color) {
-        var canvas = document.createElement("canvas");
-        canvas.width = 1024 * 3;
-        canvas.height = 1024 * 3;
-        var ctx = canvas.getContext("2d");
-        ctx.fillStyle = color;
-        ctx.fillRect(0, 0, canvas.width, canvas.height);
-
-        var imgElement = document.createElement("img");
-        imgElement.src = ""
-
-        var divElement = document.createElement("div");
-        divElement.appendChild(imgElement);
-        document.body.appendChild(divElement);
-    }
-    
-    createImage("red");
-    createImage("green");
-    createImage("blue");
-</script>
-</body>
-</html>

Modified: trunk/Source/WebCore/CMakeLists.txt (199293 => 199294)


--- trunk/Source/WebCore/CMakeLists.txt	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/CMakeLists.txt	2016-04-11 12:46:30 UTC (rev 199294)
@@ -2214,7 +2214,6 @@
     platform/graphics/Image.cpp
     platform/graphics/ImageBuffer.cpp
     platform/graphics/ImageOrientation.cpp
-    platform/graphics/ImageSource.cpp
     platform/graphics/IntPoint.cpp
     platform/graphics/IntRect.cpp
     platform/graphics/IntSize.cpp

Modified: trunk/Source/WebCore/ChangeLog (199293 => 199294)


--- trunk/Source/WebCore/ChangeLog	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/ChangeLog	2016-04-11 12:46:30 UTC (rev 199294)
@@ -1,3 +1,17 @@
+2016-04-11  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r199290.
+        https://bugs.webkit.org/show_bug.cgi?id=156465
+
+        broke 300 tests (Requested by mcatanzaro on #webkit).
+
+        Reverted changeset:
+
+        "Merge CG ImageSource and non CG ImageSource implementation in
+        one file"
+        https://bugs.webkit.org/show_bug.cgi?id=155456
+        http://trac.webkit.org/changeset/199290
+
 2016-04-11  Frederic Wang  <[email protected]>
 
         Refactor RenderMathMLUnderOver layout functions to avoid using flexbox

Modified: trunk/Source/WebCore/PlatformAppleWin.cmake (199293 => 199294)


--- trunk/Source/WebCore/PlatformAppleWin.cmake	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/PlatformAppleWin.cmake	2016-04-11 12:46:30 UTC (rev 199294)
@@ -72,6 +72,7 @@
     platform/graphics/cg/ImageBufferDataCG.cpp
     platform/graphics/cg/ImageCG.cpp
     platform/graphics/cg/ImageDecoderCG.cpp
+    platform/graphics/cg/ImageSourceCG.cpp
     platform/graphics/cg/ImageSourceCGWin.cpp
     platform/graphics/cg/IntPointCG.cpp
     platform/graphics/cg/IntRectCG.cpp

Modified: trunk/Source/WebCore/PlatformMac.cmake (199293 => 199294)


--- trunk/Source/WebCore/PlatformMac.cmake	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/PlatformMac.cmake	2016-04-11 12:46:30 UTC (rev 199294)
@@ -406,6 +406,7 @@
     platform/graphics/cg/ImageBufferDataCG.cpp
     platform/graphics/cg/ImageCG.cpp
     platform/graphics/cg/ImageDecoderCG.cpp
+    platform/graphics/cg/ImageSourceCG.cpp
     platform/graphics/cg/ImageSourceCGMac.mm
     platform/graphics/cg/IntPointCG.cpp
     platform/graphics/cg/IntRectCG.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (199293 => 199294)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-04-11 12:46:30 UTC (rev 199294)
@@ -4986,6 +4986,7 @@
 		B275355A0B053814002CE64F /* FloatRectCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B275352C0B053814002CE64F /* FloatRectCG.cpp */; };
 		B275355B0B053814002CE64F /* FloatSizeCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B275352D0B053814002CE64F /* FloatSizeCG.cpp */; };
 		B275355E0B053814002CE64F /* ImageCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535300B053814002CE64F /* ImageCG.cpp */; };
+		B275355F0B053814002CE64F /* ImageSourceCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535310B053814002CE64F /* ImageSourceCG.cpp */; };
 		B27535600B053814002CE64F /* IntPointCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535320B053814002CE64F /* IntPointCG.cpp */; };
 		B27535610B053814002CE64F /* IntRectCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535330B053814002CE64F /* IntRectCG.cpp */; };
 		B27535620B053814002CE64F /* IntSizeCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535340B053814002CE64F /* IntSizeCG.cpp */; };
@@ -12876,6 +12877,7 @@
 		B275352C0B053814002CE64F /* FloatRectCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FloatRectCG.cpp; sourceTree = "<group>"; };
 		B275352D0B053814002CE64F /* FloatSizeCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FloatSizeCG.cpp; sourceTree = "<group>"; };
 		B27535300B053814002CE64F /* ImageCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ImageCG.cpp; sourceTree = "<group>"; };
+		B27535310B053814002CE64F /* ImageSourceCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ImageSourceCG.cpp; sourceTree = "<group>"; };
 		B27535320B053814002CE64F /* IntPointCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IntPointCG.cpp; sourceTree = "<group>"; };
 		B27535330B053814002CE64F /* IntRectCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IntRectCG.cpp; sourceTree = "<group>"; };
 		B27535340B053814002CE64F /* IntSizeCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IntSizeCG.cpp; sourceTree = "<group>"; };
@@ -21783,6 +21785,7 @@
 				B27535300B053814002CE64F /* ImageCG.cpp */,
 				555B87EA1CAAF0AB00349425 /* ImageDecoderCG.cpp */,
 				555B87EB1CAAF0AB00349425 /* ImageDecoderCG.h */,
+				B27535310B053814002CE64F /* ImageSourceCG.cpp */,
 				4B3480920EEF50D400AC1B41 /* ImageSourceCG.h */,
 				4B3480910EEF50D400AC1B41 /* ImageSourceCGMac.mm */,
 				B27535320B053814002CE64F /* IntPointCG.cpp */,
@@ -30001,6 +30004,7 @@
 				2D5A592F152525230036EE51 /* ImageOrientation.cpp in Sources */,
 				B51A2F4117D7D5DE0072517A /* ImageQualityController.cpp in Sources */,
 				0F3C725E1974874B00AEDD0C /* ImageSource.cpp in Sources */,
+				B275355F0B053814002CE64F /* ImageSourceCG.cpp in Sources */,
 				4B3480930EEF50D400AC1B41 /* ImageSourceCGMac.mm in Sources */,
 				316FE1170E6E1DA700BF6088 /* ImplicitAnimation.cpp in Sources */,
 				BE961C5418AD338500D07DC5 /* InbandDataTextTrack.cpp in Sources */,

Modified: trunk/Source/WebCore/platform/Cursor.cpp (199293 => 199294)


--- trunk/Source/WebCore/platform/Cursor.cpp	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/Cursor.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -44,10 +44,10 @@
         return specifiedHotSpot;
 
     // If hot spot is not specified externally, it can be extracted from some image formats (e.g. .cur).
-    if (auto intrinsicHotSpot = image->hotSpot()) {
-        if (imageRect.contains(intrinsicHotSpot.value()))
-            return intrinsicHotSpot.value();
-    }
+    IntPoint intrinsicHotSpot;
+    bool imageHasIntrinsicHotSpot = image->getHotSpot(intrinsicHotSpot);
+    if (imageHasIntrinsicHotSpot && imageRect.contains(intrinsicHotSpot))
+        return intrinsicHotSpot;
 
     return IntPoint();
 }

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.cpp (199293 => 199294)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -254,9 +254,9 @@
     return m_sizeRespectingOrientation;
 }
 
-Optional<IntPoint> BitmapImage::hotSpot() const
+bool BitmapImage::getHotSpot(IntPoint& hotSpot) const
 {
-    auto result = m_source.hotSpot();
+    bool result = m_source.getHotSpot(hotSpot);
     didDecodeProperties();
     return result;
 }

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (199293 => 199294)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.h	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h	2016-04-11 12:46:30 UTC (rev 199294)
@@ -125,7 +125,7 @@
     FloatSize size() const override;
     IntSize sizeRespectingOrientation() const;
 
-    Optional<IntPoint> hotSpot() const override;
+    bool getHotSpot(IntPoint&) const override;
 
     unsigned decodedSize() const { return m_decodedSize; }
 

Modified: trunk/Source/WebCore/platform/graphics/Image.h (199293 => 199294)


--- trunk/Source/WebCore/platform/graphics/Image.h	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/graphics/Image.h	2016-04-11 12:46:30 UTC (rev 199294)
@@ -33,7 +33,6 @@
 #include "GraphicsTypes.h"
 #include "ImageOrientation.h"
 #include "NativeImagePtr.h"
-#include <wtf/Optional.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -108,7 +107,7 @@
     FloatRect rect() const { return FloatRect(FloatPoint(), size()); }
     float width() const { return size().width(); }
     float height() const { return size().height(); }
-    virtual Optional<IntPoint> hotSpot() const { return Nullopt; }
+    virtual bool getHotSpot(IntPoint&) const { return false; }
 
 #if PLATFORM(IOS)
     virtual FloatSize originalSize() const { return size(); }

Modified: trunk/Source/WebCore/platform/graphics/ImageSource.cpp (199293 => 199294)


--- trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2010, 2011, 2012, 2014, 2016 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006 Apple Inc.  All rights reserved.
  * Copyright (C) 2007 Alp Toker <[email protected]>
  * Copyright (C) 2008, Google Inc. All rights reserved.
  * Copyright (C) 2007-2009 Torch Mobile, Inc
@@ -29,16 +29,19 @@
 #include "config.h"
 #include "ImageSource.h"
 
-#if USE(CG)
-#include "ImageDecoderCG.h"
-#else
+#if !USE(CG)
+
 #include "ImageDecoder.h"
-#endif
 
 #include "ImageOrientation.h"
+#include "NotImplemented.h"
 
 namespace WebCore {
 
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+unsigned ImageSource::s_maxPixelsPerDecodedImage = 1024 * 1024;
+#endif
+
 ImageSource::ImageSource(ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption)
     : m_alphaOption(alphaOption)
     , m_gammaAndColorProfileOption(gammaAndColorProfileOption)
@@ -47,22 +50,15 @@
 
 ImageSource::~ImageSource()
 {
+    clear(true);
 }
 
-void ImageSource::clearFrameBufferCache(size_t clearBeforeFrame)
+void ImageSource::clear(bool destroyAll, size_t clearBeforeFrame, SharedBuffer* data, bool allDataReceived)
 {
-    if (!initialized())
+    if (!destroyAll) {
+        if (m_decoder)
+            m_decoder->clearFrameBufferCache(clearBeforeFrame);
         return;
-    m_decoder->clearFrameBufferCache(clearBeforeFrame);
-}
-
-void ImageSource::clear(bool destroyAllFrames, size_t clearBeforeFrame, SharedBuffer* data, bool allDataReceived)
-{
-    // There's no need to throw away the decoder unless we're explicitly asked
-    // to destroy all of the frames.
-    if (!destroyAllFrames) {
-        clearFrameBufferCache(clearBeforeFrame);
-        return;
     }
 
     m_decoder = nullptr;
@@ -71,12 +67,20 @@
         setData(data, allDataReceived);
 }
 
-void ImageSource::ensureDecoderIsCreated(const SharedBuffer& data)
+void ImageSource::ensureDecoderIsCreated(SharedBuffer* data)
 {
     if (initialized())
         return;
     
-    m_decoder = ImageDecoder::create(data, m_alphaOption, m_gammaAndColorProfileOption);
+    // Make the decoder by sniffing the bytes.
+    // This method will examine the data and instantiate an instance of the appropriate decoder plugin.
+    // If insufficient bytes are available to determine the image type, no decoder plugin will be
+    // made.
+    m_decoder = ImageDecoder::create(*data, m_alphaOption, m_gammaAndColorProfileOption);
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+    if (m_decoder && s_maxPixelsPerDecodedImage)
+        m_decoder->setMaxNumPixels(s_maxPixelsPerDecodedImage);
+#endif
 }
 
 void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
@@ -84,7 +88,7 @@
     if (!data)
         return;
     
-    ensureDecoderIsCreated(*data);
+    ensureDecoderIsCreated(data);
     
     if (!initialized()) {
         ASSERT_NOT_REACHED();
@@ -92,48 +96,25 @@
     }
 
     if (m_decoder)
-        m_decoder->setData(*data, allDataReceived);
+        m_decoder->setData(data, allDataReceived);
 }
 
-SubsamplingLevel ImageSource::calculateMaximumSubsamplingLevel() const
+String ImageSource::filenameExtension() const
 {
-    if (!m_allowSubsampling || !allowSubsamplingOfFrameAtIndex(0))
-        return 0;
-    
-    // FIXME: this value was chosen to be appropriate for iOS since the image
-    // subsampling is only enabled by default on iOS. Choose a different value
-    // if image subsampling is enabled on other platform.
-    const int maximumImageAreaBeforeSubsampling = 5 * 1024 * 1024;
-    const SubsamplingLevel maxSubsamplingLevel = 3;
-    
-    for (SubsamplingLevel level = 0; level < maxSubsamplingLevel; ++level) {
-        if (frameSizeAtIndex(0, level).area() < maximumImageAreaBeforeSubsampling)
-            return level;
-    }
-    
-    return maxSubsamplingLevel;
+    return m_decoder ? m_decoder->filenameExtension() : String();
 }
 
-SubsamplingLevel ImageSource::subsamplingLevelForScale(float scale) const
+SubsamplingLevel ImageSource::subsamplingLevelForScale(float) const
 {
-    if (!(scale > 0 && scale <= 1))
-        return 0;
-    
-    SubsamplingLevel maximumSubsamplingLevel = calculateMaximumSubsamplingLevel();
-    if (!maximumSubsamplingLevel)
-        return 0;
-
-    // There are four subsampling levels: 0 = 1x, 1 = 0.5x, 2 = 0.25x, 3 = 0.125x.
-    SubsamplingLevel result = std::ceil(std::log2(1 / scale));
-    return std::min(result, maximumSubsamplingLevel);
+    return 0;
 }
 
-size_t ImageSource::bytesDecodedToDetermineProperties()
+bool ImageSource::allowSubsamplingOfFrameAtIndex(size_t) const
 {
-    return ImageDecoder::bytesDecodedToDetermineProperties();
+    return false;
 }
 
-bool ImageSource::isSizeAvailable() const
+bool ImageSource::isSizeAvailable()
 {
     return initialized() && m_decoder->isSizeAvailable();
 }
@@ -148,71 +129,97 @@
     return frameSizeAtIndex(0, 0, RespectImageOrientation);
 }
 
-size_t ImageSource::frameCount() const
+IntSize ImageSource::frameSizeAtIndex(size_t index, SubsamplingLevel, RespectImageOrientationEnum shouldRespectImageOrientation) const
 {
-    return initialized() ? m_decoder->frameCount() : 0;
+    if (!initialized())
+        return { };
+
+    IntSize size = m_decoder->frameSizeAtIndex(index);
+    ImageOrientation orientation = m_decoder->orientation();
+    
+    return shouldRespectImageOrientation == RespectImageOrientation && orientation.usesWidthAsHeight() ? size.transposedSize() : size;
 }
 
-int ImageSource::repetitionCount()
+bool ImageSource::getHotSpot(IntPoint& hotSpot) const
 {
-    return initialized() ? m_decoder->repetitionCount() : cAnimationNone;
+    return initialized() && m_decoder->hotSpot(hotSpot);
 }
 
-String ImageSource::filenameExtension() const
+size_t ImageSource::bytesDecodedToDetermineProperties() const
 {
-    return initialized() ? m_decoder->filenameExtension() : String();
+    return 0;
 }
 
-Optional<IntPoint> ImageSource::hotSpot() const
+int ImageSource::repetitionCount()
 {
-    return initialized() ? m_decoder->hotSpot() : Nullopt;
+    return initialized() ? m_decoder->repetitionCount() : cAnimationNone;
 }
 
-bool ImageSource::frameIsCompleteAtIndex(size_t index)
+size_t ImageSource::frameCount() const
 {
-    return initialized() && m_decoder->frameIsCompleteAtIndex(index);
+    return initialized() ? m_decoder->frameCount() : 0;
 }
 
-bool ImageSource::frameHasAlphaAtIndex(size_t index)
+NativeImagePtr ImageSource::createFrameImageAtIndex(size_t index, SubsamplingLevel)
 {
-    return !initialized() || m_decoder->frameHasAlphaAtIndex(index);
-}
+    if (!initialized())
+        return nullptr;
 
-bool ImageSource::allowSubsamplingOfFrameAtIndex(size_t index) const
-{
-    return initialized() && m_decoder->allowSubsamplingOfFrameAtIndex(index);
+    // Zero-height images can cause problems for some ports.  If we have an
+    // empty image dimension, just bail.
+    if (size().isEmpty())
+        return nullptr;
+
+    ImageFrame* buffer = m_decoder->frameBufferAtIndex(index);
+    if (!buffer || buffer->status() == ImageFrame::FrameEmpty)
+        return nullptr;
+
+    // Return the buffer contents as a native image.  For some ports, the data
+    // is already in a native container, and this just increments its refcount.
+    return buffer->asNewNativeImage();
 }
 
-IntSize ImageSource::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel, RespectImageOrientationEnum shouldRespectImageOrientation) const
+float ImageSource::frameDurationAtIndex(size_t index)
 {
     if (!initialized())
-        return { };
+        return 0;
 
-    IntSize size = m_decoder->frameSizeAtIndex(index, subsamplingLevel);
-    if (shouldRespectImageOrientation != RespectImageOrientation)
-        return size;
+    ImageFrame* buffer = m_decoder->frameBufferAtIndex(index);
+    if (!buffer || buffer->status() == ImageFrame::FrameEmpty)
+        return 0;
 
-    return orientationAtIndex(index).usesWidthAsHeight() ? size.transposedSize() : size;
+    // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
+    // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
+    // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
+    // for more information.
+    const float duration = buffer->duration() / 1000.0f;
+    if (duration < 0.011f)
+        return 0.100f;
+    return duration;
 }
 
-unsigned ImageSource::frameBytesAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
+ImageOrientation ImageSource::orientationAtIndex(size_t) const
 {
-    return frameSizeAtIndex(index, subsamplingLevel).area() * 4;
+    return initialized() ? m_decoder->orientation() : ImageOrientation();
 }
 
-float ImageSource::frameDurationAtIndex(size_t index)
+bool ImageSource::frameHasAlphaAtIndex(size_t index)
 {
-    return initialized() ? m_decoder->frameDurationAtIndex(index) : 0;
+    return !initialized() || m_decoder->frameHasAlphaAtIndex(index);
 }
 
-ImageOrientation ImageSource::orientationAtIndex(size_t index) const
+bool ImageSource::frameIsCompleteAtIndex(size_t index)
 {
-    return initialized() ? m_decoder->orientationAtIndex(index) : ImageOrientation();
+    if (!initialized())
+        return false;
+
+    ImageFrame* buffer = m_decoder->frameBufferAtIndex(index);
+    return buffer && buffer->status() == ImageFrame::FrameComplete;
 }
-    
-NativeImagePtr ImageSource::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel)
+
+unsigned ImageSource::frameBytesAtIndex(size_t index, SubsamplingLevel) const
 {
-    return initialized() ? m_decoder->createFrameImageAtIndex(index, subsamplingLevel) : nullptr;
+    return initialized() ? m_decoder->frameBytesAtIndex(index) : 0;
 }
 
 void ImageSource::dump(TextStream& ts) const
@@ -226,3 +233,5 @@
 }
     
 }
+
+#endif // USE(CG)

Modified: trunk/Source/WebCore/platform/graphics/ImageSource.h (199293 => 199294)


--- trunk/Source/WebCore/platform/graphics/ImageSource.h	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.h	2016-04-11 12:46:30 UTC (rev 199294)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012, 2014, 2016 Apple Inc.  All rights reserved.
+ * Copyright (C) 2004, 2005, 2006 Apple Inc.  All rights reserved.
  * Copyright (C) 2007-2008 Torch Mobile, Inc.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,15 +28,18 @@
 #define ImageSource_h
 
 #include "ImageOrientation.h"
-#include "IntPoint.h"
 #include "NativeImagePtr.h"
 #include "TextStream.h"
 
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
-#include <wtf/Optional.h>
 #include <wtf/Vector.h>
 
+#if USE(CG)
+typedef struct CGImageSource* CGImageSourceRef;
+typedef const struct __CFData* CFDataRef;
+#endif
+
 namespace WebCore {
 
 class ImageOrientation;
@@ -80,7 +83,7 @@
         GammaAndColorProfileIgnored
     };
 
-    ImageSource(AlphaOption = AlphaPremultiplied, GammaAndColorProfileOption = GammaAndColorProfileApplied);
+    ImageSource(AlphaOption alphaOption = AlphaPremultiplied, GammaAndColorProfileOption gammaAndColorProfileOption = GammaAndColorProfileApplied);
     ~ImageSource();
 
     // Tells the ImageSource that the Image no longer cares about decoded frame
@@ -104,61 +107,76 @@
     // who set |destroyAll| to true if they wish to be able to continue using
     // the ImageSource.  This way implementations which choose to destroy their
     // decoders in some cases can reconstruct them correctly.
-    void clear(bool destroyAll, size_t clearBeforeFrame = 0, SharedBuffer* data = "" bool allDataReceived = false);
+    void clear(bool destroyAll,
+               size_t clearBeforeFrame = 0,
+               SharedBuffer* data = ""
+               bool allDataReceived = false);
 
     bool initialized() const { return m_decoder.get(); }
 
     void setData(SharedBuffer* data, bool allDataReceived);
+    String filenameExtension() const;
 
     SubsamplingLevel subsamplingLevelForScale(float) const;
+    bool allowSubsamplingOfFrameAtIndex(size_t) const;
     void setAllowSubsampling(bool allowSubsampling) { m_allowSubsampling = allowSubsampling; }
-    static size_t bytesDecodedToDetermineProperties();
+    SubsamplingLevel maximumSubsamplingLevel() const;
+
+    bool isSizeAvailable();
     
-    bool isSizeAvailable() const;
     // Always original size, without subsampling.
     IntSize size() const;
     IntSize sizeRespectingOrientation() const;
+    
+    // Size of optionally subsampled frame.
+    IntSize frameSizeAtIndex(size_t, SubsamplingLevel = 0, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
 
-    size_t frameCount() const;
+    bool getHotSpot(IntPoint&) const;
+
+    size_t bytesDecodedToDetermineProperties() const;
+
     int repetitionCount();
-    String filenameExtension() const;
-    Optional<IntPoint> hotSpot() const;
 
+    size_t frameCount() const;
+
+    // Callers should not call this after calling clear() with a higher index;
+    // see comments on clear() above.
+    NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = 0);
+
+    float frameDurationAtIndex(size_t);
+    bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha.
     bool frameIsCompleteAtIndex(size_t); // Whether or not the frame is completely decoded.
-    bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha.
-    bool allowSubsamplingOfFrameAtIndex(size_t) const;
-    
-    // Size of optionally subsampled frame.
-    IntSize frameSizeAtIndex(size_t, SubsamplingLevel = 0, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
-    
+    ImageOrientation orientationAtIndex(size_t) const; // EXIF image orientation
+
     // Return the number of bytes in the decoded frame. If the frame is not yet
     // decoded then return 0.
     unsigned frameBytesAtIndex(size_t, SubsamplingLevel = 0) const;
-    
-    float frameDurationAtIndex(size_t);
-    ImageOrientation orientationAtIndex(size_t) const; // EXIF image orientation
-    
-    // Callers should not call this after calling clear() with a higher index;
-    // see comments on clear() above.
-    NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = 0);
-    
+
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+    static unsigned maxPixelsPerDecodedImage() { return s_maxPixelsPerDecodedImage; }
+    static void setMaxPixelsPerDecodedImage(unsigned maxPixels) { s_maxPixelsPerDecodedImage = maxPixels; }
+#endif
+
 private:
-    void clearFrameBufferCache(size_t);
-    void ensureDecoderIsCreated(const SharedBuffer&);
+    void ensureDecoderIsCreated(SharedBuffer*);
     SubsamplingLevel calculateMaximumSubsamplingLevel() const;
     void dump(TextStream&) const;
     
     std::unique_ptr<ImageDecoder> m_decoder;
-
-    // The default value of m_allowSubsampling should be the same as defaultImageSubsamplingEnabled in Settings.cpp
+    
 #if PLATFORM(IOS)
     bool m_allowSubsampling { true };
 #else
     bool m_allowSubsampling { false };
 #endif
 
+#if !USE(CG)
     AlphaOption m_alphaOption;
     GammaAndColorProfileOption m_gammaAndColorProfileOption;
+#endif
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+    static unsigned s_maxPixelsPerDecodedImage;
+#endif
 };
 
 }

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp (199293 => 199294)


--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -122,6 +122,15 @@
     m_nativeDecoder = adoptCF(CGImageSourceCreateIncremental(nullptr));
 }
 
+SubsamplingLevel ImageDecoder::subsamplingLevelForScale(float scale, SubsamplingLevel maximumSubsamplingLevel)
+{
+    // There are four subsampling levels: 0 = 1x, 1 = 0.5x, 2 = 0.25x, 3 = 0.125x.
+    float clampedScale = std::max<float>(0.125, std::min<float>(1, scale));
+    SubsamplingLevel result = ceilf(log2f(1 / clampedScale));
+    ASSERT(result >=0 && result <= 3);
+    return std::min(result, maximumSubsamplingLevel);
+}
+
 size_t ImageDecoder::bytesDecodedToDetermineProperties()
 {
     // Measured by tracing malloc/calloc calls on Mac OS 10.6.6, x86_64.
@@ -201,25 +210,26 @@
     return cAnimationNone;
 }
 
-Optional<IntPoint> ImageDecoder::hotSpot() const
+bool ImageDecoder::hotSpot(IntPoint& hotSpot) const
 {
     RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), 0, imageSourceOptions().get()));
     if (!properties)
-        return Nullopt;
+        return false;
     
     int x = -1, y = -1;
     CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(properties.get(), CFSTR("hotspotX"));
     if (!num || !CFNumberGetValue(num, kCFNumberIntType, &x))
-        return Nullopt;
+        return false;
     
     num = (CFNumberRef)CFDictionaryGetValue(properties.get(), CFSTR("hotspotY"));
     if (!num || !CFNumberGetValue(num, kCFNumberIntType, &y))
-        return Nullopt;
+        return false;
     
     if (x < 0 || y < 0)
-        return Nullopt;
+        return false;
     
-    return IntPoint(x, y);
+    hotSpot = IntPoint(x, y);
+    return true;
 }
 
 IntSize ImageDecoder::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
@@ -376,21 +386,21 @@
     CGImageSourceUpdateData(m_nativeDecoder.get(), data, allDataReceived);
 }
 
-void ImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
+void ImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
 {
 #if PLATFORM(COCOA)
     // On Mac the NSData inside the SharedBuffer can be secretly appended to without the SharedBuffer's knowledge.
     // We use SharedBuffer's ability to wrap itself inside CFData to get around this, ensuring that ImageIO is
     // really looking at the SharedBuffer.
-    setData(data.createCFData().get(), allDataReceived);
+    setData(data->createCFData().get(), allDataReceived);
 #else
     // Create a CGDataProvider to wrap the SharedBuffer.
-    data.ref();
+    data->ref();
     // We use the GetBytesAtPosition callback rather than the GetBytePointer one because SharedBuffer
     // does not provide a way to lock down the byte pointer and guarantee that it won't move, which
     // is a requirement for using the GetBytePointer callback.
     CGDataProviderDirectCallbacks providerCallbacks = { 0, 0, 0, sharedBufferGetBytesAtPosition, sharedBufferRelease };
-    RetainPtr<CGDataProviderRef> dataProvider = adoptCF(CGDataProviderCreateDirect(&data, data.size(), &providerCallbacks));
+    RetainPtr<CGDataProviderRef> dataProvider = adoptCF(CGDataProviderCreateDirect(data, data->size(), &providerCallbacks));
     CGImageSourceUpdateDataProvider(m_nativeDecoder.get(), dataProvider.get(), allDataReceived);
 #endif
 }

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h (199293 => 199294)


--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h	2016-04-11 12:46:30 UTC (rev 199294)
@@ -29,23 +29,19 @@
 #include "ImageSourceCG.h"
 #include "IntSize.h"
 
-#include <wtf/Optional.h>
-
-typedef struct CGImageSource* CGImageSourceRef;
-typedef const struct __CFData* CFDataRef;
-
 namespace WebCore {
 
 class ImageDecoder {
 public:
     ImageDecoder();
     
-    static std::unique_ptr<ImageDecoder> create(const SharedBuffer&, ImageSource::AlphaOption, ImageSource::GammaAndColorProfileOption)
+    static std::unique_ptr<ImageDecoder> create()
     {
         return std::make_unique<ImageDecoder>();
     }
     
     static size_t bytesDecodedToDetermineProperties();
+    static SubsamplingLevel subsamplingLevelForScale(float scale, SubsamplingLevel maximumSubsamplingLevel);
     
     String filenameExtension() const;
     bool isSizeAvailable() const;
@@ -54,7 +50,7 @@
     IntSize size() const;
     size_t frameCount() const;
     int repetitionCount() const;
-    Optional<IntPoint> hotSpot() const;
+    bool hotSpot(IntPoint& hotSpot) const;
     
     IntSize frameSizeAtIndex(size_t, SubsamplingLevel) const;
     bool frameIsCompleteAtIndex(size_t) const;
@@ -68,10 +64,8 @@
     NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel) const;
     
     void setData(CFDataRef, bool allDataReceived);
-    void setData(SharedBuffer&, bool allDataReceived);
+    void setData(SharedBuffer*, bool allDataReceived);
     
-    void clearFrameBufferCache(size_t) { }
-    
 protected:
     mutable IntSize m_size;
     RetainPtr<CGImageSourceRef> m_nativeDecoder;

Copied: trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp (from rev 199293, trunk/Source/WebCore/platform/graphics/ImageSource.cpp) (0 => 199294)


--- trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2008, 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 "ImageSource.h"
+
+#if USE(CG)
+#include "ImageSourceCG.h"
+
+#include "ImageDecoderCG.h"
+#include "ImageOrientation.h"
+#include "SharedBuffer.h"
+
+namespace WebCore {
+
+ImageSource::ImageSource(ImageSource::AlphaOption, ImageSource::GammaAndColorProfileOption)
+{
+    // FIXME: AlphaOption and GammaAndColorProfileOption are ignored.
+}
+
+ImageSource::~ImageSource()
+{
+    clear(true);
+}
+
+void ImageSource::clear(bool destroyAllFrames, size_t, SharedBuffer* data, bool allDataReceived)
+{
+    // Recent versions of ImageIO discard previously decoded image frames if the client
+    // application no longer holds references to them, so there's no need to throw away
+    // the decoder unless we're explicitly asked to destroy all of the frames.
+    if (!destroyAllFrames)
+        return;
+
+    m_decoder = nullptr;
+    
+    if (data)
+        setData(data, allDataReceived);
+}
+    
+void ImageSource::ensureDecoderIsCreated(SharedBuffer*)
+{
+    if (initialized())
+        return;
+    m_decoder = ImageDecoder::create();
+}
+
+void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
+{
+    if (!data)
+        return;
+    
+    ensureDecoderIsCreated(data);
+    
+    if (!initialized()) {
+        ASSERT_NOT_REACHED();
+        return;
+    }
+    
+    m_decoder->setData(data, allDataReceived);
+}
+
+String ImageSource::filenameExtension() const
+{
+    return initialized() ? m_decoder->filenameExtension() : String();
+}
+    
+SubsamplingLevel ImageSource::calculateMaximumSubsamplingLevel() const
+{
+    if (!m_allowSubsampling || !allowSubsamplingOfFrameAtIndex(0))
+        return 0;
+
+    // Values chosen to be appropriate for iOS.
+    const int cMaximumImageAreaBeforeSubsampling = 5 * 1024 * 1024;
+    const SubsamplingLevel maxSubsamplingLevel = 3;
+
+    SubsamplingLevel currentLevel = 0;
+    for ( ; currentLevel <= maxSubsamplingLevel; ++currentLevel) {
+        IntSize frameSize = frameSizeAtIndex(0, currentLevel);
+        if (frameSize.area() < cMaximumImageAreaBeforeSubsampling)
+            break;
+    }
+
+    return currentLevel;
+}
+    
+SubsamplingLevel ImageSource::maximumSubsamplingLevel() const
+{
+#if PLATFORM(IOS)
+    return calculateMaximumSubsamplingLevel();
+#endif
+    return 0;
+}
+
+SubsamplingLevel ImageSource::subsamplingLevelForScale(float scale) const
+{
+    return ImageDecoder::subsamplingLevelForScale(scale, maximumSubsamplingLevel());
+}
+
+bool ImageSource::isSizeAvailable()
+{
+    return initialized() && m_decoder->isSizeAvailable();
+}
+
+bool ImageSource::allowSubsamplingOfFrameAtIndex(size_t index) const
+{
+    return initialized() && m_decoder->allowSubsamplingOfFrameAtIndex(index);
+}
+
+IntSize ImageSource::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel, RespectImageOrientationEnum shouldRespectImageOrientation) const
+{
+    if (!initialized())
+        return { };
+    
+    IntSize size = m_decoder->frameSizeAtIndex(index, subsamplingLevel);
+    ImageOrientation orientation = m_decoder->orientationAtIndex(index);
+    
+    return shouldRespectImageOrientation == RespectImageOrientation && orientation.usesWidthAsHeight() ? size.transposedSize() : size;
+}
+
+ImageOrientation ImageSource::orientationAtIndex(size_t index) const
+{
+    return initialized() ? m_decoder->orientationAtIndex(index) : ImageOrientation();
+}
+
+IntSize ImageSource::size() const
+{
+    return frameSizeAtIndex(0, 0);
+}
+    
+IntSize ImageSource::sizeRespectingOrientation() const
+{
+    return frameSizeAtIndex(0, 0, RespectImageOrientation);
+}
+
+bool ImageSource::getHotSpot(IntPoint& hotSpot) const
+{
+    return initialized() && m_decoder->hotSpot(hotSpot);
+}
+
+size_t ImageSource::bytesDecodedToDetermineProperties() const
+{
+    return ImageDecoder::bytesDecodedToDetermineProperties();
+}
+    
+int ImageSource::repetitionCount()
+{
+    return initialized() ? m_decoder->repetitionCount() : cAnimationLoopOnce;
+}
+
+size_t ImageSource::frameCount() const
+{
+    return initialized() ? m_decoder->frameCount() : 0;
+}
+
+RetainPtr<CGImageRef> ImageSource::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel)
+{
+    return initialized() ? m_decoder->createFrameImageAtIndex(index, subsamplingLevel) : nullptr;
+}
+
+bool ImageSource::frameIsCompleteAtIndex(size_t index)
+{
+    return initialized() && m_decoder->frameIsCompleteAtIndex(index);
+}
+
+float ImageSource::frameDurationAtIndex(size_t index)
+{
+    return initialized() ? m_decoder->frameDurationAtIndex(index) : 0;
+}
+
+bool ImageSource::frameHasAlphaAtIndex(size_t index)
+{
+    return !initialized() || m_decoder->frameHasAlphaAtIndex(index);
+}
+
+unsigned ImageSource::frameBytesAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
+{
+    IntSize frameSize = frameSizeAtIndex(index, subsamplingLevel);
+    return frameSize.area() * 4;
+}
+    
+void ImageSource::dump(TextStream& ts) const
+{
+    if (m_allowSubsampling)
+        ts.dumpProperty("allow-subsampling", m_allowSubsampling);
+    
+    ImageOrientation orientation = orientationAtIndex(0);
+    if (orientation != OriginTopLeft)
+        ts.dumpProperty("orientation", orientation);
+}
+
+}
+
+#endif // USE(CG)

Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp (199293 => 199294)


--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -1,5 +1,4 @@
 /*
- * Copyright (C) 2016 Apple Inc.  All rights reserved.
  * Copyright (C) 2008-2009 Torch Mobile, Inc.
  * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
  *
@@ -271,18 +270,15 @@
 
 }
 
-bool ImageDecoder::frameIsCompleteAtIndex(size_t index) const
+bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const
 {
     if (m_frameBufferCache.size() <= index)
-        return false;
-    return m_frameBufferCache[index].status() == ImageFrame::FrameComplete;
+        return true;
+    if (m_frameBufferCache[index].status() == ImageFrame::FrameComplete)
+        return m_frameBufferCache[index].hasAlpha();
+    return true;
 }
 
-bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const
-{
-    return !frameIsCompleteAtIndex(index) || m_frameBufferCache[index].hasAlpha();
-}
-
 unsigned ImageDecoder::frameBytesAtIndex(size_t index) const
 {
     if (m_frameBufferCache.size() <= index)
@@ -291,42 +287,6 @@
     return m_size.area() * sizeof(ImageFrame::PixelData);
 }
 
-float ImageDecoder::frameDurationAtIndex(size_t index) const
-{
-    if (m_frameBufferCache.size() <= index)
-        return 0;
-
-    if (m_frameBufferCache[index].status() == ImageFrame::FrameEmpty)
-        return 0;
-
-    // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
-    // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
-    // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
-    // for more information.
-    const float duration = m_frameBufferCache[index].duration() / 1000.0f;
-    if (duration < 0.011f)
-        return 0.100f;
-    return duration;
-}
-
-NativeImagePtr ImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel) const
-{
-    if (m_frameBufferCache.size() <= index)
-        return nullptr;
-
-    // Zero-height images can cause problems for some ports. If we have an
-    // empty image dimension, just bail.
-    if (size().isEmpty())
-        return nullptr;
-
-    if (m_frameBufferCache[index].status() == ImageFrame::FrameEmpty)
-        return nullptr;
-
-    // Return the buffer contents as a native image. For some ports, the data
-    // is already in a native container, and this just increments its refcount.
-    return m_frameBufferCache[index].asNewNativeImage();
-}
-
 void ImageDecoder::prepareScaleDataIfNecessary()
 {
     m_scaled = false;

Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h (199293 => 199294)


--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h	2016-04-11 12:46:30 UTC (rev 199294)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2016 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006 Apple Inc.  All rights reserved.
  * Copyright (C) 2008-2009 Torch Mobile, Inc.
  * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
@@ -34,7 +34,6 @@
 #include "PlatformScreen.h"
 #include "SharedBuffer.h"
 #include <wtf/Assertions.h>
-#include <wtf/Optional.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
@@ -236,14 +235,15 @@
         WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED;
     public:
         ImageDecoder(ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption)
-            : m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied)
+            : m_scaled(false)
+            , m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied)
             , m_ignoreGammaAndColorProfile(gammaAndColorProfileOption == ImageSource::GammaAndColorProfileIgnored)
-        {
-        }
+            , m_sizeAvailable(false)
+            , m_maxNumPixels(-1)
+            , m_isAllDataReceived(false)
+            , m_failed(false) { }
 
-        virtual ~ImageDecoder()
-        {
-        }
+        virtual ~ImageDecoder() { }
 
         // Returns a caller-owned decoder of the appropriate type.  Returns 0 if
         // we can't sniff a supported type from the provided data (possibly
@@ -254,11 +254,11 @@
 
         bool isAllDataReceived() const { return m_isAllDataReceived; }
 
-        virtual void setData(SharedBuffer& data, bool allDataReceived)
+        virtual void setData(SharedBuffer* data, bool allDataReceived)
         {
             if (m_failed)
                 return;
-            m_data = &data;
+            m_data = data;
             m_isAllDataReceived = allDataReceived;
         }
 
@@ -282,7 +282,7 @@
         // sizes.  This does NOT differ from size() for GIF, since decoding GIFs
         // composites any smaller frames against previous frames to create full-
         // size frames.
-        virtual IntSize frameSizeAtIndex(size_t, SubsamplingLevel) const
+        virtual IntSize frameSizeAtIndex(size_t) const
         {
             return size();
         }
@@ -310,24 +310,16 @@
         // ImageDecoder-owned pointer.
         virtual ImageFrame* frameBufferAtIndex(size_t) = 0;
 
-        bool frameIsCompleteAtIndex(size_t) const;
-
         // Make the best effort guess to check if the requested frame has alpha channel.
-        bool frameHasAlphaAtIndex(size_t) const;
+        virtual bool frameHasAlphaAtIndex(size_t) const;
 
         // Number of bytes in the decoded frame requested. Return 0 if not yet decoded.
-        unsigned frameBytesAtIndex(size_t) const;
-        
-        float frameDurationAtIndex(size_t) const;
-        
-        NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel) const;
+        virtual unsigned frameBytesAtIndex(size_t) const;
 
         void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile = flag; }
         bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfile; }
 
-        ImageOrientation orientationAtIndex(size_t) const { return m_orientation; }
-        
-        bool allowSubsamplingOfFrameAtIndex(size_t) const { return false; }
+        ImageOrientation orientation() const { return m_orientation; }
 
         enum { iccColorProfileHeaderLength = 128 };
 
@@ -338,10 +330,6 @@
             return !memcmp(&profileData[16], "RGB ", 4);
         }
 
-        static size_t bytesDecodedToDetermineProperties() { return 0; }
-        
-        static SubsamplingLevel subsamplingLevelForScale(float, SubsamplingLevel) { return 0; }
-
         static bool inputDeviceColorProfile(const char* profileData, unsigned profileLength)
         {
             ASSERT_UNUSED(profileLength, profileLength >= iccColorProfileHeaderLength);
@@ -366,9 +354,13 @@
         // compositing).
         virtual void clearFrameBufferCache(size_t) { }
 
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+        void setMaxNumPixels(int m) { m_maxNumPixels = m; }
+#endif
+
         // If the image has a cursor hot-spot, stores it in the argument
         // and returns true. Otherwise returns false.
-        virtual Optional<IntPoint> hotSpot() const { return Nullopt; }
+        virtual bool hotSpot(IntPoint&) const { return false; }
 
     protected:
         void prepareScaleDataIfNecessary();
@@ -382,7 +374,7 @@
         Vector<ImageFrame, 1> m_frameBufferCache;
         // FIXME: Do we need m_colorProfile any more, for any port?
         ColorProfile m_colorProfile;
-        bool m_scaled { false };
+        bool m_scaled;
         Vector<int> m_scaledColumns;
         Vector<int> m_scaledRows;
         bool m_premultiplyAlpha;
@@ -400,14 +392,10 @@
         }
 
         IntSize m_size;
-        bool m_sizeAvailable { false };
-#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
-        static const int m_maxNumPixels { 1024 * 1024 };
-#else
-        static const int m_maxNumPixels { -1 };
-#endif
-        bool m_isAllDataReceived { false };
-        bool m_failed { false };
+        bool m_sizeAvailable;
+        int m_maxNumPixels;
+        bool m_isAllDataReceived;
+        bool m_failed;
     };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp (199293 => 199294)


--- trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -47,14 +47,14 @@
 {
 }
 
-void BMPImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
+void BMPImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
 {
     if (failed())
         return;
 
     ImageDecoder::setData(data, allDataReceived);
     if (m_reader)
-        m_reader->setData(&data);
+        m_reader->setData(data);
 }
 
 bool BMPImageDecoder::isSizeAvailable()

Modified: trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h (199293 => 199294)


--- trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h	2016-04-11 12:46:30 UTC (rev 199294)
@@ -42,7 +42,7 @@
 
         // ImageDecoder
         virtual String filenameExtension() const { return "bmp"; }
-        virtual void setData(SharedBuffer&, bool allDataReceived);
+        virtual void setData(SharedBuffer*, bool allDataReceived);
         virtual bool isSizeAvailable();
         virtual ImageFrame* frameBufferAtIndex(size_t index);
         // CAUTION: setFailed() deletes |m_reader|.  Be careful to avoid

Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp (199293 => 199294)


--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -42,14 +42,14 @@
 {
 }
 
-void GIFImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
+void GIFImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
 {
     if (failed())
         return;
 
     ImageDecoder::setData(data, allDataReceived);
     if (m_reader)
-        m_reader->setData(&data);
+        m_reader->setData(data);
 }
 
 bool GIFImageDecoder::isSizeAvailable()
@@ -303,7 +303,7 @@
 
     if (!m_reader) {
         m_reader = std::make_unique<GIFImageReader>(this);
-        m_reader->setData(m_data.get());
+        m_reader->setData(m_data);
     }
 
     if (query == GIFSizeQuery) {

Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h (199293 => 199294)


--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h	2016-04-11 12:46:30 UTC (rev 199294)
@@ -42,7 +42,7 @@
 
         // ImageDecoder
         virtual String filenameExtension() const { return "gif"; }
-        virtual void setData(SharedBuffer& data, bool allDataReceived);
+        virtual void setData(SharedBuffer* data, bool allDataReceived);
         virtual bool isSizeAvailable();
         virtual bool setSize(unsigned width, unsigned height);
         virtual size_t frameCount();

Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageReader.h (199293 => 199294)


--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageReader.h	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageReader.h	2016-04-11 12:46:30 UTC (rev 199294)
@@ -246,7 +246,7 @@
     {
     }
 
-    void setData(WebCore::SharedBuffer* data) { m_data = data; }
+    void setData(PassRefPtr<WebCore::SharedBuffer> data) { m_data = data; }
     // FIXME: haltAtFrame should be size_t.
     bool decode(WebCore::GIFImageDecoder::GIFQuery, unsigned haltAtFrame);
 

Modified: trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp (199293 => 199294)


--- trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -55,7 +55,7 @@
 {
 }
 
-void ICOImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
+void ICOImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
 {
     if (failed())
         return;
@@ -64,7 +64,7 @@
 
     for (BMPReaders::iterator i(m_bmpReaders.begin()); i != m_bmpReaders.end(); ++i) {
         if (*i)
-            (*i)->setData(&data);
+            (*i)->setData(data);
     }
     for (size_t i = 0; i < m_pngDecoders.size(); ++i)
         setDataForPNGDecoderAtIndex(i);
@@ -128,20 +128,21 @@
     return ImageDecoder::setFailed();
 }
 
-Optional<IntPoint> ICOImageDecoder::hotSpot() const
+bool ICOImageDecoder::hotSpot(IntPoint& hotSpot) const
 {
     // When unspecified, the default frame is always frame 0. This is consistent with
     // BitmapImage where currentFrame() starts at 0 and only increases when animation is
     // requested.
-    return hotSpotAtIndex(0);
+    return hotSpotAtIndex(0, hotSpot);
 }
 
-Optional<IntPoint> ICOImageDecoder::hotSpotAtIndex(size_t index) const
+bool ICOImageDecoder::hotSpotAtIndex(size_t index, IntPoint& hotSpot) const
 {
     if (index >= m_dirEntries.size() || m_fileType != CURSOR)
-        return Nullopt;
+        return false;
 
-    return m_dirEntries[index].m_hotSpot;
+    hotSpot = m_dirEntries[index].m_hotSpot;
+    return true;
 }
 
 
@@ -164,7 +165,7 @@
     // FIXME: Save this copy by making the PNG decoder able to take an
     // optional offset.
     RefPtr<SharedBuffer> pngData(SharedBuffer::create(&m_data->data()[dirEntry.m_imageOffset], m_data->size() - dirEntry.m_imageOffset));
-    m_pngDecoders[index]->setData(*pngData, isAllDataReceived());
+    m_pngDecoders[index]->setData(pngData.get(), isAllDataReceived());
 }
 
 void ICOImageDecoder::decode(size_t index, bool onlySize)

Modified: trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h (199293 => 199294)


--- trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h	2016-04-11 12:46:30 UTC (rev 199294)
@@ -45,7 +45,7 @@
 
         // ImageDecoder
         virtual String filenameExtension() const { return "ico"; }
-        virtual void setData(SharedBuffer&, bool allDataReceived);
+        virtual void setData(SharedBuffer*, bool allDataReceived);
         virtual bool isSizeAvailable();
         virtual IntSize size() const;
         virtual IntSize frameSizeAtIndex(size_t) const;
@@ -56,7 +56,7 @@
         // avoid accessing deleted memory, especially when calling this from
         // inside BMPImageReader!
         virtual bool setFailed();
-        virtual Optional<IntPoint> hotSpot() const;
+        virtual bool hotSpot(IntPoint&) const;
 
     private:
         enum ImageType {
@@ -116,8 +116,9 @@
         // could be decoded.
         bool processDirectoryEntries();
 
-        // Returns the hot-spot for |index|, returns Nullopt if there is none.
-        Optional<IntPoint> hotSpotAtIndex(size_t) const;
+        // Stores the hot-spot for |index| in |hotSpot| and returns true,
+        // or returns false if there is none.
+        bool hotSpotAtIndex(size_t index, IntPoint& hotSpot) const;
 
         // Reads and returns a directory entry from the current offset into
         // |data|.

Modified: trunk/Source/WebKit2/ChangeLog (199293 => 199294)


--- trunk/Source/WebKit2/ChangeLog	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebKit2/ChangeLog	2016-04-11 12:46:30 UTC (rev 199294)
@@ -1,3 +1,17 @@
+2016-04-11  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r199290.
+        https://bugs.webkit.org/show_bug.cgi?id=156465
+
+        broke 300 tests (Requested by mcatanzaro on #webkit).
+
+        Reverted changeset:
+
+        "Merge CG ImageSource and non CG ImageSource implementation in
+        one file"
+        https://bugs.webkit.org/show_bug.cgi?id=155456
+        http://trac.webkit.org/changeset/199290
+
 2016-04-11  Said Abou-Hallawa  <sabouhallawa@apple,com>
 
         Merge CG ImageSource and non CG ImageSource implementation in one file

Modified: trunk/Source/WebKit2/UIProcess/API/efl/EwkView.cpp (199293 => 199294)


--- trunk/Source/WebKit2/UIProcess/API/efl/EwkView.cpp	2016-04-11 12:11:18 UTC (rev 199293)
+++ trunk/Source/WebKit2/UIProcess/API/efl/EwkView.cpp	2016-04-11 12:46:30 UTC (rev 199294)
@@ -450,9 +450,10 @@
         if (cursorImage == m_cursorIdentifier.image)
             return;
 
-        
-        Optional<IntPoint> hotSpot = cursorImage->hotSpot();
-        Ecore_X_Cursor customCursor = createCustomCursor(window, cursorImage, IntSize(cursorImage->size()), hotSpot ? hotSpot.value() : IntPoint());
+        IntPoint hotSpot;
+        cursorImage->getHotSpot(hotSpot);
+
+        Ecore_X_Cursor customCursor = createCustomCursor(window, cursorImage, IntSize(cursorImage->size()), hotSpot);
         if (!customCursor)
             return;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to