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 21 matching lines...) Expand all Loading... |
32 #include "platform/graphics/BitmapImageMetrics.h" | 32 #include "platform/graphics/BitmapImageMetrics.h" |
33 #include "platform/graphics/DeferredImageDecoder.h" | 33 #include "platform/graphics/DeferredImageDecoder.h" |
34 #include "platform/graphics/ImageObserver.h" | 34 #include "platform/graphics/ImageObserver.h" |
35 #include "platform/graphics/StaticBitmapImage.h" | 35 #include "platform/graphics/StaticBitmapImage.h" |
36 #include "platform/graphics/paint/PaintCanvas.h" | 36 #include "platform/graphics/paint/PaintCanvas.h" |
37 #include "platform/graphics/paint/PaintFlags.h" | 37 #include "platform/graphics/paint/PaintFlags.h" |
38 #include "platform/graphics/paint/PaintImage.h" | 38 #include "platform/graphics/paint/PaintImage.h" |
39 #include "platform/graphics/skia/SkiaUtils.h" | 39 #include "platform/graphics/skia/SkiaUtils.h" |
40 #include "platform/instrumentation/PlatformInstrumentation.h" | 40 #include "platform/instrumentation/PlatformInstrumentation.h" |
41 #include "platform/instrumentation/tracing/TraceEvent.h" | 41 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 42 #include "platform/scheduler/child/web_scheduler.h" |
42 #include "platform/wtf/PassRefPtr.h" | 43 #include "platform/wtf/PassRefPtr.h" |
43 #include "platform/wtf/PtrUtil.h" | 44 #include "platform/wtf/PtrUtil.h" |
44 #include "platform/wtf/text/WTFString.h" | 45 #include "platform/wtf/text/WTFString.h" |
45 | 46 |
46 namespace blink { | 47 namespace blink { |
47 | 48 |
48 namespace { | 49 namespace { |
49 | 50 |
50 ColorBehavior DefaultColorBehavior() { | 51 ColorBehavior DefaultColorBehavior() { |
51 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) | 52 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) |
(...skipping 24 matching lines...) Expand all Loading... |
76 animation_policy_(kImageAnimationPolicyAllowed), | 77 animation_policy_(kImageAnimationPolicyAllowed), |
77 animation_finished_(false), | 78 animation_finished_(false), |
78 all_data_received_(false), | 79 all_data_received_(false), |
79 have_size_(false), | 80 have_size_(false), |
80 size_available_(false), | 81 size_available_(false), |
81 have_frame_count_(false), | 82 have_frame_count_(false), |
82 repetition_count_status_(kUnknown), | 83 repetition_count_status_(kUnknown), |
83 repetition_count_(kCAnimationNone), | 84 repetition_count_(kCAnimationNone), |
84 repetitions_complete_(0), | 85 repetitions_complete_(0), |
85 desired_frame_start_time_(0), | 86 desired_frame_start_time_(0), |
86 frame_count_(0) {} | 87 frame_count_(0), |
| 88 task_runner_(Platform::Current() |
| 89 ->CurrentThread() |
| 90 ->Scheduler() |
| 91 ->CompositorTaskRunner()) {} |
87 | 92 |
88 BitmapImage::BitmapImage(const SkBitmap& bitmap, ImageObserver* observer) | 93 BitmapImage::BitmapImage(const SkBitmap& bitmap, ImageObserver* observer) |
89 : Image(observer), | 94 : Image(observer), |
90 size_(bitmap.width(), bitmap.height()), | 95 size_(bitmap.width(), bitmap.height()), |
91 current_frame_(0), | 96 current_frame_(0), |
92 cached_frame_(SkImage::MakeFromBitmap(bitmap)), | 97 cached_frame_(SkImage::MakeFromBitmap(bitmap)), |
93 cached_frame_index_(0), | 98 cached_frame_index_(0), |
94 animation_policy_(kImageAnimationPolicyAllowed), | 99 animation_policy_(kImageAnimationPolicyAllowed), |
95 animation_finished_(true), | 100 animation_finished_(true), |
96 all_data_received_(true), | 101 all_data_received_(true), |
97 have_size_(true), | 102 have_size_(true), |
98 size_available_(true), | 103 size_available_(true), |
99 have_frame_count_(true), | 104 have_frame_count_(true), |
100 repetition_count_status_(kUnknown), | 105 repetition_count_status_(kUnknown), |
101 repetition_count_(kCAnimationNone), | 106 repetition_count_(kCAnimationNone), |
102 repetitions_complete_(0), | 107 repetitions_complete_(0), |
103 frame_count_(1) { | 108 frame_count_(1), |
| 109 task_runner_(Platform::Current() |
| 110 ->CurrentThread() |
| 111 ->Scheduler() |
| 112 ->CompositorTaskRunner()) { |
104 // Since we don't have a decoder, we can't figure out the image orientation. | 113 // Since we don't have a decoder, we can't figure out the image orientation. |
105 // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0. | 114 // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0. |
106 size_respecting_orientation_ = size_; | 115 size_respecting_orientation_ = size_; |
107 | 116 |
108 frames_.Grow(1); | 117 frames_.Grow(1); |
109 frames_[0].has_alpha_ = !bitmap.isOpaque(); | 118 frames_[0].has_alpha_ = !bitmap.isOpaque(); |
110 frames_[0].have_metadata_ = true; | 119 frames_[0].have_metadata_ = true; |
111 } | 120 } |
112 | 121 |
113 BitmapImage::~BitmapImage() { | 122 BitmapImage::~BitmapImage() { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 // sync an image and some other resource (e.g. audio), especially if users | 512 // sync an image and some other resource (e.g. audio), especially if users |
504 // switch tabs (and thus stop drawing the animation, which will pause it) | 513 // switch tabs (and thus stop drawing the animation, which will pause it) |
505 // during that initial loop, then switch back later. | 514 // during that initial loop, then switch back later. |
506 if (next_frame == 0 && repetitions_complete_ == 0 && | 515 if (next_frame == 0 && repetitions_complete_ == 0 && |
507 desired_frame_start_time_ < time) | 516 desired_frame_start_time_ < time) |
508 desired_frame_start_time_ = time; | 517 desired_frame_start_time_ = time; |
509 | 518 |
510 if (catch_up_if_necessary == kDoNotCatchUp || | 519 if (catch_up_if_necessary == kDoNotCatchUp || |
511 time < desired_frame_start_time_) { | 520 time < desired_frame_start_time_) { |
512 // Haven't yet reached time for next frame to start; delay until then. | 521 // Haven't yet reached time for next frame to start; delay until then. |
513 frame_timer_ = WTF::WrapUnique( | 522 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>( |
514 new Timer<BitmapImage>(this, &BitmapImage::AdvanceAnimation)); | 523 task_runner_, this, &BitmapImage::AdvanceAnimation)); |
515 frame_timer_->StartOneShot(std::max(desired_frame_start_time_ - time, 0.), | 524 frame_timer_->StartOneShot(std::max(desired_frame_start_time_ - time, 0.), |
516 BLINK_FROM_HERE); | 525 BLINK_FROM_HERE); |
517 } else { | 526 } else { |
518 // We've already reached or passed the time for the next frame to start. | 527 // We've already reached or passed the time for the next frame to start. |
519 // See if we've also passed the time for frames after that to start, in | 528 // See if we've also passed the time for frames after that to start, in |
520 // case we need to skip some frames entirely. Remember not to advance | 529 // case we need to skip some frames entirely. Remember not to advance |
521 // to an incomplete frame. | 530 // to an incomplete frame. |
522 for (size_t frame_after_next = (next_frame + 1) % FrameCount(); | 531 for (size_t frame_after_next = (next_frame + 1) % FrameCount(); |
523 FrameIsCompleteAtIndex(frame_after_next); | 532 FrameIsCompleteAtIndex(frame_after_next); |
524 frame_after_next = (next_frame + 1) % FrameCount()) { | 533 frame_after_next = (next_frame + 1) % FrameCount()) { |
525 // Should we skip the next frame? | 534 // Should we skip the next frame? |
526 double frame_after_next_start_time = | 535 double frame_after_next_start_time = |
527 desired_frame_start_time_ + FrameDurationAtIndex(next_frame); | 536 desired_frame_start_time_ + FrameDurationAtIndex(next_frame); |
528 if (time < frame_after_next_start_time) | 537 if (time < frame_after_next_start_time) |
529 break; | 538 break; |
530 | 539 |
531 // Skip the next frame by advancing the animation forward one frame. | 540 // Skip the next frame by advancing the animation forward one frame. |
532 if (!InternalAdvanceAnimation(kSkipFramesToCatchUp)) { | 541 if (!InternalAdvanceAnimation(kSkipFramesToCatchUp)) { |
533 DCHECK(animation_finished_); | 542 DCHECK(animation_finished_); |
534 return; | 543 return; |
535 } | 544 } |
536 desired_frame_start_time_ = frame_after_next_start_time; | 545 desired_frame_start_time_ = frame_after_next_start_time; |
537 next_frame = frame_after_next; | 546 next_frame = frame_after_next; |
538 } | 547 } |
539 | 548 |
540 // Post a task to advance the frame immediately. m_desiredFrameStartTime | 549 // Post a task to advance the frame immediately. m_desiredFrameStartTime |
541 // may be in the past, meaning the next time through this function we'll | 550 // may be in the past, meaning the next time through this function we'll |
542 // kick off the next advancement sooner than this frame's duration would | 551 // kick off the next advancement sooner than this frame's duration would |
543 // suggest. | 552 // suggest. |
544 frame_timer_ = WTF::WrapUnique(new Timer<BitmapImage>( | 553 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>( |
545 this, &BitmapImage::AdvanceAnimationWithoutCatchUp)); | 554 task_runner_, this, &BitmapImage::AdvanceAnimationWithoutCatchUp)); |
546 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); | 555 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); |
547 } | 556 } |
548 } | 557 } |
549 | 558 |
550 void BitmapImage::StopAnimation() { | 559 void BitmapImage::StopAnimation() { |
551 // This timer is used to animate all occurrences of this image. Don't | 560 // This timer is used to animate all occurrences of this image. Don't |
552 // invalidate the timer unless all renderers have stopped drawing. | 561 // invalidate the timer unless all renderers have stopped drawing. |
553 frame_timer_.reset(); | 562 frame_timer_.reset(); |
554 } | 563 } |
555 | 564 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 animation_policy_ == kImageAnimationPolicyAnimateOnce) { | 626 animation_policy_ == kImageAnimationPolicyAnimateOnce) { |
618 animation_finished_ = true; | 627 animation_finished_ = true; |
619 desired_frame_start_time_ = 0; | 628 desired_frame_start_time_ = 0; |
620 | 629 |
621 // We skipped to the last frame and cannot advance further. The | 630 // We skipped to the last frame and cannot advance further. The |
622 // observer will not receive animationAdvanced notifications while | 631 // observer will not receive animationAdvanced notifications while |
623 // skipping but we still need to notify the observer to draw the | 632 // skipping but we still need to notify the observer to draw the |
624 // last frame. Skipping frames occurs while painting so we do not | 633 // last frame. Skipping frames occurs while painting so we do not |
625 // synchronously notify the observer which could cause a layout. | 634 // synchronously notify the observer which could cause a layout. |
626 if (advancement == kSkipFramesToCatchUp) { | 635 if (advancement == kSkipFramesToCatchUp) { |
627 frame_timer_ = WTF::WrapUnique(new Timer<BitmapImage>( | 636 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>( |
628 this, &BitmapImage::NotifyObserversOfAnimationAdvance)); | 637 task_runner_, this, |
| 638 &BitmapImage::NotifyObserversOfAnimationAdvance)); |
629 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); | 639 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); |
630 } | 640 } |
631 | 641 |
632 return false; | 642 return false; |
633 } | 643 } |
634 | 644 |
635 // Loop the animation back to the first frame. | 645 // Loop the animation back to the first frame. |
636 current_frame_ = 0; | 646 current_frame_ = 0; |
637 } | 647 } |
638 | 648 |
639 // We need to draw this frame if we advanced to it while not skipping. | 649 // We need to draw this frame if we advanced to it while not skipping. |
640 if (advancement != kSkipFramesToCatchUp) | 650 if (advancement != kSkipFramesToCatchUp) |
641 GetImageObserver()->AnimationAdvanced(this); | 651 GetImageObserver()->AnimationAdvanced(this); |
642 | 652 |
643 return true; | 653 return true; |
644 } | 654 } |
645 | 655 |
646 void BitmapImage::NotifyObserversOfAnimationAdvance(TimerBase*) { | 656 void BitmapImage::NotifyObserversOfAnimationAdvance(TimerBase*) { |
647 GetImageObserver()->AnimationAdvanced(this); | 657 GetImageObserver()->AnimationAdvanced(this); |
648 } | 658 } |
649 | 659 |
650 } // namespace blink | 660 } // namespace blink |
OLD | NEW |