| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 for (size_t i = 0; i < numFrames; ++i) | 128 for (size_t i = 0; i < numFrames; ++i) |
| 129 totalBytes += m_source.frameBytesAtIndex(i); | 129 totalBytes += m_source.frameBytesAtIndex(i); |
| 130 return totalBytes; | 130 return totalBytes; |
| 131 } | 131 } |
| 132 | 132 |
| 133 sk_sp<SkImage> BitmapImage::decodeAndCacheFrame(size_t index) { | 133 sk_sp<SkImage> BitmapImage::decodeAndCacheFrame(size_t index) { |
| 134 size_t numFrames = frameCount(); | 134 size_t numFrames = frameCount(); |
| 135 if (m_frames.size() < numFrames) | 135 if (m_frames.size() < numFrames) |
| 136 m_frames.grow(numFrames); | 136 m_frames.grow(numFrames); |
| 137 | 137 |
| 138 // We are caching frame snapshots. This is OK even for partially decoded fram
es, | 138 // We are caching frame snapshots. This is OK even for partially decoded |
| 139 // as they are cleared by dataChanged() when new data arrives. | 139 // frames, as they are cleared by dataChanged() when new data arrives. |
| 140 sk_sp<SkImage> image = m_source.createFrameAtIndex(index); | 140 sk_sp<SkImage> image = m_source.createFrameAtIndex(index); |
| 141 m_cachedFrame = image; | 141 m_cachedFrame = image; |
| 142 m_cachedFrameIndex = index; | 142 m_cachedFrameIndex = index; |
| 143 | 143 |
| 144 m_frames[index].m_orientation = m_source.orientationAtIndex(index); | 144 m_frames[index].m_orientation = m_source.orientationAtIndex(index); |
| 145 m_frames[index].m_haveMetadata = true; | 145 m_frames[index].m_haveMetadata = true; |
| 146 m_frames[index].m_isComplete = m_source.frameIsCompleteAtIndex(index); | 146 m_frames[index].m_isComplete = m_source.frameIsCompleteAtIndex(index); |
| 147 if (repetitionCount(false) != cAnimationNone) | 147 if (repetitionCount(false) != cAnimationNone) |
| 148 m_frames[index].m_duration = m_source.frameDurationAtIndex(index); | 148 m_frames[index].m_duration = m_source.frameDurationAtIndex(index); |
| 149 m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index); | 149 m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 canvas->save(); | 268 canvas->save(); |
| 269 | 269 |
| 270 // ImageOrientation expects the origin to be at (0, 0) | 270 // ImageOrientation expects the origin to be at (0, 0) |
| 271 canvas->translate(adjustedDstRect.x(), adjustedDstRect.y()); | 271 canvas->translate(adjustedDstRect.x(), adjustedDstRect.y()); |
| 272 adjustedDstRect.setLocation(FloatPoint()); | 272 adjustedDstRect.setLocation(FloatPoint()); |
| 273 | 273 |
| 274 canvas->concat(affineTransformToSkMatrix( | 274 canvas->concat(affineTransformToSkMatrix( |
| 275 orientation.transformFromDefault(adjustedDstRect.size()))); | 275 orientation.transformFromDefault(adjustedDstRect.size()))); |
| 276 | 276 |
| 277 if (orientation.usesWidthAsHeight()) { | 277 if (orientation.usesWidthAsHeight()) { |
| 278 // The destination rect will have it's width and height already reversed f
or the orientation of | 278 // The destination rect will have its width and height already reversed |
| 279 // the image, as it was needed for page layout, so we need to reverse it b
ack here. | 279 // for the orientation of the image, as it was needed for page layout, so |
| 280 // we need to reverse it back here. |
| 280 adjustedDstRect = | 281 adjustedDstRect = |
| 281 FloatRect(adjustedDstRect.x(), adjustedDstRect.y(), | 282 FloatRect(adjustedDstRect.x(), adjustedDstRect.y(), |
| 282 adjustedDstRect.height(), adjustedDstRect.width()); | 283 adjustedDstRect.height(), adjustedDstRect.width()); |
| 283 } | 284 } |
| 284 } | 285 } |
| 285 | 286 |
| 286 canvas->drawImageRect(image.get(), adjustedSrcRect, adjustedDstRect, &paint, | 287 canvas->drawImageRect(image.get(), adjustedSrcRect, adjustedDstRect, &paint, |
| 287 WebCoreClampingModeToSkiaRectConstraint(clampMode)); | 288 WebCoreClampingModeToSkiaRectConstraint(clampMode)); |
| 288 | 289 |
| 289 if (image->isLazyGenerated()) | 290 if (image->isLazyGenerated()) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 bool hasAlpha = m_source.frameHasAlphaAtIndex(index); | 378 bool hasAlpha = m_source.frameHasAlphaAtIndex(index); |
| 378 | 379 |
| 379 if (m_frames[index].m_haveMetadata) | 380 if (m_frames[index].m_haveMetadata) |
| 380 m_frames[index].m_hasAlpha = hasAlpha; | 381 m_frames[index].m_hasAlpha = hasAlpha; |
| 381 | 382 |
| 382 return hasAlpha; | 383 return hasAlpha; |
| 383 } | 384 } |
| 384 | 385 |
| 385 bool BitmapImage::currentFrameKnownToBeOpaque(MetadataMode metadataMode) { | 386 bool BitmapImage::currentFrameKnownToBeOpaque(MetadataMode metadataMode) { |
| 386 if (metadataMode == PreCacheMetadata) { | 387 if (metadataMode == PreCacheMetadata) { |
| 387 // frameHasAlphaAtIndex() conservatively returns false for uncached frames.
To increase the | 388 // frameHasAlphaAtIndex() conservatively returns false for uncached frames. |
| 388 // chance of an accurate answer, pre-cache the current frame metadata. | 389 // To increase the chance of an accurate answer, pre-cache the current frame |
| 390 // metadata. |
| 389 frameAtIndex(currentFrame()); | 391 frameAtIndex(currentFrame()); |
| 390 } | 392 } |
| 391 return !frameHasAlphaAtIndex(currentFrame()); | 393 return !frameHasAlphaAtIndex(currentFrame()); |
| 392 } | 394 } |
| 393 | 395 |
| 394 bool BitmapImage::currentFrameIsComplete() { | 396 bool BitmapImage::currentFrameIsComplete() { |
| 395 return frameIsCompleteAtIndex(currentFrame()); | 397 return frameIsCompleteAtIndex(currentFrame()); |
| 396 } | 398 } |
| 397 | 399 |
| 398 bool BitmapImage::currentFrameIsLazyDecoded() { | 400 bool BitmapImage::currentFrameIsLazyDecoded() { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // may be in the past, meaning the next time through this function we'll | 524 // may be in the past, meaning the next time through this function we'll |
| 523 // kick off the next advancement sooner than this frame's duration would | 525 // kick off the next advancement sooner than this frame's duration would |
| 524 // suggest. | 526 // suggest. |
| 525 m_frameTimer = wrapUnique(new Timer<BitmapImage>( | 527 m_frameTimer = wrapUnique(new Timer<BitmapImage>( |
| 526 this, &BitmapImage::advanceAnimationWithoutCatchUp)); | 528 this, &BitmapImage::advanceAnimationWithoutCatchUp)); |
| 527 m_frameTimer->startOneShot(0, BLINK_FROM_HERE); | 529 m_frameTimer->startOneShot(0, BLINK_FROM_HERE); |
| 528 } | 530 } |
| 529 } | 531 } |
| 530 | 532 |
| 531 void BitmapImage::stopAnimation() { | 533 void BitmapImage::stopAnimation() { |
| 532 // This timer is used to animate all occurrences of this image. Don't invalid
ate | 534 // This timer is used to animate all occurrences of this image. Don't |
| 533 // the timer unless all renderers have stopped drawing. | 535 // invalidate the timer unless all renderers have stopped drawing. |
| 534 m_frameTimer.reset(); | 536 m_frameTimer.reset(); |
| 535 } | 537 } |
| 536 | 538 |
| 537 void BitmapImage::resetAnimation() { | 539 void BitmapImage::resetAnimation() { |
| 538 stopAnimation(); | 540 stopAnimation(); |
| 539 m_currentFrame = 0; | 541 m_currentFrame = 0; |
| 540 m_repetitionsComplete = 0; | 542 m_repetitionsComplete = 0; |
| 541 m_desiredFrameStartTime = 0; | 543 m_desiredFrameStartTime = 0; |
| 542 m_animationFinished = false; | 544 m_animationFinished = false; |
| 543 m_cachedFrame.reset(); | 545 m_cachedFrame.reset(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 569 | 571 |
| 570 void BitmapImage::advanceAnimationWithoutCatchUp(TimerBase*) { | 572 void BitmapImage::advanceAnimationWithoutCatchUp(TimerBase*) { |
| 571 if (internalAdvanceAnimation()) | 573 if (internalAdvanceAnimation()) |
| 572 startAnimation(DoNotCatchUp); | 574 startAnimation(DoNotCatchUp); |
| 573 } | 575 } |
| 574 | 576 |
| 575 bool BitmapImage::internalAdvanceAnimation(AnimationAdvancement advancement) { | 577 bool BitmapImage::internalAdvanceAnimation(AnimationAdvancement advancement) { |
| 576 // Stop the animation. | 578 // Stop the animation. |
| 577 stopAnimation(); | 579 stopAnimation(); |
| 578 | 580 |
| 579 // See if anyone is still paying attention to this animation. If not, we don'
t | 581 // See if anyone is still paying attention to this animation. If not, we |
| 580 // advance and will remain suspended at the current frame until the animation
is resumed. | 582 // don't advance, and will remain suspended at the current frame until the |
| 583 // animation is resumed. |
| 581 if (advancement != SkipFramesToCatchUp && | 584 if (advancement != SkipFramesToCatchUp && |
| 582 getImageObserver()->shouldPauseAnimation(this)) | 585 getImageObserver()->shouldPauseAnimation(this)) |
| 583 return false; | 586 return false; |
| 584 | 587 |
| 585 if (m_currentFrame + 1 < frameCount()) { | 588 if (m_currentFrame + 1 < frameCount()) { |
| 586 m_currentFrame++; | 589 m_currentFrame++; |
| 587 } else { | 590 } else { |
| 588 m_repetitionsComplete++; | 591 m_repetitionsComplete++; |
| 589 | 592 |
| 590 // Get the repetition count again. If we weren't able to get a | 593 // Get the repetition count again. If we weren't able to get a |
| (...skipping 30 matching lines...) Expand all Loading... |
| 621 getImageObserver()->animationAdvanced(this); | 624 getImageObserver()->animationAdvanced(this); |
| 622 | 625 |
| 623 return true; | 626 return true; |
| 624 } | 627 } |
| 625 | 628 |
| 626 void BitmapImage::notifyObserversOfAnimationAdvance(TimerBase*) { | 629 void BitmapImage::notifyObserversOfAnimationAdvance(TimerBase*) { |
| 627 getImageObserver()->animationAdvanced(this); | 630 getImageObserver()->animationAdvanced(this); |
| 628 } | 631 } |
| 629 | 632 |
| 630 } // namespace blink | 633 } // namespace blink |
| OLD | NEW |