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

Side by Side Diff: content/browser/frame_host/render_widget_host_view_child_frame.cc

Issue 2688613002: RenderWidgetHostViewChildFrame should use CompositorFrameSinkSupport (Closed)
Patch Set: c Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/frame_host/render_widget_host_view_child_frame.h" 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( 50 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame(
51 RenderWidgetHost* widget_host) 51 RenderWidgetHost* widget_host)
52 : host_(RenderWidgetHostImpl::From(widget_host)), 52 : host_(RenderWidgetHostImpl::From(widget_host)),
53 frame_sink_id_( 53 frame_sink_id_(
54 base::checked_cast<uint32_t>(widget_host->GetProcess()->GetID()), 54 base::checked_cast<uint32_t>(widget_host->GetProcess()->GetID()),
55 base::checked_cast<uint32_t>(widget_host->GetRoutingID())), 55 base::checked_cast<uint32_t>(widget_host->GetRoutingID())),
56 next_surface_sequence_(1u), 56 next_surface_sequence_(1u),
57 last_compositor_frame_sink_id_(0), 57 last_compositor_frame_sink_id_(0),
58 current_surface_scale_factor_(1.f), 58 current_surface_scale_factor_(1.f),
59 ack_pending_count_(0),
60 frame_connector_(nullptr), 59 frame_connector_(nullptr),
61 begin_frame_source_(nullptr),
62 weak_factory_(this) { 60 weak_factory_(this) {
63 id_allocator_.reset(new cc::SurfaceIdAllocator()); 61 id_allocator_.reset(new cc::SurfaceIdAllocator());
64 auto* manager = GetSurfaceManager(); 62 GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
65 manager->RegisterFrameSinkId(frame_sink_id_); 63 support_ = base::MakeUnique<cc::CompositorFrameSinkSupport>(
66 surface_factory_ = 64 this, GetSurfaceManager(), frame_sink_id_, false, false, false);
67 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this);
68 } 65 }
69 66
70 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { 67 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() {
71 surface_factory_->EvictSurface(); 68 support_.reset();
72 if (GetSurfaceManager()) 69 if (GetSurfaceManager())
73 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); 70 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
74 } 71 }
75 72
76 void RenderWidgetHostViewChildFrame::Init() { 73 void RenderWidgetHostViewChildFrame::Init() {
77 RegisterFrameSinkId(); 74 RegisterFrameSinkId();
78 host_->SetView(this); 75 host_->SetView(this);
79 GetTextInputManager(); 76 GetTextInputManager();
80 } 77 }
81 78
82 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( 79 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector(
83 CrossProcessFrameConnector* frame_connector) { 80 CrossProcessFrameConnector* frame_connector) {
84 if (frame_connector_ == frame_connector) 81 if (frame_connector_ == frame_connector)
85 return; 82 return;
86 83
87 if (frame_connector_) { 84 if (frame_connector_) {
88 if (parent_frame_sink_id_.is_valid()) { 85 if (parent_frame_sink_id_.is_valid()) {
89 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, 86 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_,
90 frame_sink_id_); 87 frame_sink_id_);
91 } 88 }
92 // Unregister the client here, as it is not guaranteed in tests that the 89
93 // destructor will be called. 90 support_.reset();
94 GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_);
95 91
96 parent_frame_sink_id_ = cc::FrameSinkId(); 92 parent_frame_sink_id_ = cc::FrameSinkId();
97 93
98 // After the RenderWidgetHostViewChildFrame loses the frame_connector, it 94 // After the RenderWidgetHostViewChildFrame loses the frame_connector, it
99 // won't be able to walk up the frame tree anymore. Clean up anything that 95 // won't be able to walk up the frame tree anymore. Clean up anything that
100 // needs to be done through the CrossProcessFrameConnector before it's gone. 96 // needs to be done through the CrossProcessFrameConnector before it's gone.
101 97
102 // Unlocks the mouse if this RenderWidgetHostView holds the lock. 98 // Unlocks the mouse if this RenderWidgetHostView holds the lock.
103 UnlockMouse(); 99 UnlockMouse();
104 } 100 }
105 frame_connector_ = frame_connector; 101 frame_connector_ = frame_connector;
106 if (frame_connector_) { 102 if (frame_connector_) {
107 GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, this); 103 support_.reset();
Fady Samuel 2017/02/17 17:27:23 This isn't necessary.
Saman Sami 2017/02/17 17:31:35 Actually, if I omit it a new CompositorFrameSinkSu
104 support_ = base::MakeUnique<cc::CompositorFrameSinkSupport>(
105 this, GetSurfaceManager(), frame_sink_id_, false, false, false);
108 RenderWidgetHostViewBase* parent_view = 106 RenderWidgetHostViewBase* parent_view =
109 frame_connector_->GetParentRenderWidgetHostView(); 107 frame_connector_->GetParentRenderWidgetHostView();
110 if (parent_view) { 108 if (parent_view) {
111 parent_frame_sink_id_ = parent_view->GetFrameSinkId(); 109 parent_frame_sink_id_ = parent_view->GetFrameSinkId();
112 DCHECK(parent_frame_sink_id_.is_valid()); 110 DCHECK(parent_frame_sink_id_.is_valid());
113 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, 111 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_,
114 frame_sink_id_); 112 frame_sink_id_);
115 } 113 }
116 } 114 }
117 } 115 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // always forwarded and handled according to current scroll state in the 344 // always forwarded and handled according to current scroll state in the
347 // RenderWidgetHostInputEventRouter. 345 // RenderWidgetHostInputEventRouter.
348 if (!frame_connector_) 346 if (!frame_connector_)
349 return; 347 return;
350 if ((event.type() == blink::WebInputEvent::GestureScrollUpdate && 348 if ((event.type() == blink::WebInputEvent::GestureScrollUpdate &&
351 not_consumed) || 349 not_consumed) ||
352 event.type() == blink::WebInputEvent::GestureScrollEnd) 350 event.type() == blink::WebInputEvent::GestureScrollEnd)
353 frame_connector_->BubbleScrollEvent(event); 351 frame_connector_->BubbleScrollEvent(event);
354 } 352 }
355 353
356 void RenderWidgetHostViewChildFrame::SurfaceDrawn( 354 void RenderWidgetHostViewChildFrame::DidReceiveCompositorFrameAck() {
357 uint32_t compositor_frame_sink_id) { 355 if (!host_)
358 DCHECK_GT(ack_pending_count_, 0U); 356 return;
359 if (host_) { 357 host_->Send(new ViewMsg_ReclaimCompositorResources(
360 host_->Send(new ViewMsg_ReclaimCompositorResources( 358 host_->GetRoutingID(), last_compositor_frame_sink_id_,
361 host_->GetRoutingID(), compositor_frame_sink_id, true /* is_swap_ack */, 359 true /* is_swap_ack */, cc::ReturnedResourceArray()));
362 surface_returned_resources_));
363 surface_returned_resources_.clear();
364 }
365 ack_pending_count_--;
366 } 360 }
367 361
368 bool RenderWidgetHostViewChildFrame::ShouldCreateNewSurfaceId( 362 bool RenderWidgetHostViewChildFrame::ShouldCreateNewSurfaceId(
369 uint32_t compositor_frame_sink_id, 363 uint32_t compositor_frame_sink_id,
370 const cc::CompositorFrame& frame) { 364 const cc::CompositorFrame& frame) {
371 gfx::Size new_frame_size = frame.render_pass_list.back()->output_rect.size(); 365 gfx::Size new_frame_size = frame.render_pass_list.back()->output_rect.size();
372 float new_scale_factor = frame.metadata.device_scale_factor; 366 float new_scale_factor = frame.metadata.device_scale_factor;
373 367
374 return compositor_frame_sink_id != last_compositor_frame_sink_id_ || 368 return compositor_frame_sink_id != last_compositor_frame_sink_id_ ||
375 new_frame_size != current_surface_size_ || 369 new_frame_size != current_surface_size_ ||
376 new_scale_factor != current_surface_scale_factor_; 370 new_scale_factor != current_surface_scale_factor_;
377 } 371 }
378 372
379 void RenderWidgetHostViewChildFrame::ProcessCompositorFrame( 373 void RenderWidgetHostViewChildFrame::ProcessCompositorFrame(
380 uint32_t compositor_frame_sink_id, 374 uint32_t compositor_frame_sink_id,
381 cc::CompositorFrame frame) { 375 cc::CompositorFrame frame) {
382 if (ShouldCreateNewSurfaceId(compositor_frame_sink_id, frame)) { 376 if (ShouldCreateNewSurfaceId(compositor_frame_sink_id, frame)) {
383 ClearCompositorSurfaceIfNecessary(); 377 ClearCompositorSurfaceIfNecessary();
384 // If the renderer changed its frame sink, reset the surface factory to 378 // If the renderer changed its frame sink, reset the
385 // avoid returning stale resources. 379 // CompositorFrameSinkSupport to avoid returning stale resources.
386 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) 380 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) {
387 surface_factory_->Reset(); 381 support_.reset();
382 support_ = base::MakeUnique<cc::CompositorFrameSinkSupport>(
383 this, GetSurfaceManager(), frame_sink_id_, false, false, false);
384 }
388 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 385 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
389 current_surface_size_ = frame.render_pass_list.back()->output_rect.size(); 386 current_surface_size_ = frame.render_pass_list.back()->output_rect.size();
390 current_surface_scale_factor_ = frame.metadata.device_scale_factor; 387 current_surface_scale_factor_ = frame.metadata.device_scale_factor;
391 } 388 }
392 389
393 bool allocated_new_local_surface_id = false; 390 bool allocated_new_local_surface_id = false;
394 if (!local_surface_id_.is_valid()) { 391 if (!local_surface_id_.is_valid()) {
395 local_surface_id_ = id_allocator_->GenerateId(); 392 local_surface_id_ = id_allocator_->GenerateId();
396 allocated_new_local_surface_id = true; 393 allocated_new_local_surface_id = true;
397 } 394 }
398 395
399 cc::SurfaceFactory::DrawCallback ack_callback = 396 // ack_pending_count_++;
400 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(),
401 compositor_frame_sink_id);
402 ack_pending_count_++;
403 // If this value grows very large, something is going wrong. 397 // If this value grows very large, something is going wrong.
404 DCHECK_LT(ack_pending_count_, 1000U); 398 // DCHECK_LT(ack_pending_count_, 1000U);
405 surface_factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame), 399 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame));
406 ack_callback);
407 if (allocated_new_local_surface_id) 400 if (allocated_new_local_surface_id)
408 SendSurfaceInfoToEmbedder(); 401 SendSurfaceInfoToEmbedder();
409 ProcessFrameSwappedCallbacks(); 402 ProcessFrameSwappedCallbacks();
410 } 403 }
411 404
412 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { 405 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() {
413 cc::SurfaceSequence sequence = 406 cc::SurfaceSequence sequence =
414 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); 407 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++);
415 cc::SurfaceManager* manager = GetSurfaceManager(); 408 cc::SurfaceManager* manager = GetSurfaceManager();
416 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); 409 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 const SkColorType preferred_color_type) { 620 const SkColorType preferred_color_type) {
628 DCHECK(IsSurfaceAvailableForCopy()); 621 DCHECK(IsSurfaceAvailableForCopy());
629 622
630 std::unique_ptr<cc::CopyOutputRequest> request = 623 std::unique_ptr<cc::CopyOutputRequest> request =
631 cc::CopyOutputRequest::CreateRequest( 624 cc::CopyOutputRequest::CreateRequest(
632 base::Bind(&CopyFromCompositingSurfaceHasResult, output_size, 625 base::Bind(&CopyFromCompositingSurfaceHasResult, output_size,
633 preferred_color_type, callback)); 626 preferred_color_type, callback));
634 if (!src_subrect.IsEmpty()) 627 if (!src_subrect.IsEmpty())
635 request->set_area(src_subrect); 628 request->set_area(src_subrect);
636 629
637 surface_factory_->RequestCopyOfSurface(std::move(request)); 630 support_->RequestCopyOfSurface(std::move(request));
638 } 631 }
639 632
640 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( 633 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame(
641 const gfx::Rect& src_subrect, 634 const gfx::Rect& src_subrect,
642 const scoped_refptr<media::VideoFrame>& target, 635 const scoped_refptr<media::VideoFrame>& target,
643 const base::Callback<void(const gfx::Rect&, bool)>& callback) { 636 const base::Callback<void(const gfx::Rect&, bool)>& callback) {
644 NOTIMPLEMENTED(); 637 NOTIMPLEMENTED();
645 callback.Run(gfx::Rect(), false); 638 callback.Run(gfx::Rect(), false);
646 } 639 }
647 640
648 bool RenderWidgetHostViewChildFrame::CanCopyToVideoFrame() const { 641 bool RenderWidgetHostViewChildFrame::CanCopyToVideoFrame() const {
649 return false; 642 return false;
650 } 643 }
651 644
652 bool RenderWidgetHostViewChildFrame::HasAcceleratedSurface( 645 bool RenderWidgetHostViewChildFrame::HasAcceleratedSurface(
653 const gfx::Size& desired_size) { 646 const gfx::Size& desired_size) {
654 return false; 647 return false;
655 } 648 }
656 649
657 // cc::SurfaceFactoryClient implementation. 650 void RenderWidgetHostViewChildFrame::ReclaimResources(
658 void RenderWidgetHostViewChildFrame::ReturnResources(
659 const cc::ReturnedResourceArray& resources) { 651 const cc::ReturnedResourceArray& resources) {
660 if (resources.empty()) 652 if (!host_)
661 return; 653 return;
662 654 host_->Send(new ViewMsg_ReclaimCompositorResources(
663 if (!ack_pending_count_ && host_) { 655 host_->GetRoutingID(), last_compositor_frame_sink_id_,
664 host_->Send(new ViewMsg_ReclaimCompositorResources( 656 false /* is_swap_ack */, resources));
665 host_->GetRoutingID(), last_compositor_frame_sink_id_,
666 false /* is_swap_ack */, resources));
667 return;
668 }
669
670 std::copy(resources.begin(), resources.end(),
671 std::back_inserter(surface_returned_resources_));
672 }
673
674 void RenderWidgetHostViewChildFrame::SetBeginFrameSource(
675 cc::BeginFrameSource* source) {
676 bool needs_begin_frames = host_->needs_begin_frames();
677 if (begin_frame_source_ && needs_begin_frames)
678 begin_frame_source_->RemoveObserver(this);
679 begin_frame_source_ = source;
680 if (begin_frame_source_ && needs_begin_frames)
681 begin_frame_source_->AddObserver(this);
682 } 657 }
683 658
684 void RenderWidgetHostViewChildFrame::OnBeginFrame( 659 void RenderWidgetHostViewChildFrame::OnBeginFrame(
685 const cc::BeginFrameArgs& args) { 660 const cc::BeginFrameArgs& args) {
686 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args)); 661 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args));
687 last_begin_frame_args_ = args;
688 }
689
690 const cc::BeginFrameArgs&
691 RenderWidgetHostViewChildFrame::LastUsedBeginFrameArgs() const {
692 return last_begin_frame_args_;
693 }
694
695 void RenderWidgetHostViewChildFrame::OnBeginFrameSourcePausedChanged(
696 bool paused) {
697 // Only used on Android WebView.
698 } 662 }
699 663
700 void RenderWidgetHostViewChildFrame::SetNeedsBeginFrames( 664 void RenderWidgetHostViewChildFrame::SetNeedsBeginFrames(
701 bool needs_begin_frames) { 665 bool needs_begin_frames) {
702 if (!begin_frame_source_) 666 support_->SetNeedsBeginFrame(needs_begin_frames);
703 return;
704
705 if (needs_begin_frames)
706 begin_frame_source_->AddObserver(this);
707 else
708 begin_frame_source_->RemoveObserver(this);
709 } 667 }
710 668
711 InputEventAckState RenderWidgetHostViewChildFrame::FilterInputEvent( 669 InputEventAckState RenderWidgetHostViewChildFrame::FilterInputEvent(
712 const blink::WebInputEvent& input_event) { 670 const blink::WebInputEvent& input_event) {
713 if (input_event.type() == blink::WebInputEvent::GestureFlingStart) { 671 if (input_event.type() == blink::WebInputEvent::GestureFlingStart) {
714 const blink::WebGestureEvent& gesture_event = 672 const blink::WebGestureEvent& gesture_event =
715 static_cast<const blink::WebGestureEvent&>(input_event); 673 static_cast<const blink::WebGestureEvent&>(input_event);
716 // Zero-velocity touchpad flings are an Aura-specific signal that the 674 // Zero-velocity touchpad flings are an Aura-specific signal that the
717 // touchpad scroll has ended, and should not be forwarded to the renderer. 675 // touchpad scroll has ended, and should not be forwarded to the renderer.
718 if (gesture_event.sourceDevice == blink::WebGestureDeviceTouchpad && 676 if (gesture_event.sourceDevice == blink::WebGestureDeviceTouchpad &&
(...skipping 15 matching lines...) Expand all
734 } 692 }
735 693
736 BrowserAccessibilityManager* 694 BrowserAccessibilityManager*
737 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( 695 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager(
738 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { 696 BrowserAccessibilityDelegate* delegate, bool for_root_frame) {
739 return BrowserAccessibilityManager::Create( 697 return BrowserAccessibilityManager::Create(
740 BrowserAccessibilityManager::GetEmptyDocument(), delegate); 698 BrowserAccessibilityManager::GetEmptyDocument(), delegate);
741 } 699 }
742 700
743 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { 701 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() {
744 surface_factory_->EvictSurface(); 702 support_->EvictFrame();
745 local_surface_id_ = cc::LocalSurfaceId(); 703 local_surface_id_ = cc::LocalSurfaceId();
746 } 704 }
747 705
748 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { 706 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const {
749 return true; 707 return true;
750 } 708 }
751 709
752 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { 710 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const {
753 return cc::SurfaceId(frame_sink_id_, local_surface_id_); 711 return cc::SurfaceId(frame_sink_id_, local_surface_id_);
754 }; 712 };
755 713
756 } // namespace content 714 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698