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

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

Issue 2383373002: Reduce SurfaceIdAllocator usage and tie SurfaceFactory to a single FrameSinkId (Closed)
Patch Set: Rebased Created 4 years, 2 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>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return; 56 return;
57 } 57 }
58 surface->AddDestructionDependency(sequence); 58 surface->AddDestructionDependency(sequence);
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 //////////////////////////////////////////////////////////////////////////////// 63 ////////////////////////////////////////////////////////////////////////////////
64 // DelegatedFrameHost 64 // DelegatedFrameHost
65 65
66 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) 66 DelegatedFrameHost::DelegatedFrameHost(const cc::FrameSinkId& frame_sink_id,
67 : client_(client), 67 DelegatedFrameHostClient* client)
68 : frame_sink_id_(frame_sink_id),
69 client_(client),
68 compositor_(nullptr), 70 compositor_(nullptr),
69 tick_clock_(new base::DefaultTickClock()), 71 tick_clock_(new base::DefaultTickClock()),
70 last_compositor_frame_sink_id_(0), 72 last_compositor_frame_sink_id_(0),
71 pending_delegated_ack_count_(0), 73 pending_delegated_ack_count_(0),
72 skipped_frames_(false), 74 skipped_frames_(false),
73 background_color_(SK_ColorRED), 75 background_color_(SK_ColorRED),
74 current_scale_factor_(1.f), 76 current_scale_factor_(1.f),
75 can_lock_compositor_(YES_CAN_LOCK), 77 can_lock_compositor_(YES_CAN_LOCK),
76 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { 78 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) {
77 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 79 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
78 factory->GetContextFactory()->AddObserver(this); 80 factory->GetContextFactory()->AddObserver(this);
79 id_allocator_.reset(new cc::SurfaceIdAllocator( 81 id_allocator_.reset(new cc::SurfaceIdAllocator(frame_sink_id_));
80 factory->GetContextFactory()->AllocateFrameSinkId())); 82 factory->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
81 factory->GetSurfaceManager()->RegisterFrameSinkId( 83 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_,
82 id_allocator_->frame_sink_id()); 84 this);
83 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient(
84 id_allocator_->frame_sink_id(), this);
85 } 85 }
86 86
87 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { 87 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) {
88 delegated_frame_evictor_->SetVisible(true); 88 delegated_frame_evictor_->SetVisible(true);
89 89
90 if (surface_id_.is_null() && !released_front_lock_.get()) { 90 if (surface_id_.is_null() && !released_front_lock_.get()) {
91 if (compositor_) 91 if (compositor_)
92 released_front_lock_ = compositor_->GetCompositorLock(); 92 released_front_lock_ = compositor_->GetCompositorLock();
93 } 93 }
94 94
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { 201 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) {
202 frame_subscriber_ = std::move(subscriber); 202 frame_subscriber_ = std::move(subscriber);
203 } 203 }
204 204
205 void DelegatedFrameHost::EndFrameSubscription() { 205 void DelegatedFrameHost::EndFrameSubscription() {
206 idle_frame_subscriber_textures_.clear(); 206 idle_frame_subscriber_textures_.clear();
207 frame_subscriber_.reset(); 207 frame_subscriber_.reset();
208 } 208 }
209 209
210 cc::FrameSinkId DelegatedFrameHost::GetFrameSinkId() { 210 cc::FrameSinkId DelegatedFrameHost::GetFrameSinkId() {
211 return id_allocator_->frame_sink_id(); 211 return frame_sink_id_;
212 } 212 }
213 213
214 cc::SurfaceId DelegatedFrameHost::SurfaceIdAtPoint( 214 cc::SurfaceId DelegatedFrameHost::SurfaceIdAtPoint(
215 cc::SurfaceHittestDelegate* delegate, 215 cc::SurfaceHittestDelegate* delegate,
216 const gfx::Point& point, 216 const gfx::Point& point,
217 gfx::Point* transformed_point) { 217 gfx::Point* transformed_point) {
218 if (surface_id_.is_null()) 218 if (surface_id_.is_null())
219 return surface_id_; 219 return surface_id_;
220 cc::SurfaceHittest hittest(delegate, GetSurfaceManager()); 220 cc::SurfaceHittest hittest(delegate, GetSurfaceManager());
221 gfx::Transform target_transform; 221 gfx::Transform target_transform;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 464
465 background_color_ = frame.metadata.root_background_color; 465 background_color_ = frame.metadata.root_background_color;
466 466
467 if (frame_size.IsEmpty()) { 467 if (frame_size.IsEmpty()) {
468 DCHECK(frame_data->resource_list.empty()); 468 DCHECK(frame_data->resource_list.empty());
469 EvictDelegatedFrame(); 469 EvictDelegatedFrame();
470 } else { 470 } else {
471 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 471 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
472 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 472 cc::SurfaceManager* manager = factory->GetSurfaceManager();
473 if (!surface_factory_) { 473 if (!surface_factory_) {
474 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(manager, this); 474 surface_factory_ =
475 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this);
475 } 476 }
476 if (surface_id_.is_null() || frame_size != current_surface_size_ || 477 if (surface_id_.is_null() || frame_size != current_surface_size_ ||
477 frame_size_in_dip != current_frame_size_in_dip_) { 478 frame_size_in_dip != current_frame_size_in_dip_) {
478 if (!surface_id_.is_null()) 479 if (!surface_id_.is_null())
479 surface_factory_->Destroy(surface_id_); 480 surface_factory_->Destroy(surface_id_);
480 surface_id_ = id_allocator_->GenerateId(); 481 surface_id_ = id_allocator_->GenerateId();
481 surface_factory_->Create(surface_id_); 482 surface_factory_->Create(surface_id_);
482 // manager must outlive compositors using it. 483 // manager must outlive compositors using it.
483 client_->DelegatedFrameHostGetLayer()->SetShowSurface( 484 client_->DelegatedFrameHostGetLayer()->SetShowSurface(
484 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), 485 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)),
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 //////////////////////////////////////////////////////////////////////////////// 824 ////////////////////////////////////////////////////////////////////////////////
824 // DelegatedFrameHost, private: 825 // DelegatedFrameHost, private:
825 826
826 DelegatedFrameHost::~DelegatedFrameHost() { 827 DelegatedFrameHost::~DelegatedFrameHost() {
827 DCHECK(!compositor_); 828 DCHECK(!compositor_);
828 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 829 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
829 factory->GetContextFactory()->RemoveObserver(this); 830 factory->GetContextFactory()->RemoveObserver(this);
830 831
831 if (!surface_id_.is_null()) 832 if (!surface_id_.is_null())
832 surface_factory_->Destroy(surface_id_); 833 surface_factory_->Destroy(surface_id_);
833 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient( 834 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_);
834 id_allocator_->frame_sink_id()); 835 factory->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
835 factory->GetSurfaceManager()->InvalidateFrameSinkId(
836 id_allocator_->frame_sink_id());
837 836
838 DCHECK(!vsync_manager_.get()); 837 DCHECK(!vsync_manager_.get());
839 } 838 }
840 839
841 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { 840 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) {
842 DCHECK(!compositor_); 841 DCHECK(!compositor_);
843 if (!compositor) 842 if (!compositor)
844 return; 843 return;
845 compositor_ = compositor; 844 compositor_ = compositor;
846 compositor_->AddObserver(this); 845 compositor_->AddObserver(this);
847 DCHECK(!vsync_manager_.get()); 846 DCHECK(!vsync_manager_.get());
848 vsync_manager_ = compositor_->vsync_manager(); 847 vsync_manager_ = compositor_->vsync_manager();
849 vsync_manager_->AddObserver(this); 848 vsync_manager_->AddObserver(this);
850 849
851 compositor_->AddFrameSink(id_allocator_->frame_sink_id()); 850 compositor_->AddFrameSink(frame_sink_id_);
852 } 851 }
853 852
854 void DelegatedFrameHost::ResetCompositor() { 853 void DelegatedFrameHost::ResetCompositor() {
855 if (!compositor_) 854 if (!compositor_)
856 return; 855 return;
857 if (resize_lock_) { 856 if (resize_lock_) {
858 resize_lock_.reset(); 857 resize_lock_.reset();
859 client_->DelegatedFrameHostResizeLockWasReleased(); 858 client_->DelegatedFrameHostResizeLockWasReleased();
860 } 859 }
861 if (compositor_->HasObserver(this)) 860 if (compositor_->HasObserver(this))
862 compositor_->RemoveObserver(this); 861 compositor_->RemoveObserver(this);
863 if (vsync_manager_) { 862 if (vsync_manager_) {
864 vsync_manager_->RemoveObserver(this); 863 vsync_manager_->RemoveObserver(this);
865 vsync_manager_ = nullptr; 864 vsync_manager_ = nullptr;
866 } 865 }
867 866
868 compositor_->RemoveFrameSink(id_allocator_->frame_sink_id()); 867 compositor_->RemoveFrameSink(frame_sink_id_);
869 compositor_ = nullptr; 868 compositor_ = nullptr;
870 } 869 }
871 870
872 void DelegatedFrameHost::LockResources() { 871 void DelegatedFrameHost::LockResources() {
873 DCHECK(!surface_id_.is_null()); 872 DCHECK(!surface_id_.is_null());
874 delegated_frame_evictor_->LockFrame(); 873 delegated_frame_evictor_->LockFrame();
875 } 874 }
876 875
877 void DelegatedFrameHost::RequestCopyOfOutput( 876 void DelegatedFrameHost::RequestCopyOfOutput(
878 std::unique_ptr<cc::CopyOutputRequest> request) { 877 std::unique_ptr<cc::CopyOutputRequest> request) {
(...skipping 23 matching lines...) Expand all
902 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 901 cc::SurfaceManager* manager = factory->GetSurfaceManager();
903 new_layer->SetShowSurface( 902 new_layer->SetShowSurface(
904 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), 903 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)),
905 base::Bind(&RequireCallback, base::Unretained(manager)), 904 base::Bind(&RequireCallback, base::Unretained(manager)),
906 current_surface_size_, current_scale_factor_, 905 current_surface_size_, current_scale_factor_,
907 current_frame_size_in_dip_); 906 current_frame_size_in_dip_);
908 } 907 }
909 } 908 }
910 909
911 } // namespace content 910 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698