Title: [222196] trunk/Source/WebCore
Revision
222196
Author
[email protected]
Date
2017-09-18 19:45:32 -0700 (Mon, 18 Sep 2017)

Log Message

Make ImageFrame::duration() return Seconds instead of float
https://bugs.webkit.org/show_bug.cgi?id=177103

Patch by Said Abou-Hallawa <[email protected]> on 2017-09-18
Reviewed by Simon Fraser.

ScalableImageDecoder stores milliseconds for the duration of its ImageFrames.
But ImageFrameCache store seconds for the duration of its ImageFrames.
To fix this issue use Seconds for the ImageFrame duration.

* platform/graphics/BitmapImage.h:
* platform/graphics/ImageDecoder.h:
* platform/graphics/ImageFrame.h:
(WebCore::ImageFrame::setDuration):
(WebCore::ImageFrame::duration const):
* platform/graphics/ImageFrameCache.cpp:
(WebCore::ImageFrameCache::frameDurationAtIndex):
* platform/graphics/ImageFrameCache.h:
* platform/graphics/ImageSource.h:
(WebCore::ImageSource::frameDurationAtIndex):
* platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::ImageDecoderCG::frameDurationAtIndex const):
* platform/graphics/cg/ImageDecoderCG.h:
* platform/image-decoders/ScalableImageDecoder.cpp:
(WebCore::ScalableImageDecoder::frameDurationAtIndex const):
* platform/image-decoders/ScalableImageDecoder.h:
* platform/image-decoders/gif/GIFImageDecoder.cpp:
(WebCore::GIFImageDecoder::frameComplete):
* platform/image-decoders/png/PNGImageDecoder.cpp:
(WebCore::PNGImageDecoder::readChunks):
(WebCore::PNGImageDecoder::frameHeader): Deleted.
(WebCore::PNGImageDecoder::init): Deleted.
(WebCore::PNGImageDecoder::clearFrameBufferCache): Deleted.
(WebCore::PNGImageDecoder::initFrameBuffer): Deleted.
(WebCore::PNGImageDecoder::frameComplete): Deleted.
(WebCore::PNGImageDecoder::processingStart): Deleted.
(WebCore::PNGImageDecoder::processingFinish): Deleted.
(WebCore::PNGImageDecoder::fallbackNotAnimated): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (222195 => 222196)


--- trunk/Source/WebCore/ChangeLog	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/ChangeLog	2017-09-19 02:45:32 UTC (rev 222196)
@@ -1,3 +1,43 @@
+2017-09-18  Said Abou-Hallawa  <[email protected]>
+
+        Make ImageFrame::duration() return Seconds instead of float
+        https://bugs.webkit.org/show_bug.cgi?id=177103
+
+        Reviewed by Simon Fraser.
+
+        ScalableImageDecoder stores milliseconds for the duration of its ImageFrames.
+        But ImageFrameCache store seconds for the duration of its ImageFrames.
+        To fix this issue use Seconds for the ImageFrame duration.
+
+        * platform/graphics/BitmapImage.h:
+        * platform/graphics/ImageDecoder.h:
+        * platform/graphics/ImageFrame.h:
+        (WebCore::ImageFrame::setDuration):
+        (WebCore::ImageFrame::duration const):
+        * platform/graphics/ImageFrameCache.cpp:
+        (WebCore::ImageFrameCache::frameDurationAtIndex):
+        * platform/graphics/ImageFrameCache.h:
+        * platform/graphics/ImageSource.h:
+        (WebCore::ImageSource::frameDurationAtIndex):
+        * platform/graphics/cg/ImageDecoderCG.cpp:
+        (WebCore::ImageDecoderCG::frameDurationAtIndex const):
+        * platform/graphics/cg/ImageDecoderCG.h:
+        * platform/image-decoders/ScalableImageDecoder.cpp:
+        (WebCore::ScalableImageDecoder::frameDurationAtIndex const):
+        * platform/image-decoders/ScalableImageDecoder.h:
+        * platform/image-decoders/gif/GIFImageDecoder.cpp:
+        (WebCore::GIFImageDecoder::frameComplete):
+        * platform/image-decoders/png/PNGImageDecoder.cpp:
+        (WebCore::PNGImageDecoder::readChunks):
+        (WebCore::PNGImageDecoder::frameHeader): Deleted.
+        (WebCore::PNGImageDecoder::init): Deleted.
+        (WebCore::PNGImageDecoder::clearFrameBufferCache): Deleted.
+        (WebCore::PNGImageDecoder::initFrameBuffer): Deleted.
+        (WebCore::PNGImageDecoder::frameComplete): Deleted.
+        (WebCore::PNGImageDecoder::processingStart): Deleted.
+        (WebCore::PNGImageDecoder::processingFinish): Deleted.
+        (WebCore::PNGImageDecoder::fallbackNotAnimated): Deleted.
+
 2017-09-18  Per Arne Vollan  <[email protected]>
 
         [Win] Compile error in InbandTextTrackPrivateAVCF::readNativeSampleBuffer.

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (222195 => 222196)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.h	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h	2017-09-19 02:45:32 UTC (rev 222196)
@@ -94,7 +94,7 @@
 
     SubsamplingLevel frameSubsamplingLevelAtIndex(size_t index) const { return m_source.frameSubsamplingLevelAtIndex(index); }
 
