Chromium Code Reviews| 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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 if (resizing_mode_selector_->NeverUsesSynchronousResize()) { | 761 if (resizing_mode_selector_->NeverUsesSynchronousResize()) { |
| 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; |
| 771 bool resized = size_ != new_size || | |
| 772 physical_backing_size_ != physical_backing_size; | |
| 770 | 773 |
| 771 if (compositor_) { | 774 size_ = new_size; |
| 772 compositor_->setViewportSize(new_size, physical_backing_size); | 775 physical_backing_size_ = physical_backing_size; |
| 773 } | |
| 774 | 776 |
| 775 physical_backing_size_ = physical_backing_size; | 777 UpdateCompositorViewportSize(); |
| 778 | |
| 776 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size; | 779 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size; |
| 777 top_controls_height_ = top_controls_height; | 780 top_controls_height_ = top_controls_height; |
| 778 visible_viewport_size_ = visible_viewport_size; | 781 if (IsUseZoomForDSFEnabled()) { |
| 782 gfx::SizeF scaled_visible_viewport_size = | |
| 783 gfx::ScaleSize(gfx::SizeF(visible_viewport_size), device_scale_factor_); | |
|
danakj
2015/10/22 23:15:29
It seems odd that you're scaling things here. And
oshima
2015/10/23 18:05:36
visible_viewport_size is in DIP so we have to mult
piman
2015/10/23 19:30:33
If you look at RenderViewImpl::OnDisableAutoResize
oshima
2015/10/23 23:50:05
You're right. It takes blink's coord (WebRect). I
| |
| 784 visible_viewport_size_ = gfx::ToCeiledSize(scaled_visible_viewport_size); | |
| 785 } else { | |
| 786 visible_viewport_size_ = visible_viewport_size; | |
| 787 } | |
| 779 resizer_rect_ = resizer_rect; | 788 resizer_rect_ = resizer_rect; |
| 780 | 789 |
| 781 // NOTE: We may have entered fullscreen mode without changing our size. | 790 // NOTE: We may have entered fullscreen mode without changing our size. |
| 782 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted; | 791 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted; |
| 783 is_fullscreen_granted_ = is_fullscreen_granted; | 792 is_fullscreen_granted_ = is_fullscreen_granted; |
| 784 display_mode_ = display_mode; | 793 display_mode_ = display_mode; |
| 785 | 794 |
| 786 webwidget_->setTopControlsHeight(top_controls_height, | 795 webwidget_->setTopControlsHeight(top_controls_height, |
| 787 top_controls_shrink_blink_size_); | 796 top_controls_shrink_blink_size_); |
| 788 | 797 |
| 789 if (size_ != new_size) { | 798 if (resized) { |
| 790 size_ = new_size; | 799 gfx::Size new_widget_size = |
| 791 | 800 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_; |
| 792 // When resizing, we want to wait to paint before ACK'ing the resize. This | 801 // 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 | 802 // 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. | 803 // send an ACK if we are resized to a non-empty rect. |
| 795 webwidget_->resize(new_size); | 804 webwidget_->resize(new_widget_size); |
| 796 } | 805 } |
| 797 | 806 |
| 798 webwidget()->resizePinchViewport(gfx::Size( | 807 webwidget()->resizePinchViewport(gfx::Size( |
| 799 visible_viewport_size.width(), | 808 visible_viewport_size_.width(), |
| 800 visible_viewport_size.height())); | 809 visible_viewport_size_.height())); |
| 801 | 810 |
| 802 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) { | 811 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) { |
| 803 // In this case there is no paint/composite and therefore no | 812 // 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 | 813 // 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. | 814 // ack through a fake ViewHostMsg_UpdateRect or a different message. |
| 806 DCHECK_EQ(resize_ack, NO_RESIZE_ACK); | 815 DCHECK_EQ(resize_ack, NO_RESIZE_ACK); |
| 807 } | 816 } |
| 808 | 817 |
| 809 // Send the Resize_ACK flag once we paint again if requested. | 818 // Send the Resize_ACK flag once we paint again if requested. |
| 810 if (resize_ack == SEND_RESIZE_ACK) | 819 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()); | 1312 pending_input_event_ack_.get()); |
| 1304 Send(pending_input_event_ack_.release()); | 1313 Send(pending_input_event_ack_.release()); |
| 1305 } | 1314 } |
| 1306 total_input_handling_time_this_frame_ = base::TimeDelta(); | 1315 total_input_handling_time_this_frame_ = base::TimeDelta(); |
| 1307 } | 1316 } |
| 1308 | 1317 |
| 1309 /////////////////////////////////////////////////////////////////////////////// | 1318 /////////////////////////////////////////////////////////////////////////////// |
| 1310 // WebWidgetClient | 1319 // WebWidgetClient |
| 1311 | 1320 |
| 1312 void RenderWidget::didAutoResize(const WebSize& new_size) { | 1321 void RenderWidget::didAutoResize(const WebSize& new_size) { |
| 1322 // TODO(oshima): support UseZoomForDSFEnabled() | |
| 1313 if (size_.width() != new_size.width || size_.height() != new_size.height) { | 1323 if (size_.width() != new_size.width || size_.height() != new_size.height) { |
| 1314 size_ = new_size; | 1324 size_ = new_size; |
| 1315 | 1325 |
| 1316 if (resizing_mode_selector_->is_synchronous_mode()) { | 1326 if (resizing_mode_selector_->is_synchronous_mode()) { |
| 1317 WebRect new_pos(rootWindowRect().x, | 1327 WebRect new_pos(rootWindowRect().x, |
| 1318 rootWindowRect().y, | 1328 rootWindowRect().y, |
| 1319 new_size.width, | 1329 new_size.width, |
| 1320 new_size.height); | 1330 new_size.height); |
| 1321 view_screen_rect_ = new_pos; | 1331 view_screen_rect_ = new_pos; |
| 1322 window_screen_rect_ = new_pos; | 1332 window_screen_rect_ = new_pos; |
| 1323 } | 1333 } |
| 1324 | 1334 |
| 1325 AutoResizeCompositor(); | 1335 AutoResizeCompositor(); |
| 1326 | 1336 |
| 1327 if (!resizing_mode_selector_->is_synchronous_mode()) | 1337 if (!resizing_mode_selector_->is_synchronous_mode()) |
| 1328 need_update_rect_for_auto_resize_ = true; | 1338 need_update_rect_for_auto_resize_ = true; |
| 1329 } | 1339 } |
| 1330 } | 1340 } |
| 1331 | 1341 |
| 1332 void RenderWidget::AutoResizeCompositor() { | 1342 void RenderWidget::AutoResizeCompositor() { |
| 1333 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_); | 1343 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_); |
| 1334 if (compositor_) | 1344 UpdateCompositorViewportSize(); |
| 1335 compositor_->setViewportSize(size_, physical_backing_size_); | |
| 1336 } | 1345 } |
| 1337 | 1346 |
| 1338 void RenderWidget::initializeLayerTreeView() { | 1347 void RenderWidget::initializeLayerTreeView() { |
| 1339 DCHECK(!host_closing_); | 1348 DCHECK(!host_closing_); |
| 1340 | 1349 |
| 1341 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); | 1350 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); |
| 1342 compositor_->setViewportSize(size_, physical_backing_size_); | 1351 UpdateCompositorViewportSize(); |
| 1343 | 1352 |
| 1344 // For background pages and certain tests, we don't want to trigger | 1353 // For background pages and certain tests, we don't want to trigger |
| 1345 // OutputSurface creation. | 1354 // OutputSurface creation. |
| 1346 if (compositor_never_visible_ || !RenderThreadImpl::current()) | 1355 if (compositor_never_visible_ || !RenderThreadImpl::current()) |
| 1347 compositor_->SetNeverVisible(); | 1356 compositor_->SetNeverVisible(); |
| 1348 | 1357 |
| 1349 StartCompositor(); | 1358 StartCompositor(); |
| 1350 } | 1359 } |
| 1351 | 1360 |
| 1352 void RenderWidget::WillCloseLayerTreeView() { | 1361 void RenderWidget::WillCloseLayerTreeView() { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1590 | 1599 |
| 1591 return view_screen_rect_; | 1600 return view_screen_rect_; |
| 1592 } | 1601 } |
| 1593 | 1602 |
| 1594 void RenderWidget::setToolTipText(const blink::WebString& text, | 1603 void RenderWidget::setToolTipText(const blink::WebString& text, |
| 1595 WebTextDirection hint) { | 1604 WebTextDirection hint) { |
| 1596 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); | 1605 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); |
| 1597 } | 1606 } |
| 1598 | 1607 |
| 1599 void RenderWidget::setWindowRect(const WebRect& rect) { | 1608 void RenderWidget::setWindowRect(const WebRect& rect) { |
| 1609 // TODO(oshima): Scale back to DIP coordinates. | |
| 1600 WebRect window_rect = rect; | 1610 WebRect window_rect = rect; |
| 1601 if (popup_origin_scale_for_emulation_) { | 1611 if (popup_origin_scale_for_emulation_) { |
| 1602 float scale = popup_origin_scale_for_emulation_; | 1612 float scale = popup_origin_scale_for_emulation_; |
| 1603 window_rect.x = popup_screen_origin_for_emulation_.x() + | 1613 window_rect.x = popup_screen_origin_for_emulation_.x() + |
| 1604 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale; | 1614 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale; |
| 1605 window_rect.y = popup_screen_origin_for_emulation_.y() + | 1615 window_rect.y = popup_screen_origin_for_emulation_.y() + |
| 1606 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale; | 1616 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale; |
| 1607 } | 1617 } |
| 1608 | 1618 |
| 1609 if (!resizing_mode_selector_->is_synchronous_mode()) { | 1619 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; | 1947 text_input_mode_ = new_mode; |
| 1938 can_compose_inline_ = new_can_compose_inline; | 1948 can_compose_inline_ = new_can_compose_inline; |
| 1939 text_input_flags_ = new_info.flags; | 1949 text_input_flags_ = new_info.flags; |
| 1940 } | 1950 } |
| 1941 } | 1951 } |
| 1942 | 1952 |
| 1943 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { | 1953 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
| 1944 WebRect focus_webrect; | 1954 WebRect focus_webrect; |
| 1945 WebRect anchor_webrect; | 1955 WebRect anchor_webrect; |
| 1946 webwidget_->selectionBounds(focus_webrect, anchor_webrect); | 1956 webwidget_->selectionBounds(focus_webrect, anchor_webrect); |
| 1947 *focus = focus_webrect; | 1957 if (IsUseZoomForDSFEnabled()) { |
| 1948 *anchor = anchor_webrect; | 1958 float inverse_scale = 1.f / device_scale_factor_; |
| 1959 gfx::RectF focus_rect(focus_webrect); | |
| 1960 *focus = gfx::ToEnclosingRect(gfx::ScaleRect(focus_rect, inverse_scale)); | |
| 1961 gfx::RectF anchor_rect(anchor_webrect); | |
| 1962 *anchor = gfx::ToEnclosingRect(gfx::ScaleRect(anchor_rect, inverse_scale)); | |
| 1963 } else { | |
| 1964 *focus = focus_webrect; | |
| 1965 *anchor = anchor_webrect; | |
| 1966 } | |
| 1949 } | 1967 } |
| 1950 | 1968 |
| 1951 void RenderWidget::UpdateSelectionBounds() { | 1969 void RenderWidget::UpdateSelectionBounds() { |
| 1952 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); | 1970 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); |
| 1953 if (!webwidget_) | 1971 if (!webwidget_) |
| 1954 return; | 1972 return; |
| 1955 if (handling_ime_event_) | 1973 if (handling_ime_event_) |
| 1956 return; | 1974 return; |
| 1957 | 1975 |
| 1958 #if defined(USE_AURA) | 1976 #if defined(USE_AURA) |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2355 limits.min_transfer_buffer_size = 64 * 1024; | 2373 limits.min_transfer_buffer_size = 64 * 1024; |
| 2356 } | 2374 } |
| 2357 | 2375 |
| 2358 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 2376 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 2359 new WebGraphicsContext3DCommandBufferImpl( | 2377 new WebGraphicsContext3DCommandBufferImpl( |
| 2360 0, GetURLForGraphicsContext3D(), gpu_channel_host.get(), attributes, | 2378 0, GetURLForGraphicsContext3D(), gpu_channel_host.get(), attributes, |
| 2361 lose_context_when_out_of_memory, limits, NULL)); | 2379 lose_context_when_out_of_memory, limits, NULL)); |
| 2362 return context.Pass(); | 2380 return context.Pass(); |
| 2363 } | 2381 } |
| 2364 | 2382 |
| 2383 void RenderWidget::UpdateCompositorViewportSize() { | |
| 2384 if (!compositor_) | |
| 2385 return; | |
| 2386 if (IsUseZoomForDSFEnabled()) { | |
| 2387 compositor_->setViewportSize(size_, physical_backing_size_); | |
|
danakj
2015/10/22 23:15:29
The function that takes 2 args here should probabl
oshima
2015/10/23 18:05:36
Ah, I didn't know about that. Changed to use singl
| |
| 2388 } else { | |
| 2389 compositor_->setViewportSize(physical_backing_size_, | |
| 2390 physical_backing_size_); | |
| 2391 } | |
| 2392 } | |
| 2393 | |
| 2365 void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) { | 2394 void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) { |
| 2366 render_frame_proxies_.AddObserver(proxy); | 2395 render_frame_proxies_.AddObserver(proxy); |
| 2367 } | 2396 } |
| 2368 | 2397 |
| 2369 void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) { | 2398 void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) { |
| 2370 render_frame_proxies_.RemoveObserver(proxy); | 2399 render_frame_proxies_.RemoveObserver(proxy); |
| 2371 } | 2400 } |
| 2372 | 2401 |
| 2373 void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) { | 2402 void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) { |
| 2374 render_frames_.AddObserver(frame); | 2403 render_frames_.AddObserver(frame); |
| 2375 } | 2404 } |
| 2376 | 2405 |
| 2377 void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) { | 2406 void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) { |
| 2378 render_frames_.RemoveObserver(frame); | 2407 render_frames_.RemoveObserver(frame); |
| 2379 } | 2408 } |
| 2380 | 2409 |
| 2381 #if defined(VIDEO_HOLE) | 2410 #if defined(VIDEO_HOLE) |
| 2382 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2411 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2383 video_hole_frames_.AddObserver(frame); | 2412 video_hole_frames_.AddObserver(frame); |
| 2384 } | 2413 } |
| 2385 | 2414 |
| 2386 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2415 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2387 video_hole_frames_.RemoveObserver(frame); | 2416 video_hole_frames_.RemoveObserver(frame); |
| 2388 } | 2417 } |
| 2389 #endif // defined(VIDEO_HOLE) | 2418 #endif // defined(VIDEO_HOLE) |
| 2390 | 2419 |
| 2391 } // namespace content | 2420 } // namespace content |
| OLD | NEW |