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

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 11293121: Add latency measurement system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: create cc::LatencyInfo Created 7 years, 11 months 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 | Annotate | Revision Log
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/browser/renderer_host/render_widget_host_impl.h" 5 #include "content/browser/renderer_host/render_widget_host_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, 94 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event,
95 const WebMouseWheelEvent& new_event) { 95 const WebMouseWheelEvent& new_event) {
96 return last_event.modifiers == new_event.modifiers && 96 return last_event.modifiers == new_event.modifiers &&
97 last_event.scrollByPage == new_event.scrollByPage && 97 last_event.scrollByPage == new_event.scrollByPage &&
98 last_event.hasPreciseScrollingDeltas 98 last_event.hasPreciseScrollingDeltas
99 == new_event.hasPreciseScrollingDeltas && 99 == new_event.hasPreciseScrollingDeltas &&
100 last_event.phase == new_event.phase && 100 last_event.phase == new_event.phase &&
101 last_event.momentumPhase == new_event.momentumPhase; 101 last_event.momentumPhase == new_event.momentumPhase;
102 } 102 }
103 103
104 int64 g_current_input_number;
105
104 } // namespace 106 } // namespace
105 107
106 108
107 // static 109 // static
108 void RenderWidgetHost::RemoveAllBackingStores() { 110 void RenderWidgetHost::RemoveAllBackingStores() {
109 BackingStoreManager::RemoveAllBackingStores(); 111 BackingStoreManager::RemoveAllBackingStores();
110 } 112 }
111 113
112 // static 114 // static
113 size_t RenderWidgetHost::BackingStoreMemorySize() { 115 size_t RenderWidgetHost::BackingStoreMemorySize() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 text_direction_updated_(false), 150 text_direction_updated_(false),
149 text_direction_(WebKit::WebTextDirectionLeftToRight), 151 text_direction_(WebKit::WebTextDirectionLeftToRight),
150 text_direction_canceled_(false), 152 text_direction_canceled_(false),
151 suppress_next_char_events_(false), 153 suppress_next_char_events_(false),
152 pending_mouse_lock_request_(false), 154 pending_mouse_lock_request_(false),
153 allow_privileged_mouse_lock_(false), 155 allow_privileged_mouse_lock_(false),
154 has_touch_handler_(false), 156 has_touch_handler_(false),
155 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 157 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
156 tick_active_smooth_scroll_gestures_task_posted_(false), 158 tick_active_smooth_scroll_gestures_task_posted_(false),
157 touch_event_queue_(new TouchEventQueue(this)), 159 touch_event_queue_(new TouchEventQueue(this)),
158 gesture_event_filter_(new GestureEventFilter(this)) { 160 gesture_event_filter_(new GestureEventFilter(this)),
161 incremented_input_number_(false),
162 current_input_number_(0) {
159 CHECK(delegate_); 163 CHECK(delegate_);
160 if (routing_id_ == MSG_ROUTING_NONE) { 164 if (routing_id_ == MSG_ROUTING_NONE) {
161 routing_id_ = process_->GetNextRoutingID(); 165 routing_id_ = process_->GetNextRoutingID();
162 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( 166 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer(
163 process_->GetID(), 167 process_->GetID(),
164 routing_id_); 168 routing_id_);
165 } else { 169 } else {
166 // TODO(piman): This is a O(N) lookup, where we could forward the 170 // TODO(piman): This is a O(N) lookup, where we could forward the
167 // information from the RenderWidgetHelper. The problem is that doing so 171 // information from the RenderWidgetHelper. The problem is that doing so
168 // currently leaks outside of content all the way to chrome classes, and 172 // currently leaks outside of content all the way to chrome classes, and
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // When accelerated compositing is on, we must always repaint, even when 438 // When accelerated compositing is on, we must always repaint, even when
435 // the backing store exists. 439 // the backing store exists.
436 bool needs_repainting; 440 bool needs_repainting;
437 if (needs_repainting_on_restore_ || !backing_store || 441 if (needs_repainting_on_restore_ || !backing_store ||
438 is_accelerated_compositing_active()) { 442 is_accelerated_compositing_active()) {
439 needs_repainting = true; 443 needs_repainting = true;
440 needs_repainting_on_restore_ = false; 444 needs_repainting_on_restore_ = false;
441 } else { 445 } else {
442 needs_repainting = false; 446 needs_repainting = false;
443 } 447 }
448
449 SendStartFrame();
450
444 Send(new ViewMsg_WasShown(routing_id_, needs_repainting)); 451 Send(new ViewMsg_WasShown(routing_id_, needs_repainting));
445 452
446 process_->WidgetRestored(); 453 process_->WidgetRestored();
447 454
448 bool is_visible = true; 455 bool is_visible = true;
449 NotificationService::current()->Notify( 456 NotificationService::current()->Notify(
450 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 457 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
451 Source<RenderWidgetHost>(this), 458 Source<RenderWidgetHost>(this),
452 Details<bool>(&is_visible)); 459 Details<bool>(&is_visible));
453 460
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 return; 496 return;
490 497
491 if (in_flight_size_ != gfx::Size() && new_size == in_flight_size_ && 498 if (in_flight_size_ != gfx::Size() && new_size == in_flight_size_ &&
492 !fullscreen_changed) 499 !fullscreen_changed)
493 return; 500 return;
494 501
495 // We don't expect to receive an ACK when the requested size is empty. 502 // We don't expect to receive an ACK when the requested size is empty.
496 if (!new_size.IsEmpty() && size_changed) 503 if (!new_size.IsEmpty() && size_changed)
497 resize_ack_pending_ = true; 504 resize_ack_pending_ = true;
498 505
506 SendStartFrame();
499 if (!Send(new ViewMsg_Resize(routing_id_, new_size, 507 if (!Send(new ViewMsg_Resize(routing_id_, new_size,
500 GetRootWindowResizerRect(), is_fullscreen_))) { 508 GetRootWindowResizerRect(), is_fullscreen_))) {
501 resize_ack_pending_ = false; 509 resize_ack_pending_ = false;
502 } else { 510 } else {
503 in_flight_size_ = new_size; 511 in_flight_size_ = new_size;
504 } 512 }
505 } 513 }
506 514
507 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) { 515 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) {
508 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect)); 516 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect));
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 "x", mouse_event.x, "y", mouse_event.y); 906 "x", mouse_event.x, "y", mouse_event.y);
899 if (ignore_input_events_ || process_->IgnoreInputEvents()) 907 if (ignore_input_events_ || process_->IgnoreInputEvents())
900 return; 908 return;
901 909
902 if (CommandLine::ForCurrentProcess()->HasSwitch( 910 if (CommandLine::ForCurrentProcess()->HasSwitch(
903 switches::kSimulateTouchScreenWithMouse)) { 911 switches::kSimulateTouchScreenWithMouse)) {
904 SimulateTouchGestureWithMouse(mouse_event); 912 SimulateTouchGestureWithMouse(mouse_event);
905 return; 913 return;
906 } 914 }
907 915
916 IncrementInputNumber();
917
908 if (mouse_event.type == WebInputEvent::MouseDown && 918 if (mouse_event.type == WebInputEvent::MouseDown &&
909 gesture_event_filter_->GetTapSuppressionController()-> 919 gesture_event_filter_->GetTapSuppressionController()->
910 ShouldDeferMouseDown(mouse_event)) 920 ShouldDeferMouseDown(mouse_event))
911 return; 921 return;
912 if (mouse_event.type == WebInputEvent::MouseUp && 922 if (mouse_event.type == WebInputEvent::MouseUp &&
913 gesture_event_filter_->GetTapSuppressionController()-> 923 gesture_event_filter_->GetTapSuppressionController()->
914 ShouldSuppressMouseUp()) 924 ShouldSuppressMouseUp())
915 return; 925 return;
916 926
917 ForwardMouseEventImmediately(mouse_event); 927 ForwardMouseEventImmediately(mouse_event);
918 } 928 }
919 929
920 void RenderWidgetHostImpl::OnPointerEventActivate() { 930 void RenderWidgetHostImpl::OnPointerEventActivate() {
921 } 931 }
922 932
923 void RenderWidgetHostImpl::ForwardWheelEvent( 933 void RenderWidgetHostImpl::ForwardWheelEvent(
924 const WebMouseWheelEvent& wheel_event) { 934 const WebMouseWheelEvent& wheel_event) {
925 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardWheelEvent"); 935 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardWheelEvent");
926 if (ignore_input_events_ || process_->IgnoreInputEvents()) 936 if (ignore_input_events_ || process_->IgnoreInputEvents())
927 return; 937 return;
928 938
939 IncrementInputNumber();
929 // If there's already a mouse wheel event waiting to be sent to the renderer, 940 // If there's already a mouse wheel event waiting to be sent to the renderer,
930 // add the new deltas to that event. Not doing so (e.g., by dropping the old 941 // add the new deltas to that event. Not doing so (e.g., by dropping the old
931 // event, as for mouse moves) results in very slow scrolling on the Mac (on 942 // event, as for mouse moves) results in very slow scrolling on the Mac (on
932 // which many, very small wheel events are sent). 943 // which many, very small wheel events are sent).
933 if (mouse_wheel_pending_) { 944 if (mouse_wheel_pending_) {
934 if (coalesced_mouse_wheel_events_.empty() || 945 if (coalesced_mouse_wheel_events_.empty() ||
935 !ShouldCoalesceMouseWheelEvents(coalesced_mouse_wheel_events_.back(), 946 !ShouldCoalesceMouseWheelEvents(coalesced_mouse_wheel_events_.back(),
936 wheel_event)) { 947 wheel_event)) {
937 coalesced_mouse_wheel_events_.push_back(wheel_event); 948 coalesced_mouse_wheel_events_.push_back(wheel_event);
938 } else { 949 } else {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); 1094 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size());
1084 1095
1085 gesture_event_filter_->FlingHasBeenHalted(); 1096 gesture_event_filter_->FlingHasBeenHalted();
1086 1097
1087 // Only forward the non-native portions of our event. 1098 // Only forward the non-native portions of our event.
1088 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), 1099 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent),
1089 is_keyboard_shortcut); 1100 is_keyboard_shortcut);
1090 } 1101 }
1091 } 1102 }
1092 1103
1104 void RenderWidgetHostImpl::IncrementInputNumber() {
1105 if (incremented_input_number_)
1106 return;
1107 g_current_input_number++;
1108 current_input_number_ = g_current_input_number;
1109 incremented_input_number_ = true;
1110 TRACE_EVENT_ASYNC_BEGIN1("frame", "Input processing", this,
1111 "input_number", current_input_number_);
1112 }
1113
1114 void RenderWidgetHostImpl::SendStartFrame() {
1115 IncrementInputNumber();
1116 TRACE_EVENT_ASYNC_END1("frame", "Input processing", this,
1117 "input_number", current_input_number_);
1118 Send(new ViewMsg_StartFrame(routing_id_, current_input_number_));
1119 incremented_input_number_ = false;
1120 }
1121
1093 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, 1122 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event,
1094 int event_size, 1123 int event_size,
1095 bool is_keyboard_shortcut) { 1124 bool is_keyboard_shortcut) {
1125 IncrementInputNumber();
1126 incremented_input_number_ = false;
1127
1128 TRACE_EVENT_ASYNC_END1("frame", "Input processing", this,
1129 "input_number", current_input_number_);
1130
1096 input_event_start_time_ = TimeTicks::Now(); 1131 input_event_start_time_ = TimeTicks::Now();
1097 Send(new ViewMsg_HandleInputEvent( 1132 Send(new ViewMsg_HandleInputEvent(
1098 routing_id_, &input_event, is_keyboard_shortcut)); 1133 routing_id_, current_input_number_, &input_event, is_keyboard_shortcut));
1099 increment_in_flight_event_count(); 1134 increment_in_flight_event_count();
1100 } 1135 }
1101 1136
1102 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event, 1137 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event,
1103 int event_size, 1138 int event_size,
1104 bool is_keyboard_shortcut) { 1139 bool is_keyboard_shortcut) {
1105 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); 1140 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent");
1106 1141
1107 if (!process_->HasConnection()) 1142 if (!process_->HasConnection())
1108 return; 1143 return;
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 frame.metadata.page_scale_factor, 1560 frame.metadata.page_scale_factor,
1526 frame.metadata.min_page_scale_factor, 1561 frame.metadata.min_page_scale_factor,
1527 frame.metadata.max_page_scale_factor, 1562 frame.metadata.max_page_scale_factor,
1528 gfx::ToCeiledSize(content_size)); 1563 gfx::ToCeiledSize(content_size));
1529 } 1564 }
1530 #endif 1565 #endif
1531 } 1566 }
1532 1567
1533 void RenderWidgetHostImpl::OnUpdateRect( 1568 void RenderWidgetHostImpl::OnUpdateRect(
1534 const ViewHostMsg_UpdateRect_Params& params) { 1569 const ViewHostMsg_UpdateRect_Params& params) {
1535 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::OnUpdateRect"); 1570 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::OnUpdateRect",
1571 "input_number", params.latency_info.inputNumber,
1572 "render_thread_frame_number",
1573 params.latency_info.rendererMainFrameNumber);
1536 TimeTicks paint_start = TimeTicks::Now(); 1574 TimeTicks paint_start = TimeTicks::Now();
1537 1575
1538 // Update our knowledge of the RenderWidget's size. 1576 // Update our knowledge of the RenderWidget's size.
1539 current_size_ = params.view_size; 1577 current_size_ = params.view_size;
1540 // Update our knowledge of the RenderWidget's scroll offset. 1578 // Update our knowledge of the RenderWidget's scroll offset.
1541 last_scroll_offset_ = params.scroll_offset; 1579 last_scroll_offset_ = params.scroll_offset;
1542 1580
1543 bool is_resize_ack = 1581 bool is_resize_ack =
1544 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); 1582 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags);
1545 1583
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 } 1666 }
1629 1667
1630 void RenderWidgetHostImpl::OnUpdateIsDelayed() { 1668 void RenderWidgetHostImpl::OnUpdateIsDelayed() {
1631 if (in_get_backing_store_) 1669 if (in_get_backing_store_)
1632 abort_get_backing_store_ = true; 1670 abort_get_backing_store_ = true;
1633 } 1671 }
1634 1672
1635 void RenderWidgetHostImpl::DidUpdateBackingStore( 1673 void RenderWidgetHostImpl::DidUpdateBackingStore(
1636 const ViewHostMsg_UpdateRect_Params& params, 1674 const ViewHostMsg_UpdateRect_Params& params,
1637 const TimeTicks& paint_start) { 1675 const TimeTicks& paint_start) {
1638 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::DidUpdateBackingStore"); 1676 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::DidUpdateBackingStore",
1677 "input_number", params.latency_info.inputNumber,
1678 "render_thread_frame_number",
1679 params.latency_info.rendererMainFrameNumber);
1639 TimeTicks update_start = TimeTicks::Now(); 1680 TimeTicks update_start = TimeTicks::Now();
1640 1681
1641 if (params.needs_ack) { 1682 if (params.needs_ack) {
1642 // ACK early so we can prefetch the next PaintRect if there is a next one. 1683 // ACK early so we can prefetch the next PaintRect if there is a next one.
1643 // This must be done AFTER we're done painting with the bitmap supplied by 1684 // This must be done AFTER we're done painting with the bitmap supplied by
1644 // the renderer. This ACK is a signal to the renderer that the backing store 1685 // the renderer. This ACK is a signal to the renderer that the backing store
1645 // can be re-used, so the bitmap may be invalid after this call. 1686 // can be re-used, so the bitmap may be invalid after this call.
1646 Send(new ViewMsg_UpdateRect_ACK(routing_id_)); 1687 Send(new ViewMsg_UpdateRect_ACK(routing_id_));
1647 } 1688 }
1648 1689
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 void RenderWidgetHostImpl::AcknowledgeBufferPresent( 2334 void RenderWidgetHostImpl::AcknowledgeBufferPresent(
2294 int32 route_id, int gpu_host_id, 2335 int32 route_id, int gpu_host_id,
2295 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { 2336 const AcceleratedSurfaceMsg_BufferPresented_Params& params) {
2296 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); 2337 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id);
2297 if (ui_shim) { 2338 if (ui_shim) {
2298 ui_shim->Send(new AcceleratedSurfaceMsg_BufferPresented(route_id, 2339 ui_shim->Send(new AcceleratedSurfaceMsg_BufferPresented(route_id,
2299 params)); 2340 params));
2300 } 2341 }
2301 } 2342 }
2302 2343
2344 void RenderWidgetHostImpl::NotifyFrameDisplayed(
2345 int route_id, int gpu_host_id,
2346 const cc::LatencyInfo& latency_info) {
2347 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id);
2348 if (ui_shim)
2349 ui_shim->Send(new AcceleratedSurfaceMsg_FrameDisplayed(route_id,
2350 latency_info));
2351 }
2352
2303 void RenderWidgetHostImpl::AcknowledgeSwapBuffersToRenderer() { 2353 void RenderWidgetHostImpl::AcknowledgeSwapBuffersToRenderer() {
2304 if (!is_threaded_compositing_enabled_) 2354 if (!is_threaded_compositing_enabled_)
2305 Send(new ViewMsg_SwapBuffers_ACK(routing_id_)); 2355 Send(new ViewMsg_SwapBuffers_ACK(routing_id_));
2306 } 2356 }
2307 2357
2308 #if defined(USE_AURA) 2358 #if defined(USE_AURA)
2309 2359
2310 void RenderWidgetHostImpl::ParentChanged(gfx::NativeViewId new_parent) { 2360 void RenderWidgetHostImpl::ParentChanged(gfx::NativeViewId new_parent) {
2311 #if defined(OS_WIN) 2361 #if defined(OS_WIN)
2312 HWND hwnd = reinterpret_cast<HWND>(new_parent); 2362 HWND hwnd = reinterpret_cast<HWND>(new_parent);
(...skipping 18 matching lines...) Expand all
2331 return; 2381 return;
2332 2382
2333 OnRenderAutoResized(new_size); 2383 OnRenderAutoResized(new_size);
2334 } 2384 }
2335 2385
2336 void RenderWidgetHostImpl::DetachDelegate() { 2386 void RenderWidgetHostImpl::DetachDelegate() {
2337 delegate_ = NULL; 2387 delegate_ = NULL;
2338 } 2388 }
2339 2389
2340 } // namespace content 2390 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698