| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 } // namespace ui | 77 } // namespace ui |
| 78 | 78 |
| 79 namespace { | 79 namespace { |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 namespace ui { | 83 namespace ui { |
| 84 | 84 |
| 85 Compositor::Compositor(gfx::AcceleratedWidget widget) | 85 Compositor::Compositor(gfx::AcceleratedWidget widget) |
| 86 : root_layer_(NULL), | 86 : context_factory_(g_context_factory), |
| 87 root_layer_(NULL), |
| 87 widget_(widget), | 88 widget_(widget), |
| 88 compositor_thread_loop_(g_context_factory->GetCompositorMessageLoop()), | 89 compositor_thread_loop_(g_context_factory->GetCompositorMessageLoop()), |
| 89 vsync_manager_(new CompositorVSyncManager()), | 90 vsync_manager_(new CompositorVSyncManager()), |
| 90 device_scale_factor_(0.0f), | 91 device_scale_factor_(0.0f), |
| 91 last_started_frame_(0), | 92 last_started_frame_(0), |
| 92 last_ended_frame_(0), | 93 last_ended_frame_(0), |
| 93 disable_schedule_composite_(false), | 94 disable_schedule_composite_(false), |
| 94 compositor_lock_(NULL), | 95 compositor_lock_(NULL), |
| 95 defer_draw_scheduling_(false), | 96 defer_draw_scheduling_(false), |
| 96 waiting_on_compositing_end_(false), | 97 waiting_on_compositing_end_(false), |
| 97 draw_on_compositing_end_(false), | 98 draw_on_compositing_end_(false), |
| 98 swap_state_(SWAP_NONE), | 99 swap_state_(SWAP_NONE), |
| 99 schedule_draw_factory_(this) { | 100 schedule_draw_factory_(this) { |
| 101 Init(); |
| 102 } |
| 103 |
| 104 Compositor::Compositor(gfx::AcceleratedWidget widget, |
| 105 ui::ContextFactory* context_factory) |
| 106 : context_factory_(context_factory), |
| 107 root_layer_(NULL), |
| 108 widget_(widget), |
| 109 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), |
| 110 vsync_manager_(new CompositorVSyncManager()), |
| 111 device_scale_factor_(0.0f), |
| 112 last_started_frame_(0), |
| 113 last_ended_frame_(0), |
| 114 disable_schedule_composite_(false), |
| 115 compositor_lock_(NULL), |
| 116 defer_draw_scheduling_(false), |
| 117 waiting_on_compositing_end_(false), |
| 118 draw_on_compositing_end_(false), |
| 119 swap_state_(SWAP_NONE), |
| 120 schedule_draw_factory_(this) { |
| 121 Init(); |
| 122 } |
| 123 |
| 124 // Yes, this is the wrong place. I'm leaving here to minimize diffs since this |
| 125 // function will be nuked soonish. |
| 126 void Compositor::Init() { |
| 100 root_web_layer_ = cc::Layer::Create(); | 127 root_web_layer_ = cc::Layer::Create(); |
| 101 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); | 128 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); |
| 102 | 129 |
| 103 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 130 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 104 | 131 |
| 105 cc::LayerTreeSettings settings; | 132 cc::LayerTreeSettings settings; |
| 106 settings.refresh_rate = | 133 settings.refresh_rate = |
| 107 ContextFactory::GetInstance()->DoesCreateTestContexts() | 134 context_factory_->DoesCreateTestContexts() |
| 108 ? kTestRefreshRate | 135 ? kTestRefreshRate |
| 109 : kDefaultRefreshRate; | 136 : kDefaultRefreshRate; |
| 110 settings.main_frame_before_draw_enabled = false; | 137 settings.main_frame_before_draw_enabled = false; |
| 111 settings.main_frame_before_activation_enabled = false; | 138 settings.main_frame_before_activation_enabled = false; |
| 112 settings.throttle_frame_production = | 139 settings.throttle_frame_production = |
| 113 !command_line->HasSwitch(switches::kDisableGpuVsync); | 140 !command_line->HasSwitch(switches::kDisableGpuVsync); |
| 114 settings.partial_swap_enabled = | 141 settings.partial_swap_enabled = |
| 115 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); | 142 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); |
| 116 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
| 117 settings.per_tile_painting_enabled = true; | 144 settings.per_tile_painting_enabled = true; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 142 settings.initial_debug_state.SetRecordRenderingStats( | 169 settings.initial_debug_state.SetRecordRenderingStats( |
| 143 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 170 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
| 144 | 171 |
| 145 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); | 172 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); |
| 146 settings.use_zero_copy = IsUIZeroCopyEnabled(); | 173 settings.use_zero_copy = IsUIZeroCopyEnabled(); |
| 147 | 174 |
| 148 base::TimeTicks before_create = base::TimeTicks::Now(); | 175 base::TimeTicks before_create = base::TimeTicks::Now(); |
| 149 if (compositor_thread_loop_) { | 176 if (compositor_thread_loop_) { |
| 150 host_ = cc::LayerTreeHost::CreateThreaded( | 177 host_ = cc::LayerTreeHost::CreateThreaded( |
| 151 this, | 178 this, |
| 152 g_context_factory->GetSharedBitmapManager(), | 179 context_factory_->GetSharedBitmapManager(), |
| 153 settings, | 180 settings, |
| 154 compositor_thread_loop_); | 181 compositor_thread_loop_); |
| 155 } else { | 182 } else { |
| 156 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 183 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
| 157 this, this, g_context_factory->GetSharedBitmapManager(), settings); | 184 this, this, context_factory_->GetSharedBitmapManager(), settings); |
| 158 } | 185 } |
| 159 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 186 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
| 160 base::TimeTicks::Now() - before_create); | 187 base::TimeTicks::Now() - before_create); |
| 161 host_->SetRootLayer(root_web_layer_); | 188 host_->SetRootLayer(root_web_layer_); |
| 162 host_->SetLayerTreeHostClientReady(); | 189 host_->SetLayerTreeHostClientReady(); |
| 163 } | 190 } |
| 164 | 191 |
| 165 Compositor::~Compositor() { | 192 Compositor::~Compositor() { |
| 166 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 193 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
| 167 | 194 |
| 168 CancelCompositorLock(); | 195 CancelCompositorLock(); |
| 169 DCHECK(!compositor_lock_); | 196 DCHECK(!compositor_lock_); |
| 170 | 197 |
| 171 if (root_layer_) | 198 if (root_layer_) |
| 172 root_layer_->SetCompositor(NULL); | 199 root_layer_->SetCompositor(NULL); |
| 173 | 200 |
| 174 // Stop all outstanding draws before telling the ContextFactory to tear | 201 // Stop all outstanding draws before telling the ContextFactory to tear |
| 175 // down any contexts that the |host_| may rely upon. | 202 // down any contexts that the |host_| may rely upon. |
| 176 host_.reset(); | 203 host_.reset(); |
| 177 | 204 |
| 178 ContextFactory::GetInstance()->RemoveCompositor(this); | 205 context_factory_->RemoveCompositor(this); |
| 179 } | 206 } |
| 180 | 207 |
| 181 void Compositor::ScheduleDraw() { | 208 void Compositor::ScheduleDraw() { |
| 182 if (compositor_thread_loop_) { | 209 if (compositor_thread_loop_) { |
| 183 host_->Composite(gfx::FrameTime::Now()); | 210 host_->Composite(gfx::FrameTime::Now()); |
| 184 } else if (!defer_draw_scheduling_) { | 211 } else if (!defer_draw_scheduling_) { |
| 185 defer_draw_scheduling_ = true; | 212 defer_draw_scheduling_ = true; |
| 186 base::MessageLoop::current()->PostTask( | 213 base::MessageLoop::current()->PostTask( |
| 187 FROM_HERE, | 214 FROM_HERE, |
| 188 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); | 215 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 void Compositor::Layout() { | 320 void Compositor::Layout() { |
| 294 // We're sending damage that will be addressed during this composite | 321 // We're sending damage that will be addressed during this composite |
| 295 // cycle, so we don't need to schedule another composite to address it. | 322 // cycle, so we don't need to schedule another composite to address it. |
| 296 disable_schedule_composite_ = true; | 323 disable_schedule_composite_ = true; |
| 297 if (root_layer_) | 324 if (root_layer_) |
| 298 root_layer_->SendDamagedRects(); | 325 root_layer_->SendDamagedRects(); |
| 299 disable_schedule_composite_ = false; | 326 disable_schedule_composite_ = false; |
| 300 } | 327 } |
| 301 | 328 |
| 302 scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) { | 329 scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) { |
| 303 return ContextFactory::GetInstance()->CreateOutputSurface(this, fallback); | 330 return context_factory_->CreateOutputSurface(this, fallback); |
| 304 } | 331 } |
| 305 | 332 |
| 306 void Compositor::DidCommit() { | 333 void Compositor::DidCommit() { |
| 307 DCHECK(!IsLocked()); | 334 DCHECK(!IsLocked()); |
| 308 FOR_EACH_OBSERVER(CompositorObserver, | 335 FOR_EACH_OBSERVER(CompositorObserver, |
| 309 observer_list_, | 336 observer_list_, |
| 310 OnCompositingDidCommit(this)); | 337 OnCompositingDidCommit(this)); |
| 311 } | 338 } |
| 312 | 339 |
| 313 void Compositor::DidCommitAndDrawFrame() { | 340 void Compositor::DidCommitAndDrawFrame() { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // CompositorObservers to be notified before starting another | 429 // CompositorObservers to be notified before starting another |
| 403 // draw cycle. | 430 // draw cycle. |
| 404 ScheduleDraw(); | 431 ScheduleDraw(); |
| 405 } | 432 } |
| 406 FOR_EACH_OBSERVER(CompositorObserver, | 433 FOR_EACH_OBSERVER(CompositorObserver, |
| 407 observer_list_, | 434 observer_list_, |
| 408 OnCompositingEnded(this)); | 435 OnCompositingEnded(this)); |
| 409 } | 436 } |
| 410 | 437 |
| 411 } // namespace ui | 438 } // namespace ui |
| OLD | NEW |