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 23 matching lines...) Expand all Loading... |
34 #include "ui/gl/gl_context.h" | 34 #include "ui/gl/gl_context.h" |
35 #include "ui/gl/gl_switches.h" | 35 #include "ui/gl/gl_switches.h" |
36 | 36 |
37 namespace { | 37 namespace { |
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 bool g_compositor_initialized = false; | 42 bool g_compositor_initialized = false; |
43 base::Thread* g_compositor_thread = NULL; | 43 base::Thread* g_compositor_thread = NULL; |
44 cc::SharedBitmapManager* g_shared_bitmap_manager; | |
45 | 44 |
46 ui::ContextFactory* g_context_factory = NULL; | 45 ui::ContextFactory* g_context_factory = NULL; |
47 | 46 |
48 const int kCompositorLockTimeoutMs = 67; | 47 const int kCompositorLockTimeoutMs = 67; |
49 | 48 |
50 } // namespace | 49 } // namespace |
51 | 50 |
52 namespace ui { | 51 namespace ui { |
53 | 52 |
54 // static | 53 // static |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 settings.initial_debug_state.SetRecordRenderingStats( | 152 settings.initial_debug_state.SetRecordRenderingStats( |
154 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 153 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
155 | 154 |
156 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); | 155 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); |
157 settings.use_zero_copy = IsUIZeroCopyEnabled(); | 156 settings.use_zero_copy = IsUIZeroCopyEnabled(); |
158 | 157 |
159 base::TimeTicks before_create = base::TimeTicks::Now(); | 158 base::TimeTicks before_create = base::TimeTicks::Now(); |
160 if (!!g_compositor_thread) { | 159 if (!!g_compositor_thread) { |
161 host_ = cc::LayerTreeHost::CreateThreaded( | 160 host_ = cc::LayerTreeHost::CreateThreaded( |
162 this, | 161 this, |
163 g_shared_bitmap_manager, | 162 g_context_factory->GetSharedBitmapManager(), |
164 settings, | 163 settings, |
165 g_compositor_thread->message_loop_proxy()); | 164 g_compositor_thread->message_loop_proxy()); |
166 } else { | 165 } else { |
167 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 166 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
168 this, this, g_shared_bitmap_manager, settings); | 167 this, this, g_context_factory->GetSharedBitmapManager(), settings); |
169 } | 168 } |
170 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 169 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
171 base::TimeTicks::Now() - before_create); | 170 base::TimeTicks::Now() - before_create); |
172 host_->SetRootLayer(root_web_layer_); | 171 host_->SetRootLayer(root_web_layer_); |
173 host_->SetLayerTreeHostClientReady(); | 172 host_->SetLayerTreeHostClientReady(); |
174 } | 173 } |
175 | 174 |
176 Compositor::~Compositor() { | 175 Compositor::~Compositor() { |
177 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 176 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
178 | 177 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 if (g_compositor_thread) { | 226 if (g_compositor_thread) { |
228 g_compositor_thread->Stop(); | 227 g_compositor_thread->Stop(); |
229 delete g_compositor_thread; | 228 delete g_compositor_thread; |
230 g_compositor_thread = NULL; | 229 g_compositor_thread = NULL; |
231 } | 230 } |
232 | 231 |
233 DCHECK(g_compositor_initialized) << "Compositor::Initialize() didn't happen."; | 232 DCHECK(g_compositor_initialized) << "Compositor::Initialize() didn't happen."; |
234 g_compositor_initialized = false; | 233 g_compositor_initialized = false; |
235 } | 234 } |
236 | 235 |
237 // static | |
238 void Compositor::SetSharedBitmapManager(cc::SharedBitmapManager* manager) { | |
239 g_shared_bitmap_manager = manager; | |
240 } | |
241 | |
242 void Compositor::ScheduleDraw() { | 236 void Compositor::ScheduleDraw() { |
243 if (g_compositor_thread) { | 237 if (g_compositor_thread) { |
244 host_->Composite(gfx::FrameTime::Now()); | 238 host_->Composite(gfx::FrameTime::Now()); |
245 } else if (!defer_draw_scheduling_) { | 239 } else if (!defer_draw_scheduling_) { |
246 defer_draw_scheduling_ = true; | 240 defer_draw_scheduling_ = true; |
247 base::MessageLoop::current()->PostTask( | 241 base::MessageLoop::current()->PostTask( |
248 FROM_HERE, | 242 FROM_HERE, |
249 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); | 243 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); |
250 } | 244 } |
251 } | 245 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 // CompositorObservers to be notified before starting another | 466 // CompositorObservers to be notified before starting another |
473 // draw cycle. | 467 // draw cycle. |
474 ScheduleDraw(); | 468 ScheduleDraw(); |
475 } | 469 } |
476 FOR_EACH_OBSERVER(CompositorObserver, | 470 FOR_EACH_OBSERVER(CompositorObserver, |
477 observer_list_, | 471 observer_list_, |
478 OnCompositingEnded(this)); | 472 OnCompositingEnded(this)); |
479 } | 473 } |
480 | 474 |
481 } // namespace ui | 475 } // namespace ui |
OLD | NEW |