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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 | 49 |
50 ColorBehavior DefaultColorBehavior() { | 50 ColorBehavior DefaultColorBehavior() { |
51 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) | 51 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) |
52 return ColorBehavior::Tag(); | 52 return ColorBehavior::Tag(); |
53 return ColorBehavior::TransformToGlobalTarget(); | 53 return ColorBehavior::TransformToGlobalTarget(); |
54 } | 54 } |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 PassRefPtr<BitmapImage> BitmapImage::CreateWithOrientationForTesting( | 58 PassRefPtr<BitmapImage> BitmapImage::CreateWithOrientationForTesting( |
59 RefPtr<WebTaskRunner> task_runner, | |
59 const SkBitmap& bitmap, | 60 const SkBitmap& bitmap, |
60 ImageOrientation orientation) { | 61 ImageOrientation orientation) { |
61 if (bitmap.isNull()) { | 62 if (bitmap.isNull()) { |
62 return BitmapImage::Create(); | 63 return BitmapImage::Create(task_runner); |
63 } | 64 } |
64 | 65 |
65 RefPtr<BitmapImage> result = AdoptRef(new BitmapImage(bitmap)); | 66 RefPtr<BitmapImage> result = AdoptRef(new BitmapImage(task_runner, bitmap)); |
66 result->frames_[0].orientation_ = orientation; | 67 result->frames_[0].orientation_ = orientation; |
67 if (orientation.UsesWidthAsHeight()) | 68 if (orientation.UsesWidthAsHeight()) |
68 result->size_respecting_orientation_ = result->size_.TransposedSize(); | 69 result->size_respecting_orientation_ = result->size_.TransposedSize(); |
69 return result.Release(); | 70 return result.Release(); |
70 } | 71 } |
71 | 72 |
72 BitmapImage::BitmapImage(ImageObserver* observer) | 73 BitmapImage::BitmapImage() : BitmapImage(TimerBase::GetTimerTaskRunner()) {} |
Dan Elphick
2017/04/27 14:41:39
I guess I could just inline that function here:
P
Sami
2017/04/27 17:38:17
So this is the case where we can't tie the image t
fs
2017/04/27 17:42:54
Sorry to say, but Images don't have a 1:1 relation
Dan Elphick
2017/05/03 09:41:06
I've reworked it all now to get the Compositor tas
| |
74 | |
75 BitmapImage::BitmapImage(RefPtr<WebTaskRunner> task_runner, | |
76 ImageObserver* observer) | |
73 : Image(observer), | 77 : Image(observer), |
74 current_frame_(0), | 78 current_frame_(0), |
75 cached_frame_index_(0), | 79 cached_frame_index_(0), |
76 repetition_count_(kCAnimationNone), | 80 repetition_count_(kCAnimationNone), |
77 repetition_count_status_(kUnknown), | 81 repetition_count_status_(kUnknown), |
78 repetitions_complete_(0), | 82 repetitions_complete_(0), |
79 desired_frame_start_time_(0), | 83 desired_frame_start_time_(0), |
80 frame_count_(0), | 84 frame_count_(0), |
81 animation_policy_(kImageAnimationPolicyAllowed), | 85 animation_policy_(kImageAnimationPolicyAllowed), |
82 animation_finished_(false), | 86 animation_finished_(false), |
83 all_data_received_(false), | 87 all_data_received_(false), |
84 have_size_(false), | 88 have_size_(false), |
85 size_available_(false), | 89 size_available_(false), |
86 have_frame_count_(false) {} | 90 have_frame_count_(false), |
91 task_runner_(task_runner) {} | |
87 | 92 |
88 BitmapImage::BitmapImage(const SkBitmap& bitmap, ImageObserver* observer) | 93 BitmapImage::BitmapImage(RefPtr<WebTaskRunner> task_runner, |
94 const SkBitmap& bitmap, | |
95 ImageObserver* observer) | |
89 : Image(observer), | 96 : Image(observer), |
90 size_(bitmap.width(), bitmap.height()), | 97 size_(bitmap.width(), bitmap.height()), |
91 current_frame_(0), | 98 current_frame_(0), |
92 cached_frame_(SkImage::MakeFromBitmap(bitmap)), | 99 cached_frame_(SkImage::MakeFromBitmap(bitmap)), |
93 cached_frame_index_(0), | 100 cached_frame_index_(0), |
94 repetition_count_(kCAnimationNone), | 101 repetition_count_(kCAnimationNone), |
95 repetition_count_status_(kUnknown), | 102 repetition_count_status_(kUnknown), |
96 repetitions_complete_(0), | 103 repetitions_complete_(0), |
97 frame_count_(1), | 104 frame_count_(1), |
98 animation_policy_(kImageAnimationPolicyAllowed), | 105 animation_policy_(kImageAnimationPolicyAllowed), |
99 animation_finished_(true), | 106 animation_finished_(true), |
100 all_data_received_(true), | 107 all_data_received_(true), |
101 have_size_(true), | 108 have_size_(true), |
102 size_available_(true), | 109 size_available_(true), |
103 have_frame_count_(true) { | 110 have_frame_count_(true), |
111 task_runner_(task_runner) { | |
104 // Since we don't have a decoder, we can't figure out the image orientation. | 112 // 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. | 113 // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0. |
106 size_respecting_orientation_ = size_; | 114 size_respecting_orientation_ = size_; |
107 | 115 |
108 frames_.Grow(1); | 116 frames_.Grow(1); |
109 frames_[0].has_alpha_ = !bitmap.isOpaque(); | 117 frames_[0].has_alpha_ = !bitmap.isOpaque(); |
110 frames_[0].have_metadata_ = true; | 118 frames_[0].have_metadata_ = true; |
111 } | 119 } |
112 | 120 |
113 BitmapImage::~BitmapImage() { | 121 BitmapImage::~BitmapImage() { |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 // sync an image and some other resource (e.g. audio), especially if users | 518 // sync an image and some other resource (e.g. audio), especially if users |
511 // switch tabs (and thus stop drawing the animation, which will pause it) | 519 // switch tabs (and thus stop drawing the animation, which will pause it) |
512 // during that initial loop, then switch back later. | 520 // during that initial loop, then switch back later. |
513 if (next_frame == 0 && repetitions_complete_ == 0 && | 521 if (next_frame == 0 && repetitions_complete_ == 0 && |
514 desired_frame_start_time_ < time) | 522 desired_frame_start_time_ < time) |
515 desired_frame_start_time_ = time; | 523 desired_frame_start_time_ = time; |
516 | 524 |
517 if (catch_up_if_necessary == kDoNotCatchUp || | 525 if (catch_up_if_necessary == kDoNotCatchUp || |
518 time < desired_frame_start_time_) { | 526 time < desired_frame_start_time_) { |
519 // Haven't yet reached time for next frame to start; delay until then. | 527 // Haven't yet reached time for next frame to start; delay until then. |
520 frame_timer_ = WTF::WrapUnique( | 528 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>( |
521 new Timer<BitmapImage>(this, &BitmapImage::AdvanceAnimation)); | 529 task_runner_, this, &BitmapImage::AdvanceAnimation)); |
522 frame_timer_->StartOneShot(std::max(desired_frame_start_time_ - time, 0.), | 530 frame_timer_->StartOneShot(std::max(desired_frame_start_time_ - time, 0.), |
523 BLINK_FROM_HERE); | 531 BLINK_FROM_HERE); |
524 } else { | 532 } else { |
525 // We've already reached or passed the time for the next frame to start. | 533 // We've already reached or passed the time for the next frame to start. |
526 // See if we've also passed the time for frames after that to start, in | 534 // See if we've also passed the time for frames after that to start, in |
527 // case we need to skip some frames entirely. Remember not to advance | 535 // case we need to skip some frames entirely. Remember not to advance |
528 // to an incomplete frame. | 536 // to an incomplete frame. |
529 for (size_t frame_after_next = (next_frame + 1) % FrameCount(); | 537 for (size_t frame_after_next = (next_frame + 1) % FrameCount(); |
530 FrameIsCompleteAtIndex(frame_after_next); | 538 FrameIsCompleteAtIndex(frame_after_next); |
531 frame_after_next = (next_frame + 1) % FrameCount()) { | 539 frame_after_next = (next_frame + 1) % FrameCount()) { |
532 // Should we skip the next frame? | 540 // Should we skip the next frame? |
533 double frame_after_next_start_time = | 541 double frame_after_next_start_time = |
534 desired_frame_start_time_ + FrameDurationAtIndex(next_frame); | 542 desired_frame_start_time_ + FrameDurationAtIndex(next_frame); |
535 if (time < frame_after_next_start_time) | 543 if (time < frame_after_next_start_time) |
536 break; | 544 break; |
537 | 545 |
538 // Skip the next frame by advancing the animation forward one frame. | 546 // Skip the next frame by advancing the animation forward one frame. |
539 if (!InternalAdvanceAnimation(kSkipFramesToCatchUp)) { | 547 if (!InternalAdvanceAnimation(kSkipFramesToCatchUp)) { |
540 DCHECK(animation_finished_); | 548 DCHECK(animation_finished_); |
541 return; | 549 return; |
542 } | 550 } |
543 desired_frame_start_time_ = frame_after_next_start_time; | 551 desired_frame_start_time_ = frame_after_next_start_time; |
544 next_frame = frame_after_next; | 552 next_frame = frame_after_next; |
545 } | 553 } |
546 | 554 |
547 // Post a task to advance the frame immediately. m_desiredFrameStartTime | 555 // Post a task to advance the frame immediately. m_desiredFrameStartTime |
548 // may be in the past, meaning the next time through this function we'll | 556 // may be in the past, meaning the next time through this function we'll |
549 // kick off the next advancement sooner than this frame's duration would | 557 // kick off the next advancement sooner than this frame's duration would |
550 // suggest. | 558 // suggest. |
551 frame_timer_ = WTF::WrapUnique(new Timer<BitmapImage>( | 559 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>( |
552 this, &BitmapImage::AdvanceAnimationWithoutCatchUp)); | 560 task_runner_, this, &BitmapImage::AdvanceAnimationWithoutCatchUp)); |
553 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); | 561 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); |
554 } | 562 } |
555 } | 563 } |
556 | 564 |
557 void BitmapImage::StopAnimation() { | 565 void BitmapImage::StopAnimation() { |
558 // This timer is used to animate all occurrences of this image. Don't | 566 // This timer is used to animate all occurrences of this image. Don't |
559 // invalidate the timer unless all renderers have stopped drawing. | 567 // invalidate the timer unless all renderers have stopped drawing. |
560 frame_timer_.reset(); | 568 frame_timer_.reset(); |
561 } | 569 } |
562 | 570 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 animation_policy_ == kImageAnimationPolicyAnimateOnce) { | 632 animation_policy_ == kImageAnimationPolicyAnimateOnce) { |
625 animation_finished_ = true; | 633 animation_finished_ = true; |
626 desired_frame_start_time_ = 0; | 634 desired_frame_start_time_ = 0; |
627 | 635 |
628 // We skipped to the last frame and cannot advance further. The | 636 // We skipped to the last frame and cannot advance further. The |
629 // observer will not receive animationAdvanced notifications while | 637 // observer will not receive animationAdvanced notifications while |
630 // skipping but we still need to notify the observer to draw the | 638 // skipping but we still need to notify the observer to draw the |
631 // last frame. Skipping frames occurs while painting so we do not | 639 // last frame. Skipping frames occurs while painting so we do not |
632 // synchronously notify the observer which could cause a layout. | 640 // synchronously notify the observer which could cause a layout. |
633 if (advancement == kSkipFramesToCatchUp) { | 641 if (advancement == kSkipFramesToCatchUp) { |
634 frame_timer_ = WTF::WrapUnique(new Timer<BitmapImage>( | 642 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>( |
635 this, &BitmapImage::NotifyObserversOfAnimationAdvance)); | 643 task_runner_, this, |
644 &BitmapImage::NotifyObserversOfAnimationAdvance)); | |
636 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); | 645 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); |
637 } | 646 } |
638 | 647 |
639 return false; | 648 return false; |
640 } | 649 } |
641 | 650 |
642 // Loop the animation back to the first frame. | 651 // Loop the animation back to the first frame. |
643 current_frame_ = 0; | 652 current_frame_ = 0; |
644 } | 653 } |
645 | 654 |
646 // We need to draw this frame if we advanced to it while not skipping. | 655 // We need to draw this frame if we advanced to it while not skipping. |
647 if (advancement != kSkipFramesToCatchUp) | 656 if (advancement != kSkipFramesToCatchUp) |
648 GetImageObserver()->AnimationAdvanced(this); | 657 GetImageObserver()->AnimationAdvanced(this); |
649 | 658 |
650 return true; | 659 return true; |
651 } | 660 } |
652 | 661 |
653 void BitmapImage::NotifyObserversOfAnimationAdvance(TimerBase*) { | 662 void BitmapImage::NotifyObserversOfAnimationAdvance(TimerBase*) { |
654 GetImageObserver()->AnimationAdvanced(this); | 663 GetImageObserver()->AnimationAdvanced(this); |
655 } | 664 } |
656 | 665 |
657 } // namespace blink | 666 } // namespace blink |
OLD | NEW |