| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 const double kDefaultRefreshRate = 60.0; | 39 const double kDefaultRefreshRate = 60.0; |
| 40 const double kTestRefreshRate = 200.0; | 40 const double kTestRefreshRate = 200.0; |
| 41 | 41 |
| 42 enum SwapType { | 42 enum SwapType { |
| 43 DRAW_SWAP, | 43 DRAW_SWAP, |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 bool g_compositor_initialized = false; | 46 bool g_compositor_initialized = false; |
| 47 base::Thread* g_compositor_thread = NULL; | 47 base::Thread* g_compositor_thread = NULL; |
| 48 cc::SharedBitmapManager* g_shared_bitmap_manager; |
| 48 | 49 |
| 49 ui::ContextFactory* g_context_factory = NULL; | 50 ui::ContextFactory* g_context_factory = NULL; |
| 50 | 51 |
| 51 const int kCompositorLockTimeoutMs = 67; | 52 const int kCompositorLockTimeoutMs = 67; |
| 52 | 53 |
| 53 class PendingSwap { | 54 class PendingSwap { |
| 54 public: | 55 public: |
| 55 PendingSwap(SwapType type, ui::PostedSwapQueue* posted_swaps); | 56 PendingSwap(SwapType type, ui::PostedSwapQueue* posted_swaps); |
| 56 ~PendingSwap(); | 57 ~PendingSwap(); |
| 57 | 58 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 command_line->HasSwitch(cc::switches::kUIShowOccludingRects); | 240 command_line->HasSwitch(cc::switches::kUIShowOccludingRects); |
| 240 settings.initial_debug_state.show_non_occluding_rects = | 241 settings.initial_debug_state.show_non_occluding_rects = |
| 241 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); | 242 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); |
| 242 | 243 |
| 243 settings.initial_debug_state.SetRecordRenderingStats( | 244 settings.initial_debug_state.SetRecordRenderingStats( |
| 244 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 245 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
| 245 | 246 |
| 246 base::TimeTicks before_create = base::TimeTicks::Now(); | 247 base::TimeTicks before_create = base::TimeTicks::Now(); |
| 247 if (!!g_compositor_thread) { | 248 if (!!g_compositor_thread) { |
| 248 host_ = cc::LayerTreeHost::CreateThreaded( | 249 host_ = cc::LayerTreeHost::CreateThreaded( |
| 249 this, NULL, settings, g_compositor_thread->message_loop_proxy()); | 250 this, |
| 251 g_shared_bitmap_manager, |
| 252 settings, |
| 253 g_compositor_thread->message_loop_proxy()); |
| 250 } else { | 254 } else { |
| 251 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); | 255 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
| 256 this, this, g_shared_bitmap_manager, settings); |
| 252 } | 257 } |
| 253 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 258 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
| 254 base::TimeTicks::Now() - before_create); | 259 base::TimeTicks::Now() - before_create); |
| 255 host_->SetRootLayer(root_web_layer_); | 260 host_->SetRootLayer(root_web_layer_); |
| 256 host_->SetLayerTreeHostClientReady(); | 261 host_->SetLayerTreeHostClientReady(); |
| 257 } | 262 } |
| 258 | 263 |
| 259 Compositor::~Compositor() { | 264 Compositor::~Compositor() { |
| 260 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 265 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
| 261 | 266 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if (g_compositor_thread) { | 315 if (g_compositor_thread) { |
| 311 g_compositor_thread->Stop(); | 316 g_compositor_thread->Stop(); |
| 312 delete g_compositor_thread; | 317 delete g_compositor_thread; |
| 313 g_compositor_thread = NULL; | 318 g_compositor_thread = NULL; |
| 314 } | 319 } |
| 315 | 320 |
| 316 DCHECK(g_compositor_initialized) << "Compositor::Initialize() didn't happen."; | 321 DCHECK(g_compositor_initialized) << "Compositor::Initialize() didn't happen."; |
| 317 g_compositor_initialized = false; | 322 g_compositor_initialized = false; |
| 318 } | 323 } |
| 319 | 324 |
| 325 // static |
| 326 void Compositor::SetSharedBitmapManager(cc::SharedBitmapManager* manager) { |
| 327 g_shared_bitmap_manager = manager; |
| 328 } |
| 329 |
| 320 void Compositor::ScheduleDraw() { | 330 void Compositor::ScheduleDraw() { |
| 321 if (g_compositor_thread) { | 331 if (g_compositor_thread) { |
| 322 host_->Composite(gfx::FrameTime::Now()); | 332 host_->Composite(gfx::FrameTime::Now()); |
| 323 } else if (!defer_draw_scheduling_) { | 333 } else if (!defer_draw_scheduling_) { |
| 324 defer_draw_scheduling_ = true; | 334 defer_draw_scheduling_ = true; |
| 325 base::MessageLoop::current()->PostTask( | 335 base::MessageLoop::current()->PostTask( |
| 326 FROM_HERE, | 336 FROM_HERE, |
| 327 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); | 337 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); |
| 328 } | 338 } |
| 329 } | 339 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 // CompositorObservers to be notified before starting another | 567 // CompositorObservers to be notified before starting another |
| 558 // draw cycle. | 568 // draw cycle. |
| 559 ScheduleDraw(); | 569 ScheduleDraw(); |
| 560 } | 570 } |
| 561 FOR_EACH_OBSERVER(CompositorObserver, | 571 FOR_EACH_OBSERVER(CompositorObserver, |
| 562 observer_list_, | 572 observer_list_, |
| 563 OnCompositingEnded(this)); | 573 OnCompositingEnded(this)); |
| 564 } | 574 } |
| 565 | 575 |
| 566 } // namespace ui | 576 } // namespace ui |
| OLD | NEW |