OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/test/layer_tree_test_common.h" | 5 #include "cc/test/layer_tree_test_common.h" |
6 | 6 |
7 #include "cc/active_animation.h" | 7 #include "cc/active_animation.h" |
| 8 #include "cc/animation_registrar.h" |
8 #include "cc/content_layer.h" | 9 #include "cc/content_layer.h" |
9 #include "cc/font_atlas.h" | 10 #include "cc/font_atlas.h" |
10 #include "cc/input_handler.h" | 11 #include "cc/input_handler.h" |
11 #include "cc/layer.h" | 12 #include "cc/layer.h" |
12 #include "cc/layer_animation_controller.h" | 13 #include "cc/layer_animation_controller.h" |
13 #include "cc/layer_impl.h" | 14 #include "cc/layer_impl.h" |
14 #include "cc/layer_tree_host_impl.h" | 15 #include "cc/layer_tree_host_impl.h" |
15 #include "cc/scoped_thread_proxy.h" | 16 #include "cc/scoped_thread_proxy.h" |
16 #include "cc/single_thread_proxy.h" | 17 #include "cc/single_thread_proxy.h" |
17 #include "cc/thread_impl.h" | 18 #include "cc/thread_impl.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 void MockLayerTreeHostImpl::drawLayers(FrameData& frame) | 67 void MockLayerTreeHostImpl::drawLayers(FrameData& frame) |
67 { | 68 { |
68 LayerTreeHostImpl::drawLayers(frame); | 69 LayerTreeHostImpl::drawLayers(frame); |
69 m_testHooks->drawLayersOnThread(this); | 70 m_testHooks->drawLayersOnThread(this); |
70 } | 71 } |
71 | 72 |
72 void MockLayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::T
ime wallClockTime) | 73 void MockLayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::T
ime wallClockTime) |
73 { | 74 { |
74 m_testHooks->willAnimateLayers(this, monotonicTime); | 75 m_testHooks->willAnimateLayers(this, monotonicTime); |
75 LayerTreeHostImpl::animateLayers(monotonicTime, wallClockTime); | 76 LayerTreeHostImpl::animateLayers(monotonicTime, wallClockTime); |
76 m_testHooks->animateLayers(this, monotonicTime); | 77 bool hasUnfinishedAnimation = false; |
| 78 AnimationRegistrar::AnimationControllerMap::const_iterator iter = activeAnim
ationControllers().begin(); |
| 79 for (; iter != activeAnimationControllers().end(); ++iter) { |
| 80 if (iter->second->hasActiveAnimation()) { |
| 81 hasUnfinishedAnimation = true; |
| 82 break; |
| 83 } |
| 84 } |
| 85 m_testHooks->animateLayers(this, monotonicTime, hasUnfinishedAnimation); |
77 } | 86 } |
78 | 87 |
79 base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const | 88 base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const |
80 { | 89 { |
81 return base::TimeDelta::FromMilliseconds(16); | 90 return base::TimeDelta::FromMilliseconds(16); |
82 } | 91 } |
83 | 92 |
84 MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr
eeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) | 93 MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr
eeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) |
85 : LayerTreeHostImpl(settings, client, proxy) | 94 : LayerTreeHostImpl(settings, client, proxy) |
86 , m_testHooks(testHooks) | 95 , m_testHooks(testHooks) |
87 { | 96 { |
88 } | 97 } |
89 | 98 |
90 // Adapts LayerTreeHost for test. Injects MockLayerTreeHostImpl. | 99 // Adapts LayerTreeHost for test. Injects MockLayerTreeHostImpl. |
91 class MockLayerTreeHost : public cc::LayerTreeHost { | 100 class MockLayerTreeHost : public cc::LayerTreeHost { |
92 public: | 101 public: |
93 static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerT
reeHostClient* client, const cc::LayerTreeSettings& settings, scoped_ptr<cc::Thr
ead> implThread) | 102 static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerT
reeHostClient* client, const cc::LayerTreeSettings& settings, scoped_ptr<cc::Thr
ead> implThread) |
94 { | 103 { |
95 scoped_ptr<MockLayerTreeHost> layerTreeHost(new MockLayerTreeHost(testHo
oks, client, settings)); | 104 scoped_ptr<MockLayerTreeHost> layerTreeHost(new MockLayerTreeHost(testHo
oks, client, settings)); |
96 bool success = layerTreeHost->initialize(implThread.Pass()); | 105 bool success = layerTreeHost->initialize(implThread.Pass()); |
97 EXPECT_TRUE(success); | 106 EXPECT_TRUE(success); |
98 return layerTreeHost.Pass(); | 107 return layerTreeHost.Pass(); |
99 } | 108 } |
100 | 109 |
101 virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerT
reeHostImplClient* client) | 110 virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerT
reeHostImplClient* client) |
102 { | 111 { |
103 return MockLayerTreeHostImpl::create(m_testHooks, settings(), client, pr
oxy()).PassAs<cc::LayerTreeHostImpl>(); | 112 return MockLayerTreeHostImpl::create(m_testHooks, settings(), client, pr
oxy()).PassAs<cc::LayerTreeHostImpl>(); |
104 } | 113 } |
105 | 114 |
106 virtual void didAddAnimation() OVERRIDE | |
107 { | |
108 LayerTreeHost::didAddAnimation(); | |
109 m_testHooks->didAddAnimation(); | |
110 } | |
111 | |
112 virtual void setNeedsCommit() OVERRIDE | 115 virtual void setNeedsCommit() OVERRIDE |
113 { | 116 { |
114 if (!m_testStarted) | 117 if (!m_testStarted) |
115 return; | 118 return; |
116 LayerTreeHost::setNeedsCommit(); | 119 LayerTreeHost::setNeedsCommit(); |
117 } | 120 } |
118 | 121 |
119 void setTestStarted(bool started) { m_testStarted = started; } | 122 void setTestStarted(bool started) { m_testStarted = started; } |
120 | 123 |
121 virtual void didDeferCommit() OVERRIDE | 124 virtual void didDeferCommit() OVERRIDE |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 void ThreadedTest::postSetNeedsRedrawToMainThread() | 275 void ThreadedTest::postSetNeedsRedrawToMainThread() |
273 { | 276 { |
274 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsRedraw, base::Unretained(this))); | 277 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsRedraw, base::Unretained(this))); |
275 } | 278 } |
276 | 279 |
277 void ThreadedTest::postSetVisibleToMainThread(bool visible) | 280 void ThreadedTest::postSetVisibleToMainThread(bool visible) |
278 { | 281 { |
279 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
Visible, base::Unretained(this), visible)); | 282 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
Visible, base::Unretained(this), visible)); |
280 } | 283 } |
281 | 284 |
282 void ThreadedTest::postDidAddAnimationToMainThread() | |
283 { | |
284 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchDid
AddAnimation, base::Unretained(this))); | |
285 } | |
286 | |
287 void ThreadedTest::doBeginTest() | 285 void ThreadedTest::doBeginTest() |
288 { | 286 { |
289 m_client = ThreadedMockLayerTreeHostClient::create(this); | 287 m_client = ThreadedMockLayerTreeHostClient::create(this); |
290 | 288 |
291 scoped_ptr<cc::Thread> implCCThread(NULL); | 289 scoped_ptr<cc::Thread> implCCThread(NULL); |
292 if (m_implThread) | 290 if (m_implThread) |
293 implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->me
ssage_loop_proxy()); | 291 implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->me
ssage_loop_proxy()); |
294 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), m_settings
, implCCThread.Pass()); | 292 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), m_settings
, implCCThread.Pass()); |
295 ASSERT_TRUE(m_layerTreeHost.get()); | 293 ASSERT_TRUE(m_layerTreeHost.get()); |
296 | 294 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 m_layerTreeHost->setVisible(visible); | 402 m_layerTreeHost->setVisible(visible); |
405 } | 403 } |
406 | 404 |
407 void ThreadedTest::dispatchComposite() | 405 void ThreadedTest::dispatchComposite() |
408 { | 406 { |
409 m_scheduled = false; | 407 m_scheduled = false; |
410 if (m_layerTreeHost.get()) | 408 if (m_layerTreeHost.get()) |
411 m_layerTreeHost->composite(); | 409 m_layerTreeHost->composite(); |
412 } | 410 } |
413 | 411 |
414 void ThreadedTest::dispatchDidAddAnimation() | |
415 { | |
416 DCHECK(!proxy() || proxy()->isMainThread()); | |
417 | |
418 if (m_layerTreeHost.get()) | |
419 m_layerTreeHost->didAddAnimation(); | |
420 } | |
421 | |
422 void ThreadedTest::runTest(bool threaded) | 412 void ThreadedTest::runTest(bool threaded) |
423 { | 413 { |
424 if (threaded) { | 414 if (threaded) { |
425 m_implThread.reset(new base::Thread("ThreadedTest")); | 415 m_implThread.reset(new base::Thread("ThreadedTest")); |
426 ASSERT_TRUE(m_implThread->Start()); | 416 ASSERT_TRUE(m_implThread->Start()); |
427 } | 417 } |
428 | 418 |
429 m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); | 419 m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); |
430 m_mainThreadProxy = ScopedThreadProxy::create(m_mainCCThread.get()); | 420 m_mainThreadProxy = ScopedThreadProxy::create(m_mainCCThread.get()); |
431 | 421 |
(...skipping 12 matching lines...) Expand all Loading... |
444 ASSERT_FALSE(m_layerTreeHost.get()); | 434 ASSERT_FALSE(m_layerTreeHost.get()); |
445 m_client.reset(); | 435 m_client.reset(); |
446 if (m_timedOut) { | 436 if (m_timedOut) { |
447 FAIL() << "Test timed out"; | 437 FAIL() << "Test timed out"; |
448 return; | 438 return; |
449 } | 439 } |
450 afterTest(); | 440 afterTest(); |
451 } | 441 } |
452 | 442 |
453 } // namespace cc | 443 } // namespace cc |
OLD | NEW |