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/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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 bool msg_is_ok = true; | 420 bool msg_is_ok = true; |
421 IPC_BEGIN_MESSAGE_MAP_EX(RenderWidgetHostImpl, msg, msg_is_ok) | 421 IPC_BEGIN_MESSAGE_MAP_EX(RenderWidgetHostImpl, msg, msg_is_ok) |
422 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnRenderViewReady) | 422 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnRenderViewReady) |
423 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnRenderViewGone) | 423 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnRenderViewGone) |
424 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) | 424 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) |
425 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateScreenRects_ACK, | 425 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateScreenRects_ACK, |
426 OnUpdateScreenRectsAck) | 426 OnUpdateScreenRectsAck) |
427 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove) | 427 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove) |
428 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnSetTooltipText) | 428 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnSetTooltipText) |
429 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnPaintAtSizeAck) | 429 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnPaintAtSizeAck) |
| 430 #if defined(OS_MACOSX) |
430 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped, | 431 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped, |
431 OnCompositorSurfaceBuffersSwapped) | 432 OnCompositorSurfaceBuffersSwapped) |
| 433 #endif |
432 IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_SwapCompositorFrame, | 434 IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_SwapCompositorFrame, |
433 msg_is_ok = OnSwapCompositorFrame(msg)) | 435 msg_is_ok = OnSwapCompositorFrame(msg)) |
434 IPC_MESSAGE_HANDLER(ViewHostMsg_DidOverscroll, OnOverscrolled) | 436 IPC_MESSAGE_HANDLER(ViewHostMsg_DidOverscroll, OnOverscrolled) |
435 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 437 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
436 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateIsDelayed, OnUpdateIsDelayed) | 438 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateIsDelayed, OnUpdateIsDelayed) |
437 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) | 439 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) |
438 IPC_MESSAGE_HANDLER(ViewHostMsg_BeginSmoothScroll, OnBeginSmoothScroll) | 440 IPC_MESSAGE_HANDLER(ViewHostMsg_BeginSmoothScroll, OnBeginSmoothScroll) |
439 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck) | 441 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck) |
440 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) | 442 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) |
441 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnFocus) | 443 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnFocus) |
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 } | 1739 } |
1738 | 1740 |
1739 void RenderWidgetHostImpl::OnPaintAtSizeAck(int tag, const gfx::Size& size) { | 1741 void RenderWidgetHostImpl::OnPaintAtSizeAck(int tag, const gfx::Size& size) { |
1740 std::pair<int, gfx::Size> details = std::make_pair(tag, size); | 1742 std::pair<int, gfx::Size> details = std::make_pair(tag, size); |
1741 NotificationService::current()->Notify( | 1743 NotificationService::current()->Notify( |
1742 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, | 1744 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, |
1743 Source<RenderWidgetHost>(this), | 1745 Source<RenderWidgetHost>(this), |
1744 Details<std::pair<int, gfx::Size> >(&details)); | 1746 Details<std::pair<int, gfx::Size> >(&details)); |
1745 } | 1747 } |
1746 | 1748 |
| 1749 #if defined(OS_MACOSX) |
1747 void RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped( | 1750 void RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped( |
1748 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params) { | 1751 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params) { |
1749 TRACE_EVENT0("renderer_host", | 1752 TRACE_EVENT0("renderer_host", |
1750 "RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped"); | 1753 "RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped"); |
1751 if (!view_) { | 1754 if (!view_) { |
1752 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 1755 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
1753 ack_params.sync_point = 0; | 1756 ack_params.sync_point = 0; |
1754 RenderWidgetHostImpl::AcknowledgeBufferPresent(params.route_id, | 1757 RenderWidgetHostImpl::AcknowledgeBufferPresent(params.route_id, |
1755 params.gpu_process_host_id, | 1758 params.gpu_process_host_id, |
1756 ack_params); | 1759 ack_params); |
1757 return; | 1760 return; |
1758 } | 1761 } |
1759 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params gpu_params; | 1762 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params gpu_params; |
1760 gpu_params.surface_id = params.surface_id; | 1763 gpu_params.surface_id = params.surface_id; |
1761 gpu_params.surface_handle = params.surface_handle; | 1764 gpu_params.surface_handle = params.surface_handle; |
1762 gpu_params.route_id = params.route_id; | 1765 gpu_params.route_id = params.route_id; |
1763 gpu_params.size = params.size; | 1766 gpu_params.size = params.size; |
1764 gpu_params.scale_factor = params.scale_factor; | 1767 gpu_params.scale_factor = params.scale_factor; |
1765 gpu_params.latency_info = params.latency_info; | 1768 gpu_params.latency_info = params.latency_info; |
1766 view_->AcceleratedSurfaceBuffersSwapped(gpu_params, | 1769 view_->AcceleratedSurfaceBuffersSwapped(gpu_params, |
1767 params.gpu_process_host_id); | 1770 params.gpu_process_host_id); |
| 1771 view_->DidReceiveRendererFrame(); |
1768 } | 1772 } |
| 1773 #endif // OS_MACOSX |
1769 | 1774 |
1770 bool RenderWidgetHostImpl::OnSwapCompositorFrame( | 1775 bool RenderWidgetHostImpl::OnSwapCompositorFrame( |
1771 const IPC::Message& message) { | 1776 const IPC::Message& message) { |
1772 ViewHostMsg_SwapCompositorFrame::Param param; | 1777 ViewHostMsg_SwapCompositorFrame::Param param; |
1773 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 1778 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
1774 return false; | 1779 return false; |
1775 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 1780 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
1776 param.a.AssignTo(frame.get()); | 1781 param.a.AssignTo(frame.get()); |
1777 | 1782 |
1778 if (view_) { | 1783 if (view_) { |
1779 view_->OnSwapCompositorFrame(frame.Pass()); | 1784 view_->OnSwapCompositorFrame(frame.Pass()); |
| 1785 view_->DidReceiveRendererFrame(); |
1780 } else { | 1786 } else { |
1781 cc::CompositorFrameAck ack; | 1787 cc::CompositorFrameAck ack; |
1782 if (frame->gl_frame_data) { | 1788 if (frame->gl_frame_data) { |
1783 ack.gl_frame_data = frame->gl_frame_data.Pass(); | 1789 ack.gl_frame_data = frame->gl_frame_data.Pass(); |
1784 ack.gl_frame_data->sync_point = 0; | 1790 ack.gl_frame_data->sync_point = 0; |
1785 } else if (frame->delegated_frame_data) { | 1791 } else if (frame->delegated_frame_data) { |
1786 ack.resources.swap(frame->delegated_frame_data->resource_list); | 1792 ack.resources.swap(frame->delegated_frame_data->resource_list); |
1787 } else if (frame->software_frame_data) { | 1793 } else if (frame->software_frame_data) { |
1788 ack.last_software_frame_id = frame->software_frame_data->id; | 1794 ack.last_software_frame_id = frame->software_frame_data->id; |
1789 } | 1795 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1929 // early return after the ACK is sent, however, or the renderer will not send | 1935 // early return after the ACK is sent, however, or the renderer will not send |
1930 // us more data. | 1936 // us more data. |
1931 if (is_hidden_) | 1937 if (is_hidden_) |
1932 return; | 1938 return; |
1933 | 1939 |
1934 // Now paint the view. Watch out: it might be destroyed already. | 1940 // Now paint the view. Watch out: it might be destroyed already. |
1935 if (view_ && !is_accelerated_compositing_active_) { | 1941 if (view_ && !is_accelerated_compositing_active_) { |
1936 view_being_painted_ = true; | 1942 view_being_painted_ = true; |
1937 view_->DidUpdateBackingStore(params.scroll_rect, params.scroll_delta, | 1943 view_->DidUpdateBackingStore(params.scroll_rect, params.scroll_delta, |
1938 params.copy_rects, params.latency_info); | 1944 params.copy_rects, params.latency_info); |
| 1945 view_->DidReceiveRendererFrame(); |
1939 view_being_painted_ = false; | 1946 view_being_painted_ = false; |
1940 } | 1947 } |
1941 | 1948 |
1942 // If we got a resize ack, then perhaps we have another resize to send? | 1949 // If we got a resize ack, then perhaps we have another resize to send? |
1943 bool is_resize_ack = | 1950 bool is_resize_ack = |
1944 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); | 1951 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); |
1945 if (is_resize_ack) | 1952 if (is_resize_ack) |
1946 WasResized(); | 1953 WasResized(); |
1947 | 1954 |
1948 // Log the time delta for processing a paint message. | 1955 // Log the time delta for processing a paint message. |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2634 rendering_stats_.input_event_count += l->second.event_count; | 2641 rendering_stats_.input_event_count += l->second.event_count; |
2635 rendering_stats_.total_input_latency += | 2642 rendering_stats_.total_input_latency += |
2636 l->second.event_count * | 2643 l->second.event_count * |
2637 (latency_info.swap_timestamp - l->second.event_time); | 2644 (latency_info.swap_timestamp - l->second.event_time); |
2638 | 2645 |
2639 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2646 if (CommandLine::ForCurrentProcess()->HasSwitch( |
2640 switches::kEnableGpuBenchmarking)) | 2647 switches::kEnableGpuBenchmarking)) |
2641 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); | 2648 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); |
2642 } | 2649 } |
2643 | 2650 |
| 2651 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
| 2652 view_->DidReceiveRendererFrame(); |
| 2653 } |
| 2654 |
2644 // static | 2655 // static |
2645 void RenderWidgetHostImpl::CompositorFrameDrawn( | 2656 void RenderWidgetHostImpl::CompositorFrameDrawn( |
2646 const ui::LatencyInfo& latency_info) { | 2657 const ui::LatencyInfo& latency_info) { |
2647 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2658 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
2648 latency_info.latency_components.begin(); | 2659 latency_info.latency_components.begin(); |
2649 b != latency_info.latency_components.end(); | 2660 b != latency_info.latency_components.end(); |
2650 ++b) { | 2661 ++b) { |
2651 if (b->first.first != ui::INPUT_EVENT_LATENCY_RWH_COMPONENT) | 2662 if (b->first.first != ui::INPUT_EVENT_LATENCY_RWH_COMPONENT) |
2652 continue; | 2663 continue; |
2653 // Matches with GetLatencyComponentId | 2664 // Matches with GetLatencyComponentId |
2654 int routing_id = b->first.second & 0xffffffff; | 2665 int routing_id = b->first.second & 0xffffffff; |
2655 int process_id = (b->first.second >> 32) & 0xffffffff; | 2666 int process_id = (b->first.second >> 32) & 0xffffffff; |
2656 RenderWidgetHost* rwh = | 2667 RenderWidgetHost* rwh = |
2657 RenderWidgetHost::FromID(process_id, routing_id); | 2668 RenderWidgetHost::FromID(process_id, routing_id); |
2658 if (!rwh) | 2669 if (!rwh) |
2659 continue; | 2670 continue; |
2660 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); | 2671 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); |
2661 } | 2672 } |
2662 } | 2673 } |
2663 | 2674 |
2664 } // namespace content | 2675 } // namespace content |
OLD | NEW |