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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 is_hidden_(false), | 69 is_hidden_(false), |
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 RenderProcess::current()->AddRefProcess(); | 81 RenderProcess::current()->AddRefProcess(); |
81 DCHECK(render_thread_); | 82 DCHECK(render_thread_); |
82 } | 83 } |
83 | 84 |
84 RenderWidget::~RenderWidget() { | 85 RenderWidget::~RenderWidget() { |
85 DCHECK(!webwidget_) << "Leaking our WebWidget!"; | 86 DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
86 if (current_paint_buf_) { | 87 if (current_paint_buf_) { |
87 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); | 88 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
88 current_paint_buf_ = NULL; | 89 current_paint_buf_ = NULL; |
89 } | 90 } |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 canvas->drawIRect(irect, paint); | 480 canvas->drawIRect(irect, paint); |
480 } | 481 } |
481 | 482 |
482 void RenderWidget::CallDoDeferredUpdate() { | 483 void RenderWidget::CallDoDeferredUpdate() { |
483 DoDeferredUpdate(); | 484 DoDeferredUpdate(); |
484 | 485 |
485 if (pending_input_event_ack_.get()) | 486 if (pending_input_event_ack_.get()) |
486 Send(pending_input_event_ack_.release()); | 487 Send(pending_input_event_ack_.release()); |
487 } | 488 } |
488 | 489 |
| 490 void RenderWidget::UpdateAnimationsIfNeeded() { |
| 491 if (!is_hidden() && animation_update_pending_ && |
| 492 base::Time::Now() > animation_floor_time_) { |
| 493 animation_update_pending_ = false; |
| 494 webwidget_->animate(); |
| 495 } |
| 496 } |
| 497 |
489 void RenderWidget::DoDeferredUpdate() { | 498 void RenderWidget::DoDeferredUpdate() { |
490 if (!webwidget_ || !paint_aggregator_.HasPendingUpdate() || | 499 if (!webwidget_ || update_reply_pending()) |
491 update_reply_pending()) | |
492 return; | 500 return; |
493 | 501 |
494 // Suppress updating when we are hidden. | 502 // Suppress updating when we are hidden. |
495 if (is_hidden_ || size_.IsEmpty()) { | 503 if (is_hidden_ || size_.IsEmpty()) { |
496 paint_aggregator_.ClearPendingUpdate(); | 504 paint_aggregator_.ClearPendingUpdate(); |
497 needs_repainting_on_restore_ = true; | 505 needs_repainting_on_restore_ = true; |
498 return; | 506 return; |
499 } | 507 } |
500 | 508 |
| 509 if (base::Time::Now() > animation_floor_time_) |
| 510 UpdateAnimationsIfNeeded(); |
| 511 |
501 // Layout may generate more invalidation. It may also enable the | 512 // Layout may generate more invalidation. It may also enable the |
502 // GPU acceleration, so make sure to run layout before we send the | 513 // GPU acceleration, so make sure to run layout before we send the |
503 // GpuRenderingActivated message. | 514 // GpuRenderingActivated message. |
504 webwidget_->layout(); | 515 webwidget_->layout(); |
505 | 516 |
| 517 // Suppress painting if nothing is dirty. This has to be done after updating |
| 518 // animations running layout as these may generate further invalidations. |
| 519 if (!paint_aggregator_.HasPendingUpdate()) |
| 520 return; |
| 521 |
506 // OK, save the pending update to a local since painting may cause more | 522 // OK, save the pending update to a local since painting may cause more |
507 // invalidation. Some WebCore rendering objects only layout when painted. | 523 // invalidation. Some WebCore rendering objects only layout when painted. |
508 PaintAggregator::PendingUpdate update; | 524 PaintAggregator::PendingUpdate update; |
509 paint_aggregator_.PopPendingUpdate(&update); | 525 paint_aggregator_.PopPendingUpdate(&update); |
510 | 526 |
511 gfx::Rect scroll_damage = update.GetScrollDamage(); | 527 gfx::Rect scroll_damage = update.GetScrollDamage(); |
512 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage); | 528 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage); |
513 | 529 |
514 // A plugin may be able to do an optimized paint. First check this, in which | 530 // A plugin may be able to do an optimized paint. First check this, in which |
515 // case we can skip all of the bitmap generation and regular paint code. | 531 // case we can skip all of the bitmap generation and regular paint code. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 void RenderWidget::scheduleComposite() { | 690 void RenderWidget::scheduleComposite() { |
675 // TODO(nduca): replace with something a little less hacky. The reason this | 691 // TODO(nduca): replace with something a little less hacky. The reason this |
676 // hack is still used is because the Invalidate-DoDeferredUpdate loop | 692 // hack is still used is because the Invalidate-DoDeferredUpdate loop |
677 // contains a lot of host-renderer synchronization logic that is still | 693 // contains a lot of host-renderer synchronization logic that is still |
678 // important for the accelerated compositing case. The option of simply | 694 // important for the accelerated compositing case. The option of simply |
679 // duplicating all that code is less desirable than "faking out" the | 695 // duplicating all that code is less desirable than "faking out" the |
680 // invalidation path using a magical damage rect. | 696 // invalidation path using a magical damage rect. |
681 didInvalidateRect(WebRect(0, 0, 1, 1)); | 697 didInvalidateRect(WebRect(0, 0, 1, 1)); |
682 } | 698 } |
683 | 699 |
| 700 void RenderWidget::scheduleAnimation() { |
| 701 if (!animation_update_pending_) { |
| 702 animation_update_pending_ = true; |
| 703 animation_floor_time_ = |
| 704 base::Time::Now() + base::TimeDelta::FromMilliseconds(10); |
| 705 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
| 706 this, &RenderWidget::UpdateAnimationsIfNeeded), 10); |
| 707 } |
| 708 } |
| 709 |
684 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { | 710 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
685 // TODO(darin): Eliminate this temporary. | 711 // TODO(darin): Eliminate this temporary. |
686 WebCursor cursor(cursor_info); | 712 WebCursor cursor(cursor_info); |
687 | 713 |
688 // Only send a SetCursor message if we need to make a change. | 714 // Only send a SetCursor message if we need to make a change. |
689 if (!current_cursor_.IsEqual(cursor)) { | 715 if (!current_cursor_.IsEqual(cursor)) { |
690 current_cursor_ = cursor; | 716 current_cursor_ = cursor; |
691 Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); | 717 Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); |
692 } | 718 } |
693 } | 719 } |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 | 1047 |
1022 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { | 1048 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
1023 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); | 1049 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
1024 i != plugin_window_moves_.end(); ++i) { | 1050 i != plugin_window_moves_.end(); ++i) { |
1025 if (i->window == window) { | 1051 if (i->window == window) { |
1026 plugin_window_moves_.erase(i); | 1052 plugin_window_moves_.erase(i); |
1027 break; | 1053 break; |
1028 } | 1054 } |
1029 } | 1055 } |
1030 } | 1056 } |
OLD | NEW |