OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/debug/trace_event_synthetic_delay.h" | 10 #include "base/debug/trace_event_synthetic_delay.h" |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 handling_touchstart_event_(false), | 376 handling_touchstart_event_(false), |
377 closing_(false), | 377 closing_(false), |
378 is_swapped_out_(swapped_out), | 378 is_swapped_out_(swapped_out), |
379 input_method_is_active_(false), | 379 input_method_is_active_(false), |
380 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 380 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
381 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 381 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
382 can_compose_inline_(true), | 382 can_compose_inline_(true), |
383 popup_type_(popup_type), | 383 popup_type_(popup_type), |
384 pending_window_rect_count_(0), | 384 pending_window_rect_count_(0), |
385 suppress_next_char_events_(false), | 385 suppress_next_char_events_(false), |
386 is_accelerated_compositing_active_(false), | |
387 screen_info_(screen_info), | 386 screen_info_(screen_info), |
388 device_scale_factor_(screen_info_.deviceScaleFactor), | 387 device_scale_factor_(screen_info_.deviceScaleFactor), |
389 is_threaded_compositing_enabled_(false), | 388 is_threaded_compositing_enabled_(false), |
390 next_output_surface_id_(0), | 389 next_output_surface_id_(0), |
391 #if defined(OS_ANDROID) | 390 #if defined(OS_ANDROID) |
392 text_field_is_dirty_(false), | 391 text_field_is_dirty_(false), |
393 outstanding_ime_acks_(0), | 392 outstanding_ime_acks_(0), |
394 body_background_color_(SK_ColorWHITE), | 393 body_background_color_(SK_ColorWHITE), |
395 #endif | 394 #endif |
396 #if defined(OS_MACOSX) | 395 #if defined(OS_MACOSX) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 return false; | 478 return false; |
480 } | 479 } |
481 } | 480 } |
482 | 481 |
483 // This is used to complete pending inits and non-pending inits. | 482 // This is used to complete pending inits and non-pending inits. |
484 void RenderWidget::CompleteInit() { | 483 void RenderWidget::CompleteInit() { |
485 DCHECK(routing_id_ != MSG_ROUTING_NONE); | 484 DCHECK(routing_id_ != MSG_ROUTING_NONE); |
486 | 485 |
487 init_complete_ = true; | 486 init_complete_ = true; |
488 | 487 |
489 if (webwidget_) { | 488 if (webwidget_) |
490 if (is_threaded_compositing_enabled_ || ForceCompositingModeEnabled()) { | 489 webwidget_->enterForceCompositingMode(true); |
491 webwidget_->enterForceCompositingMode(true); | |
492 } | |
493 } | |
494 if (compositor_) | 490 if (compositor_) |
495 StartCompositor(); | 491 StartCompositor(); |
496 | 492 |
497 Send(new ViewHostMsg_RenderViewReady(routing_id_)); | 493 Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
498 } | 494 } |
499 | 495 |
500 void RenderWidget::SetSwappedOut(bool is_swapped_out) { | 496 void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
501 // We should only toggle between states. | 497 // We should only toggle between states. |
502 DCHECK(is_swapped_out_ != is_swapped_out); | 498 DCHECK(is_swapped_out_ != is_swapped_out); |
503 is_swapped_out_ = is_swapped_out; | 499 is_swapped_out_ = is_swapped_out; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 if (!webwidget_) | 773 if (!webwidget_) |
778 return; | 774 return; |
779 | 775 |
780 // See OnWasHidden | 776 // See OnWasHidden |
781 SetHidden(false); | 777 SetHidden(false); |
782 | 778 |
783 if (!needs_repainting) | 779 if (!needs_repainting) |
784 return; | 780 return; |
785 | 781 |
786 // Generate a full repaint. | 782 // Generate a full repaint. |
787 if (!is_accelerated_compositing_active_) { | 783 if (compositor_) |
788 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); | 784 compositor_->SetNeedsForcedRedraw(); |
789 } else { | 785 scheduleComposite(); |
790 if (compositor_) | |
791 compositor_->SetNeedsForcedRedraw(); | |
792 scheduleComposite(); | |
793 } | |
794 } | 786 } |
795 | 787 |
796 void RenderWidget::OnWasSwappedOut() { | 788 void RenderWidget::OnWasSwappedOut() { |
797 // If we have been swapped out and no one else is using this process, | 789 // If we have been swapped out and no one else is using this process, |
798 // it's safe to exit now. If we get swapped back in, we will call | 790 // it's safe to exit now. If we get swapped back in, we will call |
799 // AddRefProcess in SetSwappedOut. | 791 // AddRefProcess in SetSwappedOut. |
800 if (is_swapped_out_) | 792 if (is_swapped_out_) |
801 RenderProcess::current()->ReleaseProcess(); | 793 RenderProcess::current()->ReleaseProcess(); |
802 } | 794 } |
803 | 795 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 } | 1157 } |
1166 } | 1158 } |
1167 | 1159 |
1168 void RenderWidget::AutoResizeCompositor() { | 1160 void RenderWidget::AutoResizeCompositor() { |
1169 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_, | 1161 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_, |
1170 device_scale_factor_)); | 1162 device_scale_factor_)); |
1171 if (compositor_) | 1163 if (compositor_) |
1172 compositor_->setViewportSize(size_, physical_backing_size_); | 1164 compositor_->setViewportSize(size_, physical_backing_size_); |
1173 } | 1165 } |
1174 | 1166 |
1175 void RenderWidget::didActivateCompositor() { | |
1176 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor"); | |
1177 | |
1178 is_accelerated_compositing_active_ = true; | |
1179 webwidget_->enterForceCompositingMode(true); | |
1180 } | |
1181 | |
1182 void RenderWidget::didDeactivateCompositor() { | |
1183 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor"); | |
1184 | |
1185 is_accelerated_compositing_active_ = false; | |
1186 } | |
1187 | |
1188 void RenderWidget::initializeLayerTreeView() { | 1167 void RenderWidget::initializeLayerTreeView() { |
1189 compositor_ = RenderWidgetCompositor::Create( | 1168 compositor_ = RenderWidgetCompositor::Create( |
1190 this, is_threaded_compositing_enabled_); | 1169 this, is_threaded_compositing_enabled_); |
1191 compositor_->setViewportSize(size_, physical_backing_size_); | 1170 compositor_->setViewportSize(size_, physical_backing_size_); |
1192 if (init_complete_) | 1171 if (init_complete_) |
1193 StartCompositor(); | 1172 StartCompositor(); |
1194 } | 1173 } |
1195 | 1174 |
1196 blink::WebLayerTreeView* RenderWidget::layerTreeView() { | 1175 blink::WebLayerTreeView* RenderWidget::layerTreeView() { |
1197 return compositor_.get(); | 1176 return compositor_.get(); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 if (!webwidget_) | 1457 if (!webwidget_) |
1479 return; | 1458 return; |
1480 | 1459 |
1481 // Even if the browser provides an empty damage rect, it's still expecting to | 1460 // Even if the browser provides an empty damage rect, it's still expecting to |
1482 // receive a repaint ack so just damage the entire widget bounds. | 1461 // receive a repaint ack so just damage the entire widget bounds. |
1483 if (size_to_paint.IsEmpty()) { | 1462 if (size_to_paint.IsEmpty()) { |
1484 size_to_paint = size_; | 1463 size_to_paint = size_; |
1485 } | 1464 } |
1486 | 1465 |
1487 set_next_paint_is_repaint_ack(); | 1466 set_next_paint_is_repaint_ack(); |
1488 if (is_accelerated_compositing_active_ && compositor_) { | 1467 if (compositor_) |
1489 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint)); | 1468 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint)); |
1490 } else { | |
1491 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); | |
1492 didInvalidateRect(repaint_rect); | |
1493 } | |
1494 } | 1469 } |
1495 | 1470 |
1496 void RenderWidget::OnSyntheticGestureCompleted() { | 1471 void RenderWidget::OnSyntheticGestureCompleted() { |
1497 DCHECK(!pending_synthetic_gesture_callbacks_.empty()); | 1472 DCHECK(!pending_synthetic_gesture_callbacks_.empty()); |
1498 | 1473 |
1499 pending_synthetic_gesture_callbacks_.front().Run(); | 1474 pending_synthetic_gesture_callbacks_.front().Run(); |
1500 pending_synthetic_gesture_callbacks_.pop(); | 1475 pending_synthetic_gesture_callbacks_.pop(); |
1501 } | 1476 } |
1502 | 1477 |
1503 void RenderWidget::OnSetTextDirection(WebTextDirection direction) { | 1478 void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 #else | 1514 #else |
1540 return !!webwidget_; | 1515 return !!webwidget_; |
1541 #endif | 1516 #endif |
1542 } | 1517 } |
1543 | 1518 |
1544 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { | 1519 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { |
1545 if (device_scale_factor_ == device_scale_factor) | 1520 if (device_scale_factor_ == device_scale_factor) |
1546 return; | 1521 return; |
1547 | 1522 |
1548 device_scale_factor_ = device_scale_factor; | 1523 device_scale_factor_ = device_scale_factor; |
1549 | 1524 scheduleComposite(); |
1550 if (!is_accelerated_compositing_active_) { | |
1551 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); | |
1552 } else { | |
1553 scheduleComposite(); | |
1554 } | |
1555 } | 1525 } |
1556 | 1526 |
1557 void RenderWidget::OnOrientationChange() { | 1527 void RenderWidget::OnOrientationChange() { |
1558 } | 1528 } |
1559 | 1529 |
1560 gfx::Vector2d RenderWidget::GetScrollOffset() { | 1530 gfx::Vector2d RenderWidget::GetScrollOffset() { |
1561 // Bare RenderWidgets don't support scroll offset. | 1531 // Bare RenderWidgets don't support scroll offset. |
1562 return gfx::Vector2d(); | 1532 return gfx::Vector2d(); |
1563 } | 1533 } |
1564 | 1534 |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 | 2073 |
2104 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2074 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2105 swapped_out_frames_.AddObserver(frame); | 2075 swapped_out_frames_.AddObserver(frame); |
2106 } | 2076 } |
2107 | 2077 |
2108 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2078 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2109 swapped_out_frames_.RemoveObserver(frame); | 2079 swapped_out_frames_.RemoveObserver(frame); |
2110 } | 2080 } |
2111 | 2081 |
2112 } // namespace content | 2082 } // namespace content |
OLD | NEW |