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 && getImageObserver()->shouldPauseAnimation(this)) return false; ++m_currentFrame; bool advancedAnimation = true; if (m_currentFrame >= frameCount()) { ++m_repetitionsComplete; // Get the repetition count again. If we weren't able to get a // repetition count before, we should have decoded the whole image by // now, so it should now be available. // Note that we don't need to special-case cAnimationLoopOnce here // because it is 0 (see comments on its declaration in ImageAnimation.h). if ((repetitionCount(true) != cAnimationLoopInfinite && m_repetitionsComplete > m_repetitionCount) || (m_animationPolicy == ImageAnimationPolicyAnimateOnce && m_repetitionsComplete > 0)) { m_animationFinished = true; m_desiredFrameStartTime = 0; --m_currentFrame; advancedAnimation = false; } else m_currentFrame = 0; } destroyDecodedDataIfNecessary(); // We need to draw this frame if we advanced to it while not skipping, or if // while trying to skip frames we hit the last frame and thus had to stop. if (skippingFrames != advancedAnimation) getImageObserver()->animationAdvanced(this); return advancedAnimation; }
void BitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum shouldRespectImageOrientation, ImageClampingMode clampMode) { TRACE_EVENT0("skia", "BitmapImage::draw"); RefPtr<SkImage> image = imageForCurrentFrame(); if (!image) return; // It's too early and we don't have an image yet. FloatRect adjustedSrcRect = srcRect; adjustedSrcRect.intersect(FloatRect(0, 0, image->width(), image->height())); if (adjustedSrcRect.isEmpty() || dstRect.isEmpty()) return; // Nothing to draw. ImageOrientation orientation = DefaultImageOrientation; if (shouldRespectImageOrientation == RespectImageOrientation) orientation = frameOrientationAtIndex(m_currentFrame); int initialSaveCount = canvas->getSaveCount(); FloatRect adjustedDstRect = dstRect; if (orientation != DefaultImageOrientation) { canvas->save(); // ImageOrientation expects the origin to be at (0, 0) canvas->translate(adjustedDstRect.x(), adjustedDstRect.y()); adjustedDstRect.setLocation(FloatPoint()); canvas->concat(affineTransformToSkMatrix(orientation.transformFromDefault(adjustedDstRect.size()))); if (orientation.usesWidthAsHeight()) { // The destination rect will have it's width and height already reversed for the orientation of // the image, as it was needed for page layout, so we need to reverse it back here. adjustedDstRect = FloatRect(adjustedDstRect.x(), adjustedDstRect.y(), adjustedDstRect.height(), adjustedDstRect.width()); } } SkRect skSrcRect = adjustedSrcRect; canvas->drawImageRect(image.get(), skSrcRect, adjustedDstRect, &paint, WebCoreClampingModeToSkiaRectConstraint(clampMode)); canvas->restoreToCount(initialSaveCount); if (currentFrameIsLazyDecoded()) PlatformInstrumentation::didDrawLazyPixelRef(image->uniqueID()); if (ImageObserver* observer = getImageObserver()) observer->didDraw(this); startAnimation(); }
void StaticBitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum, ImageClampingMode clampMode) { FloatRect adjustedSrcRect = srcRect; adjustedSrcRect.intersect(SkRect::Make(m_image->bounds())); if (dstRect.isEmpty() || adjustedSrcRect.isEmpty()) return; // Nothing to draw. canvas->drawImageRect(m_image.get(), adjustedSrcRect, dstRect, &paint, WebCoreClampingModeToSkiaRectConstraint(clampMode)); if (ImageObserver* observer = getImageObserver()) observer->didDraw(this); }
void StaticBitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum, ImageClampingMode clampMode) { ASSERT(dstRect.width() >= 0 && dstRect.height() >= 0); ASSERT(srcRect.width() >= 0 && srcRect.height() >= 0); FloatRect adjustedSrcRect = srcRect; adjustedSrcRect.intersect(FloatRect(0, 0, m_image->width(), m_image->height())); if (adjustedSrcRect.isEmpty() || dstRect.isEmpty()) return; // Nothing to draw. ASSERT(adjustedSrcRect.width() <= m_image->width() && adjustedSrcRect.height() <= m_image->height()); SkRect srcSkRect = adjustedSrcRect; canvas->drawImageRect(m_image.get(), srcSkRect, dstRect, &paint, WebCoreClampingModeToSkiaRectConstraint(clampMode)); if (ImageObserver* observer = getImageObserver()) observer->didDraw(this); }
bool BitmapImage::shouldAnimate() { bool animated = repetitionCount(false) != cAnimationNone && !m_animationFinished && getImageObserver(); if (animated && m_animationPolicy == ImageAnimationPolicyNoAnimation) animated = false; return animated; }
void BitmapImage::notifyMemoryChanged(int delta) { if (delta && getImageObserver()) getImageObserver()->decodedSizeChanged(this, delta); }