| 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 "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "cc/active_animation.h" | 8 #include "cc/active_animation.h" |
| 9 #include "cc/content_layer.h" | 9 #include "cc/content_layer.h" |
| 10 #include "cc/font_atlas.h" | 10 #include "cc/font_atlas.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 void MockLayerTreeHostImpl::drawLayers(FrameData& frame) | 112 void MockLayerTreeHostImpl::drawLayers(FrameData& frame) |
| 113 { | 113 { |
| 114 LayerTreeHostImpl::drawLayers(frame); | 114 LayerTreeHostImpl::drawLayers(frame); |
| 115 m_testHooks->drawLayersOnThread(this); | 115 m_testHooks->drawLayersOnThread(this); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void MockLayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::T
ime wallClockTime) | 118 void MockLayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::T
ime wallClockTime) |
| 119 { | 119 { |
| 120 m_testHooks->willAnimateLayers(this, monotonicTime); | 120 m_testHooks->willAnimateLayers(this, monotonicTime); |
| 121 LayerTreeHostImpl::animateLayers(monotonicTime, wallClockTime); | 121 LayerTreeHostImpl::animateLayers(monotonicTime, wallClockTime); |
| 122 m_testHooks->animateLayers(this, monotonicTime); | 122 bool hasUnfinishedAnimation = false; |
| 123 LayerTreeHostImpl::AnimationControllerMap::const_iterator iter = activeAnima
tionControllers().begin(); |
| 124 for (; iter != activeAnimationControllers().end(); ++iter) { |
| 125 if (iter->second->hasActiveAnimation()) { |
| 126 hasUnfinishedAnimation = true; |
| 127 break; |
| 128 } |
| 129 } |
| 130 m_testHooks->animateLayers(this, monotonicTime, hasUnfinishedAnimation); |
| 123 } | 131 } |
| 124 | 132 |
| 125 base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const | 133 base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const |
| 126 { | 134 { |
| 127 return base::TimeDelta::FromMilliseconds(16); | 135 return base::TimeDelta::FromMilliseconds(16); |
| 128 } | 136 } |
| 129 | 137 |
| 130 MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr
eeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) | 138 MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr
eeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) |
| 131 : LayerTreeHostImpl(settings, client, proxy) | 139 : LayerTreeHostImpl(settings, client, proxy) |
| 132 , m_testHooks(testHooks) | 140 , m_testHooks(testHooks) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 149 layerTreeHost->rootLayer()->setLayerAnimationDelegate(testHooks); | 157 layerTreeHost->rootLayer()->setLayerAnimationDelegate(testHooks); |
| 150 | 158 |
| 151 return layerTreeHost.Pass(); | 159 return layerTreeHost.Pass(); |
| 152 } | 160 } |
| 153 | 161 |
| 154 virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerT
reeHostImplClient* client) | 162 virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerT
reeHostImplClient* client) |
| 155 { | 163 { |
| 156 return MockLayerTreeHostImpl::create(m_testHooks, settings(), client, pr
oxy()).PassAs<cc::LayerTreeHostImpl>(); | 164 return MockLayerTreeHostImpl::create(m_testHooks, settings(), client, pr
oxy()).PassAs<cc::LayerTreeHostImpl>(); |
| 157 } | 165 } |
| 158 | 166 |
| 159 virtual void didAddAnimation() OVERRIDE | |
| 160 { | |
| 161 LayerTreeHost::didAddAnimation(); | |
| 162 m_testHooks->didAddAnimation(); | |
| 163 } | |
| 164 | |
| 165 virtual void setNeedsCommit() OVERRIDE | 167 virtual void setNeedsCommit() OVERRIDE |
| 166 { | 168 { |
| 167 if (!m_testStarted) | 169 if (!m_testStarted) |
| 168 return; | 170 return; |
| 169 LayerTreeHost::setNeedsCommit(); | 171 LayerTreeHost::setNeedsCommit(); |
| 170 } | 172 } |
| 171 | 173 |
| 174 virtual void DidActivateAnimationController(cc::LayerAnimationController* co
ntroller) OVERRIDE |
| 175 { |
| 176 LayerTreeHost::DidActivateAnimationController(controller); |
| 177 m_testHooks->didAddAnimation(); |
| 178 } |
| 179 |
| 172 void setTestStarted(bool started) { m_testStarted = started; } | 180 void setTestStarted(bool started) { m_testStarted = started; } |
| 173 | 181 |
| 174 virtual void didDeferCommit() OVERRIDE | 182 virtual void didDeferCommit() OVERRIDE |
| 175 { | 183 { |
| 176 m_testHooks->didDeferCommit(); | 184 m_testHooks->didDeferCommit(); |
| 177 } | 185 } |
| 178 | 186 |
| 179 private: | 187 private: |
| 180 MockLayerTreeHost(TestHooks* testHooks, cc::LayerTreeHostClient* client, con
st cc::LayerTreeSettings& settings) | 188 MockLayerTreeHost(TestHooks* testHooks, cc::LayerTreeHostClient* client, con
st cc::LayerTreeSettings& settings) |
| 181 : LayerTreeHost(client, settings) | 189 : LayerTreeHost(client, settings) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 void ThreadedTest::postSetNeedsRedrawToMainThread() | 336 void ThreadedTest::postSetNeedsRedrawToMainThread() |
| 329 { | 337 { |
| 330 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsRedraw, base::Unretained(this))); | 338 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsRedraw, base::Unretained(this))); |
| 331 } | 339 } |
| 332 | 340 |
| 333 void ThreadedTest::postSetVisibleToMainThread(bool visible) | 341 void ThreadedTest::postSetVisibleToMainThread(bool visible) |
| 334 { | 342 { |
| 335 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
Visible, base::Unretained(this), visible)); | 343 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
Visible, base::Unretained(this), visible)); |
| 336 } | 344 } |
| 337 | 345 |
| 338 void ThreadedTest::postDidAddAnimationToMainThread() | |
| 339 { | |
| 340 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchDid
AddAnimation, base::Unretained(this))); | |
| 341 } | |
| 342 | |
| 343 void ThreadedTest::doBeginTest() | 346 void ThreadedTest::doBeginTest() |
| 344 { | 347 { |
| 345 m_client = ThreadedMockLayerTreeHostClient::create(this); | 348 m_client = ThreadedMockLayerTreeHostClient::create(this); |
| 346 | 349 |
| 347 scoped_refptr<Layer> rootLayer = Layer::create(); | 350 scoped_refptr<Layer> rootLayer = Layer::create(); |
| 348 scoped_ptr<cc::Thread> implCCThread(NULL); | 351 scoped_ptr<cc::Thread> implCCThread(NULL); |
| 349 if (m_implThread) | 352 if (m_implThread) |
| 350 implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->me
ssage_loop_proxy()); | 353 implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->me
ssage_loop_proxy()); |
| 351 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer,
m_settings, implCCThread.Pass()); | 354 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer,
m_settings, implCCThread.Pass()); |
| 352 ASSERT_TRUE(m_layerTreeHost.get()); | 355 ASSERT_TRUE(m_layerTreeHost.get()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 m_layerTreeHost->setVisible(visible); | 465 m_layerTreeHost->setVisible(visible); |
| 463 } | 466 } |
| 464 | 467 |
| 465 void ThreadedTest::dispatchComposite() | 468 void ThreadedTest::dispatchComposite() |
| 466 { | 469 { |
| 467 m_scheduled = false; | 470 m_scheduled = false; |
| 468 if (m_layerTreeHost.get() && !m_finished) | 471 if (m_layerTreeHost.get() && !m_finished) |
| 469 m_layerTreeHost->composite(); | 472 m_layerTreeHost->composite(); |
| 470 } | 473 } |
| 471 | 474 |
| 472 void ThreadedTest::dispatchDidAddAnimation() | |
| 473 { | |
| 474 DCHECK(!proxy() || proxy()->isMainThread()); | |
| 475 | |
| 476 if (m_finished) | |
| 477 return; | |
| 478 | |
| 479 if (m_layerTreeHost.get()) | |
| 480 m_layerTreeHost->didAddAnimation(); | |
| 481 } | |
| 482 | |
| 483 void ThreadedTest::runTest(bool threaded) | 475 void ThreadedTest::runTest(bool threaded) |
| 484 { | 476 { |
| 485 if (threaded) { | 477 if (threaded) { |
| 486 m_implThread.reset(new base::Thread("ThreadedTest")); | 478 m_implThread.reset(new base::Thread("ThreadedTest")); |
| 487 ASSERT_TRUE(m_implThread->Start()); | 479 ASSERT_TRUE(m_implThread->Start()); |
| 488 } | 480 } |
| 489 | 481 |
| 490 m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); | 482 m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); |
| 491 m_mainThreadProxy = ScopedThreadProxy::create(m_mainCCThread.get()); | 483 m_mainThreadProxy = ScopedThreadProxy::create(m_mainCCThread.get()); |
| 492 | 484 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 505 ASSERT_FALSE(m_layerTreeHost.get()); | 497 ASSERT_FALSE(m_layerTreeHost.get()); |
| 506 m_client.reset(); | 498 m_client.reset(); |
| 507 if (m_timedOut) { | 499 if (m_timedOut) { |
| 508 FAIL() << "Test timed out"; | 500 FAIL() << "Test timed out"; |
| 509 return; | 501 return; |
| 510 } | 502 } |
| 511 afterTest(); | 503 afterTest(); |
| 512 } | 504 } |
| 513 | 505 |
| 514 } // namespace cc | 506 } // namespace cc |
| OLD | NEW |