WebCore/ChangeLog

 12008-06-18 Peter Kasting <zerodpx@gmail.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 https://bugs.webkit.org/show_bug.cgi?id=19663
 6 Account for paint lag when animating images.
 7
 8 * platform/graphics/BitmapImage.cpp:
 9 (WebCore::BitmapImage::BitmapImage):
 10 (WebCore::BitmapImage::startAnimation):
 11 (WebCore::BitmapImage::advanceAnimation):
 12 * platform/graphics/BitmapImage.h:
 13
1142008-06-18 Timothy Hatcher <timothy@apple.com>
215
316 Add a script build phase to remove the WebKit.qrc file from
34652

WebCore/platform/graphics/BitmapImage.cpp

3131#include "ImageObserver.h"
3232#include "IntRect.h"
3333#include "PlatformString.h"
 34#include "SystemTime.h"
3435#include "Timer.h"
3536#include <wtf/Vector.h>
3637#include "MIMETypeRegistry.h"

@@BitmapImage::BitmapImage(ImageObserver*
4849 , m_frameTimer(0)
4950 , m_repetitionCount(0)
5051 , m_repetitionsComplete(0)
 52 , m_lastAnimationFrameTime(0)
5153 , m_isSolidColor(false)
5254 , m_animatingImageType(true)
5355 , m_animationFinished(false)

@@void BitmapImage::startAnimation()
232234 if (!m_allDataReceived && m_repetitionCount == cAnimationLoopOnce && m_currentFrame >= (frameCount() - 1))
233235 return;
234236
 237 // Calculate desired delay. frameDurationAtIndex() tells us how long the
 238 // current frame wants to be visible. Reduce this by the amount of time
 239 // we've spent drawing since we advanced to this frame, so that the
 240 // animation appears to run at the correct framerate regardless of drawing
 241 // lag. (In the common case, the drawing lag for the next frame will be
 242 // similar, and thus the frame will actually be visible for almost the exact
 243 // same amount of time it requests to be visible.)
 244 double delay = frameDurationAtIndex(m_currentFrame);
 245 if (m_lastAnimationFrameTime != 0)
 246 delay -= (currentTime() - m_lastAnimationFrameTime);
 247 if (delay < 0)
 248 delay = 0;
 249
235250 m_frameTimer = new Timer<BitmapImage>(this, &BitmapImage::advanceAnimation);
236  m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
 251 m_frameTimer->startOneShot(delay);
237252}
238253
239254void BitmapImage::stopAnimation()

@@void BitmapImage::advanceAnimation(Timer
299314 // We do not advance the animation explicitly. We rely on a subsequent draw of the image
300315 // to force a request for the next frame via startAnimation(). This allows images that move offscreen while
301316 // scrolling to stop animating (thus saving memory from additional decoded frames and
302  // CPU time spent doing the decoding).
 317 // CPU time spent doing the decoding). However, this drawing will take nonzero time. So,
 318 // save the current time, so that if we do want to draw another frame, we can delay it
 319 // relative to right now, rather than relative to when the drawing actually finishes. This
 320 // makes the animation speed not vary based on our drawing lag.
 321 m_lastAnimationFrameTime = currentTime();
303322}
304323
305324}
34652

WebCore/platform/graphics/BitmapImage.h

@@protected:
183183 Timer<BitmapImage>* m_frameTimer;
184184 int m_repetitionCount; // How many total animation loops we should do.
185185 int m_repetitionsComplete; // How many repetitions we've finished.
 186 double m_lastAnimationFrameTime; // The system time at which we finished advancing the last animation frame.
186187
187188#if PLATFORM(MAC)
188189 mutable RetainPtr<NSImage> m_nsImage; // A cached NSImage of frame 0. Only built lazily if someone actually queries for one.
34652