| 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_( |
| 85 context_factory->AllocateSurfaceClientId())), | 85 new cc::SurfaceIdAllocator(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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 host_ = cc::LayerTreeHostInProcess::CreateSingleThreaded(this, ¶ms); | 201 host_ = cc::LayerTreeHostInProcess::CreateSingleThreaded(this, ¶ms); |
| 202 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 202 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
| 203 base::TimeTicks::Now() - before_create); | 203 base::TimeTicks::Now() - before_create); |
| 204 | 204 |
| 205 animation_timeline_ = | 205 animation_timeline_ = |
| 206 cc::AnimationTimeline::Create(cc::AnimationIdProvider::NextTimelineId()); | 206 cc::AnimationTimeline::Create(cc::AnimationIdProvider::NextTimelineId()); |
| 207 host_->GetLayerTree()->animation_host()->AddAnimationTimeline( | 207 host_->GetLayerTree()->animation_host()->AddAnimationTimeline( |
| 208 animation_timeline_.get()); | 208 animation_timeline_.get()); |
| 209 | 209 |
| 210 host_->GetLayerTree()->SetRootLayer(root_web_layer_); | 210 host_->GetLayerTree()->SetRootLayer(root_web_layer_); |
| 211 host_->SetSurfaceClientId(surface_id_allocator_->client_id()); | 211 host_->SetFrameSinkId(surface_id_allocator_->frame_sink_id()); |
| 212 host_->SetVisible(true); | 212 host_->SetVisible(true); |
| 213 } | 213 } |
| 214 | 214 |
| 215 Compositor::~Compositor() { | 215 Compositor::~Compositor() { |
| 216 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 216 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
| 217 | 217 |
| 218 CancelCompositorLock(); | 218 CancelCompositorLock(); |
| 219 DCHECK(!compositor_lock_); | 219 DCHECK(!compositor_lock_); |
| 220 | 220 |
| 221 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 221 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
| 222 OnCompositingShuttingDown(this)); | 222 OnCompositingShuttingDown(this)); |
| 223 | 223 |
| 224 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, | 224 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, |
| 225 OnCompositingShuttingDown(this)); | 225 OnCompositingShuttingDown(this)); |
| 226 | 226 |
| 227 if (root_layer_) | 227 if (root_layer_) |
| 228 root_layer_->ResetCompositor(); | 228 root_layer_->ResetCompositor(); |
| 229 | 229 |
| 230 if (animation_timeline_) | 230 if (animation_timeline_) |
| 231 host_->GetLayerTree()->animation_host()->RemoveAnimationTimeline( | 231 host_->GetLayerTree()->animation_host()->RemoveAnimationTimeline( |
| 232 animation_timeline_.get()); | 232 animation_timeline_.get()); |
| 233 | 233 |
| 234 // Stop all outstanding draws before telling the ContextFactory to tear | 234 // Stop all outstanding draws before telling the ContextFactory to tear |
| 235 // down any contexts that the |host_| may rely upon. | 235 // down any contexts that the |host_| may rely upon. |
| 236 host_.reset(); | 236 host_.reset(); |
| 237 | 237 |
| 238 context_factory_->RemoveCompositor(this); | 238 context_factory_->RemoveCompositor(this); |
| 239 auto* manager = context_factory_->GetSurfaceManager(); | 239 auto* manager = context_factory_->GetSurfaceManager(); |
| 240 for (auto& client : surface_clients_) { | 240 for (auto& client : frame_sinks_) { |
| 241 DCHECK(client.second); | 241 DCHECK(!client.second.is_null()); |
| 242 manager->UnregisterSurfaceNamespaceHierarchy(client.second, client.first); | 242 manager->UnregisterFrameSinkHierarchy(client.second, client.first); |
| 243 } | 243 } |
| 244 manager->InvalidateSurfaceClientId(surface_id_allocator_->client_id()); | 244 manager->InvalidateFrameSinkId(surface_id_allocator_->frame_sink_id()); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void Compositor::AddSurfaceClient(uint32_t client_id) { | 247 void Compositor::AddFrameSink(const cc::FrameSinkId& frame_sink_id) { |
| 248 uint32_t parent_client_id = surface_id_allocator_->client_id(); | 248 const cc::FrameSinkId& parent_frame_sink_id = |
| 249 context_factory_->GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( | 249 surface_id_allocator_->frame_sink_id(); |
| 250 parent_client_id, client_id); | 250 context_factory_->GetSurfaceManager()->RegisterFrameSinkHierarchy( |
| 251 surface_clients_[client_id] = parent_client_id; | 251 parent_frame_sink_id, frame_sink_id); |
| 252 frame_sinks_[frame_sink_id] = parent_frame_sink_id; |
| 252 } | 253 } |
| 253 | 254 |
| 254 void Compositor::RemoveSurfaceClient(uint32_t client_id) { | 255 void Compositor::RemoveFrameSink(const cc::FrameSinkId& frame_sink_id) { |
| 255 auto it = surface_clients_.find(client_id); | 256 auto it = frame_sinks_.find(frame_sink_id); |
| 256 DCHECK(it != surface_clients_.end()); | 257 DCHECK(it != frame_sinks_.end()); |
| 257 DCHECK(it->second); | 258 DCHECK(!it->second.is_null()); |
| 258 context_factory_->GetSurfaceManager()->UnregisterSurfaceNamespaceHierarchy( | 259 context_factory_->GetSurfaceManager()->UnregisterFrameSinkHierarchy( |
| 259 it->second, it->first); | 260 it->second, it->first); |
| 260 surface_clients_.erase(it); | 261 frame_sinks_.erase(it); |
| 261 } | 262 } |
| 262 | 263 |
| 263 void Compositor::SetCompositorFrameSink( | 264 void Compositor::SetCompositorFrameSink( |
| 264 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink) { | 265 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink) { |
| 265 compositor_frame_sink_requested_ = false; | 266 compositor_frame_sink_requested_ = false; |
| 266 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); | 267 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
| 267 // Display properties are reset when the output surface is lost, so update it | 268 // Display properties are reset when the output surface is lost, so update it |
| 268 // to match the Compositor's. | 269 // to match the Compositor's. |
| 269 context_factory_->SetDisplayVisible(this, host_->IsVisible()); | 270 context_factory_->SetDisplayVisible(this, host_->IsVisible()); |
| 270 context_factory_->SetDisplayColorSpace(this, color_space_); | 271 context_factory_->SetDisplayColorSpace(this, color_space_); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 observer_list_, | 550 observer_list_, |
| 550 OnCompositingLockStateChanged(this)); | 551 OnCompositingLockStateChanged(this)); |
| 551 } | 552 } |
| 552 | 553 |
| 553 void Compositor::CancelCompositorLock() { | 554 void Compositor::CancelCompositorLock() { |
| 554 if (compositor_lock_) | 555 if (compositor_lock_) |
| 555 compositor_lock_->CancelLock(); | 556 compositor_lock_->CancelLock(); |
| 556 } | 557 } |
| 557 | 558 |
| 558 } // namespace ui | 559 } // namespace ui |
| OLD | NEW |