Commit b57170b4 authored by eric@webkit.org's avatar eric@webkit.org
Browse files

No review, rollback only.

        Roll out Peter's change (per his request)
        http://trac.webkit.org/changeset/36069
        https://bugs.webkit.org/show_bug.cgi?id=19663
        This change has been the source of numerous regressions
        (several of which were latent bugs revealed by this change,
        others were bugs in this change)

        * platform/graphics/BitmapImage.cpp:
        (WebCore::BitmapImage::BitmapImage):
        (WebCore::BitmapImage::startAnimation):
        (WebCore::BitmapImage::advanceAnimation):
        * platform/graphics/BitmapImage.h:
        * platform/graphics/cairo/ImageCairo.cpp:
        (WebCore::BitmapImage::draw):
        * platform/graphics/cg/ImageCG.cpp:
        (WebCore::BitmapImage::draw):
        * platform/graphics/qt/ImageQt.cpp:
        (WebCore::BitmapImage::draw):
        * platform/graphics/wx/ImageWx.cpp:
        (WebCore::BitmapImage::draw):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@36781 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent dc318205
2008-09-22 Eric Seidel <eric@webkit.org>
No review, rollback only.
Roll out Peter's change (per his request)
http://trac.webkit.org/changeset/36069
https://bugs.webkit.org/show_bug.cgi?id=19663
This change has been the source of numerous regressions
(several of which were latent bugs revealed by this change,
others were bugs in this change)
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::BitmapImage):
(WebCore::BitmapImage::startAnimation):
(WebCore::BitmapImage::advanceAnimation):
* platform/graphics/BitmapImage.h:
* platform/graphics/cairo/ImageCairo.cpp:
(WebCore::BitmapImage::draw):
* platform/graphics/cg/ImageCG.cpp:
(WebCore::BitmapImage::draw):
* platform/graphics/qt/ImageQt.cpp:
(WebCore::BitmapImage::draw):
* platform/graphics/wx/ImageWx.cpp:
(WebCore::BitmapImage::draw):
2008-09-22 Dan Bernstein <mitz@apple.com>
Reviewed by Sam Weinig.
......
......@@ -31,7 +31,6 @@
#include "ImageObserver.h"
#include "IntRect.h"
#include "PlatformString.h"
#include "SystemTime.h"
#include "Timer.h"
#include <wtf/Vector.h>
#include "MIMETypeRegistry.h"
......@@ -42,11 +41,6 @@ namespace WebCore {
// one frame at a time.
const unsigned cLargeAnimationCutoff = 5242880;
// When an animated image is more than five minutes out of date, don't try to
// resync on repaint, so we don't waste CPU cycles on an edge case the user
// doesn't care about.
const double cAnimationResyncCutoff = 5 * 60;
BitmapImage::BitmapImage(ImageObserver* observer)
: Image(observer)
, m_currentFrame(0)
......@@ -54,7 +48,6 @@ BitmapImage::BitmapImage(ImageObserver* observer)
, m_frameTimer(0)
, m_repetitionCount(0)
, m_repetitionsComplete(0)
, m_desiredFrameStartTime(0)
, m_isSolidColor(false)
, m_animatingImageType(true)
, m_animationFinished(false)
......@@ -257,50 +250,8 @@ void BitmapImage::startAnimation()
if (!m_allDataReceived && m_repetitionCount == cAnimationLoopOnce && m_currentFrame >= (frameCount() - 1))
return;
// Determine time for next frame to start. By ignoring paint and timer lag
// in this calculation, we make the animation appear to run at its desired
// rate regardless of how fast it's being repainted.
const double currentDuration = frameDurationAtIndex(m_currentFrame);
const double time = currentTime();
if (!m_desiredFrameStartTime)
m_desiredFrameStartTime = time + currentDuration;
else {
m_desiredFrameStartTime += currentDuration;
// If we're too far behind, the user probably doesn't care about
// resyncing and we could burn a lot of time looping through frames
// below. Just reset the timings.
if ((time - m_desiredFrameStartTime) > cAnimationResyncCutoff)
m_desiredFrameStartTime = time + currentDuration;
}
if (time < m_desiredFrameStartTime) {
// Haven't yet reached time for next frame to start; delay until then.
m_frameTimer = new Timer<BitmapImage>(this, &BitmapImage::advanceAnimation);
m_frameTimer->startOneShot(m_desiredFrameStartTime - time);
} else {
// We've already reached or passed the time for the next frame to start.
// See if we've also passed the time for frames after that to start, in
// case we need to skip some frames entirely.
size_t nextFrame = (m_currentFrame + 1) % frameCount();
while (m_source.frameIsCompleteAtIndex(nextFrame)) {
// Should we skip the current frame?
double nextFrameStartTime = m_desiredFrameStartTime + frameDurationAtIndex(nextFrame);
if (time < nextFrameStartTime)
break;
// Yes; skip over it without notifying our observers.
if (!internalAdvanceAnimation(true))
return;
m_desiredFrameStartTime = nextFrameStartTime;
nextFrame = (nextFrame + 1) % frameCount();
}
// Draw the next frame immediately. Note that m_desiredFrameStartTime
// may be in the past, meaning the next time through this function we'll
// kick off the next advancement sooner than this frame's duration would
// suggest.
internalAdvanceAnimation(false);
}
m_frameTimer = new Timer<BitmapImage>(this, &BitmapImage::advanceAnimation);
m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
}
void BitmapImage::stopAnimation()
......@@ -325,19 +276,14 @@ void BitmapImage::resetAnimation()
}
void BitmapImage::advanceAnimation(Timer<BitmapImage>* timer)
{
internalAdvanceAnimation(false);
}
bool BitmapImage::internalAdvanceAnimation(bool skippingFrames)
{
// Stop the animation.
stopAnimation();
// See if anyone is still paying attention to this animation. If not, we don't
// advance and will remain suspended at the current frame until the animation is resumed.
if (!skippingFrames && imageObserver()->shouldPauseAnimation(this))
return false;
if (imageObserver()->shouldPauseAnimation(this))
return;
m_currentFrame++;
if (m_currentFrame >= frameCount()) {
......@@ -348,30 +294,12 @@ bool BitmapImage::internalAdvanceAnimation(bool skippingFrames)
m_repetitionCount = m_source.repetitionCount();
if (m_repetitionCount && m_repetitionsComplete >= m_repetitionCount) {
m_animationFinished = true;
m_desiredFrameStartTime = 0;
m_currentFrame--;
if (skippingFrames) {
// Uh oh. We tried to skip past the end of the animation. We'd
// better draw this last frame.
notifyObserverAndTrimDecodedData();
}
return false;
return;
}
m_currentFrame = 0;
}
if (!skippingFrames)
notifyObserverAndTrimDecodedData();
// We do not advance the animation explicitly. We rely on a subsequent draw of the image
// to force a request for the next frame via startAnimation(). This allows images that move offscreen while
// scrolling to stop animating (thus saving memory from additional decoded frames and
// CPU time spent doing the decoding).
return true;
}
void BitmapImage::notifyObserverAndTrimDecodedData()
{
// Notify our observer that the animation has advanced.
imageObserver()->animationAdvanced(this);
......@@ -385,6 +313,11 @@ void BitmapImage::notifyObserverAndTrimDecodedData()
// Go ahead and decode the next frame.
frameAtIndex(m_currentFrame);
}
// We do not advance the animation explicitly. We rely on a subsequent draw of the image
// to force a request for the next frame via startAnimation(). This allows images that move offscreen while
// scrolling to stop animating (thus saving memory from additional decoded frames and
// CPU time spent doing the decoding).
}
}
......@@ -167,17 +167,7 @@ protected:
bool shouldAnimate();
virtual void startAnimation();
void advanceAnimation(Timer<BitmapImage>*);
// Function that does the real work of advancing the animation. When
// skippingFrames is true, we're in the middle of a loop trying to skip over
// a bunch of animation frames, so we should not do things like decode each
// one or notify our observers.
// Returns whether the animation was advanced.
bool internalAdvanceAnimation(bool skippingFrames);
// Helper for internalAdvanceAnimation().
void notifyObserverAndTrimDecodedData();
// Handle platform-specific data
void initPlatformData();
void invalidatePlatformData();
......@@ -197,7 +187,6 @@ protected:
Timer<BitmapImage>* m_frameTimer;
int m_repetitionCount; // How many total animation loops we should do.
int m_repetitionsComplete; // How many repetitions we've finished.
double m_desiredFrameStartTime; // The system time at which we hope to see the next call to startAnimation().
#if PLATFORM(MAC)
mutable RetainPtr<NSImage> m_nsImage; // A cached NSImage of frame 0. Only built lazily if someone actually queries for one.
......
......@@ -82,15 +82,13 @@ BitmapImage::BitmapImage(cairo_surface_t* surface, ImageObserver* observer)
void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const FloatRect& src, CompositeOperator op)
{
startAnimation();
FloatRect srcRect(src);
FloatRect dstRect(dst);
cairo_surface_t* image = frameAtIndex(m_currentFrame);
if (!image) // If it's too early we won't have an image yet.
return;
FloatRect srcRect(src);
FloatRect dstRect(dst);
if (mayFillWithSolidColor()) {
fillWithSolidColor(context, dstRect, solidColor(), op);
return;
......@@ -133,6 +131,8 @@ void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const Flo
cairo_restore(cr);
startAnimation();
if (imageObserver())
imageObserver()->didDraw(this);
}
......
......@@ -129,8 +129,6 @@ CGImageRef BitmapImage::getCGImageRef()
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOp)
{
startAnimation();
CGImageRef image = frameAtIndex(m_currentFrame);
if (!image) // If it's too early we won't have an image yet.
return;
......@@ -195,6 +193,8 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& destRect, const F
ctxt->restore();
startAnimation();
if (imageObserver())
imageObserver()->didDraw(this);
}
......
......@@ -108,8 +108,6 @@ void BitmapImage::invalidatePlatformData()
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
const FloatRect& src, CompositeOperator op)
{
startAnimation();
QPixmap* image = nativeImageForCurrentFrame();
if (!image)
return;
......@@ -133,6 +131,8 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
painter->drawPixmap(dst, *image, src);
ctxt->restore();
startAnimation();
}
void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
......
......@@ -98,8 +98,6 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst, const FloatR
wxWindowDC* context = ctxt->platformContext();
#endif
startAnimation();
wxBitmap* bitmap = frameAtIndex(m_currentFrame);
if (!bitmap) // If it's too early we won't have an image yet.
return;
......@@ -143,6 +141,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst, const FloatR
bitmap = NULL;
}
ctxt->restore();
startAnimation();
}
void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, CompositeOperator, const FloatRect& dstRect)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment