WebCore/ChangeLog

 12008-09-19 Peter Kasting <pkasting@google.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4 https://bugs.webkit.org/show_bug.cgi?id=20945
 5 Some non-animating images were considered to be animating ones because
 6 shouldAnimate() was checked before m_repetitionCount was set.
 7
 8 * platform/graphics/BitmapImage.cpp:
 9 (WebCore::BitmapImage::BitmapImage):
 10 (WebCore::BitmapImage::cacheFrame):
 11 (WebCore::BitmapImage::repetitionCount):
 12 (WebCore::BitmapImage::shouldAnimate):
 13 (WebCore::BitmapImage::startAnimation):
 14 (WebCore::BitmapImage::internalAdvanceAnimation):
 15 * platform/graphics/BitmapImage.h:
 16 (WebCore::BitmapImage::):
 17 * platform/graphics/cairo/ImageCairo.cpp:
 18 (WebCore::BitmapImage::BitmapImage):
 19 * platform/graphics/cg/ImageCG.cpp:
 20 (WebCore::BitmapImage::BitmapImage):
 21
1222008-09-19 Chris Fleizach <cfleizach@apple.com>
223
324 Removed unnecessary #if
36677

WebCore/platform/graphics/BitmapImage.cpp

@@BitmapImage::BitmapImage(ImageObserver*
5252 , m_currentFrame(0)
5353 , m_frames(0)
5454 , m_frameTimer(0)
55  , m_repetitionCount(0)
 55 , m_repetitionCount(cAnimationNone)
 56 , m_repetitionCountStatus(Unknown)
5657 , m_repetitionsComplete(0)
5758 , m_desiredFrameStartTime(0)
5859 , m_isSolidColor(false)
59  , m_animatingImageType(true)
6060 , m_animationFinished(false)
6161 , m_allDataReceived(false)
6262 , m_haveSize(false)

@@void BitmapImage::cacheFrame(size_t inde
113113 size_t numFrames = frameCount();
114114 ASSERT(m_decodedSize == 0 || numFrames > 1);
115115
116  if (!m_frames.size() && shouldAnimate()) {
117  // Snag the repetition count. Note that the repetition count may not be
118  // accurate yet for GIFs; if we haven't gotten the count from the source
119  // image yet, it will default to cAnimationLoopOnce, and we'll try and
120  // read it again once the whole image is decoded.
121  m_repetitionCount = m_source.repetitionCount();
122  if (m_repetitionCount == cAnimationNone)
123  m_animatingImageType = false;
124  }
125 
126116 if (m_frames.size() < numFrames)
127117 m_frames.grow(numFrames);
128118

@@bool BitmapImage::frameHasAlphaAtIndex(s
248238 return m_frames[index].m_hasAlpha;
249239}
250240
 241int BitmapImage::repetitionCount(bool imageKnownToBeComplete)
 242{
 243 if ((m_repetitionCountStatus == Unknown) || ((m_repetitionCountStatus == Uncertain) && imageKnownToBeComplete)) {
 244 // Snag the repetition count. If |imageKnownToBeComplete| is false, the
 245 // repetition count may not be accurate yet for GIFs; in this case the
 246 // decoder will default to cAnimationLoopOnce, and we'll try and read
 247 // the count again once the whole image is decoded.
 248 m_repetitionCount = m_source.repetitionCount();
 249 m_repetitionCountStatus = (imageKnownToBeComplete || m_repetitionCount == cAnimationNone) ? Certain : Uncertain;
 250 }
 251 return m_repetitionCount;
 252}
 253
251254bool BitmapImage::shouldAnimate()
252255{
253  return (m_animatingImageType && !m_animationFinished && imageObserver());
 256 return (repetitionCount(false) != cAnimationNone && !m_animationFinished && imageObserver());
254257}
255258
256259void BitmapImage::startAnimation()

@@void BitmapImage::startAnimation()
266269 // yet and our repetition count is potentially unset. The repetition count
267270 // in a GIF can potentially come after all the rest of the image data, so
268271 // wait on it.
269  if (!m_allDataReceived && m_repetitionCount == cAnimationLoopOnce && m_currentFrame >= (frameCount() - 1))
 272 if (!m_allDataReceived && repetitionCount(false) == cAnimationLoopOnce && m_currentFrame >= (frameCount() - 1))
270273 return;
271274
272275 // Determine time for next frame to start. By ignoring paint and timer lag

@@bool BitmapImage::internalAdvanceAnimati
353356
354357 m_currentFrame++;
355358 if (m_currentFrame >= frameCount()) {
356  m_repetitionsComplete += 1;
 359 ++m_repetitionsComplete;
357360 // Get the repetition count again. If we weren't able to get a
358361 // repetition count before, we should have decoded the whole image by
359362 // now, so it should now be available.
360  m_repetitionCount = m_source.repetitionCount();
361  if (m_repetitionCount && m_repetitionsComplete >= m_repetitionCount) {
 363 if (repetitionCount(true) && m_repetitionsComplete >= m_repetitionCount) {
362364 m_animationFinished = true;
363365 m_desiredFrameStartTime = 0;
364366 m_currentFrame--;
36669

WebCore/platform/graphics/BitmapImage.h

@@public:
138138 virtual NativeImagePtr nativeImageForCurrentFrame() { return frameAtIndex(currentFrame()); }
139139
140140protected:
 141 enum RepetitionCountStatus {
 142 Unknown, // We haven't checked the source's repetition count.
 143 Uncertain, // We have a repetition count, but it might be wrong (some GIFs have a count after the image data, and will report "loop once" until all data has been decoded).
 144 Certain, // The repetition count is known to be correct.
 145 };
 146
141147 BitmapImage(NativeImagePtr, ImageObserver* = 0);
142148 BitmapImage(ImageObserver* = 0);
143149

@@protected:
167173 bool isSizeAvailable();
168174
169175 // Animation.
 176 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplete| should be set if the caller knows the entire image has been decoded.
170177 bool shouldAnimate();
171178 virtual void startAnimation();
172179 void advanceAnimation(Timer<BitmapImage>*);

@@protected:
198205 Vector<FrameData> m_frames; // An array of the cached frames of the animation. We have to ref frames to pin them in the cache.
199206
200207 Timer<BitmapImage>* m_frameTimer;
201  int m_repetitionCount; // How many total animation loops we should do.
 208 int m_repetitionCount; // How many total animation loops we should do. This will be cAnimationNone if this image type is incapable of animation.
 209 RepetitionCountStatus m_repetitionCountStatus;
202210 int m_repetitionsComplete; // How many repetitions we've finished.
203211 double m_desiredFrameStartTime; // The system time at which we hope to see the next call to startAnimation().
204212

@@protected:
210218 Color m_solidColor; // If we're a 1x1 solid color, this is the color to use to fill.
211219 bool m_isSolidColor; // Whether or not we are a 1x1 solid image.
212220
213  bool m_animatingImageType; // Whether or not we're an image type that is capable of animating (GIF).
214221 bool m_animationFinished; // Whether or not we've completed the entire animation.
215222
216223 bool m_allDataReceived; // Whether or not we've received all our data.
36669

WebCore/platform/graphics/cairo/ImageCairo.cpp

@@BitmapImage::BitmapImage(cairo_surface_t
5454 , m_currentFrame(0)
5555 , m_frames(0)
5656 , m_frameTimer(0)
57  , m_repetitionCount(0)
 57 , m_repetitionCount(cAnimationNone)
 58 , m_repetitionCountStatus(Unknown)
5859 , m_repetitionsComplete(0)
5960 , m_isSolidColor(false)
6061 , m_animatingImageType(false)
36669

WebCore/platform/graphics/cg/ImageCG.cpp

@@BitmapImage::BitmapImage(CGImageRef cgIm
6767 , m_currentFrame(0)
6868 , m_frames(0)
6969 , m_frameTimer(0)
70  , m_repetitionCount(0)
 70 , m_repetitionCount(cAnimationNone)
 71 , m_repetitionCountStatus(Unknown)
7172 , m_repetitionsComplete(0)
7273 , m_isSolidColor(false)
73  , m_animatingImageType(false)
7474 , m_animationFinished(true)
7575 , m_allDataReceived(true)
7676 , m_haveSize(true)
36669