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

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

Issue 2774373002: Use MojoCompositorFrameSink in RendererCompositorFrameSink (Closed)
Patch Set: addressed comments 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 owned_by_render_frame_host_(false), 289 owned_by_render_frame_host_(false),
290 is_focused_(false), 290 is_focused_(false),
291 hung_renderer_delay_( 291 hung_renderer_delay_(
292 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), 292 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)),
293 hang_monitor_event_type_(blink::WebInputEvent::kUndefined), 293 hang_monitor_event_type_(blink::WebInputEvent::kUndefined),
294 last_event_type_(blink::WebInputEvent::kUndefined), 294 last_event_type_(blink::WebInputEvent::kUndefined),
295 new_content_rendering_delay_( 295 new_content_rendering_delay_(
296 base::TimeDelta::FromMilliseconds(kNewContentRenderingDelayMs)), 296 base::TimeDelta::FromMilliseconds(kNewContentRenderingDelayMs)),
297 current_content_source_id_(0), 297 current_content_source_id_(0),
298 monitoring_composition_info_(false), 298 monitoring_composition_info_(false),
299 compositor_frame_sink_binding_(this),
299 weak_factory_(this) { 300 weak_factory_(this) {
300 CHECK(delegate_); 301 CHECK(delegate_);
301 CHECK_NE(MSG_ROUTING_NONE, routing_id_); 302 CHECK_NE(MSG_ROUTING_NONE, routing_id_);
302 latency_tracker_.SetDelegate(delegate_); 303 latency_tracker_.SetDelegate(delegate_);
303 304
304 DCHECK(base::TaskScheduler::GetInstance()) 305 DCHECK(base::TaskScheduler::GetInstance())
305 << "Ref. Prerequisite section of post_task.h"; 306 << "Ref. Prerequisite section of post_task.h";
306 #if defined(OS_WIN) 307 #if defined(OS_WIN)
307 // Update the display color profile cache so that it is likely to be up to 308 // Update the display color profile cache so that it is likely to be up to
308 // date when the renderer process requests the color profile. 309 // date when the renderer process requests the color profile.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 405 }
405 406
406 // static 407 // static
407 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { 408 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) {
408 return static_cast<RenderWidgetHostImpl*>(rwh); 409 return static_cast<RenderWidgetHostImpl*>(rwh);
409 } 410 }
410 411
411 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) { 412 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) {
412 if (view) { 413 if (view) {
413 view_ = view->GetWeakPtr(); 414 view_ = view->GetWeakPtr();
415 if (renderer_compositor_frame_sink_.is_bound()) {
416 view->DidCreateNewRendererCompositorFrameSink(
417 renderer_compositor_frame_sink_.get());
418 }
414 // Views start out not needing begin frames, so only update its state 419 // Views start out not needing begin frames, so only update its state
415 // if the value has changed. 420 // if the value has changed.
416 if (needs_begin_frames_) 421 if (needs_begin_frames_)
417 view_->SetNeedsBeginFrames(needs_begin_frames_); 422 view_->SetNeedsBeginFrames(needs_begin_frames_);
418 } else { 423 } else {
419 view_.reset(); 424 view_.reset();
420 } 425 }
421 426
422 synthetic_gesture_controller_.reset(); 427 synthetic_gesture_controller_.reset();
423 } 428 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 IPC_MESSAGE_HANDLER(FrameHostMsg_HittestData, OnHittestData) 554 IPC_MESSAGE_HANDLER(FrameHostMsg_HittestData, OnHittestData)
550 IPC_MESSAGE_HANDLER(InputHostMsg_QueueSyntheticGesture, 555 IPC_MESSAGE_HANDLER(InputHostMsg_QueueSyntheticGesture,
551 OnQueueSyntheticGesture) 556 OnQueueSyntheticGesture)
552 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, 557 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition,
553 OnImeCancelComposition) 558 OnImeCancelComposition)
554 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) 559 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose)
555 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateScreenRects_ACK, 560 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateScreenRects_ACK,
556 OnUpdateScreenRectsAck) 561 OnUpdateScreenRectsAck)
557 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove) 562 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove)
558 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnSetTooltipText) 563 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnSetTooltipText)
559 IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_SwapCompositorFrame, 564 IPC_MESSAGE_HANDLER(ViewHostMsg_BeginFrameDidNotSwap, BeginFrameDidNotSwap)
560 OnSwapCompositorFrame(msg))
561 IPC_MESSAGE_HANDLER(ViewHostMsg_BeginFrameDidNotSwap,
562 OnBeginFrameDidNotSwap)
563 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) 565 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect)
564 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) 566 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor)
565 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, 567 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged,
566 OnTextInputStateChanged) 568 OnTextInputStateChanged)
567 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) 569 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse)
568 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) 570 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse)
569 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDisambiguationPopup, 571 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDisambiguationPopup,
570 OnShowDisambiguationPopup) 572 OnShowDisambiguationPopup)
571 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged, 573 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged,
572 OnSelectionBoundsChanged) 574 OnSelectionBoundsChanged)
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 863
862 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() { 864 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() {
863 // Do not pause if the view is hidden. 865 // Do not pause if the view is hidden.
864 if (is_hidden()) 866 if (is_hidden())
865 return false; 867 return false;
866 868
867 // Do not pause if there is not a paint or resize already coming. 869 // Do not pause if there is not a paint or resize already coming.
868 if (!repaint_ack_pending_ && !resize_ack_pending_) 870 if (!repaint_ack_pending_ && !resize_ack_pending_)
869 return false; 871 return false;
870 872
873 if (!renderer_compositor_frame_sink_.is_bound())
874 return false;
875
871 return true; 876 return true;
872 } 877 }
873 878
874 void RenderWidgetHostImpl::WaitForSurface() { 879 void RenderWidgetHostImpl::WaitForSurface() {
875 // How long to (synchronously) wait for the renderer to respond with a 880 // How long to (synchronously) wait for the renderer to respond with a
876 // new frame when our current frame doesn't exist or is the wrong size. 881 // new frame when our current frame doesn't exist or is the wrong size.
877 // This timeout impacts the "choppiness" of our window resize. 882 // This timeout impacts the "choppiness" of our window resize.
878 const int kPaintMsgTimeoutMS = 50; 883 const int kPaintMsgTimeoutMS = 50;
879 884
880 if (!view_) 885 if (!view_)
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 SendScreenRects(); 1897 SendScreenRects();
1893 } 1898 }
1894 1899
1895 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) { 1900 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) {
1896 if (view_) { 1901 if (view_) {
1897 view_->SetBounds(pos); 1902 view_->SetBounds(pos);
1898 Send(new ViewMsg_Move_ACK(routing_id_)); 1903 Send(new ViewMsg_Move_ACK(routing_id_));
1899 } 1904 }
1900 } 1905 }
1901 1906
1902 bool RenderWidgetHostImpl::OnSwapCompositorFrame( 1907 void RenderWidgetHostImpl::BeginFrameDidNotSwap(const cc::BeginFrameAck& ack) {
1903 const IPC::Message& message) {
1904 // This trace event is used in
1905 // chrome/browser/extensions/api/cast_streaming/performance_test.cc
1906 TRACE_EVENT0("test_fps,benchmark", "OnSwapCompositorFrame");
1907
1908 ViewHostMsg_SwapCompositorFrame::Param param;
1909 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param))
1910 return false;
1911 uint32_t compositor_frame_sink_id = std::get<0>(param);
1912 cc::LocalSurfaceId local_surface_id = std::get<1>(param);
1913 cc::CompositorFrame frame(std::move(std::get<2>(param)));
1914
1915 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) {
1916 if (view_)
1917 view_->DidCreateNewRendererCompositorFrameSink();
1918 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
1919 }
1920
1921 SubmitCompositorFrame(local_surface_id, std::move(frame));
1922
1923 return true;
1924 }
1925
1926 void RenderWidgetHostImpl::OnBeginFrameDidNotSwap(
1927 const cc::BeginFrameAck& ack) {
1928 if (ack.sequence_number < cc::BeginFrameArgs::kStartingFrameNumber) { 1908 if (ack.sequence_number < cc::BeginFrameArgs::kStartingFrameNumber) {
1929 // Received an invalid ack, renderer misbehaved. 1909 // Received an invalid ack, renderer misbehaved.
1930 bad_message::ReceivedBadMessage( 1910 bad_message::ReceivedBadMessage(
1931 GetProcess(), bad_message::RWH_INVALID_BEGIN_FRAME_ACK_DID_NOT_SWAP); 1911 GetProcess(), bad_message::RWH_INVALID_BEGIN_FRAME_ACK_DID_NOT_SWAP);
1932 return; 1912 return;
1933 } 1913 }
1934 1914
1935 // |has_damage| is not transmitted. 1915 // |has_damage| is not transmitted.
1936 cc::BeginFrameAck modified_ack = ack; 1916 cc::BeginFrameAck modified_ack = ack;
1937 modified_ack.has_damage = false; 1917 modified_ack.has_damage = false;
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 pending_mouse_lock_request_ = false; 2340 pending_mouse_lock_request_ = false;
2361 if (!view_ || !view_->HasFocus()|| !view_->LockMouse()) { 2341 if (!view_ || !view_->HasFocus()|| !view_->LockMouse()) {
2362 Send(new ViewMsg_LockMouse_ACK(routing_id_, false)); 2342 Send(new ViewMsg_LockMouse_ACK(routing_id_, false));
2363 return false; 2343 return false;
2364 } 2344 }
2365 2345
2366 Send(new ViewMsg_LockMouse_ACK(routing_id_, true)); 2346 Send(new ViewMsg_LockMouse_ACK(routing_id_, true));
2367 return true; 2347 return true;
2368 } 2348 }
2369 2349
2370 void RenderWidgetHostImpl::SendReclaimCompositorResources(
2371 bool is_swap_ack,
2372 const cc::ReturnedResourceArray& resources) {
2373 Send(new ViewMsg_ReclaimCompositorResources(
2374 routing_id_, last_compositor_frame_sink_id_, is_swap_ack, resources));
2375 }
2376
2377 void RenderWidgetHostImpl::DelayedAutoResized() { 2350 void RenderWidgetHostImpl::DelayedAutoResized() {
2378 gfx::Size new_size = new_auto_size_; 2351 gfx::Size new_size = new_auto_size_;
2379 // Clear the new_auto_size_ since the empty value is used as a flag to 2352 // Clear the new_auto_size_ since the empty value is used as a flag to
2380 // indicate that no callback is in progress (i.e. without this line 2353 // indicate that no callback is in progress (i.e. without this line
2381 // DelayedAutoResized will not get called again). 2354 // DelayedAutoResized will not get called again).
2382 new_auto_size_.SetSize(0, 0); 2355 new_auto_size_.SetSize(0, 0);
2383 if (!auto_resize_enabled_) 2356 if (!auto_resize_enabled_)
2384 return; 2357 return;
2385 2358
2386 if (delegate_) 2359 if (delegate_)
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 2575
2603 void RenderWidgetHostImpl::RequestCompositionUpdates(bool immediate_request, 2576 void RenderWidgetHostImpl::RequestCompositionUpdates(bool immediate_request,
2604 bool monitor_updates) { 2577 bool monitor_updates) {
2605 if (!immediate_request && monitor_updates == monitoring_composition_info_) 2578 if (!immediate_request && monitor_updates == monitoring_composition_info_)
2606 return; 2579 return;
2607 monitoring_composition_info_ = monitor_updates; 2580 monitoring_composition_info_ = monitor_updates;
2608 Send(new InputMsg_RequestCompositionUpdates(routing_id_, immediate_request, 2581 Send(new InputMsg_RequestCompositionUpdates(routing_id_, immediate_request,
2609 monitor_updates)); 2582 monitor_updates));
2610 } 2583 }
2611 2584
2585 void RenderWidgetHostImpl::RequestMojoCompositorFrameSink(
2586 cc::mojom::MojoCompositorFrameSinkRequest request,
2587 cc::mojom::MojoCompositorFrameSinkClientPtr client) {
2588 if (compositor_frame_sink_binding_.is_bound())
2589 compositor_frame_sink_binding_.Close();
2590 #if defined(OS_MACOSX)
2591 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
2592 ui::WindowResizeHelperMac::Get()->task_runner();
2593 // In tests, task_runner might not be initialized.
2594 if (task_runner)
2595 compositor_frame_sink_binding_.Bind(std::move(request), task_runner);
2596 else
2597 compositor_frame_sink_binding_.Bind(std::move(request));
2598 #else
2599 compositor_frame_sink_binding_.Bind(std::move(request));
2600 #endif
2601 renderer_compositor_frame_sink_ = std::move(client);
2602 if (view_) {
2603 view_->DidCreateNewRendererCompositorFrameSink(
2604 renderer_compositor_frame_sink_.get());
piman 2017/04/10 23:35:57 So, if the MojoCompositorFrameSinkClient is recrea
Saman Sami 2017/04/11 00:09:52 That's a good point. I think it's better to do tha
2605 }
2606 }
2607
2608 void RenderWidgetHostImpl::SetNeedsBeginFrame(bool needs_begin_frame) {
2609 OnSetNeedsBeginFrames(needs_begin_frame);
2610 }
2611
2612 void RenderWidgetHostImpl::SubmitCompositorFrame( 2612 void RenderWidgetHostImpl::SubmitCompositorFrame(
2613 const cc::LocalSurfaceId& local_surface_id, 2613 const cc::LocalSurfaceId& local_surface_id,
2614 cc::CompositorFrame frame) { 2614 cc::CompositorFrame frame) {
2615 // The renderer should not send empty frames. 2615 // The renderer should not send empty frames.
2616 if (frame.render_pass_list.empty()) { 2616 if (frame.render_pass_list.empty()) {
2617 DLOG(ERROR) << "Renderer sent an empty frame."; 2617 DLOG(ERROR) << "Renderer sent an empty frame.";
2618 return; 2618 return;
2619 } 2619 }
2620 2620
2621 // The renderer must allocate a new LocalSurfaceId if frame size or device 2621 // The renderer must allocate a new LocalSurfaceId if frame size or device
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2672 // stale graphics on top-level frames. We accept frames that have a source ID 2672 // stale graphics on top-level frames. We accept frames that have a source ID
2673 // greater than |current_content_source_id_| because in some cases the first 2673 // greater than |current_content_source_id_| because in some cases the first
2674 // compositor frame can arrive before the navigation commit message that 2674 // compositor frame can arrive before the navigation commit message that
2675 // updates that value. 2675 // updates that value.
2676 if (view_ && frame.metadata.content_source_id >= current_content_source_id_) { 2676 if (view_ && frame.metadata.content_source_id >= current_content_source_id_) {
2677 view_->SubmitCompositorFrame(local_surface_id, std::move(frame)); 2677 view_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2678 view_->DidReceiveRendererFrame(); 2678 view_->DidReceiveRendererFrame();
2679 } else { 2679 } else {
2680 cc::ReturnedResourceArray resources; 2680 cc::ReturnedResourceArray resources;
2681 cc::TransferableResource::ReturnResources(frame.resource_list, &resources); 2681 cc::TransferableResource::ReturnResources(frame.resource_list, &resources);
2682 SendReclaimCompositorResources(true /* is_swap_ack */, resources); 2682 renderer_compositor_frame_sink_->ReclaimResources(resources);
2683 renderer_compositor_frame_sink_->DidReceiveCompositorFrameAck();
piman 2017/04/10 23:35:58 Could we avoid splitting this into 2 IPCs?
Saman Sami 2017/04/11 00:09:52 I proposed that, but other folks objected because
2683 } 2684 }
2684 2685
2685 // After navigation, if a frame belonging to the new page is received, stop 2686 // After navigation, if a frame belonging to the new page is received, stop
2686 // the timer that triggers clearing the graphics of the last page. 2687 // the timer that triggers clearing the graphics of the last page.
2687 if (last_received_content_source_id_ >= current_content_source_id_ && 2688 if (last_received_content_source_id_ >= current_content_source_id_ &&
2688 new_content_rendering_timeout_->IsRunning()) { 2689 new_content_rendering_timeout_->IsRunning()) {
2689 new_content_rendering_timeout_->Stop(); 2690 new_content_rendering_timeout_->Stop();
2690 } 2691 }
2691 2692
2692 if (delegate_) 2693 if (delegate_)
(...skipping 25 matching lines...) Expand all
2718 RenderProcessHost* rph = GetProcess(); 2719 RenderProcessHost* rph = GetProcess();
2719 for (std::vector<IPC::Message>::const_iterator i = messages.begin(); 2720 for (std::vector<IPC::Message>::const_iterator i = messages.begin();
2720 i != messages.end(); ++i) { 2721 i != messages.end(); ++i) {
2721 rph->OnMessageReceived(*i); 2722 rph->OnMessageReceived(*i);
2722 if (i->dispatch_error()) 2723 if (i->dispatch_error())
2723 rph->OnBadMessageReceived(*i); 2724 rph->OnBadMessageReceived(*i);
2724 } 2725 }
2725 } 2726 }
2726 2727
2727 } // namespace content 2728 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698