-    float frameDurationAtIndex(size_t index) const { return m_source.frameDurationAtIndex(index); }
+    Seconds frameDurationAtIndex(size_t index) const { return m_source.frameDurationAtIndex(index); }
     ImageOrientation frameOrientationAtIndex(size_t index) const { return m_source.frameOrientationAtIndex(index); }
 
     size_t currentFrame() const { return m_currentFrame; }

Modified: trunk/Source/WebCore/platform/graphics/ImageDecoder.h (222195 => 222196)


--- trunk/Source/WebCore/platform/graphics/ImageDecoder.h	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/graphics/ImageDecoder.h	2017-09-19 02:45:32 UTC (rev 222196)
@@ -32,6 +32,7 @@
 #include "IntSize.h"
 #include "NativeImage.h"
 #include <wtf/Optional.h>
+#include <wtf/Seconds.h>
 #include <wtf/text/WTFString.h>
 #include <wtf/ThreadSafeRefCounted.h>
 
@@ -60,7 +61,7 @@
     virtual bool frameIsCompleteAtIndex(size_t) const = 0;
     virtual ImageOrientation frameOrientationAtIndex(size_t) const = 0;
 
-    virtual float frameDurationAtIndex(size_t) const = 0;
+    virtual Seconds frameDurationAtIndex(size_t) const = 0;
     virtual bool frameHasAlphaAtIndex(size_t) const = 0;
     virtual bool frameAllowSubsamplingAtIndex(size_t) const = 0;
     virtual unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const = 0;

Modified: trunk/Source/WebCore/platform/graphics/ImageFrame.h (222195 => 222196)


--- trunk/Source/WebCore/platform/graphics/ImageFrame.h	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/graphics/ImageFrame.h	2017-09-19 02:45:32 UTC (rev 222196)
@@ -32,6 +32,7 @@
 #include "ImageTypes.h"
 #include "IntSize.h"
 #include "NativeImage.h"
+#include <wtf/Seconds.h>
 
 namespace WebCore {
 
@@ -80,8 +81,8 @@
     void setOrientation(ImageOrientation orientation) { m_orientation = orientation; };
     ImageOrientation orientation() const { return m_orientation; }
 
-    void setDuration(float duration) { m_duration = duration; }
-    float duration() const { return m_duration; }
+    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; }
@@ -112,7 +113,7 @@
     DecodingOptions m_decodingOptions;
 
     ImageOrientation m_orientation { DefaultImageOrientation };
-    float m_duration { 0 };
+    Seconds m_duration;
     bool m_hasAlpha { true };
 };
 

Modified: trunk/Source/WebCore/platform/graphics/ImageFrameCache.cpp (222195 => 222196)


