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