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

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

Issue 2789773003: Send FrameSwapMessageQueue's messages with a separate IPC (Closed)
Patch Set: Remove semicolon Created 3 years, 8 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
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 8
9 #include <set> 9 #include <set>
10 #include <tuple> 10 #include <tuple>
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDisambiguationPopup, 567 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDisambiguationPopup,
568 OnShowDisambiguationPopup) 568 OnShowDisambiguationPopup)
569 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged, 569 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged,
570 OnSelectionBoundsChanged) 570 OnSelectionBoundsChanged)
571 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, 571 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged,
572 OnImeCompositionRangeChanged) 572 OnImeCompositionRangeChanged)
573 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, OnSetNeedsBeginFrames) 573 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, OnSetNeedsBeginFrames)
574 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeTouched, OnFocusedNodeTouched) 574 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeTouched, OnFocusedNodeTouched)
575 IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging, OnStartDragging) 575 IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging, OnStartDragging)
576 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) 576 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor)
577 IPC_MESSAGE_HANDLER(ViewHostMsg_FrameSwapMessages,
578 OnFrameSwapMessagesReceived)
577 IPC_MESSAGE_UNHANDLED(handled = false) 579 IPC_MESSAGE_UNHANDLED(handled = false)
578 IPC_END_MESSAGE_MAP() 580 IPC_END_MESSAGE_MAP()
579 581
580 if (!handled && input_router_ && input_router_->OnMessageReceived(msg)) 582 if (!handled && input_router_ && input_router_->OnMessageReceived(msg))
581 return true; 583 return true;
582 584
583 if (!handled && view_ && view_->OnMessageReceived(msg)) 585 if (!handled && view_ && view_->OnMessageReceived(msg))
584 return true; 586 return true;
585 587
586 return handled; 588 return handled;
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 1571
1570 void RenderWidgetHostImpl::OnUpdateDragCursor(WebDragOperation current_op) { 1572 void RenderWidgetHostImpl::OnUpdateDragCursor(WebDragOperation current_op) {
1571 if (delegate_ && delegate_->OnUpdateDragCursor()) 1573 if (delegate_ && delegate_->OnUpdateDragCursor())
1572 return; 1574 return;
1573 1575
1574 RenderViewHostDelegateView* view = delegate_->GetDelegateView(); 1576 RenderViewHostDelegateView* view = delegate_->GetDelegateView();
1575 if (view) 1577 if (view)
1576 view->UpdateDragCursor(current_op); 1578 view->UpdateDragCursor(current_op);
1577 } 1579 }
1578 1580
1581 void RenderWidgetHostImpl::OnFrameSwapMessagesReceived(
1582 uint32_t frame_token,
1583 std::vector<IPC::Message> messages) {
1584 // Zero token is invalid.
1585 if (!frame_token) {
1586 bad_message::ReceivedBadMessage(GetProcess(),
1587 bad_message::RWH_INVALID_FRAME_TOKEN);
1588 return;
1589 }
1590
1591 // Frame tokens always increase.
1592 if (queued_messages_.size() && frame_token <= queued_messages_.back().first) {
1593 bad_message::ReceivedBadMessage(GetProcess(),
1594 bad_message::RWH_INVALID_FRAME_TOKEN);
1595 return;
1596 }
1597
1598 if (frame_token <= last_received_frame_token_) {
1599 ProcessSwapMessages(std::move(messages));
1600 return;
1601 }
1602
1603 queued_messages_.push(std::make_pair(frame_token, std::move(messages)));
1604 }
1605
1579 void RenderWidgetHostImpl::RendererExited(base::TerminationStatus status, 1606 void RenderWidgetHostImpl::RendererExited(base::TerminationStatus status,
1580 int exit_code) { 1607 int exit_code) {
1581 if (!renderer_initialized_) 1608 if (!renderer_initialized_)
1582 return; 1609 return;
1583 1610
1584 // Clear this flag so that we can ask the next renderer for composition 1611 // Clear this flag so that we can ask the next renderer for composition
1585 // updates. 1612 // updates.
1586 monitoring_composition_info_ = false; 1613 monitoring_composition_info_ = false;
1587 1614
1588 // Clearing this flag causes us to re-create the renderer when recovering 1615 // Clearing this flag causes us to re-create the renderer when recovering
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 } 1648 }
1622 1649
1623 // Reconstruct the input router to ensure that it has fresh state for a new 1650 // Reconstruct the input router to ensure that it has fresh state for a new
1624 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an 1651 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an
1625 // event. (In particular, the above call to view_->RenderProcessGone will 1652 // event. (In particular, the above call to view_->RenderProcessGone will
1626 // destroy the aura window, which may dispatch a synthetic mouse move.) 1653 // destroy the aura window, which may dispatch a synthetic mouse move.)
1627 input_router_.reset(new InputRouterImpl( 1654 input_router_.reset(new InputRouterImpl(
1628 process_, this, this, routing_id_, GetInputRouterConfigForPlatform())); 1655 process_, this, this, routing_id_, GetInputRouterConfigForPlatform()));
1629 1656
1630 synthetic_gesture_controller_.reset(); 1657 synthetic_gesture_controller_.reset();
1658
1659 last_received_frame_token_ = 0;
1660 while (queued_messages_.size()) {
1661 ProcessSwapMessages(std::move(queued_messages_.front().second));
Saman Sami 2017/04/04 19:43:12 OK, maybe this is not a good idea. Maybe it's bett
piman 2017/04/04 19:49:49 Recipients have to deal with render process dying
1662 queued_messages_.pop();
1663 }
1631 } 1664 }
1632 1665
1633 void RenderWidgetHostImpl::UpdateTextDirection(WebTextDirection direction) { 1666 void RenderWidgetHostImpl::UpdateTextDirection(WebTextDirection direction) {
1634 text_direction_updated_ = true; 1667 text_direction_updated_ = true;
1635 text_direction_ = direction; 1668 text_direction_ = direction;
1636 } 1669 }
1637 1670
1638 void RenderWidgetHostImpl::CancelUpdateTextDirection() { 1671 void RenderWidgetHostImpl::CancelUpdateTextDirection() {
1639 if (text_direction_updated_) 1672 if (text_direction_updated_)
1640 text_direction_canceled_ = true; 1673 text_direction_canceled_ = true;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 // This trace event is used in 1875 // This trace event is used in
1843 // chrome/browser/extensions/api/cast_streaming/performance_test.cc 1876 // chrome/browser/extensions/api/cast_streaming/performance_test.cc
1844 TRACE_EVENT0("test_fps,benchmark", "OnSwapCompositorFrame"); 1877 TRACE_EVENT0("test_fps,benchmark", "OnSwapCompositorFrame");
1845 1878
1846 ViewHostMsg_SwapCompositorFrame::Param param; 1879 ViewHostMsg_SwapCompositorFrame::Param param;
1847 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param)) 1880 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param))
1848 return false; 1881 return false;
1849 uint32_t compositor_frame_sink_id = std::get<0>(param); 1882 uint32_t compositor_frame_sink_id = std::get<0>(param);
1850 cc::LocalSurfaceId local_surface_id = std::get<1>(param); 1883 cc::LocalSurfaceId local_surface_id = std::get<1>(param);
1851 cc::CompositorFrame frame(std::move(std::get<2>(param))); 1884 cc::CompositorFrame frame(std::move(std::get<2>(param)));
1852 std::vector<IPC::Message> messages_to_deliver_with_frame;
1853 messages_to_deliver_with_frame.swap(std::get<3>(param));
1854 1885
1855 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { 1886 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) {
1856 if (view_) 1887 if (view_)
1857 view_->DidCreateNewRendererCompositorFrameSink(); 1888 view_->DidCreateNewRendererCompositorFrameSink();
1858 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 1889 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
1859 } 1890 }
1860 1891
1861 SubmitCompositorFrame(local_surface_id, std::move(frame)); 1892 SubmitCompositorFrame(local_surface_id, std::move(frame));
1862 1893
1863 RenderProcessHost* rph = GetProcess();
1864 for (std::vector<IPC::Message>::const_iterator i =
1865 messages_to_deliver_with_frame.begin();
1866 i != messages_to_deliver_with_frame.end();
1867 ++i) {
1868 rph->OnMessageReceived(*i);
1869 if (i->dispatch_error())
1870 rph->OnBadMessageReceived(*i);
1871 }
1872 messages_to_deliver_with_frame.clear();
1873
1874 return true; 1894 return true;
1875 } 1895 }
1876 1896
1877 void RenderWidgetHostImpl::OnBeginFrameDidNotSwap( 1897 void RenderWidgetHostImpl::OnBeginFrameDidNotSwap(
1878 const cc::BeginFrameAck& ack) { 1898 const cc::BeginFrameAck& ack) {
1879 if (ack.sequence_number < cc::BeginFrameArgs::kStartingFrameNumber) { 1899 if (ack.sequence_number < cc::BeginFrameArgs::kStartingFrameNumber) {
1880 // Received an invalid ack, renderer misbehaved. 1900 // Received an invalid ack, renderer misbehaved.
1881 bad_message::ReceivedBadMessage( 1901 bad_message::ReceivedBadMessage(
1882 GetProcess(), bad_message::RWH_INVALID_BEGIN_FRAME_ACK_DID_NOT_SWAP); 1902 GetProcess(), bad_message::RWH_INVALID_BEGIN_FRAME_ACK_DID_NOT_SWAP);
1883 return; 1903 return;
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 (frame_size != last_frame_size_ || 2622 (frame_size != last_frame_size_ ||
2603 device_scale_factor != last_device_scale_factor_)) { 2623 device_scale_factor != last_device_scale_factor_)) {
2604 DLOG(ERROR) << "Renderer submitted frame of wrong size to its surface." 2624 DLOG(ERROR) << "Renderer submitted frame of wrong size to its surface."
2605 << " Expected: size=" << last_frame_size_.ToString() 2625 << " Expected: size=" << last_frame_size_.ToString()
2606 << ",scale=" << last_device_scale_factor_ 2626 << ",scale=" << last_device_scale_factor_
2607 << " Received: size=" << frame_size.ToString() 2627 << " Received: size=" << frame_size.ToString()
2608 << ",scale=" << device_scale_factor; 2628 << ",scale=" << device_scale_factor;
2609 return; 2629 return;
2610 } 2630 }
2611 2631
2632 uint32_t frame_token = frame.metadata.frame_token;
2633
2612 last_local_surface_id_ = local_surface_id; 2634 last_local_surface_id_ = local_surface_id;
2613 last_frame_size_ = frame_size; 2635 last_frame_size_ = frame_size;
2614 last_device_scale_factor_ = device_scale_factor; 2636 last_device_scale_factor_ = device_scale_factor;
2615 2637
2616 last_received_content_source_id_ = frame.metadata.content_source_id; 2638 last_received_content_source_id_ = frame.metadata.content_source_id;
2617 2639
2618 if (frame.metadata.begin_frame_ack.sequence_number < 2640 if (frame.metadata.begin_frame_ack.sequence_number <
2619 cc::BeginFrameArgs::kStartingFrameNumber) { 2641 cc::BeginFrameArgs::kStartingFrameNumber) {
2620 // Received an invalid ack, renderer misbehaved. 2642 // Received an invalid ack, renderer misbehaved.
2621 bad_message::ReceivedBadMessage( 2643 bad_message::ReceivedBadMessage(
(...skipping 30 matching lines...) Expand all
2652 cc::TransferableResource::ReturnResources(frame.resource_list, &resources); 2674 cc::TransferableResource::ReturnResources(frame.resource_list, &resources);
2653 SendReclaimCompositorResources(true /* is_swap_ack */, resources); 2675 SendReclaimCompositorResources(true /* is_swap_ack */, resources);
2654 } 2676 }
2655 2677
2656 // After navigation, if a frame belonging to the new page is received, stop 2678 // After navigation, if a frame belonging to the new page is received, stop
2657 // the timer that triggers clearing the graphics of the last page. 2679 // the timer that triggers clearing the graphics of the last page.
2658 if (last_received_content_source_id_ >= current_content_source_id_ && 2680 if (last_received_content_source_id_ >= current_content_source_id_ &&
2659 new_content_rendering_timeout_->IsRunning()) { 2681 new_content_rendering_timeout_->IsRunning()) {
2660 new_content_rendering_timeout_->Stop(); 2682 new_content_rendering_timeout_->Stop();
2661 } 2683 }
2684
2685 if (frame_token)
2686 DidProcessFrame(frame_token);
2687 }
2688
2689 void RenderWidgetHostImpl::DidProcessFrame(uint32_t frame_token) {
2690 // Frame tokens always increase.
2691 if (frame_token <= last_received_frame_token_) {
2692 bad_message::ReceivedBadMessage(GetProcess(),
2693 bad_message::RWH_INVALID_FRAME_TOKEN);
2694 return;
2695 }
2696
2697 last_received_frame_token_ = frame_token;
2698
2699 while (queued_messages_.size() &&
2700 queued_messages_.front().first <= frame_token) {
2701 ProcessSwapMessages(std::move(queued_messages_.front().second));
2702 queued_messages_.pop();
2703 }
2704 }
2705
2706 void RenderWidgetHostImpl::ProcessSwapMessages(
2707 std::vector<IPC::Message> messages) {
2708 RenderProcessHost* rph = GetProcess();
2709 for (std::vector<IPC::Message>::const_iterator i = messages.begin();
2710 i != messages.end(); ++i) {
2711 rph->OnMessageReceived(*i);
2712 if (i->dispatch_error())
2713 rph->OnBadMessageReceived(*i);
2714 }
2662 } 2715 }
2663 2716
2664 } // namespace content 2717 } // 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