--- trunk/Source/WebCore/platform/graphics/ImageFrameCache.cpp	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/graphics/ImageFrameCache.cpp	2017-09-19 02:45:32 UTC (rev 222196)
@@ -534,9 +534,9 @@
     return frameMetadataAtIndexCacheIfNeeded<unsigned>(index, (&ImageFrame::frameBytes), nullptr, ImageFrame::Caching::Metadata, subsamplingLevel);
 }
 
-float ImageFrameCache::frameDurationAtIndex(size_t index)
+Seconds ImageFrameCache::frameDurationAtIndex(size_t index)
 {
-    return frameMetadataAtIndexCacheIfNeeded<float>(index, (&ImageFrame::duration), nullptr, ImageFrame::Caching::Metadata);
+    return frameMetadataAtIndexCacheIfNeeded<Seconds>(index, (&ImageFrame::duration), nullptr, ImageFrame::Caching::Metadata);
 }
 
 ImageOrientation ImageFrameCache::frameOrientationAtIndex(size_t index)

Modified: trunk/Source/WebCore/platform/graphics/ImageFrameCache.h (222195 => 222196)


--- trunk/Source/WebCore/platform/graphics/ImageFrameCache.h	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/graphics/ImageFrameCache.h	2017-09-19 02:45:32 UTC (rev 222196)
@@ -103,7 +103,7 @@
     // ImageFrame metadata which forces caching or re-caching the ImageFrame.
     IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default);
     unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default);
-    float frameDurationAtIndex(size_t);
+    Seconds frameDurationAtIndex(size_t);
     ImageOrientation frameOrientationAtIndex(size_t);
 
     NativeImagePtr frameImageAtIndex(size_t);

Modified: trunk/Source/WebCore/platform/graphics/ImageSource.h (222195 => 222196)


--- trunk/Source/WebCore/platform/graphics/ImageSource.h	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.h	2017-09-19 02:45:32 UTC (rev 222196)
@@ -101,7 +101,7 @@
     // ImageFrame metadata which forces caching or re-caching the ImageFrame.
     IntSize frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel = SubsamplingLevel::Default) { return m_frameCache->frameSizeAtIndex(index, subsamplingLevel); }
     unsigned frameBytesAtIndex(size_t index, SubsamplingLevel subsamplingLevel = SubsamplingLevel::Default) { return m_frameCache->frameBytesAtIndex(index, subsamplingLevel); }
-    float frameDurationAtIndex(size_t index) { return m_frameCache->frameDurationAtIndex(index); }
+    Seconds frameDurationAtIndex(size_t index) { return m_frameCache->frameDurationAtIndex(index); }
     ImageOrientation frameOrientationAtIndex(size_t index) { return m_frameCache->frameOrientationAtIndex(index); }
 
     NativeImagePtr frameImageAtIndex(size_t index) { return m_frameCache->frameImageAtIndex(index); }

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


--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp	2017-09-19 02:45:32 UTC (rev 222196)
@@ -330,9 +330,9 @@
     return orientationFromProperties(properties.get());
 }
 
-float ImageDecoderCG::frameDurationAtIndex(size_t index) const
+Seconds ImageDecoderCG::frameDurationAtIndex(size_t index) const
 {
-    float duration = 0;
+    float value = 0;
     RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), index, imageSourceOptions().get()));
     if (properties) {
         CFDictionaryRef gifProperties = (CFDictionaryRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyGIFDictionary);
@@ -339,10 +339,10 @@
         if (gifProperties) {
             if (CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(gifProperties, kCGImagePropertyGIFUnclampedDelayTime)) {
                 // Use the unclamped frame delay if it exists.
-                CFNumberGetValue(num, kCFNumberFloatType, &duration);
+                CFNumberGetValue(num, kCFNumberFloatType, &value);
             } else if (CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(gifProperties, kCGImagePropertyGIFDelayTime)) {
                 // Fall back to the clamped frame delay if the unclamped frame delay does not exist.
-                CFNumberGetValue(num, kCFNumberFloatType, &duration);
+                CFNumberGetValue(num, kCFNumberFloatType, &value);
             }
         }
         
@@ -349,18 +349,20 @@
         CFDictionaryRef pngProperties = (CFDictionaryRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyPNGDictionary);
         if (pngProperties) {
             if (CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(pngProperties, WebCoreCGImagePropertyAPNGUnclampedDelayTime))
-                CFNumberGetValue(num, kCFNumberFloatType, &duration);
+                CFNumberGetValue(num, kCFNumberFloatType, &value);
             else if (CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(pngProperties, WebCoreCGImagePropertyAPNGDelayTime))
-                CFNumberGetValue(num, kCFNumberFloatType, &duration);
+                CFNumberGetValue(num, kCFNumberFloatType, &value);
         }
     }
