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

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

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

Powered by Google App Engine
This is Rietveld 408576698