Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 } | 481 } |
| 482 | 482 |
| 483 void RenderWidget::CallDoDeferredUpdate() { | 483 void RenderWidget::CallDoDeferredUpdate() { |
| 484 DoDeferredUpdate(); | 484 DoDeferredUpdate(); |
| 485 | 485 |
| 486 if (pending_input_event_ack_.get()) | 486 if (pending_input_event_ack_.get()) |
| 487 Send(pending_input_event_ack_.release()); | 487 Send(pending_input_event_ack_.release()); |
| 488 } | 488 } |
| 489 | 489 |
| 490 void RenderWidget::UpdateAnimationsIfNeeded() { | 490 void RenderWidget::UpdateAnimationsIfNeeded() { |
| 491 static const int64 kMinimumAnimationDelay = 16; // Target 60 FPS. | |
| 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_) { |
| 494 animation_update_pending_ = false; | 495 animation_update_pending_ = false; |
| 496 animation_floor_time_ = base::Time::Now() + | |
| 497 base::TimeDelta::FromMilliseconds(kMinimumAnimationDelay); | |
| 495 webwidget_->animate(); | 498 webwidget_->animate(); |
| 496 } else { | 499 } else { |
| 497 // This code uses base::Time::Now() to calculate the floor and next fire | 500 // 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 | 501 // time because javascript's Date object uses base::Time::Now(). The |
| 499 // message loop uses base::TimeTicks, which on windows can have a | 502 // message loop uses base::TimeTicks, which on windows can have a |
| 500 // different granularity than base::Time. | 503 // different granularity than base::Time. |
| 501 // The upshot of all this is that this function might be called before | 504 // 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 | 505 // base::Time::Now() has advanced past the animation_floor_time_. To |
| 503 // avoid exposing this delay to javascript, we keep posting delayed | 506 // avoid exposing this delay to javascript, we keep posting delayed |
| 504 // tasks until we observe base::Time::Now() advancing far enough. | 507 // tasks until base::Time::Now() has advanced far enough. |
| 505 int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp(); | 508 int64 delay = std::min( |
| 509 (animation_floor_time_ - now).InMillisecondsRoundedUp(), | |
| 510 kMinimumAnimationDelay); | |
| 506 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( | 511 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
| 507 this, &RenderWidget::UpdateAnimationsIfNeeded), delay); | 512 this, &RenderWidget::UpdateAnimationsIfNeeded), delay); |
| 508 } | 513 } |
| 509 } | 514 } |
| 510 } | 515 } |
| 511 | 516 |
| 512 void RenderWidget::DoDeferredUpdate() { | 517 void RenderWidget::DoDeferredUpdate() { |
| 513 if (!webwidget_ || update_reply_pending()) | 518 if (!webwidget_ || update_reply_pending()) |
| 514 return; | 519 return; |
| 515 | 520 |
| 516 // Suppress updating when we are hidden. | 521 // Suppress updating when we are hidden. |
| 517 if (is_hidden_ || size_.IsEmpty()) { | 522 if (is_hidden_ || size_.IsEmpty()) { |
| 518 paint_aggregator_.ClearPendingUpdate(); | 523 paint_aggregator_.ClearPendingUpdate(); |
| 519 needs_repainting_on_restore_ = true; | 524 needs_repainting_on_restore_ = true; |
| 520 return; | 525 return; |
| 521 } | 526 } |
| 522 | 527 |
| 523 if (base::Time::Now() > animation_floor_time_) | |
| 524 UpdateAnimationsIfNeeded(); | |
|
darin (slow to review)
2011/01/31 19:01:09
it seems like you should still consider calling We
| |
| 525 | |
| 526 // Layout may generate more invalidation. It may also enable the | 528 // Layout may generate more invalidation. It may also enable the |
| 527 // GPU acceleration, so make sure to run layout before we send the | 529 // GPU acceleration, so make sure to run layout before we send the |
| 528 // GpuRenderingActivated message. | 530 // GpuRenderingActivated message. |
| 529 webwidget_->layout(); | 531 webwidget_->layout(); |
| 530 | 532 |
| 531 // Suppress painting if nothing is dirty. This has to be done after updating | 533 // Suppress painting if nothing is dirty. This has to be done after updating |
| 532 // animations running layout as these may generate further invalidations. | 534 // animations running layout as these may generate further invalidations. |
| 533 if (!paint_aggregator_.HasPendingUpdate()) | 535 if (!paint_aggregator_.HasPendingUpdate()) |
| 534 return; | 536 return; |
| 535 | 537 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 // contains a lot of host-renderer synchronization logic that is still | 712 // contains a lot of host-renderer synchronization logic that is still |
| 711 // important for the accelerated compositing case. The option of simply | 713 // important for the accelerated compositing case. The option of simply |
| 712 // duplicating all that code is less desirable than "faking out" the | 714 // duplicating all that code is less desirable than "faking out" the |
| 713 // invalidation path using a magical damage rect. | 715 // invalidation path using a magical damage rect. |
| 714 didInvalidateRect(WebRect(0, 0, 1, 1)); | 716 didInvalidateRect(WebRect(0, 0, 1, 1)); |
| 715 } | 717 } |
| 716 | 718 |
| 717 void RenderWidget::scheduleAnimation() { | 719 void RenderWidget::scheduleAnimation() { |
| 718 if (!animation_update_pending_) { | 720 if (!animation_update_pending_) { |
| 719 animation_update_pending_ = true; | 721 animation_update_pending_ = true; |
| 720 animation_floor_time_ = | 722 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 721 base::Time::Now() + base::TimeDelta::FromMilliseconds(10); | 723 this, &RenderWidget::UpdateAnimationsIfNeeded)); |
| 722 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( | |
| 723 this, &RenderWidget::UpdateAnimationsIfNeeded), 10); | |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 | 726 |
| 727 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { | 727 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
| 728 // TODO(darin): Eliminate this temporary. | 728 // TODO(darin): Eliminate this temporary. |
| 729 WebCursor cursor(cursor_info); | 729 WebCursor cursor(cursor_info); |
| 730 | 730 |
| 731 // Only send a SetCursor message if we need to make a change. | 731 // Only send a SetCursor message if we need to make a change. |
| 732 if (!current_cursor_.IsEqual(cursor)) { | 732 if (!current_cursor_.IsEqual(cursor)) { |
| 733 current_cursor_ = cursor; | 733 current_cursor_ = cursor; |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1069 | 1069 |
| 1070 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { | 1070 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
| 1071 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); | 1071 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
| 1072 i != plugin_window_moves_.end(); ++i) { | 1072 i != plugin_window_moves_.end(); ++i) { |
| 1073 if (i->window == window) { | 1073 if (i->window == window) { |
| 1074 plugin_window_moves_.erase(i); | 1074 plugin_window_moves_.erase(i); |
| 1075 break; | 1075 break; |
| 1076 } | 1076 } |
| 1077 } | 1077 } |
| 1078 } | 1078 } |
| OLD | NEW |