| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), | 74 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), |
| 75 task_runner_(task_runner), | 75 task_runner_(task_runner), |
| 76 vsync_manager_(new CompositorVSyncManager()), | 76 vsync_manager_(new CompositorVSyncManager()), |
| 77 device_scale_factor_(0.0f), | 77 device_scale_factor_(0.0f), |
| 78 last_started_frame_(0), | 78 last_started_frame_(0), |
| 79 last_ended_frame_(0), | 79 last_ended_frame_(0), |
| 80 locks_will_time_out_(true), | 80 locks_will_time_out_(true), |
| 81 compositor_lock_(NULL), | 81 compositor_lock_(NULL), |
| 82 layer_animator_collection_(this), | 82 layer_animator_collection_(this), |
| 83 weak_ptr_factory_(this) { | 83 weak_ptr_factory_(this) { |
| 84 root_web_layer_ = cc::Layer::Create(); | |
| 85 | |
| 86 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 84 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 87 | 85 |
| 88 cc::LayerTreeSettings settings; | 86 cc::LayerTreeSettings settings; |
| 87 |
| 88 cc::LayerSettings ui_layer_settings; |
| 89 if (command_line->HasSwitch( |
| 90 switches::kUIEnableCompositorAnimationTimelines)) { |
| 91 settings.hud_layer_settings_.use_compositor_animation_timelines = true; |
| 92 ui_layer_settings.use_compositor_animation_timelines = true; |
| 93 } |
| 94 Layer::SetUILayerSettings(ui_layer_settings); |
| 95 |
| 96 root_web_layer_ = cc::Layer::Create(Layer::UILayerSettings()); |
| 97 |
| 89 // When impl-side painting is enabled, this will ensure PictureLayers always | 98 // When impl-side painting is enabled, this will ensure PictureLayers always |
| 90 // can have LCD text, to match the previous behaviour with ContentLayers, | 99 // can have LCD text, to match the previous behaviour with ContentLayers, |
| 91 // where LCD-not-allowed notifications were ignored. | 100 // where LCD-not-allowed notifications were ignored. |
| 92 settings.layers_always_allowed_lcd_text = true; | 101 settings.layers_always_allowed_lcd_text = true; |
| 93 settings.renderer_settings.refresh_rate = | 102 settings.renderer_settings.refresh_rate = |
| 94 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate | 103 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate |
| 95 : kDefaultRefreshRate; | 104 : kDefaultRefreshRate; |
| 96 settings.main_frame_before_activation_enabled = false; | 105 settings.main_frame_before_activation_enabled = false; |
| 97 settings.throttle_frame_production = | 106 settings.throttle_frame_production = |
| 98 !command_line->HasSwitch(switches::kDisableGpuVsync); | 107 !command_line->HasSwitch(switches::kDisableGpuVsync); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 128 | 137 |
| 129 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); | 138 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); |
| 130 settings.use_display_lists = IsUISlimmingPaintEnabled(); | 139 settings.use_display_lists = IsUISlimmingPaintEnabled(); |
| 131 settings.use_zero_copy = IsUIZeroCopyEnabled(); | 140 settings.use_zero_copy = IsUIZeroCopyEnabled(); |
| 132 settings.use_one_copy = IsUIOneCopyEnabled(); | 141 settings.use_one_copy = IsUIOneCopyEnabled(); |
| 133 settings.use_image_texture_target = context_factory_->GetImageTextureTarget(); | 142 settings.use_image_texture_target = context_factory_->GetImageTextureTarget(); |
| 134 // Note: gathering of pixel refs is only needed when using multiple | 143 // Note: gathering of pixel refs is only needed when using multiple |
| 135 // raster threads. | 144 // raster threads. |
| 136 settings.gather_pixel_refs = false; | 145 settings.gather_pixel_refs = false; |
| 137 | 146 |
| 138 settings.use_compositor_animation_timelines = | |
| 139 command_line->HasSwitch(switches::kUIEnableCompositorAnimationTimelines); | |
| 140 | |
| 141 base::TimeTicks before_create = base::TimeTicks::Now(); | 147 base::TimeTicks before_create = base::TimeTicks::Now(); |
| 142 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 148 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
| 143 this, this, context_factory_->GetSharedBitmapManager(), | 149 this, this, context_factory_->GetSharedBitmapManager(), |
| 144 context_factory_->GetGpuMemoryBufferManager(), | 150 context_factory_->GetGpuMemoryBufferManager(), |
| 145 context_factory_->GetTaskGraphRunner(), settings, task_runner_, nullptr); | 151 context_factory_->GetTaskGraphRunner(), settings, task_runner_, nullptr); |
| 146 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 152 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
| 147 base::TimeTicks::Now() - before_create); | 153 base::TimeTicks::Now() - before_create); |
| 148 host_->SetRootLayer(root_web_layer_); | 154 host_->SetRootLayer(root_web_layer_); |
| 149 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); | 155 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); |
| 150 host_->SetLayerTreeHostClientReady(); | 156 host_->SetLayerTreeHostClientReady(); |
| 151 } | 157 } |
| 152 | 158 |
| 153 Compositor::~Compositor() { | 159 Compositor::~Compositor() { |
| 154 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 160 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
| 155 | 161 |
| 156 CancelCompositorLock(); | 162 CancelCompositorLock(); |
| 157 DCHECK(!compositor_lock_); | 163 DCHECK(!compositor_lock_); |
| 158 | 164 |
| 159 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 165 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
| 160 OnCompositingShuttingDown(this)); | 166 OnCompositingShuttingDown(this)); |
| 161 | 167 |
| 162 DCHECK(begin_frame_observer_list_.empty()); | 168 DCHECK(begin_frame_observer_list_.empty()); |
| 163 | 169 |
| 164 if (root_layer_) | 170 if (root_layer_) |
| 165 root_layer_->SetCompositor(NULL); | 171 root_layer_->ResetCompositor(); |
| 166 | 172 |
| 167 // Stop all outstanding draws before telling the ContextFactory to tear | 173 // Stop all outstanding draws before telling the ContextFactory to tear |
| 168 // down any contexts that the |host_| may rely upon. | 174 // down any contexts that the |host_| may rely upon. |
| 169 host_.reset(); | 175 host_.reset(); |
| 170 | 176 |
| 171 context_factory_->RemoveCompositor(this); | 177 context_factory_->RemoveCompositor(this); |
| 172 } | 178 } |
| 173 | 179 |
| 174 void Compositor::SetOutputSurface( | 180 void Compositor::SetOutputSurface( |
| 175 scoped_ptr<cc::OutputSurface> output_surface) { | 181 scoped_ptr<cc::OutputSurface> output_surface) { |
| 176 host_->SetOutputSurface(output_surface.Pass()); | 182 host_->SetOutputSurface(output_surface.Pass()); |
| 177 } | 183 } |
| 178 | 184 |
| 179 void Compositor::ScheduleDraw() { | 185 void Compositor::ScheduleDraw() { |
| 180 host_->SetNeedsCommit(); | 186 host_->SetNeedsCommit(); |
| 181 } | 187 } |
| 182 | 188 |
| 183 void Compositor::SetRootLayer(Layer* root_layer) { | 189 void Compositor::SetRootLayer(Layer* root_layer) { |
| 184 if (root_layer_ == root_layer) | 190 if (root_layer_ == root_layer) |
| 185 return; | 191 return; |
| 186 if (root_layer_) | 192 if (root_layer_) |
| 187 root_layer_->SetCompositor(NULL); | 193 root_layer_->ResetCompositor(); |
| 188 root_layer_ = root_layer; | 194 root_layer_ = root_layer; |
| 189 if (root_layer_ && !root_layer_->GetCompositor()) | |
| 190 root_layer_->SetCompositor(this); | |
| 191 root_web_layer_->RemoveAllChildren(); | 195 root_web_layer_->RemoveAllChildren(); |
| 192 if (root_layer_) | 196 if (root_layer_) |
| 193 root_web_layer_->AddChild(root_layer_->cc_layer()); | 197 root_layer_->SetCompositor(this, root_web_layer_); |
| 194 } | 198 } |
| 195 | 199 |
| 196 void Compositor::SetHostHasTransparentBackground( | 200 void Compositor::SetHostHasTransparentBackground( |
| 197 bool host_has_transparent_background) { | 201 bool host_has_transparent_background) { |
| 198 host_->set_has_transparent_background(host_has_transparent_background); | 202 host_->set_has_transparent_background(host_has_transparent_background); |
| 199 } | 203 } |
| 200 | 204 |
| 201 void Compositor::ScheduleFullRedraw() { | 205 void Compositor::ScheduleFullRedraw() { |
| 202 // TODO(enne): Some callers (mac) call this function expecting that it | 206 // TODO(enne): Some callers (mac) call this function expecting that it |
| 203 // will also commit. This should probably just redraw the screen | 207 // will also commit. This should probably just redraw the screen |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 observer_list_, | 428 observer_list_, |
| 425 OnCompositingLockStateChanged(this)); | 429 OnCompositingLockStateChanged(this)); |
| 426 } | 430 } |
| 427 | 431 |
| 428 void Compositor::CancelCompositorLock() { | 432 void Compositor::CancelCompositorLock() { |
| 429 if (compositor_lock_) | 433 if (compositor_lock_) |
| 430 compositor_lock_->CancelLock(); | 434 compositor_lock_->CancelLock(); |
| 431 } | 435 } |
| 432 | 436 |
| 433 } // namespace ui | 437 } // namespace ui |
| OLD | NEW |