OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/renderer_host/render_widget_host.h" | 5 #include "content/browser/renderer_host/render_widget_host.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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 : renderer_initialized_(false), | 82 : renderer_initialized_(false), |
83 renderer_accessible_(false), | 83 renderer_accessible_(false), |
84 view_(NULL), | 84 view_(NULL), |
85 process_(process), | 85 process_(process), |
86 routing_id_(routing_id), | 86 routing_id_(routing_id), |
87 is_loading_(false), | 87 is_loading_(false), |
88 is_hidden_(false), | 88 is_hidden_(false), |
89 is_accelerated_compositing_active_(false), | 89 is_accelerated_compositing_active_(false), |
90 repaint_ack_pending_(false), | 90 repaint_ack_pending_(false), |
91 resize_ack_pending_(false), | 91 resize_ack_pending_(false), |
| 92 should_auto_size_(false), |
92 mouse_move_pending_(false), | 93 mouse_move_pending_(false), |
93 mouse_wheel_pending_(false), | 94 mouse_wheel_pending_(false), |
94 touch_move_pending_(false), | 95 touch_move_pending_(false), |
95 touch_event_is_queued_(false), | 96 touch_event_is_queued_(false), |
96 needs_repainting_on_restore_(false), | 97 needs_repainting_on_restore_(false), |
97 is_unresponsive_(false), | 98 is_unresponsive_(false), |
98 in_get_backing_store_(false), | 99 in_get_backing_store_(false), |
99 view_being_painted_(false), | 100 view_being_painted_(false), |
100 ignore_input_events_(false), | 101 ignore_input_events_(false), |
101 text_direction_updated_(false), | 102 text_direction_updated_(false), |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 // | 325 // |
325 // TODO: ideally ViewMsg_WasRestored would take a size. This way, the renderer | 326 // TODO: ideally ViewMsg_WasRestored would take a size. This way, the renderer |
326 // could handle both the restore and resize at once. This isn't that big a | 327 // could handle both the restore and resize at once. This isn't that big a |
327 // deal as RenderWidget::WasRestored delays updating, so that the resize from | 328 // deal as RenderWidget::WasRestored delays updating, so that the resize from |
328 // WasResized is usually processed before the renderer is painted. | 329 // WasResized is usually processed before the renderer is painted. |
329 WasResized(); | 330 WasResized(); |
330 } | 331 } |
331 | 332 |
332 void RenderWidgetHost::WasResized() { | 333 void RenderWidgetHost::WasResized() { |
333 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || | 334 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || |
334 !renderer_initialized_) { | 335 !renderer_initialized_ || should_auto_size_) { |
335 return; | 336 return; |
336 } | 337 } |
337 | 338 |
338 #if !defined(OS_MACOSX) | 339 #if !defined(OS_MACOSX) |
339 gfx::Size new_size = view_->GetViewBounds().size(); | 340 gfx::Size new_size = view_->GetViewBounds().size(); |
340 #else | 341 #else |
341 // When UI scaling is enabled on OS X, allocate a smaller bitmap and | 342 // When UI scaling is enabled on OS X, allocate a smaller bitmap and |
342 // pixel-scale it up. | 343 // pixel-scale it up. |
343 // TODO(thakis): Use pixel size on mac and set UI scale in renderer. | 344 // TODO(thakis): Use pixel size on mac and set UI scale in renderer. |
344 // http://crbug.com/31960 | 345 // http://crbug.com/31960 |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 } | 843 } |
843 | 844 |
844 bool RenderWidgetHost::IsMouseLocked() const { | 845 bool RenderWidgetHost::IsMouseLocked() const { |
845 return view_ ? view_->mouse_locked() : false; | 846 return view_ ? view_->mouse_locked() : false; |
846 } | 847 } |
847 | 848 |
848 bool RenderWidgetHost::IsFullscreen() const { | 849 bool RenderWidgetHost::IsFullscreen() const { |
849 return false; | 850 return false; |
850 } | 851 } |
851 | 852 |
| 853 void RenderWidgetHost::setShouldAutoSize(bool enable) { |
| 854 // Note if this switches from true to false then one has to verify that the |
| 855 // mechanics about all the messaging works. For example, what happens to a |
| 856 // update message rect that was in progress from the render widget. Perhaps, |
| 857 // on a transition to false, this should do a WasResized, but what if that |
| 858 // will not trigger a resize message...etc. Due to these complications it is |
| 859 // fitting that this method doesn't look like a simple set method. |
| 860 DCHECK(enable); |
| 861 |
| 862 // TODO: Change this to enable instead of true when this supports turning |
| 863 // off autosize. |
| 864 should_auto_size_ = true; |
| 865 } |
| 866 |
852 void RenderWidgetHost::Destroy() { | 867 void RenderWidgetHost::Destroy() { |
853 content::NotificationService::current()->Notify( | 868 content::NotificationService::current()->Notify( |
854 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 869 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
855 content::Source<RenderWidgetHost>(this), | 870 content::Source<RenderWidgetHost>(this), |
856 content::NotificationService::NoDetails()); | 871 content::NotificationService::NoDetails()); |
857 | 872 |
858 // Tell the view to die. | 873 // Tell the view to die. |
859 // Note that in the process of the view shutting down, it can call a ton | 874 // Note that in the process of the view shutting down, it can call a ton |
860 // of other messages on us. So if you do any other deinitialization here, | 875 // of other messages on us. So if you do any other deinitialization here, |
861 // do it after this call to view_->Destroy(). | 876 // do it after this call to view_->Destroy(). |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 // Update our knowledge of the RenderWidget's size. | 980 // Update our knowledge of the RenderWidget's size. |
966 current_size_ = params.view_size; | 981 current_size_ = params.view_size; |
967 // Update our knowledge of the RenderWidget's scroll offset. | 982 // Update our knowledge of the RenderWidget's scroll offset. |
968 last_scroll_offset_ = params.scroll_offset; | 983 last_scroll_offset_ = params.scroll_offset; |
969 | 984 |
970 bool is_resize_ack = | 985 bool is_resize_ack = |
971 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); | 986 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); |
972 | 987 |
973 // resize_ack_pending_ needs to be cleared before we call DidPaintRect, since | 988 // resize_ack_pending_ needs to be cleared before we call DidPaintRect, since |
974 // that will end up reaching GetBackingStore. | 989 // that will end up reaching GetBackingStore. |
975 if (is_resize_ack) { | 990 if (is_resize_ack || should_auto_size_) { |
976 DCHECK(resize_ack_pending_); | 991 if (is_resize_ack) { |
977 resize_ack_pending_ = false; | 992 DCHECK(resize_ack_pending_); |
978 in_flight_size_.SetSize(0, 0); | 993 resize_ack_pending_ = false; |
979 in_flight_reserved_rect_.SetRect(0, 0, 0, 0); | 994 in_flight_size_.SetSize(0, 0); |
| 995 in_flight_reserved_rect_.SetRect(0, 0, 0, 0); |
| 996 } |
980 // Update our knowledge of the RenderWidget's resizer rect. | 997 // Update our knowledge of the RenderWidget's resizer rect. |
981 // ViewMsg_Resize is acknowledged only when view size is actually changed, | 998 // ViewMsg_Resize is acknowledged only when view size is actually changed, |
982 // otherwise current_reserved_rect_ is updated immediately after sending | 999 // otherwise current_reserved_rect_ is updated immediately after sending |
983 // ViewMsg_Resize to the RenderWidget and can be clobbered by | 1000 // ViewMsg_Resize to the RenderWidget and can be clobbered by |
984 // OnMsgUpdateRect called for a paint that was initiated before the resize | 1001 // OnMsgUpdateRect called for a paint that was initiated before the resize |
985 // message was sent. | 1002 // message was sent. |
986 current_reserved_rect_ = params.resizer_rect; | 1003 current_reserved_rect_ = params.resizer_rect; |
987 } | 1004 } |
988 | 1005 |
989 bool is_repaint_ack = | 1006 bool is_repaint_ack = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 base::Bind(&RenderWidgetHost::DidUpdateBackingStore, | 1047 base::Bind(&RenderWidgetHost::DidUpdateBackingStore, |
1031 weak_factory_.GetWeakPtr(), params, paint_start)); | 1048 weak_factory_.GetWeakPtr(), params, paint_start)); |
1032 } | 1049 } |
1033 } | 1050 } |
1034 } | 1051 } |
1035 | 1052 |
1036 if (!was_async) { | 1053 if (!was_async) { |
1037 DidUpdateBackingStore(params, paint_start); | 1054 DidUpdateBackingStore(params, paint_start); |
1038 } | 1055 } |
1039 | 1056 |
| 1057 if (should_auto_size_) { |
| 1058 OnRenderSizeChanged(params.view_size); |
| 1059 } |
| 1060 |
1040 // Log the time delta for processing a paint message. On platforms that don't | 1061 // Log the time delta for processing a paint message. On platforms that don't |
1041 // support asynchronous painting, this is equivalent to | 1062 // support asynchronous painting, this is equivalent to |
1042 // MPArch.RWH_TotalPaintTime. | 1063 // MPArch.RWH_TotalPaintTime. |
1043 TimeDelta delta = TimeTicks::Now() - paint_start; | 1064 TimeDelta delta = TimeTicks::Now() - paint_start; |
1044 UMA_HISTOGRAM_TIMES("MPArch.RWH_OnMsgUpdateRect", delta); | 1065 UMA_HISTOGRAM_TIMES("MPArch.RWH_OnMsgUpdateRect", delta); |
1045 } | 1066 } |
1046 | 1067 |
1047 void RenderWidgetHost::DidUpdateBackingStore( | 1068 void RenderWidgetHost::DidUpdateBackingStore( |
1048 const ViewHostMsg_UpdateRect_Params& params, | 1069 const ViewHostMsg_UpdateRect_Params& params, |
1049 const TimeTicks& paint_start) { | 1070 const TimeTicks& paint_start) { |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 } | 1508 } |
1488 | 1509 |
1489 // static | 1510 // static |
1490 void RenderWidgetHost::AcknowledgePostSubBuffer(int32 route_id, | 1511 void RenderWidgetHost::AcknowledgePostSubBuffer(int32 route_id, |
1491 int gpu_host_id) { | 1512 int gpu_host_id) { |
1492 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); | 1513 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); |
1493 if (ui_shim) | 1514 if (ui_shim) |
1494 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); | 1515 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); |
1495 } | 1516 } |
1496 #endif | 1517 #endif |
OLD | NEW |