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

Side by Side Diff: ui/compositor/compositor.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
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/compositor/compositor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/compositor/compositor.h" 5 #include "ui/compositor/compositor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <deque> 10 #include <deque>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 Compositor::Compositor(ui::ContextFactory* context_factory, 74 Compositor::Compositor(ui::ContextFactory* context_factory,
75 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 75 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
76 : context_factory_(context_factory), 76 : context_factory_(context_factory),
77 root_layer_(NULL), 77 root_layer_(NULL),
78 widget_(gfx::kNullAcceleratedWidget), 78 widget_(gfx::kNullAcceleratedWidget),
79 #if defined(USE_AURA) 79 #if defined(USE_AURA)
80 window_(nullptr), 80 window_(nullptr),
81 #endif 81 #endif
82 widget_valid_(false), 82 widget_valid_(false),
83 compositor_frame_sink_requested_(false), 83 compositor_frame_sink_requested_(false),
84 surface_id_allocator_(base::MakeUnique<cc::SurfaceIdAllocator>( 84 frame_sink_id_(context_factory->AllocateFrameSinkId()),
85 context_factory->AllocateFrameSinkId())), 85 surface_id_allocator_(
86 base::MakeUnique<cc::SurfaceIdAllocator>(frame_sink_id_)),
86 task_runner_(task_runner), 87 task_runner_(task_runner),
87 vsync_manager_(new CompositorVSyncManager()), 88 vsync_manager_(new CompositorVSyncManager()),
88 device_scale_factor_(0.0f), 89 device_scale_factor_(0.0f),
89 locks_will_time_out_(true), 90 locks_will_time_out_(true),
90 compositor_lock_(NULL), 91 compositor_lock_(NULL),
91 layer_animator_collection_(this), 92 layer_animator_collection_(this),
92 weak_ptr_factory_(this) { 93 weak_ptr_factory_(this) {
93 context_factory->GetSurfaceManager()->RegisterFrameSinkId( 94 context_factory->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
94 surface_id_allocator_->frame_sink_id());
95 root_web_layer_ = cc::Layer::Create(); 95 root_web_layer_ = cc::Layer::Create();
96 96
97 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 97 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
98 98
99 cc::LayerTreeSettings settings; 99 cc::LayerTreeSettings settings;
100 100
101 // This will ensure PictureLayers always can have LCD text, to match the 101 // This will ensure PictureLayers always can have LCD text, to match the
102 // previous behaviour with ContentLayers, where LCD-not-allowed notifications 102 // previous behaviour with ContentLayers, where LCD-not-allowed notifications
103 // were ignored. 103 // were ignored.
104 settings.layers_always_allowed_lcd_text = true; 104 settings.layers_always_allowed_lcd_text = true;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 host_ = cc::LayerTreeHostInProcess::CreateSingleThreaded(this, &params); 199 host_ = cc::LayerTreeHostInProcess::CreateSingleThreaded(this, &params);
200 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", 200 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor",
201 base::TimeTicks::Now() - before_create); 201 base::TimeTicks::Now() - before_create);
202 202
203 animation_timeline_ = 203 animation_timeline_ =
204 cc::AnimationTimeline::Create(cc::AnimationIdProvider::NextTimelineId()); 204 cc::AnimationTimeline::Create(cc::AnimationIdProvider::NextTimelineId());
205 host_->GetLayerTree()->animation_host()->AddAnimationTimeline( 205 host_->GetLayerTree()->animation_host()->AddAnimationTimeline(
206 animation_timeline_.get()); 206 animation_timeline_.get());
207 207
208 host_->GetLayerTree()->SetRootLayer(root_web_layer_); 208 host_->GetLayerTree()->SetRootLayer(root_web_layer_);
209 host_->SetFrameSinkId(surface_id_allocator_->frame_sink_id()); 209 host_->SetFrameSinkId(frame_sink_id_);
210 host_->SetVisible(true); 210 host_->SetVisible(true);
211 } 211 }
212 212
213 Compositor::~Compositor() { 213 Compositor::~Compositor() {
214 TRACE_EVENT0("shutdown", "Compositor::destructor"); 214 TRACE_EVENT0("shutdown", "Compositor::destructor");
215 215
216 CancelCompositorLock(); 216 CancelCompositorLock();
217 DCHECK(!compositor_lock_); 217 DCHECK(!compositor_lock_);
218 218
219 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, 219 FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
220 OnCompositingShuttingDown(this)); 220 OnCompositingShuttingDown(this));
221 221
222 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, 222 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_,
223 OnCompositingShuttingDown(this)); 223 OnCompositingShuttingDown(this));
224 224
225 if (root_layer_) 225 if (root_layer_)
226 root_layer_->ResetCompositor(); 226 root_layer_->ResetCompositor();
227 227
228 if (animation_timeline_) 228 if (animation_timeline_)
229 host_->GetLayerTree()->animation_host()->RemoveAnimationTimeline( 229 host_->GetLayerTree()->animation_host()->RemoveAnimationTimeline(
230 animation_timeline_.get()); 230 animation_timeline_.get());
231 231
232 // Stop all outstanding draws before telling the ContextFactory to tear 232 // Stop all outstanding draws before telling the ContextFactory to tear
233 // down any contexts that the |host_| may rely upon. 233 // down any contexts that the |host_| may rely upon.
234 host_.reset(); 234 host_.reset();
235 235
236 context_factory_->RemoveCompositor(this); 236 context_factory_->RemoveCompositor(this);
237 auto* manager = context_factory_->GetSurfaceManager(); 237 auto* manager = context_factory_->GetSurfaceManager();
238 for (auto& client : frame_sinks_) { 238 for (auto& client : child_frame_sinks_) {
239 DCHECK(!client.second.is_null()); 239 DCHECK(!client.is_null());
240 manager->UnregisterFrameSinkHierarchy(client.second, client.first); 240 manager->UnregisterFrameSinkHierarchy(frame_sink_id_, client);
241 } 241 }
242 manager->InvalidateFrameSinkId(surface_id_allocator_->frame_sink_id()); 242 manager->InvalidateFrameSinkId(frame_sink_id_);
243 } 243 }
244 244
245 void Compositor::AddFrameSink(const cc::FrameSinkId& frame_sink_id) { 245 void Compositor::AddFrameSink(const cc::FrameSinkId& frame_sink_id) {
246 const cc::FrameSinkId& parent_frame_sink_id =
247 surface_id_allocator_->frame_sink_id();
248 context_factory_->GetSurfaceManager()->RegisterFrameSinkHierarchy( 246 context_factory_->GetSurfaceManager()->RegisterFrameSinkHierarchy(
249 parent_frame_sink_id, frame_sink_id); 247 frame_sink_id_, frame_sink_id);
250 frame_sinks_[frame_sink_id] = parent_frame_sink_id; 248 child_frame_sinks_.insert(frame_sink_id);
251 } 249 }
252 250
253 void Compositor::RemoveFrameSink(const cc::FrameSinkId& frame_sink_id) { 251 void Compositor::RemoveFrameSink(const cc::FrameSinkId& frame_sink_id) {
254 auto it = frame_sinks_.find(frame_sink_id); 252 auto it = child_frame_sinks_.find(frame_sink_id);
255 DCHECK(it != frame_sinks_.end()); 253 DCHECK(it != child_frame_sinks_.end());
256 DCHECK(!it->second.is_null()); 254 DCHECK(!it->is_null());
257 context_factory_->GetSurfaceManager()->UnregisterFrameSinkHierarchy( 255 context_factory_->GetSurfaceManager()->UnregisterFrameSinkHierarchy(
258 it->second, it->first); 256 frame_sink_id_, *it);
259 frame_sinks_.erase(it); 257 child_frame_sinks_.erase(it);
260 } 258 }
261 259
262 void Compositor::SetCompositorFrameSink( 260 void Compositor::SetCompositorFrameSink(
263 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink) { 261 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink) {
264 compositor_frame_sink_requested_ = false; 262 compositor_frame_sink_requested_ = false;
265 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); 263 host_->SetCompositorFrameSink(std::move(compositor_frame_sink));
266 // Display properties are reset when the output surface is lost, so update it 264 // Display properties are reset when the output surface is lost, so update it
267 // to match the Compositor's. 265 // to match the Compositor's.
268 context_factory_->SetDisplayVisible(this, host_->IsVisible()); 266 context_factory_->SetDisplayVisible(this, host_->IsVisible());
269 context_factory_->SetDisplayColorSpace(this, color_space_); 267 context_factory_->SetDisplayColorSpace(this, color_space_);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 observer_list_, 546 observer_list_,
549 OnCompositingLockStateChanged(this)); 547 OnCompositingLockStateChanged(this));
550 } 548 }
551 549
552 void Compositor::CancelCompositorLock() { 550 void Compositor::CancelCompositorLock() {
553 if (compositor_lock_) 551 if (compositor_lock_)
554 compositor_lock_->CancelLock(); 552 compositor_lock_->CancelLock();
555 } 553 }
556 554
557 } // namespace ui 555 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/compositor/compositor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698