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

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

Issue 2693423005: DelegatedFrameHost should use CompositorFrameSinkSupport (Closed)
Patch Set: c Created 3 years, 9 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/renderer_host/delegated_frame_host.h" 5 #include "content/browser/renderer_host/delegated_frame_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/time/default_tick_clock.h" 15 #include "base/time/default_tick_clock.h"
16 #include "cc/base/switches.h" 16 #include "cc/base/switches.h"
17 #include "cc/output/compositor_frame.h" 17 #include "cc/output/compositor_frame.h"
18 #include "cc/output/copy_output_request.h" 18 #include "cc/output/copy_output_request.h"
19 #include "cc/resources/single_release_callback.h" 19 #include "cc/resources/single_release_callback.h"
20 #include "cc/resources/texture_mailbox.h" 20 #include "cc/resources/texture_mailbox.h"
21 #include "cc/surfaces/compositor_frame_sink_support.h"
21 #include "cc/surfaces/local_surface_id_allocator.h" 22 #include "cc/surfaces/local_surface_id_allocator.h"
22 #include "cc/surfaces/surface.h" 23 #include "cc/surfaces/surface.h"
23 #include "cc/surfaces/surface_factory.h" 24 #include "cc/surfaces/surface_factory.h"
24 #include "cc/surfaces/surface_hittest.h" 25 #include "cc/surfaces/surface_hittest.h"
25 #include "cc/surfaces/surface_manager.h" 26 #include "cc/surfaces/surface_manager.h"
26 #include "components/display_compositor/gl_helper.h" 27 #include "components/display_compositor/gl_helper.h"
27 #include "content/browser/compositor/surface_utils.h" 28 #include "content/browser/compositor/surface_utils.h"
28 #include "content/browser/gpu/compositor_util.h" 29 #include "content/browser/gpu/compositor_util.h"
29 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber .h" 30 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber .h"
30 #include "content/browser/renderer_host/resize_lock.h" 31 #include "content/browser/renderer_host/resize_lock.h"
(...skipping 11 matching lines...) Expand all
42 //////////////////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////////////////
43 // DelegatedFrameHost 44 // DelegatedFrameHost
44 45
45 DelegatedFrameHost::DelegatedFrameHost(const cc::FrameSinkId& frame_sink_id, 46 DelegatedFrameHost::DelegatedFrameHost(const cc::FrameSinkId& frame_sink_id,
46 DelegatedFrameHostClient* client) 47 DelegatedFrameHostClient* client)
47 : frame_sink_id_(frame_sink_id), 48 : frame_sink_id_(frame_sink_id),
48 client_(client), 49 client_(client),
49 compositor_(nullptr), 50 compositor_(nullptr),
50 tick_clock_(new base::DefaultTickClock()), 51 tick_clock_(new base::DefaultTickClock()),
51 last_compositor_frame_sink_id_(0), 52 last_compositor_frame_sink_id_(0),
52 pending_delegated_ack_count_(0),
53 skipped_frames_(false), 53 skipped_frames_(false),
54 background_color_(SK_ColorRED), 54 background_color_(SK_ColorRED),
55 current_scale_factor_(1.f), 55 current_scale_factor_(1.f),
56 can_lock_compositor_(YES_CAN_LOCK), 56 can_lock_compositor_(YES_CAN_LOCK),
57 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { 57 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) {
58 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 58 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
59 factory->GetContextFactory()->AddObserver(this); 59 factory->GetContextFactory()->AddObserver(this);
60 id_allocator_.reset(new cc::LocalSurfaceIdAllocator()); 60 id_allocator_.reset(new cc::LocalSurfaceIdAllocator());
61 factory->GetContextFactoryPrivate()->GetSurfaceManager()->RegisterFrameSinkId( 61 factory->GetContextFactoryPrivate()->GetSurfaceManager()->RegisterFrameSinkId(
62 frame_sink_id_); 62 frame_sink_id_);
63 factory->GetContextFactoryPrivate() 63 CreateCompositorFrameSinkSupport();
64 ->GetSurfaceManager() 64 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this);
65 ->RegisterSurfaceFactoryClient(frame_sink_id_, this); 65 client_->SetBeginFrameSource(begin_frame_source_.get());
66 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(
67 frame_sink_id_, factory->GetContextFactoryPrivate()->GetSurfaceManager(),
68 this);
69 } 66 }
70 67
71 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { 68 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) {
72 delegated_frame_evictor_->SetVisible(true); 69 delegated_frame_evictor_->SetVisible(true);
73 70
74 if (!local_surface_id_.is_valid() && !released_front_lock_.get()) { 71 if (!local_surface_id_.is_valid() && !released_front_lock_.get()) {
75 if (compositor_) 72 if (compositor_)
76 released_front_lock_ = compositor_->GetCompositorLock(); 73 released_front_lock_ = compositor_->GetCompositorLock();
77 } 74 }
78 75
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 subscriber_texture->target())); 369 subscriber_texture->target()));
373 } 370 }
374 371
375 if (local_surface_id_.is_valid()) { 372 if (local_surface_id_.is_valid()) {
376 // To avoid unnecessary composites, go directly to the Surface rather than 373 // To avoid unnecessary composites, go directly to the Surface rather than
377 // through RequestCopyOfOutput (which goes through the browser 374 // through RequestCopyOfOutput (which goes through the browser
378 // compositor). 375 // compositor).
379 if (!request_copy_of_output_callback_for_testing_.is_null()) 376 if (!request_copy_of_output_callback_for_testing_.is_null())
380 request_copy_of_output_callback_for_testing_.Run(std::move(request)); 377 request_copy_of_output_callback_for_testing_.Run(std::move(request));
381 else 378 else
382 surface_factory_->RequestCopyOfSurface(std::move(request)); 379 support_->RequestCopyOfSurface(std::move(request));
383 } else { 380 } else {
384 request->set_area(gfx::Rect(current_frame_size_in_dip_)); 381 request->set_area(gfx::Rect(current_frame_size_in_dip_));
385 RequestCopyOfOutput(std::move(request)); 382 RequestCopyOfOutput(std::move(request));
386 } 383 }
387 } 384 }
388 385
389 void DelegatedFrameHost::SwapDelegatedFrame(uint32_t compositor_frame_sink_id, 386 void DelegatedFrameHost::SwapDelegatedFrame(uint32_t compositor_frame_sink_id,
390 cc::CompositorFrame frame) { 387 cc::CompositorFrame frame) {
391 #if defined(OS_CHROMEOS) 388 #if defined(OS_CHROMEOS)
392 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); 389 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 429
433 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { 430 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) {
434 // Resource ids are scoped by the output surface. 431 // Resource ids are scoped by the output surface.
435 // If the originating output surface doesn't match the last one, it 432 // If the originating output surface doesn't match the last one, it
436 // indicates the renderer's output surface may have been recreated, in which 433 // indicates the renderer's output surface may have been recreated, in which
437 // case we should recreate the DelegatedRendererLayer, to avoid matching 434 // case we should recreate the DelegatedRendererLayer, to avoid matching
438 // resources from the old one with resources from the new one which would 435 // resources from the old one with resources from the new one which would
439 // have the same id. Changing the layer to showing painted content destroys 436 // have the same id. Changing the layer to showing painted content destroys
440 // the DelegatedRendererLayer. 437 // the DelegatedRendererLayer.
441 EvictDelegatedFrame(); 438 EvictDelegatedFrame();
442 surface_factory_->Reset(); 439 ResetCompositorFrameSinkSupport();
443 surface_returned_resources_.clear(); 440 CreateCompositorFrameSinkSupport();
444 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 441 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
445 } 442 }
446 pending_delegated_ack_count_++;
447 443
448 background_color_ = frame.metadata.root_background_color; 444 background_color_ = frame.metadata.root_background_color;
449 445
450 if (frame_size.IsEmpty()) { 446 if (frame_size.IsEmpty()) {
451 DCHECK(frame.resource_list.empty()); 447 DCHECK(frame.resource_list.empty());
452 EvictDelegatedFrame(); 448 EvictDelegatedFrame();
453 } else { 449 } else {
454 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 450 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
455 cc::SurfaceManager* manager = 451 cc::SurfaceManager* manager =
456 factory->GetContextFactoryPrivate()->GetSurfaceManager(); 452 factory->GetContextFactoryPrivate()->GetSurfaceManager();
(...skipping 10 matching lines...) Expand all
467 frame.metadata.latency_info.begin(), 463 frame.metadata.latency_info.begin(),
468 frame.metadata.latency_info.end()); 464 frame.metadata.latency_info.end());
469 frame.metadata.latency_info.clear(); 465 frame.metadata.latency_info.clear();
470 } else { 466 } else {
471 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), 467 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(),
472 skipped_latency_info_list_.begin(), 468 skipped_latency_info_list_.begin(),
473 skipped_latency_info_list_.end()); 469 skipped_latency_info_list_.end());
474 skipped_latency_info_list_.clear(); 470 skipped_latency_info_list_.clear();
475 } 471 }
476 472
477 auto ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, 473 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame));
478 AsWeakPtr(), compositor_frame_sink_id); 474
479 surface_factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame),
480 ack_callback);
481 if (allocated_new_local_surface_id) { 475 if (allocated_new_local_surface_id) {
482 // manager must outlive compositors using it. 476 // manager must outlive compositors using it.
483 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); 477 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_);
484 cc::SurfaceInfo surface_info(surface_id, frame_device_scale_factor, 478 cc::SurfaceInfo surface_info(surface_id, frame_device_scale_factor,
485 frame_size); 479 frame_size);
486 client_->DelegatedFrameHostGetLayer()->SetShowSurface( 480 client_->DelegatedFrameHostGetLayer()->SetShowSurface(
487 surface_info, manager->reference_factory()); 481 surface_info, manager->reference_factory());
488 current_surface_size_ = frame_size; 482 current_surface_size_ = frame_size;
489 current_scale_factor_ = frame_device_scale_factor; 483 current_scale_factor_ = frame_device_scale_factor;
490 } 484 }
(...skipping 17 matching lines...) Expand all
508 client_->DelegatedFrameHostIsVisible()); 502 client_->DelegatedFrameHostIsVisible());
509 } 503 }
510 // Note: the frame may have been evicted immediately. 504 // Note: the frame may have been evicted immediately.
511 } 505 }
512 506
513 void DelegatedFrameHost::ClearDelegatedFrame() { 507 void DelegatedFrameHost::ClearDelegatedFrame() {
514 if (local_surface_id_.is_valid()) 508 if (local_surface_id_.is_valid())
515 EvictDelegatedFrame(); 509 EvictDelegatedFrame();
516 } 510 }
517 511
518 void DelegatedFrameHost::SendReclaimCompositorResources( 512 void DelegatedFrameHost::DidReceiveCompositorFrameAck() {
519 uint32_t compositor_frame_sink_id,
520 bool is_swap_ack) {
521 client_->DelegatedFrameHostSendReclaimCompositorResources( 513 client_->DelegatedFrameHostSendReclaimCompositorResources(
522 compositor_frame_sink_id, is_swap_ack, surface_returned_resources_); 514 last_compositor_frame_sink_id_, true /* is_swap_ack */,
523 surface_returned_resources_.clear(); 515 cc::ReturnedResourceArray());
524 if (is_swap_ack) {
525 DCHECK_GT(pending_delegated_ack_count_, 0);
526 pending_delegated_ack_count_--;
527 }
528 } 516 }
529 517
530 void DelegatedFrameHost::SurfaceDrawn(uint32_t compositor_frame_sink_id) { 518 void DelegatedFrameHost::ReclaimResources(
531 SendReclaimCompositorResources(compositor_frame_sink_id,
532 true /* is_swap_ack */);
533 }
534
535 void DelegatedFrameHost::ReturnResources(
536 const cc::ReturnedResourceArray& resources) { 519 const cc::ReturnedResourceArray& resources) {
537 if (resources.empty()) 520 client_->DelegatedFrameHostSendReclaimCompositorResources(
538 return; 521 last_compositor_frame_sink_id_, false /* is_swap_ack */, resources);
539 std::copy(resources.begin(), resources.end(),
540 std::back_inserter(surface_returned_resources_));
541 if (!pending_delegated_ack_count_) {
542 SendReclaimCompositorResources(last_compositor_frame_sink_id_,
543 false /* is_swap_ack */);
544 }
545 } 522 }
546 523
547 void DelegatedFrameHost::WillDrawSurface(const cc::LocalSurfaceId& id, 524 void DelegatedFrameHost::WillDrawSurface(const cc::LocalSurfaceId& id,
548 const gfx::Rect& damage_rect) { 525 const gfx::Rect& damage_rect) {
549 // Frame subscribers are only interested in changes to the target surface, so 526 // Frame subscribers are only interested in changes to the target surface, so
550 // do not attempt capture if |damage_rect| is empty. This prevents the draws 527 // do not attempt capture if |damage_rect| is empty. This prevents the draws
551 // of parent surfaces from triggering extra frame captures, which can affect 528 // of parent surfaces from triggering extra frame captures, which can affect
552 // smoothness. 529 // smoothness.
553 if (id != local_surface_id_ || damage_rect.IsEmpty()) 530 if (id != local_surface_id_ || damage_rect.IsEmpty())
554 return; 531 return;
555 AttemptFrameSubscriberCapture(damage_rect); 532 AttemptFrameSubscriberCapture(damage_rect);
556 } 533 }
557 534
558 void DelegatedFrameHost::SetBeginFrameSource( 535 void DelegatedFrameHost::OnBeginFrame(const cc::BeginFrameArgs& args) {
559 cc::BeginFrameSource* begin_frame_source) { 536 begin_frame_source_->OnBeginFrame(args);
560 client_->SetBeginFrameSource(begin_frame_source);
561 } 537 }
562 538
563 void DelegatedFrameHost::EvictDelegatedFrame() { 539 void DelegatedFrameHost::EvictDelegatedFrame() {
564 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); 540 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent();
565 if (local_surface_id_.is_valid()) { 541 if (local_surface_id_.is_valid()) {
566 surface_factory_->EvictSurface(); 542 support_->EvictFrame();
567 local_surface_id_ = cc::LocalSurfaceId(); 543 local_surface_id_ = cc::LocalSurfaceId();
568 } 544 }
569 delegated_frame_evictor_->DiscardedFrame(); 545 delegated_frame_evictor_->DiscardedFrame();
570 UpdateGutters(); 546 UpdateGutters();
571 } 547 }
572 548
573 // static 549 // static
574 void DelegatedFrameHost::ReturnSubscriberTexture( 550 void DelegatedFrameHost::ReturnSubscriberTexture(
575 base::WeakPtr<DelegatedFrameHost> dfh, 551 base::WeakPtr<DelegatedFrameHost> dfh,
576 scoped_refptr<OwnedMailbox> subscriber_texture, 552 scoped_refptr<OwnedMailbox> subscriber_texture,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 yuv_readback_pipeline_.reset(); 766 yuv_readback_pipeline_.reset();
791 } 767 }
792 768
793 //////////////////////////////////////////////////////////////////////////////// 769 ////////////////////////////////////////////////////////////////////////////////
794 // DelegatedFrameHost, private: 770 // DelegatedFrameHost, private:
795 771
796 DelegatedFrameHost::~DelegatedFrameHost() { 772 DelegatedFrameHost::~DelegatedFrameHost() {
797 DCHECK(!compositor_); 773 DCHECK(!compositor_);
798 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 774 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
799 factory->GetContextFactory()->RemoveObserver(this); 775 factory->GetContextFactory()->RemoveObserver(this);
800 surface_factory_->EvictSurface(); 776
801 factory->GetContextFactoryPrivate() 777 begin_frame_source_.reset();
802 ->GetSurfaceManager() 778 ResetCompositorFrameSinkSupport();
803 ->UnregisterSurfaceFactoryClient(frame_sink_id_); 779
804 factory->GetContextFactoryPrivate() 780 factory->GetContextFactoryPrivate()
805 ->GetSurfaceManager() 781 ->GetSurfaceManager()
806 ->InvalidateFrameSinkId(frame_sink_id_); 782 ->InvalidateFrameSinkId(frame_sink_id_);
807 783
808 DCHECK(!vsync_manager_.get()); 784 DCHECK(!vsync_manager_.get());
809 } 785 }
810 786
811 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { 787 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) {
812 DCHECK(!compositor_); 788 DCHECK(!compositor_);
813 if (!compositor) 789 if (!compositor)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput( 828 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput(
853 std::move(request)); 829 std::move(request));
854 } 830 }
855 } 831 }
856 832
857 void DelegatedFrameHost::UnlockResources() { 833 void DelegatedFrameHost::UnlockResources() {
858 DCHECK(local_surface_id_.is_valid()); 834 DCHECK(local_surface_id_.is_valid());
859 delegated_frame_evictor_->UnlockFrame(); 835 delegated_frame_evictor_->UnlockFrame();
860 } 836 }
861 837
838 void DelegatedFrameHost::OnNeedsBeginFrames(bool needs_begin_frames) {
839 needs_begin_frame_ = needs_begin_frames;
840 support_->SetNeedsBeginFrame(needs_begin_frames);
841 }
842
843 void DelegatedFrameHost::OnDidFinishFrame(const cc::BeginFrameAck& ack) {}
844
845 void DelegatedFrameHost::CreateCompositorFrameSinkSupport() {
846 DCHECK(!support_);
847 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
848 support_ = base::MakeUnique<cc::CompositorFrameSinkSupport>(
849 this, factory->GetContextFactoryPrivate()->GetSurfaceManager(),
850 frame_sink_id_, false /* is_root */,
851 false /* handles_frame_sink_id_invalidation */,
852 true /* needs_sync_points */);
853 if (compositor_)
854 compositor_->AddFrameSink(frame_sink_id_);
855 if (needs_begin_frame_)
856 support_->SetNeedsBeginFrame(true);
857 }
858
859 void DelegatedFrameHost::ResetCompositorFrameSinkSupport() {
860 if (!support_)
861 return;
862 if (compositor_)
863 compositor_->RemoveFrameSink(frame_sink_id_);
864 support_.reset();
865 }
866
862 } // namespace content 867 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698