Fix regression from throwing away frames of large animated images. Alter
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2007 23:58:11 +0000 (23:58 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2007 23:58:11 +0000 (23:58 +0000)
        animated images so that they refuse to advance the animation until the
        current displayed frame has been fully decoded.

        Reviewed by ggaren

        * platform/graphics/BitmapImage.cpp:
        (WebCore::BitmapImage::startAnimation):
        (WebCore::BitmapImage::advanceAnimation):
        * platform/graphics/ImageSource.h:
        * platform/graphics/cg/ImageSourceCG.cpp:
        (WebCore::ImageSource::frameIsCompleteAtIndex):

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

WebCore/ChangeLog
WebCore/platform/graphics/BitmapImage.cpp
WebCore/platform/graphics/ImageSource.h
WebCore/platform/graphics/cg/ImageSourceCG.cpp

index b25ebbb..8e60e12 100644 (file)
@@ -1,5 +1,20 @@
 2007-03-08  David Hyatt  <hyatt@apple.com>
 
+        Fix regression from throwing away frames of large animated images.  Alter
+        animated images so that they refuse to advance the animation until the
+        current displayed frame has been fully decoded.
+
+        Reviewed by ggaren
+
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::startAnimation):
+        (WebCore::BitmapImage::advanceAnimation):
+        * platform/graphics/ImageSource.h:
+        * platform/graphics/cg/ImageSourceCG.cpp:
+        (WebCore::ImageSource::frameIsCompleteAtIndex):
+
+2007-03-08  David Hyatt  <hyatt@apple.com>
+
         Fix 2% performance regression on the PLT.  Increase the large animated
         image cutoff from 1MB to 5MB.
 
index 136bc26..b4f66d2 100644 (file)
@@ -209,6 +209,10 @@ void BitmapImage::startAnimation()
     if (m_frameTimer || !shouldAnimate() || frameCount() <= 1)
         return;
 
+    // Don't advance the animation until the current frame has completely loaded.
+    if (!m_source.frameIsCompleteAtIndex(m_currentFrame))
+        return;
+
     m_frameTimer = new Timer<BitmapImage>(this, &BitmapImage::advanceAnimation);
     m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
 }
@@ -275,7 +279,10 @@ void BitmapImage::advanceAnimation(Timer<BitmapImage>* timer)
         }
     }
     
-    // Kick off a timer to move to the next frame.
+    // Kick off a timer to move to the next frame, but only if the current frame is complete.
+    if (!m_source.frameIsCompleteAtIndex(m_currentFrame))
+        return;
+
     m_frameTimer = new Timer<BitmapImage>(this, &BitmapImage::advanceAnimation);
     m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
 }
index 04b08df..25edf1f 100644 (file)
@@ -86,6 +86,7 @@ public:
     
     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.
 
 private:
     NativeImageSourcePtr m_decoder;
index c33303a..88f1ff0 100644 (file)
@@ -155,6 +155,11 @@ void ImageSource::destroyFrameAtIndex(size_t index)
     CGImageRelease(image);
 }
 
+bool ImageSource::frameIsCompleteAtIndex(size_t index)
+{
+    return CGImageSourceGetStatusAtIndex(m_decoder, index) == kCGImageStatusComplete;
+}
+
 float ImageSource::frameDurationAtIndex(size_t index)
 {
     float duration = 0;