OLD | NEW |
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 Loading... |
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_(new cc::SurfaceIdAllocator( | 84 surface_id_allocator_(base::MakeUnique<cc::SurfaceIdAllocator>( |
85 context_factory->AllocateSurfaceClientId())), | 85 context_factory->AllocateFrameSinkId())), |
86 task_runner_(task_runner), | 86 task_runner_(task_runner), |
87 vsync_manager_(new CompositorVSyncManager()), | 87 vsync_manager_(new CompositorVSyncManager()), |
88 device_scale_factor_(0.0f), | 88 device_scale_factor_(0.0f), |
89 locks_will_time_out_(true), | 89 locks_will_time_out_(true), |
90 compositor_lock_(NULL), | 90 compositor_lock_(NULL), |
91 layer_animator_collection_(this), | 91 layer_animator_collection_(this), |
92 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
93 context_factory->GetSurfaceManager()->RegisterSurfaceClientId( | 93 context_factory->GetSurfaceManager()->RegisterFrameSinkId( |
94 surface_id_allocator_->client_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 Loading... |
199 host_ = cc::LayerTreeHostInProcess::CreateSingleThreaded(this, ¶ms); | 199 host_ = cc::LayerTreeHostInProcess::CreateSingleThreaded(this, ¶ms); |
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_->SetSurfaceClientId(surface_id_allocator_->client_id()); | 209 host_->SetFrameSinkId(surface_id_allocator_->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 : surface_clients_) { | 238 for (auto& client : frame_sinks_) { |
239 DCHECK(client.second); | 239 DCHECK(!client.second.is_null()); |
240 manager->UnregisterSurfaceNamespaceHierarchy(client.second, client.first); | 240 manager->UnregisterFrameSinkHierarchy(client.second, client.first); |
241 } | 241 } |
242 manager->InvalidateSurfaceClientId(surface_id_allocator_->client_id()); | 242 manager->InvalidateFrameSinkId(surface_id_allocator_->frame_sink_id()); |
243 } | 243 } |
244 | 244 |
245 void Compositor::AddSurfaceClient(uint32_t client_id) { | 245 void Compositor::AddFrameSink(const cc::FrameSinkId& frame_sink_id) { |
246 uint32_t parent_client_id = surface_id_allocator_->client_id(); | 246 const cc::FrameSinkId& parent_frame_sink_id = |
247 context_factory_->GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( | 247 surface_id_allocator_->frame_sink_id(); |
248 parent_client_id, client_id); | 248 context_factory_->GetSurfaceManager()->RegisterFrameSinkHierarchy( |
249 surface_clients_[client_id] = parent_client_id; | 249 parent_frame_sink_id, frame_sink_id); |
| 250 frame_sinks_[frame_sink_id] = parent_frame_sink_id; |
250 } | 251 } |
251 | 252 |
252 void Compositor::RemoveSurfaceClient(uint32_t client_id) { | 253 void Compositor::RemoveFrameSink(const cc::FrameSinkId& frame_sink_id) { |
253 auto it = surface_clients_.find(client_id); | 254 auto it = frame_sinks_.find(frame_sink_id); |
254 DCHECK(it != surface_clients_.end()); | 255 DCHECK(it != frame_sinks_.end()); |
255 DCHECK(it->second); | 256 DCHECK(!it->second.is_null()); |
256 context_factory_->GetSurfaceManager()->UnregisterSurfaceNamespaceHierarchy( | 257 context_factory_->GetSurfaceManager()->UnregisterFrameSinkHierarchy( |
257 it->second, it->first); | 258 it->second, it->first); |
258 surface_clients_.erase(it); | 259 frame_sinks_.erase(it); |
259 } | 260 } |
260 | 261 |
261 void Compositor::SetCompositorFrameSink( | 262 void Compositor::SetCompositorFrameSink( |
262 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink) { | 263 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink) { |
263 compositor_frame_sink_requested_ = false; | 264 compositor_frame_sink_requested_ = false; |
264 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); | 265 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
265 // Display properties are reset when the output surface is lost, so update it | 266 // Display properties are reset when the output surface is lost, so update it |
266 // to match the Compositor's. | 267 // to match the Compositor's. |
267 context_factory_->SetDisplayVisible(this, host_->IsVisible()); | 268 context_factory_->SetDisplayVisible(this, host_->IsVisible()); |
268 context_factory_->SetDisplayColorSpace(this, color_space_); | 269 context_factory_->SetDisplayColorSpace(this, color_space_); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 observer_list_, | 548 observer_list_, |
548 OnCompositingLockStateChanged(this)); | 549 OnCompositingLockStateChanged(this)); |
549 } | 550 } |
550 | 551 |
551 void Compositor::CancelCompositorLock() { | 552 void Compositor::CancelCompositorLock() { |
552 if (compositor_lock_) | 553 if (compositor_lock_) |
553 compositor_lock_->CancelLock(); | 554 compositor_lock_->CancelLock(); |
554 } | 555 } |
555 | 556 |
556 } // namespace ui | 557 } // namespace ui |
OLD | NEW |