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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 frames_.Grow(num_frames); | 147 frames_.Grow(num_frames); |
148 | 148 |
149 // We are caching frame snapshots. This is OK even for partially decoded | 149 // We are caching frame snapshots. This is OK even for partially decoded |
150 // frames, as they are cleared by dataChanged() when new data arrives. | 150 // frames, as they are cleared by dataChanged() when new data arrives. |
151 sk_sp<SkImage> image = source_.CreateFrameAtIndex(index); | 151 sk_sp<SkImage> image = source_.CreateFrameAtIndex(index); |
152 cached_frame_ = image; | 152 cached_frame_ = image; |
153 cached_frame_index_ = index; | 153 cached_frame_index_ = index; |
154 | 154 |
155 frames_[index].orientation_ = source_.OrientationAtIndex(index); | 155 frames_[index].orientation_ = source_.OrientationAtIndex(index); |
156 frames_[index].have_metadata_ = true; | 156 frames_[index].have_metadata_ = true; |
157 frames_[index].is_complete_ = source_.FrameIsCompleteAtIndex(index); | 157 frames_[index].is_complete_ = source_.FrameIsReceivedAtIndex(index); |
158 if (RepetitionCount(false) != kAnimationNone) | 158 if (RepetitionCount(false) != kAnimationNone) |
159 frames_[index].duration_ = source_.FrameDurationAtIndex(index); | 159 frames_[index].duration_ = source_.FrameDurationAtIndex(index); |
160 frames_[index].has_alpha_ = source_.FrameHasAlphaAtIndex(index); | 160 frames_[index].has_alpha_ = source_.FrameHasAlphaAtIndex(index); |
161 frames_[index].frame_bytes_ = source_.FrameBytesAtIndex(index); | 161 frames_[index].frame_bytes_ = source_.FrameBytesAtIndex(index); |
162 | 162 |
163 NotifyMemoryChanged(); | 163 NotifyMemoryChanged(); |
164 return image; | 164 return image; |
165 } | 165 } |
166 | 166 |
167 void BitmapImage::UpdateSize() const { | 167 void BitmapImage::UpdateSize() const { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 sk_sp<SkImage> BitmapImage::FrameAtIndex(size_t index) { | 342 sk_sp<SkImage> BitmapImage::FrameAtIndex(size_t index) { |
343 if (index >= FrameCount()) | 343 if (index >= FrameCount()) |
344 return nullptr; | 344 return nullptr; |
345 | 345 |
346 if (index == cached_frame_index_ && cached_frame_) | 346 if (index == cached_frame_index_ && cached_frame_) |
347 return cached_frame_; | 347 return cached_frame_; |
348 | 348 |
349 return DecodeAndCacheFrame(index); | 349 return DecodeAndCacheFrame(index); |
350 } | 350 } |
351 | 351 |
352 bool BitmapImage::FrameIsCompleteAtIndex(size_t index) const { | 352 bool BitmapImage::FrameIsReceivedAtIndex(size_t index) const { |
353 if (index < frames_.size() && frames_[index].have_metadata_ && | 353 if (index < frames_.size() && frames_[index].have_metadata_ && |
354 frames_[index].is_complete_) | 354 frames_[index].is_complete_) |
355 return true; | 355 return true; |
356 | 356 |
357 return source_.FrameIsCompleteAtIndex(index); | 357 return source_.FrameIsReceivedAtIndex(index); |
358 } | 358 } |
359 | 359 |
360 float BitmapImage::FrameDurationAtIndex(size_t index) const { | 360 float BitmapImage::FrameDurationAtIndex(size_t index) const { |
361 if (index < frames_.size() && frames_[index].have_metadata_) | 361 if (index < frames_.size() && frames_[index].have_metadata_) |
362 return frames_[index].duration_; | 362 return frames_[index].duration_; |
363 | 363 |
364 return source_.FrameDurationAtIndex(index); | 364 return source_.FrameDurationAtIndex(index); |
365 } | 365 } |
366 | 366 |
367 sk_sp<SkImage> BitmapImage::ImageForCurrentFrame() { | 367 sk_sp<SkImage> BitmapImage::ImageForCurrentFrame() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 if (metadata_mode == kPreCacheMetadata) { | 399 if (metadata_mode == kPreCacheMetadata) { |
400 // frameHasAlphaAtIndex() conservatively returns false for uncached frames. | 400 // frameHasAlphaAtIndex() conservatively returns false for uncached frames. |
401 // To increase the chance of an accurate answer, pre-cache the current frame | 401 // To increase the chance of an accurate answer, pre-cache the current frame |
402 // metadata. | 402 // metadata. |
403 FrameAtIndex(CurrentFrame()); | 403 FrameAtIndex(CurrentFrame()); |
404 } | 404 } |
405 return !FrameHasAlphaAtIndex(CurrentFrame()); | 405 return !FrameHasAlphaAtIndex(CurrentFrame()); |
406 } | 406 } |
407 | 407 |
408 bool BitmapImage::CurrentFrameIsComplete() { | 408 bool BitmapImage::CurrentFrameIsComplete() { |
409 return FrameIsCompleteAtIndex(CurrentFrame()); | 409 return FrameIsReceivedAtIndex(CurrentFrame()); |
410 } | 410 } |
411 | 411 |
412 bool BitmapImage::CurrentFrameIsLazyDecoded() { | 412 bool BitmapImage::CurrentFrameIsLazyDecoded() { |
413 sk_sp<SkImage> image = FrameAtIndex(CurrentFrame()); | 413 sk_sp<SkImage> image = FrameAtIndex(CurrentFrame()); |
414 return image && image->isLazyGenerated(); | 414 return image && image->isLazyGenerated(); |
415 } | 415 } |
416 | 416 |
417 ImageOrientation BitmapImage::CurrentFrameOrientation() { | 417 ImageOrientation BitmapImage::CurrentFrameOrientation() { |
418 return FrameOrientationAtIndex(CurrentFrame()); | 418 return FrameOrientationAtIndex(CurrentFrame()); |
419 } | 419 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 if (frame_timer_ || !ShouldAnimate() || FrameCount() <= 1) | 457 if (frame_timer_ || !ShouldAnimate() || FrameCount() <= 1) |
458 return; | 458 return; |
459 | 459 |
460 // If we aren't already animating, set now as the animation start time. | 460 // If we aren't already animating, set now as the animation start time. |
461 const double time = MonotonicallyIncreasingTime(); | 461 const double time = MonotonicallyIncreasingTime(); |
462 if (!desired_frame_start_time_) | 462 if (!desired_frame_start_time_) |
463 desired_frame_start_time_ = time; | 463 desired_frame_start_time_ = time; |
464 | 464 |
465 // Don't advance the animation to an incomplete frame. | 465 // Don't advance the animation to an incomplete frame. |
466 size_t next_frame = (current_frame_ + 1) % FrameCount(); | 466 size_t next_frame = (current_frame_ + 1) % FrameCount(); |
467 if (!all_data_received_ && !FrameIsCompleteAtIndex(next_frame)) | 467 if (!all_data_received_ && !FrameIsReceivedAtIndex(next_frame)) |
468 return; | 468 return; |
469 | 469 |
470 // Don't advance past the last frame if we haven't decoded the whole image | 470 // Don't advance past the last frame if we haven't decoded the whole image |
471 // yet and our repetition count is potentially unset. The repetition count | 471 // yet and our repetition count is potentially unset. The repetition count |
472 // in a GIF can potentially come after all the rest of the image data, so | 472 // in a GIF can potentially come after all the rest of the image data, so |
473 // wait on it. | 473 // wait on it. |
474 if (!all_data_received_ && | 474 if (!all_data_received_ && |
475 (RepetitionCount(false) == kAnimationLoopOnce || | 475 (RepetitionCount(false) == kAnimationLoopOnce || |
476 animation_policy_ == kImageAnimationPolicyAnimateOnce) && | 476 animation_policy_ == kImageAnimationPolicyAnimateOnce) && |
477 current_frame_ >= (FrameCount() - 1)) | 477 current_frame_ >= (FrameCount() - 1)) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>( | 510 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>( |
511 task_runner_, this, &BitmapImage::AdvanceAnimation)); | 511 task_runner_, this, &BitmapImage::AdvanceAnimation)); |
512 frame_timer_->StartOneShot(std::max(desired_frame_start_time_ - time, 0.), | 512 frame_timer_->StartOneShot(std::max(desired_frame_start_time_ - time, 0.), |
513 BLINK_FROM_HERE); | 513 BLINK_FROM_HERE); |
514 } else { | 514 } else { |
515 // We've already reached or passed the time for the next frame to start. | 515 // We've already reached or passed the time for the next frame to start. |
516 // See if we've also passed the time for frames after that to start, in | 516 // See if we've also passed the time for frames after that to start, in |
517 // case we need to skip some frames entirely. Remember not to advance | 517 // case we need to skip some frames entirely. Remember not to advance |
518 // to an incomplete frame. | 518 // to an incomplete frame. |
519 for (size_t frame_after_next = (next_frame + 1) % FrameCount(); | 519 for (size_t frame_after_next = (next_frame + 1) % FrameCount(); |
520 FrameIsCompleteAtIndex(frame_after_next); | 520 FrameIsReceivedAtIndex(frame_after_next); |
521 frame_after_next = (next_frame + 1) % FrameCount()) { | 521 frame_after_next = (next_frame + 1) % FrameCount()) { |
522 // Should we skip the next frame? | 522 // Should we skip the next frame? |
523 double frame_after_next_start_time = | 523 double frame_after_next_start_time = |
524 desired_frame_start_time_ + FrameDurationAtIndex(next_frame); | 524 desired_frame_start_time_ + FrameDurationAtIndex(next_frame); |
525 if (time < frame_after_next_start_time) | 525 if (time < frame_after_next_start_time) |
526 break; | 526 break; |
527 | 527 |
528 // Skip the next frame by advancing the animation forward one frame. | 528 // Skip the next frame by advancing the animation forward one frame. |
529 if (!InternalAdvanceAnimation(kSkipFramesToCatchUp)) { | 529 if (!InternalAdvanceAnimation(kSkipFramesToCatchUp)) { |
530 DCHECK(animation_finished_); | 530 DCHECK(animation_finished_); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 | 643 |
644 return true; | 644 return true; |
645 } | 645 } |
646 | 646 |
647 void BitmapImage::NotifyObserversOfAnimationAdvance(TimerBase*) { | 647 void BitmapImage::NotifyObserversOfAnimationAdvance(TimerBase*) { |
648 if (GetImageObserver()) | 648 if (GetImageObserver()) |
649 GetImageObserver()->AnimationAdvanced(this); | 649 GetImageObserver()->AnimationAdvanced(this); |
650 } | 650 } |
651 | 651 |
652 } // namespace blink | 652 } // namespace blink |
OLD | NEW |