Chromium Code Reviews| 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 const double kDefaultRefreshRate = 60.0; | 38 const double kDefaultRefreshRate = 60.0; |
| 39 const double kTestRefreshRate = 200.0; | 39 const double kTestRefreshRate = 200.0; |
| 40 | 40 |
| 41 enum SwapType { | 41 enum SwapType { |
| 42 DRAW_SWAP, | 42 DRAW_SWAP, |
| 43 READPIXELS_SWAP, | 43 READPIXELS_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; | |
|
danakj
2014/01/30 22:59:01
Can we pass it to ui::Compositor constructor inste
| |
| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 settings.initial_debug_state.show_replica_screen_space_rects = | 234 settings.initial_debug_state.show_replica_screen_space_rects = |
| 234 command_line->HasSwitch(cc::switches::kUIShowReplicaScreenSpaceRects); | 235 command_line->HasSwitch(cc::switches::kUIShowReplicaScreenSpaceRects); |
| 235 settings.initial_debug_state.show_occluding_rects = | 236 settings.initial_debug_state.show_occluding_rects = |
| 236 command_line->HasSwitch(cc::switches::kUIShowOccludingRects); | 237 command_line->HasSwitch(cc::switches::kUIShowOccludingRects); |
| 237 settings.initial_debug_state.show_non_occluding_rects = | 238 settings.initial_debug_state.show_non_occluding_rects = |
| 238 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); | 239 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); |
| 239 | 240 |
| 240 base::TimeTicks before_create = base::TimeTicks::Now(); | 241 base::TimeTicks before_create = base::TimeTicks::Now(); |
| 241 if (!!g_compositor_thread) { | 242 if (!!g_compositor_thread) { |
| 242 host_ = cc::LayerTreeHost::CreateThreaded( | 243 host_ = cc::LayerTreeHost::CreateThreaded( |
| 243 this, NULL, settings, g_compositor_thread->message_loop_proxy()); | 244 this, |
| 245 g_shared_bitmap_manager, | |
| 246 settings, | |
| 247 g_compositor_thread->message_loop_proxy()); | |
| 244 } else { | 248 } else { |
| 245 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); | 249 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
| 250 this, this, g_shared_bitmap_manager, settings); | |
| 246 } | 251 } |
| 247 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 252 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
| 248 base::TimeTicks::Now() - before_create); | 253 base::TimeTicks::Now() - before_create); |
| 249 host_->SetRootLayer(root_web_layer_); | 254 host_->SetRootLayer(root_web_layer_); |
| 250 host_->SetLayerTreeHostClientReady(); | 255 host_->SetLayerTreeHostClientReady(); |
| 251 } | 256 } |
| 252 | 257 |
| 253 Compositor::~Compositor() { | 258 Compositor::~Compositor() { |
| 254 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 259 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
| 255 | 260 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 if (g_compositor_thread) { | 313 if (g_compositor_thread) { |
| 309 g_compositor_thread->Stop(); | 314 g_compositor_thread->Stop(); |
| 310 delete g_compositor_thread; | 315 delete g_compositor_thread; |
| 311 g_compositor_thread = NULL; | 316 g_compositor_thread = NULL; |
| 312 } | 317 } |
| 313 | 318 |
| 314 DCHECK(g_compositor_initialized) << "Compositor::Initialize() didn't happen."; | 319 DCHECK(g_compositor_initialized) << "Compositor::Initialize() didn't happen."; |
| 315 g_compositor_initialized = false; | 320 g_compositor_initialized = false; |
| 316 } | 321 } |
| 317 | 322 |
| 323 // static | |
| 324 void Compositor::SetSharedBitmapManager(cc::SharedBitmapManager* manager) { | |
| 325 g_shared_bitmap_manager = manager; | |
| 326 } | |
| 327 | |
| 318 void Compositor::ScheduleDraw() { | 328 void Compositor::ScheduleDraw() { |
| 319 if (g_compositor_thread) { | 329 if (g_compositor_thread) { |
| 320 host_->Composite(gfx::FrameTime::Now()); | 330 host_->Composite(gfx::FrameTime::Now()); |
| 321 } else if (!defer_draw_scheduling_) { | 331 } else if (!defer_draw_scheduling_) { |
| 322 defer_draw_scheduling_ = true; | 332 defer_draw_scheduling_ = true; |
| 323 base::MessageLoop::current()->PostTask( | 333 base::MessageLoop::current()->PostTask( |
| 324 FROM_HERE, | 334 FROM_HERE, |
| 325 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); | 335 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); |
| 326 } | 336 } |
| 327 } | 337 } |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 // CompositorObservers to be notified before starting another | 583 // CompositorObservers to be notified before starting another |
| 574 // draw cycle. | 584 // draw cycle. |
| 575 ScheduleDraw(); | 585 ScheduleDraw(); |
| 576 } | 586 } |
| 577 FOR_EACH_OBSERVER(CompositorObserver, | 587 FOR_EACH_OBSERVER(CompositorObserver, |
| 578 observer_list_, | 588 observer_list_, |
| 579 OnCompositingEnded(this)); | 589 OnCompositingEnded(this)); |
| 580 } | 590 } |
| 581 | 591 |
| 582 } // namespace ui | 592 } // namespace ui |
| OLD | NEW |