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

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

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

Powered by Google App Engine
This is Rietveld 408576698