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 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 Compositor::~Compositor() { | 164 Compositor::~Compositor() { |
165 // Don't call |CompositorDelegate::ScheduleDraw| from this point. | 165 // Don't call |CompositorDelegate::ScheduleDraw| from this point. |
166 delegate_ = NULL; | 166 delegate_ = NULL; |
167 // There's a cycle between |root_web_layer_| and |host_|, which results in | 167 // There's a cycle between |root_web_layer_| and |host_|, which results in |
168 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle | 168 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle |
169 // is broken. | 169 // is broken. |
170 host_.setRootLayer(NULL); | 170 host_.setRootLayer(NULL); |
171 if (root_layer_) | 171 if (root_layer_) |
172 root_layer_->SetCompositor(NULL); | 172 root_layer_->SetCompositor(NULL); |
| 173 |
| 174 // Stop all outstanding draws before telling the ContextFactory to tear |
| 175 // down any contexts that the |host_| may rely upon. |
| 176 host_.reset(); |
| 177 |
173 if (!test_compositor_enabled) | 178 if (!test_compositor_enabled) |
174 ContextFactory::GetInstance()->RemoveCompositor(this); | 179 ContextFactory::GetInstance()->RemoveCompositor(this); |
175 } | 180 } |
176 | 181 |
177 void Compositor::Initialize(bool use_thread) { | 182 void Compositor::Initialize(bool use_thread) { |
178 #if defined(WEBCOMPOSITOR_OWNS_SETTINGS) | 183 #if defined(WEBCOMPOSITOR_OWNS_SETTINGS) |
179 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 184 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
180 // These settings must be applied before we initialize the compositor. | 185 // These settings must be applied before we initialize the compositor. |
181 WebKit::WebCompositor::setPartialSwapEnabled( | 186 WebKit::WebCompositor::setPartialSwapEnabled( |
182 command_line->HasSwitch(switches::kUIEnablePartialSwap)); | 187 command_line->HasSwitch(switches::kUIEnablePartialSwap)); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 290 } |
286 | 291 |
287 void Compositor::RemoveObserver(CompositorObserver* observer) { | 292 void Compositor::RemoveObserver(CompositorObserver* observer) { |
288 observer_list_.RemoveObserver(observer); | 293 observer_list_.RemoveObserver(observer); |
289 } | 294 } |
290 | 295 |
291 bool Compositor::HasObserver(CompositorObserver* observer) { | 296 bool Compositor::HasObserver(CompositorObserver* observer) { |
292 return observer_list_.HasObserver(observer); | 297 return observer_list_.HasObserver(observer); |
293 } | 298 } |
294 | 299 |
| 300 bool Compositor::IsThreaded() const { |
| 301 return g_compositor_thread != NULL; |
| 302 } |
| 303 |
295 void Compositor::OnSwapBuffersPosted() { | 304 void Compositor::OnSwapBuffersPosted() { |
296 swap_posted_ = true; | 305 swap_posted_ = true; |
297 } | 306 } |
298 | 307 |
299 void Compositor::OnSwapBuffersComplete() { | 308 void Compositor::OnSwapBuffersComplete() { |
300 DCHECK(swap_posted_); | 309 DCHECK(swap_posted_); |
301 swap_posted_ = false; | 310 swap_posted_ = false; |
302 NotifyEnd(); | 311 NotifyEnd(); |
303 } | 312 } |
304 | 313 |
(...skipping 30 matching lines...) Expand all Loading... |
335 test_context->Initialize(); | 344 test_context->Initialize(); |
336 return test_context; | 345 return test_context; |
337 } else { | 346 } else { |
338 return ContextFactory::GetInstance()->CreateContext(this); | 347 return ContextFactory::GetInstance()->CreateContext(this); |
339 } | 348 } |
340 } | 349 } |
341 | 350 |
342 void Compositor::didRebindGraphicsContext(bool success) { | 351 void Compositor::didRebindGraphicsContext(bool success) { |
343 } | 352 } |
344 | 353 |
| 354 // Called once per draw in single-threaded compositor mode and potentially |
| 355 // many times between draws in the multi-threaded compositor mode. |
| 356 void Compositor::didCommit() { |
| 357 FOR_EACH_OBSERVER(CompositorObserver, |
| 358 observer_list_, |
| 359 OnCompositingDidCommit(this)); |
| 360 } |
| 361 |
345 void Compositor::didCommitAndDrawFrame() { | 362 void Compositor::didCommitAndDrawFrame() { |
346 // TODO(backer): Plumb through an earlier impl side will start. | 363 // TODO(backer): Plumb through an earlier impl side will start. |
347 if (g_compositor_thread) | 364 if (g_compositor_thread) |
348 FOR_EACH_OBSERVER(CompositorObserver, | 365 FOR_EACH_OBSERVER(CompositorObserver, |
349 observer_list_, | 366 observer_list_, |
350 OnCompositingWillStart(this)); | 367 OnCompositingWillStart(this)); |
351 | 368 |
352 FOR_EACH_OBSERVER(CompositorObserver, | 369 FOR_EACH_OBSERVER(CompositorObserver, |
353 observer_list_, | 370 observer_list_, |
354 OnCompositingStarted(this)); | 371 OnCompositingStarted(this)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 425 |
409 COMPOSITOR_EXPORT void DisableTestCompositor() { | 426 COMPOSITOR_EXPORT void DisableTestCompositor() { |
410 test_compositor_enabled = false; | 427 test_compositor_enabled = false; |
411 } | 428 } |
412 | 429 |
413 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 430 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
414 return test_compositor_enabled; | 431 return test_compositor_enabled; |
415 } | 432 } |
416 | 433 |
417 } // namespace ui | 434 } // namespace ui |
OLD | NEW |