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

Side by Side Diff: chrome/renderer/render_widget.cc

Issue 6409007: Calculate animation_floor_time_ only when actually updating animations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add bool to track if we've called animate() and are waiting for a paint to happen Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_widget.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/render_widget.h" 5 #include "chrome/renderer/render_widget.h"
6 6
7 #include "app/surface/transport_dib.h" 7 #include "app/surface/transport_dib.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 needs_repainting_on_restore_(false), 70 needs_repainting_on_restore_(false),
71 has_focus_(false), 71 has_focus_(false),
72 handling_input_event_(false), 72 handling_input_event_(false),
73 closing_(false), 73 closing_(false),
74 input_method_is_active_(false), 74 input_method_is_active_(false),
75 text_input_type_(WebKit::WebTextInputTypeNone), 75 text_input_type_(WebKit::WebTextInputTypeNone),
76 popup_type_(popup_type), 76 popup_type_(popup_type),
77 pending_window_rect_count_(0), 77 pending_window_rect_count_(0),
78 suppress_next_char_events_(false), 78 suppress_next_char_events_(false),
79 is_accelerated_compositing_active_(false), 79 is_accelerated_compositing_active_(false),
80 animation_update_pending_(false) { 80 animation_update_pending_(false),
81 animation_waiting_for_paint_(false) {
81 RenderProcess::current()->AddRefProcess(); 82 RenderProcess::current()->AddRefProcess();
82 DCHECK(render_thread_); 83 DCHECK(render_thread_);
83 } 84 }
84 85
85 RenderWidget::~RenderWidget() { 86 RenderWidget::~RenderWidget() {
86 DCHECK(!webwidget_) << "Leaking our WebWidget!"; 87 DCHECK(!webwidget_) << "Leaking our WebWidget!";
87 if (current_paint_buf_) { 88 if (current_paint_buf_) {
88 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); 89 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
89 current_paint_buf_ = NULL; 90 current_paint_buf_ = NULL;
90 } 91 }
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 void RenderWidget::CallDoDeferredUpdate() { 484 void RenderWidget::CallDoDeferredUpdate() {
484 DoDeferredUpdate(); 485 DoDeferredUpdate();
485 486
486 if (pending_input_event_ack_.get()) 487 if (pending_input_event_ack_.get())
487 Send(pending_input_event_ack_.release()); 488 Send(pending_input_event_ack_.release());
488 } 489 }
489 490
490 void RenderWidget::UpdateAnimationsIfNeeded() { 491 void RenderWidget::UpdateAnimationsIfNeeded() {
491 if (!is_hidden() && animation_update_pending_) { 492 if (!is_hidden() && animation_update_pending_) {
492 base::Time now = base::Time::Now(); 493 base::Time now = base::Time::Now();
493 if (now >= animation_floor_time_) { 494 if (now >= animation_floor_time_ && !animation_waiting_for_paint_) {
494 animation_update_pending_ = false; 495 animation_update_pending_ = false;
496 animation_floor_time_ = base::Time::Now() +
497 base::TimeDelta::FromMilliseconds(16); // Target 60FPS.
darin (slow to review) 2011/01/31 22:25:57 nit: 4 space indent instead of 3 nit: 2 spaces bef
495 webwidget_->animate(); 498 webwidget_->animate();
499 webwidget_->layout();
500 if (paint_aggregator_.HasPendingUpdate())
501 animation_waiting_for_paint_ = true;
darin (slow to review) 2011/01/31 22:25:57 nit: 2 space indent
496 } else { 502 } else {
497 // This code uses base::Time::Now() to calculate the floor and next fire 503 // This code uses base::Time::Now() to calculate the floor and next fire
498 // time because javascript's Date object uses base::Time::Now(). The 504 // time because javascript's Date object uses base::Time::Now(). The
499 // message loop uses base::TimeTicks, which on windows can have a 505 // message loop uses base::TimeTicks, which on windows can have a
500 // different granularity than base::Time. 506 // different granularity than base::Time.
501 // The upshot of all this is that this function might be called before 507 // The upshot of all this is that this function might be called before
502 // base::Time::Now() has advanced past the animation_floor_time_. To 508 // base::Time::Now() has advanced past the animation_floor_time_. To
503 // avoid exposing this delay to javascript, we keep posting delayed 509 // avoid exposing this delay to javascript, we keep posting delayed
504 // tasks until we observe base::Time::Now() advancing far enough. 510 // tasks until base::Time::Now() has advanced far enough.
505 int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp(); 511 int64 delay =
512 std::max(static_cast<int64>(0),
513 (animation_floor_time_ - now).InMillisecondsRoundedUp());
darin (slow to review) 2011/01/31 22:25:57 if we are waiting for paint, then why bother sched
506 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( 514 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(
507 this, &RenderWidget::UpdateAnimationsIfNeeded), delay); 515 this, &RenderWidget::UpdateAnimationsIfNeeded), delay);
508 } 516 }
509 } 517 }
510 } 518 }
511 519
512 void RenderWidget::DoDeferredUpdate() { 520 void RenderWidget::DoDeferredUpdate() {
513 if (!webwidget_ || update_reply_pending()) 521 if (!webwidget_ || update_reply_pending())
514 return; 522 return;
515 523
516 // Suppress updating when we are hidden. 524 // Suppress updating when we are hidden.
517 if (is_hidden_ || size_.IsEmpty()) { 525 if (is_hidden_ || size_.IsEmpty()) {
518 paint_aggregator_.ClearPendingUpdate(); 526 paint_aggregator_.ClearPendingUpdate();
519 needs_repainting_on_restore_ = true; 527 needs_repainting_on_restore_ = true;
520 return; 528 return;
521 } 529 }
522 530
523 if (base::Time::Now() > animation_floor_time_) 531 if (base::Time::Now() > animation_floor_time_)
524 UpdateAnimationsIfNeeded(); 532 UpdateAnimationsIfNeeded();
darin (slow to review) 2011/01/31 22:25:57 nit: 2 space indent
darin (slow to review) 2011/01/31 22:25:57 maybe this should just call animate() directly? y
533
534 animation_waiting_for_paint_ = false;
525 535
526 // Layout may generate more invalidation. It may also enable the 536 // Layout may generate more invalidation. It may also enable the
527 // GPU acceleration, so make sure to run layout before we send the 537 // GPU acceleration, so make sure to run layout before we send the
528 // GpuRenderingActivated message. 538 // GpuRenderingActivated message.
529 webwidget_->layout(); 539 webwidget_->layout();
530 540
531 // Suppress painting if nothing is dirty. This has to be done after updating 541 // Suppress painting if nothing is dirty. This has to be done after updating
532 // animations running layout as these may generate further invalidations. 542 // animations running layout as these may generate further invalidations.
533 if (!paint_aggregator_.HasPendingUpdate()) 543 if (!paint_aggregator_.HasPendingUpdate())
534 return; 544 return;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 // contains a lot of host-renderer synchronization logic that is still 720 // contains a lot of host-renderer synchronization logic that is still
711 // important for the accelerated compositing case. The option of simply 721 // important for the accelerated compositing case. The option of simply
712 // duplicating all that code is less desirable than "faking out" the 722 // duplicating all that code is less desirable than "faking out" the
713 // invalidation path using a magical damage rect. 723 // invalidation path using a magical damage rect.
714 didInvalidateRect(WebRect(0, 0, 1, 1)); 724 didInvalidateRect(WebRect(0, 0, 1, 1));
715 } 725 }
716 726
717 void RenderWidget::scheduleAnimation() { 727 void RenderWidget::scheduleAnimation() {
718 if (!animation_update_pending_) { 728 if (!animation_update_pending_) {
719 animation_update_pending_ = true; 729 animation_update_pending_ = true;
720 animation_floor_time_ = 730 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
721 base::Time::Now() + base::TimeDelta::FromMilliseconds(10); 731 this, &RenderWidget::UpdateAnimationsIfNeeded));
722 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(
723 this, &RenderWidget::UpdateAnimationsIfNeeded), 10);
724 } 732 }
725 } 733 }
726 734
727 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { 735 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
728 // TODO(darin): Eliminate this temporary. 736 // TODO(darin): Eliminate this temporary.
729 WebCursor cursor(cursor_info); 737 WebCursor cursor(cursor_info);
730 738
731 // Only send a SetCursor message if we need to make a change. 739 // Only send a SetCursor message if we need to make a change.
732 if (!current_cursor_.IsEqual(cursor)) { 740 if (!current_cursor_.IsEqual(cursor)) {
733 current_cursor_ = cursor; 741 current_cursor_ = cursor;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 1077
1070 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { 1078 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1071 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); 1079 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1072 i != plugin_window_moves_.end(); ++i) { 1080 i != plugin_window_moves_.end(); ++i) {
1073 if (i->window == window) { 1081 if (i->window == window) {
1074 plugin_window_moves_.erase(i); 1082 plugin_window_moves_.erase(i);
1075 break; 1083 break;
1076 } 1084 }
1077 } 1085 }
1078 } 1086 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698