Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/BitmapImage.cpp

Issue 2810423003: Schedule bitmap animation timers on the compositor task runner. (Closed)
Patch Set: remove TODO comments from tests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
76 repetition_count_(kCAnimationNone), 77 repetition_count_(kCAnimationNone),
77 repetition_count_status_(kUnknown), 78 repetition_count_status_(kUnknown),
78 repetitions_complete_(0), 79 repetitions_complete_(0),
79 desired_frame_start_time_(0), 80 desired_frame_start_time_(0),
80 frame_count_(0), 81 frame_count_(0),
81 animation_policy_(kImageAnimationPolicyAllowed), 82 animation_policy_(kImageAnimationPolicyAllowed),
82 animation_finished_(false), 83 animation_finished_(false),
83 all_data_received_(false), 84 all_data_received_(false),
84 have_size_(false), 85 have_size_(false),
85 size_available_(false), 86 size_available_(false),
86 have_frame_count_(false) {} 87 have_frame_count_(false),
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 repetition_count_(kCAnimationNone), 99 repetition_count_(kCAnimationNone),
95 repetition_count_status_(kUnknown), 100 repetition_count_status_(kUnknown),
96 repetitions_complete_(0), 101 repetitions_complete_(0),
97 frame_count_(1), 102 frame_count_(1),
98 animation_policy_(kImageAnimationPolicyAllowed), 103 animation_policy_(kImageAnimationPolicyAllowed),
99 animation_finished_(true), 104 animation_finished_(true),
100 all_data_received_(true), 105 all_data_received_(true),
101 have_size_(true), 106 have_size_(true),
102 size_available_(true), 107 size_available_(true),
103 have_frame_count_(true) { 108 have_frame_count_(true),
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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // sync an image and some other resource (e.g. audio), especially if users 519 // 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) 520 // switch tabs (and thus stop drawing the animation, which will pause it)
512 // during that initial loop, then switch back later. 521 // during that initial loop, then switch back later.
513 if (next_frame == 0 && repetitions_complete_ == 0 && 522 if (next_frame == 0 && repetitions_complete_ == 0 &&
514 desired_frame_start_time_ < time) 523 desired_frame_start_time_ < time)
515 desired_frame_start_time_ = time; 524 desired_frame_start_time_ = time;
516 525
517 if (catch_up_if_necessary == kDoNotCatchUp || 526 if (catch_up_if_necessary == kDoNotCatchUp ||
518 time < desired_frame_start_time_) { 527 time < desired_frame_start_time_) {
519 // Haven't yet reached time for next frame to start; delay until then. 528 // Haven't yet reached time for next frame to start; delay until then.
520 frame_timer_ = WTF::WrapUnique( 529 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>(
521 new Timer<BitmapImage>(this, &BitmapImage::AdvanceAnimation)); 530 task_runner_, this, &BitmapImage::AdvanceAnimation));
522 frame_timer_->StartOneShot(std::max(desired_frame_start_time_ - time, 0.), 531 frame_timer_->StartOneShot(std::max(desired_frame_start_time_ - time, 0.),
523 BLINK_FROM_HERE); 532 BLINK_FROM_HERE);
524 } else { 533 } else {
525 // We've already reached or passed the time for the next frame to start. 534 // 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 535 // 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 536 // case we need to skip some frames entirely. Remember not to advance
528 // to an incomplete frame. 537 // to an incomplete frame.
529 for (size_t frame_after_next = (next_frame + 1) % FrameCount(); 538 for (size_t frame_after_next = (next_frame + 1) % FrameCount();
530 FrameIsCompleteAtIndex(frame_after_next); 539 FrameIsCompleteAtIndex(frame_after_next);
531 frame_after_next = (next_frame + 1) % FrameCount()) { 540 frame_after_next = (next_frame + 1) % FrameCount()) {
532 // Should we skip the next frame? 541 // Should we skip the next frame?
533 double frame_after_next_start_time = 542 double frame_after_next_start_time =
534 desired_frame_start_time_ + FrameDurationAtIndex(next_frame); 543 desired_frame_start_time_ + FrameDurationAtIndex(next_frame);
535 if (time < frame_after_next_start_time) 544 if (time < frame_after_next_start_time)
536 break; 545 break;
537 546
538 // Skip the next frame by advancing the animation forward one frame. 547 // Skip the next frame by advancing the animation forward one frame.
539 if (!InternalAdvanceAnimation(kSkipFramesToCatchUp)) { 548 if (!InternalAdvanceAnimation(kSkipFramesToCatchUp)) {
540 DCHECK(animation_finished_); 549 DCHECK(animation_finished_);
541 return; 550 return;
542 } 551 }
543 desired_frame_start_time_ = frame_after_next_start_time; 552 desired_frame_start_time_ = frame_after_next_start_time;
544 next_frame = frame_after_next; 553 next_frame = frame_after_next;
545 } 554 }
546 555
547 // Post a task to advance the frame immediately. m_desiredFrameStartTime 556 // 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 557 // 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 558 // kick off the next advancement sooner than this frame's duration would
550 // suggest. 559 // suggest.
551 frame_timer_ = WTF::WrapUnique(new Timer<BitmapImage>( 560 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>(
552 this, &BitmapImage::AdvanceAnimationWithoutCatchUp)); 561 task_runner_, this, &BitmapImage::AdvanceAnimationWithoutCatchUp));
553 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); 562 frame_timer_->StartOneShot(0, BLINK_FROM_HERE);
554 } 563 }
555 } 564 }
556 565
557 void BitmapImage::StopAnimation() { 566 void BitmapImage::StopAnimation() {
558 // This timer is used to animate all occurrences of this image. Don't 567 // This timer is used to animate all occurrences of this image. Don't
559 // invalidate the timer unless all renderers have stopped drawing. 568 // invalidate the timer unless all renderers have stopped drawing.
560 frame_timer_.reset(); 569 frame_timer_.reset();
561 } 570 }
562 571
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 animation_policy_ == kImageAnimationPolicyAnimateOnce) { 633 animation_policy_ == kImageAnimationPolicyAnimateOnce) {
625 animation_finished_ = true; 634 animation_finished_ = true;
626 desired_frame_start_time_ = 0; 635 desired_frame_start_time_ = 0;
627 636
628 // We skipped to the last frame and cannot advance further. The 637 // We skipped to the last frame and cannot advance further. The
629 // observer will not receive animationAdvanced notifications while 638 // observer will not receive animationAdvanced notifications while
630 // skipping but we still need to notify the observer to draw the 639 // skipping but we still need to notify the observer to draw the
631 // last frame. Skipping frames occurs while painting so we do not 640 // last frame. Skipping frames occurs while painting so we do not
632 // synchronously notify the observer which could cause a layout. 641 // synchronously notify the observer which could cause a layout.
633 if (advancement == kSkipFramesToCatchUp) { 642 if (advancement == kSkipFramesToCatchUp) {
634 frame_timer_ = WTF::WrapUnique(new Timer<BitmapImage>( 643 frame_timer_ = WTF::WrapUnique(new TaskRunnerTimer<BitmapImage>(
635 this, &BitmapImage::NotifyObserversOfAnimationAdvance)); 644 task_runner_, this,
645 &BitmapImage::NotifyObserversOfAnimationAdvance));
636 frame_timer_->StartOneShot(0, BLINK_FROM_HERE); 646 frame_timer_->StartOneShot(0, BLINK_FROM_HERE);
637 } 647 }
638 648
639 return false; 649 return false;
640 } 650 }
641 651
642 // Loop the animation back to the first frame. 652 // Loop the animation back to the first frame.
643 current_frame_ = 0; 653 current_frame_ = 0;
644 } 654 }
645 655
646 // We need to draw this frame if we advanced to it while not skipping. 656 // We need to draw this frame if we advanced to it while not skipping.
647 if (advancement != kSkipFramesToCatchUp) 657 if (advancement != kSkipFramesToCatchUp)
648 GetImageObserver()->AnimationAdvanced(this); 658 GetImageObserver()->AnimationAdvanced(this);
649 659
650 return true; 660 return true;
651 } 661 }
652 662
653 void BitmapImage::NotifyObserversOfAnimationAdvance(TimerBase*) { 663 void BitmapImage::NotifyObserversOfAnimationAdvance(TimerBase*) {
654 GetImageObserver()->AnimationAdvanced(this); 664 GetImageObserver()->AnimationAdvanced(this);
655 } 665 }
656 666
657 } // namespace blink 667 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698