-    
+
+    Seconds duration(value);
+
     // 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.
-    if (duration < 0.011f)
-        return 0.1f;
+    if (duration < 11_ms)
+        return 100_ms;
     return duration;
 }
 

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


--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h	2017-09-19 02:45:32 UTC (rev 222196)
@@ -53,7 +53,7 @@
     bool frameIsCompleteAtIndex(size_t) const final;
     ImageOrientation frameOrientationAtIndex(size_t) const final;
 
-    float frameDurationAtIndex(size_t) const final;
+    Seconds frameDurationAtIndex(size_t) const final;
     bool frameHasAlphaAtIndex(size_t) const final;
     bool frameAllowSubsamplingAtIndex(size_t) const final;
     unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const final;

Modified: trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp (222195 => 222196)


--- trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp	2017-09-19 02:45:32 UTC (rev 222196)
@@ -196,7 +196,7 @@
     return (m_size.area() * sizeof(RGBA32)).unsafeGet();
 }
 
-float ScalableImageDecoder::frameDurationAtIndex(size_t index) const
+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
@@ -203,16 +203,15 @@
     // allows const.
     ImageFrame* buffer = const_cast<ScalableImageDecoder*>(this)->frameBufferAtIndex(index);
     if (!buffer || buffer->isInvalid())
-        return 0;
+        return 0_s;
     
     // 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;
+    if (buffer->duration() < 11_ms)
+        return 100_ms;
+    return buffer->duration();
 }
 
 NativeImagePtr ScalableImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel, const DecodingOptions&)

Modified: trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h (222195 => 222196)


--- trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h	2017-09-19 02:45:32 UTC (rev 222196)
@@ -143,7 +143,7 @@
     // Number of bytes in the decoded frame requested. Return 0 if not yet decoded.
     unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const override;
 
-    float frameDurationAtIndex(size_t) const override;
+    Seconds frameDurationAtIndex(size_t) const final;
 
     NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default, const DecodingOptions& = DecodingMode::Synchronous) override;
 

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


--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp	2017-09-19 02:45:32 UTC (rev 222196)
@@ -248,7 +248,7 @@
         return false; // initFrameBuffer() has already called setFailed().
 
     buffer.setDecodingStatus(DecodingStatus::Complete);
-    buffer.setDuration(frameDuration);
+    buffer.setDuration(Seconds::fromMilliseconds(frameDuration));
     buffer.setDisposalMethod(disposalMethod);
 
     if (!m_currentBufferSawAlpha) {

Modified: trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp (222195 => 222196)


--- trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp	2017-09-19 01:56:34 UTC (rev 222195)
+++ trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp	2017-09-19 02:45:32 UTC (rev 222196)
@@ -650,9 +650,9 @@
             ImageFrame& buffer = m_frameBufferCache[m_currentFrame];
 
             if (!m_delayDenominator)
-                buffer.setDuration(m_delayNumerator * 10);
+                buffer.setDuration(Seconds::fromMilliseconds(m_delayNumerator * 10));
             else
-                buffer.setDuration(m_delayNumerator * 1000 / m_delayDenominator);
+                buffer.setDuration(Seconds::fromMilliseconds(m_delayNumerator * 1000 / m_delayDenominator));
 
             if (m_dispose == 2)
                 buffer.setDisposalMethod(ImageFrame::DisposalMethod::RestoreToPrevious);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to