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

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: Fix rebase mistake 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 auto doomed = std::move(queued_messages_);
1631 } 1661 }
1632 1662
1633 void RenderWidgetHostImpl::UpdateTextDirection(WebTextDirection direction) { 1663 void RenderWidgetHostImpl::UpdateTextDirection(WebTextDirection direction) {
1634 text_direction_updated_ = true; 1664 text_direction_updated_ = true;
1635 text_direction_ = direction; 1665 text_direction_ = direction;
1636 } 1666 }
1637 1667
1638 void RenderWidgetHostImpl::CancelUpdateTextDirection() { 1668 void RenderWidgetHostImpl::CancelUpdateTextDirection() {
1639 if (text_direction_updated_) 1669 if (text_direction_updated_)
1640 text_direction_canceled_ = true; 1670 text_direction_canceled_ = true;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 // This trace event is used in 1898 // This trace event is used in
1869 // chrome/browser/extensions/api/cast_streaming/performance_test.cc 1899 // chrome/browser/extensions/api/cast_streaming/performance_test.cc
1870 TRACE_EVENT0("test_fps,benchmark", "OnSwapCompositorFrame"); 1900 TRACE_EVENT0("test_fps,benchmark", "OnSwapCompositorFrame");
1871 1901
1872 ViewHostMsg_SwapCompositorFrame::Param param; 1902 ViewHostMsg_SwapCompositorFrame::Param param;
1873 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param)) 1903 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param))
1874 return false; 1904 return false;
1875 uint32_t compositor_frame_sink_id = std::get<0>(param); 1905 uint32_t compositor_frame_sink_id = std::get<0>(param);
1876 cc::LocalSurfaceId local_surface_id = std::get<1>(param); 1906 cc::LocalSurfaceId local_surface_id = std::get<1>(param);
1877 cc::CompositorFrame frame(std::move(std::get<2>(param))); 1907 cc::CompositorFrame frame(std::move(std::get<2>(param)));
1878 std::vector<IPC::Message> messages_to_deliver_with_frame;
1879 messages_to_deliver_with_frame.swap(std::get<3>(param));
1880 1908
1881 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { 1909 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) {
1882 if (view_) 1910 if (view_)
1883 view_->DidCreateNewRendererCompositorFrameSink(); 1911 view_->DidCreateNewRendererCompositorFrameSink();
1884 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 1912 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
1885 } 1913 }
1886 1914
1887 SubmitCompositorFrame(local_surface_id, std::move(frame)); 1915 SubmitCompositorFrame(local_surface_id, std::move(frame));
1888 1916
1889 RenderProcessHost* rph = GetProcess();
1890 for (std::vector<IPC::Message>::const_iterator i =
1891 messages_to_deliver_with_frame.begin();
1892 i != messages_to_deliver_with_frame.end();
1893 ++i) {
1894 rph->OnMessageReceived(*i);
1895 if (i->dispatch_error())
1896 rph->OnBadMessageReceived(*i);
1897 }
1898 messages_to_deliver_with_frame.clear();
1899
1900 return true; 1917 return true;
1901 } 1918 }
1902 1919
1903 void RenderWidgetHostImpl::OnBeginFrameDidNotSwap( 1920 void RenderWidgetHostImpl::OnBeginFrameDidNotSwap(
1904 const cc::BeginFrameAck& ack) { 1921 const cc::BeginFrameAck& ack) {
1905 if (ack.sequence_number < cc::BeginFrameArgs::kStartingFrameNumber) { 1922 if (ack.sequence_number < cc::BeginFrameArgs::kStartingFrameNumber) {
1906 // Received an invalid ack, renderer misbehaved. 1923 // Received an invalid ack, renderer misbehaved.
1907 bad_message::ReceivedBadMessage( 1924 bad_message::ReceivedBadMessage(
1908 GetProcess(), bad_message::RWH_INVALID_BEGIN_FRAME_ACK_DID_NOT_SWAP); 1925 GetProcess(), bad_message::RWH_INVALID_BEGIN_FRAME_ACK_DID_NOT_SWAP);
1909 return; 1926 return;
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
2603 (frame_size != last_frame_size_ || 2620 (frame_size != last_frame_size_ ||
2604 device_scale_factor != last_device_scale_factor_)) { 2621 device_scale_factor != last_device_scale_factor_)) {
2605 DLOG(ERROR) << "Renderer submitted frame of wrong size to its surface." 2622 DLOG(ERROR) << "Renderer submitted frame of wrong size to its surface."
2606 << " Expected: size=" << last_frame_size_.ToString() 2623 << " Expected: size=" << last_frame_size_.ToString()
2607 << ",scale=" << last_device_scale_factor_ 2624 << ",scale=" << last_device_scale_factor_
2608 << " Received: size=" << frame_size.ToString() 2625 << " Received: size=" << frame_size.ToString()
2609 << ",scale=" << device_scale_factor; 2626 << ",scale=" << device_scale_factor;
2610 return; 2627 return;
2611 } 2628 }
2612 2629
2630 uint32_t frame_token = frame.metadata.frame_token;
2631
2613 last_local_surface_id_ = local_surface_id; 2632 last_local_surface_id_ = local_surface_id;
2614 last_frame_size_ = frame_size; 2633 last_frame_size_ = frame_size;
2615 last_device_scale_factor_ = device_scale_factor; 2634 last_device_scale_factor_ = device_scale_factor;
2616 2635
2617 last_received_content_source_id_ = frame.metadata.content_source_id; 2636 last_received_content_source_id_ = frame.metadata.content_source_id;
2618 2637
2619 if (frame.metadata.begin_frame_ack.sequence_number < 2638 if (frame.metadata.begin_frame_ack.sequence_number <
2620 cc::BeginFrameArgs::kStartingFrameNumber) { 2639 cc::BeginFrameArgs::kStartingFrameNumber) {
2621 // Received an invalid ack, renderer misbehaved. 2640 // Received an invalid ack, renderer misbehaved.
2622 bad_message::ReceivedBadMessage( 2641 bad_message::ReceivedBadMessage(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 2677
2659 // 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
2660 // the timer that triggers clearing the graphics of the last page. 2679 // the timer that triggers clearing the graphics of the last page.
2661 if (last_received_content_source_id_ >= current_content_source_id_ && 2680 if (last_received_content_source_id_ >= current_content_source_id_ &&
2662 new_content_rendering_timeout_->IsRunning()) { 2681 new_content_rendering_timeout_->IsRunning()) {
2663 new_content_rendering_timeout_->Stop(); 2682 new_content_rendering_timeout_->Stop();
2664 } 2683 }
2665 2684
2666 if (delegate_) 2685 if (delegate_)
2667 delegate_->DidReceiveCompositorFrame(); 2686 delegate_->DidReceiveCompositorFrame();
2687
2688 if (frame_token)
2689 DidProcessFrame(frame_token);
2690 }
2691
2692 void RenderWidgetHostImpl::DidProcessFrame(uint32_t frame_token) {
2693 // Frame tokens always increase.
2694 if (frame_token <= last_received_frame_token_) {
2695 bad_message::ReceivedBadMessage(GetProcess(),
2696 bad_message::RWH_INVALID_FRAME_TOKEN);
2697 return;
2698 }
2699
2700 last_received_frame_token_ = frame_token;
2701
2702 while (queued_messages_.size() &&
2703 queued_messages_.front().first <= frame_token) {
2704 ProcessSwapMessages(std::move(queued_messages_.front().second));
2705 queued_messages_.pop();
2706 }
2707 }
2708
2709 void RenderWidgetHostImpl::ProcessSwapMessages(
2710 std::vector<IPC::Message> messages) {
2711 RenderProcessHost* rph = GetProcess();
2712 for (std::vector<IPC::Message>::const_iterator i = messages.begin();
2713 i != messages.end(); ++i) {
2714 rph->OnMessageReceived(*i);
2715 if (i->dispatch_error())
2716 rph->OnBadMessageReceived(*i);
2717 }
2668 } 2718 }
2669 2719
2670 } // namespace content 2720 } // 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