Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: content/renderer/render_widget.cc

Issue 1412663005: Introduce painted-device-scale-factor and use it when --enable-use-zoom-for-dsf is specified. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/render_widget.h ('k') | third_party/WebKit/Source/web/WebPagePopupImpl.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/render_widget_scheduling_state.h" 25 #include "components/scheduler/renderer/render_widget_scheduling_state.h"
26 #include "components/scheduler/renderer/renderer_scheduler.h" 26 #include "components/scheduler/renderer/renderer_scheduler.h"
27 #include "content/child/npapi/webplugin.h" 27 #include "content/child/npapi/webplugin.h"
28 #include "content/common/content_switches_internal.h"
28 #include "content/common/gpu/client/context_provider_command_buffer.h" 29 #include "content/common/gpu/client/context_provider_command_buffer.h"
29 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 30 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
30 #include "content/common/gpu/gpu_process_launch_causes.h" 31 #include "content/common/gpu/gpu_process_launch_causes.h"
31 #include "content/common/input/synthetic_gesture_packet.h" 32 #include "content/common/input/synthetic_gesture_packet.h"
32 #include "content/common/input/web_input_event_traits.h" 33 #include "content/common/input/web_input_event_traits.h"
33 #include "content/common/input_messages.h" 34 #include "content/common/input_messages.h"
34 #include "content/common/swapped_out_messages.h" 35 #include "content/common/swapped_out_messages.h"
35 #include "content/common/view_messages.h" 36 #include "content/common/view_messages.h"
36 #include "content/public/common/content_switches.h" 37 #include "content/public/common/content_switches.h"
37 #include "content/public/common/context_menu_params.h" 38 #include "content/public/common/context_menu_params.h"
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // A resize ack shouldn't be requested if we have not ACK'd the previous 786 // A resize ack shouldn't be requested if we have not ACK'd the previous
786 // one. 787 // one.
787 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack()); 788 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
788 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK); 789 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
789 } 790 }
790 791
791 // Ignore this during shutdown. 792 // Ignore this during shutdown.
792 if (!webwidget_) 793 if (!webwidget_)
793 return; 794 return;
794 795
795 if (compositor_) { 796 if (compositor_)
796 compositor_->setViewportSize(new_size, physical_backing_size); 797 compositor_->setViewportSize(physical_backing_size);
797 }
798 798
799 bool resized = size_ != new_size ||
800 physical_backing_size_ != physical_backing_size;
801
802 size_ = new_size;
799 physical_backing_size_ = physical_backing_size; 803 physical_backing_size_ = physical_backing_size;
804
800 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size; 805 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
801 top_controls_height_ = top_controls_height; 806 top_controls_height_ = top_controls_height;
802 visible_viewport_size_ = visible_viewport_size; 807 visible_viewport_size_ = visible_viewport_size;
803 resizer_rect_ = resizer_rect; 808 resizer_rect_ = resizer_rect;
804 809
805 // NOTE: We may have entered fullscreen mode without changing our size. 810 // NOTE: We may have entered fullscreen mode without changing our size.
806 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted; 811 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
807 is_fullscreen_granted_ = is_fullscreen_granted; 812 is_fullscreen_granted_ = is_fullscreen_granted;
808 display_mode_ = display_mode; 813 display_mode_ = display_mode;
809 814
810 webwidget_->setTopControlsHeight(top_controls_height, 815 webwidget_->setTopControlsHeight(top_controls_height,
811 top_controls_shrink_blink_size_); 816 top_controls_shrink_blink_size_);
812 817
813 if (size_ != new_size) { 818 if (resized) {
814 size_ = new_size; 819 gfx::Size new_widget_size =
815 820 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_;
816 // When resizing, we want to wait to paint before ACK'ing the resize. This 821 // When resizing, we want to wait to paint before ACK'ing the resize. This
817 // ensures that we only resize as fast as we can paint. We only need to 822 // ensures that we only resize as fast as we can paint. We only need to
818 // send an ACK if we are resized to a non-empty rect. 823 // send an ACK if we are resized to a non-empty rect.
819 webwidget_->resize(new_size); 824 webwidget_->resize(new_widget_size);
825 }
826 WebSize pinch_viewport_size;
827
828 if (IsUseZoomForDSFEnabled()) {
829 gfx::SizeF scaled_visible_viewport_size =
830 gfx::ScaleSize(gfx::SizeF(visible_viewport_size), device_scale_factor_);
831 pinch_viewport_size = gfx::ToCeiledSize(scaled_visible_viewport_size);
832 } else {
833 pinch_viewport_size = visible_viewport_size_;
820 } 834 }
821 835
822 webwidget()->resizePinchViewport(gfx::Size( 836 webwidget()->resizePinchViewport(pinch_viewport_size);
823 visible_viewport_size.width(),
824 visible_viewport_size.height()));
825 837
826 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) { 838 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
827 // In this case there is no paint/composite and therefore no 839 // In this case there is no paint/composite and therefore no
828 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the 840 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
829 // ack through a fake ViewHostMsg_UpdateRect or a different message. 841 // ack through a fake ViewHostMsg_UpdateRect or a different message.
830 DCHECK_EQ(resize_ack, NO_RESIZE_ACK); 842 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
831 } 843 }
832 844
833 // Send the Resize_ACK flag once we paint again if requested. 845 // Send the Resize_ACK flag once we paint again if requested.
834 if (resize_ack == SEND_RESIZE_ACK) 846 if (resize_ack == SEND_RESIZE_ACK)
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 pending_input_event_ack_.get()); 1339 pending_input_event_ack_.get());
1328 Send(pending_input_event_ack_.release()); 1340 Send(pending_input_event_ack_.release());
1329 } 1341 }
1330 total_input_handling_time_this_frame_ = base::TimeDelta(); 1342 total_input_handling_time_this_frame_ = base::TimeDelta();
1331 } 1343 }
1332 1344
1333 /////////////////////////////////////////////////////////////////////////////// 1345 ///////////////////////////////////////////////////////////////////////////////
1334 // WebWidgetClient 1346 // WebWidgetClient
1335 1347
1336 void RenderWidget::didAutoResize(const WebSize& new_size) { 1348 void RenderWidget::didAutoResize(const WebSize& new_size) {
1349 // TODO(oshima): support UseZoomForDSFEnabled()
1337 if (size_.width() != new_size.width || size_.height() != new_size.height) { 1350 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1338 size_ = new_size; 1351 size_ = new_size;
1339 1352
1340 if (resizing_mode_selector_->is_synchronous_mode()) { 1353 if (resizing_mode_selector_->is_synchronous_mode()) {
1341 WebRect new_pos(rootWindowRect().x, 1354 WebRect new_pos(rootWindowRect().x,
1342 rootWindowRect().y, 1355 rootWindowRect().y,
1343 new_size.width, 1356 new_size.width,
1344 new_size.height); 1357 new_size.height);
1345 view_screen_rect_ = new_pos; 1358 view_screen_rect_ = new_pos;
1346 window_screen_rect_ = new_pos; 1359 window_screen_rect_ = new_pos;
1347 } 1360 }
1348 1361
1349 AutoResizeCompositor(); 1362 AutoResizeCompositor();
1350 1363
1351 if (!resizing_mode_selector_->is_synchronous_mode()) 1364 if (!resizing_mode_selector_->is_synchronous_mode())
1352 need_update_rect_for_auto_resize_ = true; 1365 need_update_rect_for_auto_resize_ = true;
1353 } 1366 }
1354 } 1367 }
1355 1368
1356 void RenderWidget::AutoResizeCompositor() { 1369 void RenderWidget::AutoResizeCompositor() {
1357 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_); 1370 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
1358 if (compositor_) 1371 if (compositor_)
1359 compositor_->setViewportSize(size_, physical_backing_size_); 1372 compositor_->setViewportSize(physical_backing_size_);
1360 } 1373 }
1361 1374
1362 void RenderWidget::initializeLayerTreeView() { 1375 void RenderWidget::initializeLayerTreeView() {
1363 DCHECK(!host_closing_); 1376 DCHECK(!host_closing_);
1364 1377
1365 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); 1378 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1366 compositor_->setViewportSize(size_, physical_backing_size_); 1379 compositor_->setViewportSize(physical_backing_size_);
1367 1380
1368 // For background pages and certain tests, we don't want to trigger 1381 // For background pages and certain tests, we don't want to trigger
1369 // OutputSurface creation. 1382 // OutputSurface creation.
1370 if (compositor_never_visible_ || !RenderThreadImpl::current()) 1383 if (compositor_never_visible_ || !RenderThreadImpl::current())
1371 compositor_->SetNeverVisible(); 1384 compositor_->SetNeverVisible();
1372 1385
1373 StartCompositor(); 1386 StartCompositor();
1374 } 1387 }
1375 1388
1376 void RenderWidget::WillCloseLayerTreeView() { 1389 void RenderWidget::WillCloseLayerTreeView() {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 1627
1615 return view_screen_rect_; 1628 return view_screen_rect_;
1616 } 1629 }
1617 1630
1618 void RenderWidget::setToolTipText(const blink::WebString& text, 1631 void RenderWidget::setToolTipText(const blink::WebString& text,
1619 WebTextDirection hint) { 1632 WebTextDirection hint) {
1620 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); 1633 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
1621 } 1634 }
1622 1635
1623 void RenderWidget::setWindowRect(const WebRect& rect) { 1636 void RenderWidget::setWindowRect(const WebRect& rect) {
1637 // TODO(oshima): Scale back to DIP coordinates.
1624 WebRect window_rect = rect; 1638 WebRect window_rect = rect;
1625 if (popup_origin_scale_for_emulation_) { 1639 if (popup_origin_scale_for_emulation_) {
1626 float scale = popup_origin_scale_for_emulation_; 1640 float scale = popup_origin_scale_for_emulation_;
1627 window_rect.x = popup_screen_origin_for_emulation_.x() + 1641 window_rect.x = popup_screen_origin_for_emulation_.x() +
1628 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale; 1642 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1629 window_rect.y = popup_screen_origin_for_emulation_.y() + 1643 window_rect.y = popup_screen_origin_for_emulation_.y() +
1630 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale; 1644 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
1631 } 1645 }
1632 1646
1633 if (!resizing_mode_selector_->is_synchronous_mode()) { 1647 if (!resizing_mode_selector_->is_synchronous_mode()) {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 text_input_mode_ = new_mode; 1978 text_input_mode_ = new_mode;
1965 can_compose_inline_ = new_can_compose_inline; 1979 can_compose_inline_ = new_can_compose_inline;
1966 text_input_flags_ = new_info.flags; 1980 text_input_flags_ = new_info.flags;
1967 } 1981 }
1968 } 1982 }
1969 1983
1970 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { 1984 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1971 WebRect focus_webrect; 1985 WebRect focus_webrect;
1972 WebRect anchor_webrect; 1986 WebRect anchor_webrect;
1973 webwidget_->selectionBounds(focus_webrect, anchor_webrect); 1987 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1974 *focus = focus_webrect; 1988 if (IsUseZoomForDSFEnabled()) {
1975 *anchor = anchor_webrect; 1989 float inverse_scale = 1.f / device_scale_factor_;
1990 gfx::RectF focus_rect(focus_webrect);
1991 *focus = gfx::ToEnclosingRect(gfx::ScaleRect(focus_rect, inverse_scale));
1992 gfx::RectF anchor_rect(anchor_webrect);
1993 *anchor = gfx::ToEnclosingRect(gfx::ScaleRect(anchor_rect, inverse_scale));
1994 } else {
1995 *focus = focus_webrect;
1996 *anchor = anchor_webrect;
1997 }
1976 } 1998 }
1977 1999
1978 void RenderWidget::UpdateSelectionBounds() { 2000 void RenderWidget::UpdateSelectionBounds() {
1979 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); 2001 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
1980 if (!webwidget_) 2002 if (!webwidget_)
1981 return; 2003 return;
1982 if (handling_ime_event_) 2004 if (handling_ime_event_)
1983 return; 2005 return;
1984 2006
1985 #if defined(USE_AURA) 2007 #if defined(USE_AURA)
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 #endif 2135 #endif
2114 2136
2115 bool RenderWidget::CanComposeInline() { 2137 bool RenderWidget::CanComposeInline() {
2116 return true; 2138 return true;
2117 } 2139 }
2118 2140
2119 WebScreenInfo RenderWidget::screenInfo() { 2141 WebScreenInfo RenderWidget::screenInfo() {
2120 return screen_info_; 2142 return screen_info_;
2121 } 2143 }
2122 2144
2123 float RenderWidget::deviceScaleFactor() {
2124 return device_scale_factor_;
2125 }
2126
2127 void RenderWidget::resetInputMethod() { 2145 void RenderWidget::resetInputMethod() {
2128 ImeEventGuard guard(this); 2146 ImeEventGuard guard(this);
2129 // If the last text input type is not None, then we should finish any 2147 // If the last text input type is not None, then we should finish any
2130 // ongoing composition regardless of the new text input type. 2148 // ongoing composition regardless of the new text input type.
2131 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 2149 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
2132 // If a composition text exists, then we need to let the browser process 2150 // If a composition text exists, then we need to let the browser process
2133 // to cancel the input method's ongoing composition session. 2151 // to cancel the input method's ongoing composition session.
2134 if (webwidget_->confirmComposition()) 2152 if (webwidget_->confirmComposition())
2135 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 2153 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
2136 } 2154 }
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2411 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { 2429 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2412 video_hole_frames_.AddObserver(frame); 2430 video_hole_frames_.AddObserver(frame);
2413 } 2431 }
2414 2432
2415 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { 2433 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2416 video_hole_frames_.RemoveObserver(frame); 2434 video_hole_frames_.RemoveObserver(frame);
2417 } 2435 }
2418 #endif // defined(VIDEO_HOLE) 2436 #endif // defined(VIDEO_HOLE)
2419 2437
2420 } // namespace content 2438 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | third_party/WebKit/Source/web/WebPagePopupImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698