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 26 matching lines...) Expand all Loading... |
37 const double kTestRefreshRate = 200.0; | 37 const double kTestRefreshRate = 200.0; |
38 | 38 |
39 const int kCompositorLockTimeoutMs = 67; | 39 const int kCompositorLockTimeoutMs = 67; |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 namespace ui { | 43 namespace ui { |
44 | 44 |
45 CompositorLock::CompositorLock(Compositor* compositor) | 45 CompositorLock::CompositorLock(Compositor* compositor) |
46 : compositor_(compositor) { | 46 : compositor_(compositor) { |
47 base::MessageLoop::current()->PostDelayedTask( | 47 compositor_->task_runner_->PostDelayedTask( |
48 FROM_HERE, | 48 FROM_HERE, |
49 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()), | 49 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()), |
50 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); | 50 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); |
51 } | 51 } |
52 | 52 |
53 CompositorLock::~CompositorLock() { | 53 CompositorLock::~CompositorLock() { |
54 CancelLock(); | 54 CancelLock(); |
55 } | 55 } |
56 | 56 |
57 void CompositorLock::CancelLock() { | 57 void CompositorLock::CancelLock() { |
58 if (!compositor_) | 58 if (!compositor_) |
59 return; | 59 return; |
60 compositor_->UnlockCompositor(); | 60 compositor_->UnlockCompositor(); |
61 compositor_ = NULL; | 61 compositor_ = NULL; |
62 } | 62 } |
63 | 63 |
64 } // namespace ui | 64 } // namespace ui |
65 | 65 |
66 namespace { | 66 namespace { |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 namespace ui { | 70 namespace ui { |
71 | 71 |
72 Compositor::Compositor(gfx::AcceleratedWidget widget, | 72 Compositor::Compositor(gfx::AcceleratedWidget widget, |
73 ui::ContextFactory* context_factory) | 73 ui::ContextFactory* context_factory, |
| 74 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
74 : context_factory_(context_factory), | 75 : context_factory_(context_factory), |
75 root_layer_(NULL), | 76 root_layer_(NULL), |
76 widget_(widget), | 77 widget_(widget), |
77 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), | 78 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), |
| 79 task_runner_(task_runner), |
78 vsync_manager_(new CompositorVSyncManager()), | 80 vsync_manager_(new CompositorVSyncManager()), |
79 device_scale_factor_(0.0f), | 81 device_scale_factor_(0.0f), |
80 last_started_frame_(0), | 82 last_started_frame_(0), |
81 last_ended_frame_(0), | 83 last_ended_frame_(0), |
82 disable_schedule_composite_(false), | 84 disable_schedule_composite_(false), |
83 compositor_lock_(NULL), | 85 compositor_lock_(NULL), |
84 defer_draw_scheduling_(false), | 86 defer_draw_scheduling_(false), |
85 waiting_on_compositing_end_(false), | 87 waiting_on_compositing_end_(false), |
86 draw_on_compositing_end_(false), | 88 draw_on_compositing_end_(false), |
87 swap_state_(SWAP_NONE), | 89 swap_state_(SWAP_NONE), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 137 |
136 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); | 138 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); |
137 settings.use_zero_copy = IsUIZeroCopyEnabled(); | 139 settings.use_zero_copy = IsUIZeroCopyEnabled(); |
138 | 140 |
139 base::TimeTicks before_create = base::TimeTicks::Now(); | 141 base::TimeTicks before_create = base::TimeTicks::Now(); |
140 if (compositor_thread_loop_) { | 142 if (compositor_thread_loop_) { |
141 host_ = cc::LayerTreeHost::CreateThreaded( | 143 host_ = cc::LayerTreeHost::CreateThreaded( |
142 this, | 144 this, |
143 context_factory_->GetSharedBitmapManager(), | 145 context_factory_->GetSharedBitmapManager(), |
144 settings, | 146 settings, |
145 base::MessageLoopProxy::current(), | 147 task_runner_, |
146 compositor_thread_loop_); | 148 compositor_thread_loop_); |
147 } else { | 149 } else { |
148 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 150 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
149 this, | 151 this, |
150 this, | 152 this, |
151 context_factory_->GetSharedBitmapManager(), | 153 context_factory_->GetSharedBitmapManager(), |
152 settings, | 154 settings, |
153 base::MessageLoopProxy::current()); | 155 task_runner_); |
154 } | 156 } |
155 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 157 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
156 base::TimeTicks::Now() - before_create); | 158 base::TimeTicks::Now() - before_create); |
157 host_->SetRootLayer(root_web_layer_); | 159 host_->SetRootLayer(root_web_layer_); |
158 host_->SetLayerTreeHostClientReady(); | 160 host_->SetLayerTreeHostClientReady(); |
159 } | 161 } |
160 | 162 |
161 Compositor::~Compositor() { | 163 Compositor::~Compositor() { |
162 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 164 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
163 | 165 |
164 CancelCompositorLock(); | 166 CancelCompositorLock(); |
165 DCHECK(!compositor_lock_); | 167 DCHECK(!compositor_lock_); |
166 | 168 |
167 if (root_layer_) | 169 if (root_layer_) |
168 root_layer_->SetCompositor(NULL); | 170 root_layer_->SetCompositor(NULL); |
169 | 171 |
170 // Stop all outstanding draws before telling the ContextFactory to tear | 172 // Stop all outstanding draws before telling the ContextFactory to tear |
171 // down any contexts that the |host_| may rely upon. | 173 // down any contexts that the |host_| may rely upon. |
172 host_.reset(); | 174 host_.reset(); |
173 | 175 |
174 context_factory_->RemoveCompositor(this); | 176 context_factory_->RemoveCompositor(this); |
175 } | 177 } |
176 | 178 |
177 void Compositor::ScheduleDraw() { | 179 void Compositor::ScheduleDraw() { |
178 if (compositor_thread_loop_) { | 180 if (compositor_thread_loop_) { |
179 host_->SetNeedsCommit(); | 181 host_->SetNeedsCommit(); |
180 } else if (!defer_draw_scheduling_) { | 182 } else if (!defer_draw_scheduling_) { |
181 defer_draw_scheduling_ = true; | 183 defer_draw_scheduling_ = true; |
182 base::MessageLoop::current()->PostTask( | 184 task_runner_->PostTask( |
183 FROM_HERE, | 185 FROM_HERE, |
184 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); | 186 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); |
185 } | 187 } |
186 } | 188 } |
187 | 189 |
188 void Compositor::SetRootLayer(Layer* root_layer) { | 190 void Compositor::SetRootLayer(Layer* root_layer) { |
189 if (root_layer_ == root_layer) | 191 if (root_layer_ == root_layer) |
190 return; | 192 return; |
191 if (root_layer_) | 193 if (root_layer_) |
192 root_layer_->SetCompositor(NULL); | 194 root_layer_->SetCompositor(NULL); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 // CompositorObservers to be notified before starting another | 411 // CompositorObservers to be notified before starting another |
410 // draw cycle. | 412 // draw cycle. |
411 ScheduleDraw(); | 413 ScheduleDraw(); |
412 } | 414 } |
413 FOR_EACH_OBSERVER(CompositorObserver, | 415 FOR_EACH_OBSERVER(CompositorObserver, |
414 observer_list_, | 416 observer_list_, |
415 OnCompositingEnded(this)); | 417 OnCompositingEnded(this)); |
416 } | 418 } |
417 | 419 |
418 } // namespace ui | 420 } // namespace ui |
OLD | NEW |