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/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "base/trace_event/trace_event_synthetic_delay.h" | 19 #include "base/trace_event/trace_event_synthetic_delay.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "cc/base/switches.h" | 21 #include "cc/base/switches.h" |
22 #include "cc/debug/benchmark_instrumentation.h" | 22 #include "cc/debug/benchmark_instrumentation.h" |
23 #include "cc/output/output_surface.h" | 23 #include "cc/output/output_surface.h" |
24 #include "cc/trees/layer_tree_host.h" | 24 #include "cc/trees/layer_tree_host.h" |
25 #include "components/scheduler/renderer/renderer_scheduler.h" | 25 #include "components/scheduler/renderer/renderer_scheduler.h" |
26 #include "content/child/npapi/webplugin.h" | 26 #include "content/child/npapi/webplugin.h" |
| 27 #include "content/common/content_switches_internal.h" |
27 #include "content/common/gpu/client/context_provider_command_buffer.h" | 28 #include "content/common/gpu/client/context_provider_command_buffer.h" |
28 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 29 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
29 #include "content/common/gpu/gpu_process_launch_causes.h" | 30 #include "content/common/gpu/gpu_process_launch_causes.h" |
30 #include "content/common/input/synthetic_gesture_packet.h" | 31 #include "content/common/input/synthetic_gesture_packet.h" |
31 #include "content/common/input/web_input_event_traits.h" | 32 #include "content/common/input/web_input_event_traits.h" |
32 #include "content/common/input_messages.h" | 33 #include "content/common/input_messages.h" |
33 #include "content/common/swapped_out_messages.h" | 34 #include "content/common/swapped_out_messages.h" |
34 #include "content/common/view_messages.h" | 35 #include "content/common/view_messages.h" |
35 #include "content/public/common/content_switches.h" | 36 #include "content/public/common/content_switches.h" |
36 #include "content/public/common/context_menu_params.h" | 37 #include "content/public/common/context_menu_params.h" |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 // A resize ack shouldn't be requested if we have not ACK'd the previous | 762 // A resize ack shouldn't be requested if we have not ACK'd the previous |
762 // one. | 763 // one. |
763 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack()); | 764 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack()); |
764 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK); | 765 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK); |
765 } | 766 } |
766 | 767 |
767 // Ignore this during shutdown. | 768 // Ignore this during shutdown. |
768 if (!webwidget_) | 769 if (!webwidget_) |
769 return; | 770 return; |
770 | 771 |
771 if (compositor_) { | 772 if (compositor_) |
772 compositor_->setViewportSize(new_size, physical_backing_size); | 773 compositor_->setViewportSize(physical_backing_size); |
773 } | |
774 | 774 |
| 775 bool resized = size_ != new_size || |
| 776 physical_backing_size_ != physical_backing_size; |
| 777 |
| 778 size_ = new_size; |
775 physical_backing_size_ = physical_backing_size; | 779 physical_backing_size_ = physical_backing_size; |
| 780 |
776 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size; | 781 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size; |
777 top_controls_height_ = top_controls_height; | 782 top_controls_height_ = top_controls_height; |
778 visible_viewport_size_ = visible_viewport_size; | 783 if (IsUseZoomForDSFEnabled()) { |
| 784 gfx::SizeF scaled_visible_viewport_size = |
| 785 gfx::ScaleSize(gfx::SizeF(visible_viewport_size), device_scale_factor_); |
| 786 visible_viewport_size_ = gfx::ToCeiledSize(scaled_visible_viewport_size); |
| 787 } else { |
| 788 visible_viewport_size_ = visible_viewport_size; |
| 789 } |
779 resizer_rect_ = resizer_rect; | 790 resizer_rect_ = resizer_rect; |
780 | 791 |
781 // NOTE: We may have entered fullscreen mode without changing our size. | 792 // NOTE: We may have entered fullscreen mode without changing our size. |
782 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted; | 793 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted; |
783 is_fullscreen_granted_ = is_fullscreen_granted; | 794 is_fullscreen_granted_ = is_fullscreen_granted; |
784 display_mode_ = display_mode; | 795 display_mode_ = display_mode; |
785 | 796 |
786 webwidget_->setTopControlsHeight(top_controls_height, | 797 webwidget_->setTopControlsHeight(top_controls_height, |
787 top_controls_shrink_blink_size_); | 798 top_controls_shrink_blink_size_); |
788 | 799 |
789 if (size_ != new_size) { | 800 if (resized) { |
790 size_ = new_size; | 801 gfx::Size new_widget_size = |
791 | 802 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_; |
792 // When resizing, we want to wait to paint before ACK'ing the resize. This | 803 // When resizing, we want to wait to paint before ACK'ing the resize. This |
793 // ensures that we only resize as fast as we can paint. We only need to | 804 // ensures that we only resize as fast as we can paint. We only need to |
794 // send an ACK if we are resized to a non-empty rect. | 805 // send an ACK if we are resized to a non-empty rect. |
795 webwidget_->resize(new_size); | 806 webwidget_->resize(new_widget_size); |
796 } | 807 } |
797 | 808 |
798 webwidget()->resizePinchViewport(gfx::Size( | 809 webwidget()->resizePinchViewport(gfx::Size( |
799 visible_viewport_size.width(), | 810 visible_viewport_size_.width(), |
800 visible_viewport_size.height())); | 811 visible_viewport_size_.height())); |
801 | 812 |
802 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) { | 813 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) { |
803 // In this case there is no paint/composite and therefore no | 814 // In this case there is no paint/composite and therefore no |
804 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the | 815 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the |
805 // ack through a fake ViewHostMsg_UpdateRect or a different message. | 816 // ack through a fake ViewHostMsg_UpdateRect or a different message. |
806 DCHECK_EQ(resize_ack, NO_RESIZE_ACK); | 817 DCHECK_EQ(resize_ack, NO_RESIZE_ACK); |
807 } | 818 } |
808 | 819 |
809 // Send the Resize_ACK flag once we paint again if requested. | 820 // Send the Resize_ACK flag once we paint again if requested. |
810 if (resize_ack == SEND_RESIZE_ACK) | 821 if (resize_ack == SEND_RESIZE_ACK) |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 pending_input_event_ack_.get()); | 1314 pending_input_event_ack_.get()); |
1304 Send(pending_input_event_ack_.release()); | 1315 Send(pending_input_event_ack_.release()); |
1305 } | 1316 } |
1306 total_input_handling_time_this_frame_ = base::TimeDelta(); | 1317 total_input_handling_time_this_frame_ = base::TimeDelta(); |
1307 } | 1318 } |
1308 | 1319 |
1309 /////////////////////////////////////////////////////////////////////////////// | 1320 /////////////////////////////////////////////////////////////////////////////// |
1310 // WebWidgetClient | 1321 // WebWidgetClient |
1311 | 1322 |
1312 void RenderWidget::didAutoResize(const WebSize& new_size) { | 1323 void RenderWidget::didAutoResize(const WebSize& new_size) { |
| 1324 // TODO(oshima): support UseZoomForDSFEnabled() |
1313 if (size_.width() != new_size.width || size_.height() != new_size.height) { | 1325 if (size_.width() != new_size.width || size_.height() != new_size.height) { |
1314 size_ = new_size; | 1326 size_ = new_size; |
1315 | 1327 |
1316 if (resizing_mode_selector_->is_synchronous_mode()) { | 1328 if (resizing_mode_selector_->is_synchronous_mode()) { |
1317 WebRect new_pos(rootWindowRect().x, | 1329 WebRect new_pos(rootWindowRect().x, |
1318 rootWindowRect().y, | 1330 rootWindowRect().y, |
1319 new_size.width, | 1331 new_size.width, |
1320 new_size.height); | 1332 new_size.height); |
1321 view_screen_rect_ = new_pos; | 1333 view_screen_rect_ = new_pos; |
1322 window_screen_rect_ = new_pos; | 1334 window_screen_rect_ = new_pos; |
1323 } | 1335 } |
1324 | 1336 |
1325 AutoResizeCompositor(); | 1337 AutoResizeCompositor(); |
1326 | 1338 |
1327 if (!resizing_mode_selector_->is_synchronous_mode()) | 1339 if (!resizing_mode_selector_->is_synchronous_mode()) |
1328 need_update_rect_for_auto_resize_ = true; | 1340 need_update_rect_for_auto_resize_ = true; |
1329 } | 1341 } |
1330 } | 1342 } |
1331 | 1343 |
1332 void RenderWidget::AutoResizeCompositor() { | 1344 void RenderWidget::AutoResizeCompositor() { |
1333 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_); | 1345 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_); |
1334 if (compositor_) | 1346 if (compositor_) |
1335 compositor_->setViewportSize(size_, physical_backing_size_); | 1347 compositor_->setViewportSize(physical_backing_size_); |
1336 } | 1348 } |
1337 | 1349 |
1338 void RenderWidget::initializeLayerTreeView() { | 1350 void RenderWidget::initializeLayerTreeView() { |
1339 DCHECK(!host_closing_); | 1351 DCHECK(!host_closing_); |
1340 | 1352 |
1341 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); | 1353 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); |
1342 compositor_->setViewportSize(size_, physical_backing_size_); | 1354 compositor_->setViewportSize(physical_backing_size_); |
1343 | 1355 |
1344 // For background pages and certain tests, we don't want to trigger | 1356 // For background pages and certain tests, we don't want to trigger |
1345 // OutputSurface creation. | 1357 // OutputSurface creation. |
1346 if (compositor_never_visible_ || !RenderThreadImpl::current()) | 1358 if (compositor_never_visible_ || !RenderThreadImpl::current()) |
1347 compositor_->SetNeverVisible(); | 1359 compositor_->SetNeverVisible(); |
1348 | 1360 |
1349 StartCompositor(); | 1361 StartCompositor(); |
1350 } | 1362 } |
1351 | 1363 |
1352 void RenderWidget::WillCloseLayerTreeView() { | 1364 void RenderWidget::WillCloseLayerTreeView() { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 | 1602 |
1591 return view_screen_rect_; | 1603 return view_screen_rect_; |
1592 } | 1604 } |
1593 | 1605 |
1594 void RenderWidget::setToolTipText(const blink::WebString& text, | 1606 void RenderWidget::setToolTipText(const blink::WebString& text, |
1595 WebTextDirection hint) { | 1607 WebTextDirection hint) { |
1596 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); | 1608 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); |
1597 } | 1609 } |
1598 | 1610 |
1599 void RenderWidget::setWindowRect(const WebRect& rect) { | 1611 void RenderWidget::setWindowRect(const WebRect& rect) { |
| 1612 // TODO(oshima): Scale back to DIP coordinates. |
1600 WebRect window_rect = rect; | 1613 WebRect window_rect = rect; |
1601 if (popup_origin_scale_for_emulation_) { | 1614 if (popup_origin_scale_for_emulation_) { |
1602 float scale = popup_origin_scale_for_emulation_; | 1615 float scale = popup_origin_scale_for_emulation_; |
1603 window_rect.x = popup_screen_origin_for_emulation_.x() + | 1616 window_rect.x = popup_screen_origin_for_emulation_.x() + |
1604 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale; | 1617 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale; |
1605 window_rect.y = popup_screen_origin_for_emulation_.y() + | 1618 window_rect.y = popup_screen_origin_for_emulation_.y() + |
1606 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale; | 1619 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale; |
1607 } | 1620 } |
1608 | 1621 |
1609 if (!resizing_mode_selector_->is_synchronous_mode()) { | 1622 if (!resizing_mode_selector_->is_synchronous_mode()) { |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 text_input_mode_ = new_mode; | 1950 text_input_mode_ = new_mode; |
1938 can_compose_inline_ = new_can_compose_inline; | 1951 can_compose_inline_ = new_can_compose_inline; |
1939 text_input_flags_ = new_info.flags; | 1952 text_input_flags_ = new_info.flags; |
1940 } | 1953 } |
1941 } | 1954 } |
1942 | 1955 |
1943 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { | 1956 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
1944 WebRect focus_webrect; | 1957 WebRect focus_webrect; |
1945 WebRect anchor_webrect; | 1958 WebRect anchor_webrect; |
1946 webwidget_->selectionBounds(focus_webrect, anchor_webrect); | 1959 webwidget_->selectionBounds(focus_webrect, anchor_webrect); |
1947 *focus = focus_webrect; | 1960 if (IsUseZoomForDSFEnabled()) { |
1948 *anchor = anchor_webrect; | 1961 float inverse_scale = 1.f / device_scale_factor_; |
| 1962 gfx::RectF focus_rect(focus_webrect); |
| 1963 *focus = gfx::ToEnclosingRect(gfx::ScaleRect(focus_rect, inverse_scale)); |
| 1964 gfx::RectF anchor_rect(anchor_webrect); |
| 1965 *anchor = gfx::ToEnclosingRect(gfx::ScaleRect(anchor_rect, inverse_scale)); |
| 1966 } else { |
| 1967 *focus = focus_webrect; |
| 1968 *anchor = anchor_webrect; |
| 1969 } |
1949 } | 1970 } |
1950 | 1971 |
1951 void RenderWidget::UpdateSelectionBounds() { | 1972 void RenderWidget::UpdateSelectionBounds() { |
1952 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); | 1973 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); |
1953 if (!webwidget_) | 1974 if (!webwidget_) |
1954 return; | 1975 return; |
1955 if (handling_ime_event_) | 1976 if (handling_ime_event_) |
1956 return; | 1977 return; |
1957 | 1978 |
1958 #if defined(USE_AURA) | 1979 #if defined(USE_AURA) |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2382 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2403 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2383 video_hole_frames_.AddObserver(frame); | 2404 video_hole_frames_.AddObserver(frame); |
2384 } | 2405 } |
2385 | 2406 |
2386 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2407 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2387 video_hole_frames_.RemoveObserver(frame); | 2408 video_hole_frames_.RemoveObserver(frame); |
2388 } | 2409 } |
2389 #endif // defined(VIDEO_HOLE) | 2410 #endif // defined(VIDEO_HOLE) |
2390 | 2411 |
2391 } // namespace content | 2412 } // namespace content |
OLD | NEW |