| 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/animation.h" | 7 #include "cc/animation.h" |
| 8 #include "cc/animation_registrar.h" | 8 #include "cc/animation_registrar.h" |
| 9 #include "cc/content_layer.h" | 9 #include "cc/content_layer.h" |
| 10 #include "cc/input_handler.h" | 10 #include "cc/input_handler.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 { | 195 { |
| 196 } | 196 } |
| 197 | 197 |
| 198 TestHooks* m_testHooks; | 198 TestHooks* m_testHooks; |
| 199 bool m_testStarted; | 199 bool m_testStarted; |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 // Implementation of LayerTreeHost callback interface. | 202 // Implementation of LayerTreeHost callback interface. |
| 203 class ThreadedMockLayerTreeHostClient : public MockLayerImplTreeHostClient { | 203 class ThreadedMockLayerTreeHostClient : public MockLayerImplTreeHostClient { |
| 204 public: | 204 public: |
| 205 static scoped_ptr<ThreadedMockLayerTreeHostClient> create(TestHooks* testHoo
ks) | 205 static scoped_ptr<ThreadedMockLayerTreeHostClient> Create(TestHooks* testHoo
ks) |
| 206 { | 206 { |
| 207 return make_scoped_ptr(new ThreadedMockLayerTreeHostClient(testHooks)); | 207 return make_scoped_ptr(new ThreadedMockLayerTreeHostClient(testHooks)); |
| 208 } | 208 } |
| 209 | 209 |
| 210 virtual void willBeginFrame() OVERRIDE | 210 virtual void willBeginFrame() OVERRIDE |
| 211 { | 211 { |
| 212 } | 212 } |
| 213 | 213 |
| 214 virtual void didBeginFrame() OVERRIDE | 214 virtual void didBeginFrame() OVERRIDE |
| 215 { | 215 { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 proxy()->MainThread()->postTask(base::Bind(&ThreadedTest::dispatchSetNeedsRe
draw, m_mainThreadWeakPtr)); | 347 proxy()->MainThread()->postTask(base::Bind(&ThreadedTest::dispatchSetNeedsRe
draw, m_mainThreadWeakPtr)); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void ThreadedTest::postSetVisibleToMainThread(bool visible) | 350 void ThreadedTest::postSetVisibleToMainThread(bool visible) |
| 351 { | 351 { |
| 352 proxy()->MainThread()->postTask(base::Bind(&ThreadedTest::dispatchSetVisible
, m_mainThreadWeakPtr, visible)); | 352 proxy()->MainThread()->postTask(base::Bind(&ThreadedTest::dispatchSetVisible
, m_mainThreadWeakPtr, visible)); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void ThreadedTest::doBeginTest() | 355 void ThreadedTest::doBeginTest() |
| 356 { | 356 { |
| 357 m_client = ThreadedMockLayerTreeHostClient::create(this); | 357 m_client = ThreadedMockLayerTreeHostClient::Create(this); |
| 358 | 358 |
| 359 scoped_ptr<cc::Thread> implCCThread(NULL); | 359 scoped_ptr<cc::Thread> implCCThread(NULL); |
| 360 if (m_implThread) | 360 if (m_implThread) |
| 361 implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->me
ssage_loop_proxy()); | 361 implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->me
ssage_loop_proxy()); |
| 362 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), m_settings
, implCCThread.Pass()); | 362 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), m_settings
, implCCThread.Pass()); |
| 363 ASSERT_TRUE(m_layerTreeHost.get()); | 363 ASSERT_TRUE(m_layerTreeHost); |
| 364 | 364 |
| 365 m_started = true; | 365 m_started = true; |
| 366 m_beginning = true; | 366 m_beginning = true; |
| 367 setupTree(); | 367 setupTree(); |
| 368 m_layerTreeHost->setSurfaceReady(); | 368 m_layerTreeHost->setSurfaceReady(); |
| 369 beginTest(); | 369 beginTest(); |
| 370 m_beginning = false; | 370 m_beginning = false; |
| 371 if (m_endWhenBeginReturns) | 371 if (m_endWhenBeginReturns) |
| 372 realEndTest(); | 372 realEndTest(); |
| 373 | 373 |
| 374 // Allow commits to happen once beginTest() has had a chance to post tasks | 374 // Allow commits to happen once beginTest() has had a chance to post tasks |
| 375 // so that those tasks will happen before the first commit. | 375 // so that those tasks will happen before the first commit. |
| 376 if (m_layerTreeHost) | 376 if (m_layerTreeHost) |
| 377 static_cast<MockLayerTreeHost*>(m_layerTreeHost.get())->setTestStarted(t
rue); | 377 static_cast<MockLayerTreeHost*>(m_layerTreeHost.get())->setTestStarted(t
rue); |
| 378 } | 378 } |
| 379 | 379 |
| 380 void ThreadedTest::setupTree() | 380 void ThreadedTest::setupTree() |
| 381 { | 381 { |
| 382 if (!m_layerTreeHost->rootLayer()) { | 382 if (!m_layerTreeHost->rootLayer()) { |
| 383 scoped_refptr<Layer> rootLayer = Layer::create(); | 383 scoped_refptr<Layer> rootLayer = Layer::Create(); |
| 384 rootLayer->setBounds(gfx::Size(1, 1)); | 384 rootLayer->SetBounds(gfx::Size(1, 1)); |
| 385 m_layerTreeHost->setRootLayer(rootLayer); | 385 m_layerTreeHost->setRootLayer(rootLayer); |
| 386 } | 386 } |
| 387 | 387 |
| 388 gfx::Size rootBounds = m_layerTreeHost->rootLayer()->bounds(); | 388 gfx::Size rootBounds = m_layerTreeHost->rootLayer()->bounds(); |
| 389 gfx::Size deviceRootBounds = gfx::ToCeiledSize( | 389 gfx::Size deviceRootBounds = gfx::ToCeiledSize( |
| 390 gfx::ScaleSize(rootBounds, m_layerTreeHost->deviceScaleFactor())); | 390 gfx::ScaleSize(rootBounds, m_layerTreeHost->deviceScaleFactor())); |
| 391 m_layerTreeHost->setViewportSize(rootBounds, deviceRootBounds); | 391 m_layerTreeHost->setViewportSize(rootBounds, deviceRootBounds); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void ThreadedTest::timeout() | 394 void ThreadedTest::timeout() |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 499 |
| 500 m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); | 500 m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); |
| 501 | 501 |
| 502 initializeSettings(m_settings); | 502 initializeSettings(m_settings); |
| 503 | 503 |
| 504 m_mainCCThread->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unreta
ined(this))); | 504 m_mainCCThread->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unreta
ined(this))); |
| 505 m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this))); | 505 m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this))); |
| 506 m_mainCCThread->postDelayedTask(m_timeout.callback(), 5000); | 506 m_mainCCThread->postDelayedTask(m_timeout.callback(), 5000); |
| 507 MessageLoop::current()->Run(); | 507 MessageLoop::current()->Run(); |
| 508 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) | 508 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) |
| 509 m_layerTreeHost->rootLayer()->setLayerTreeHost(0); | 509 m_layerTreeHost->rootLayer()->SetLayerTreeHost(0); |
| 510 m_layerTreeHost.reset(); | 510 m_layerTreeHost.reset(); |
| 511 | 511 |
| 512 m_timeout.Cancel(); | 512 m_timeout.Cancel(); |
| 513 | 513 |
| 514 ASSERT_FALSE(m_layerTreeHost.get()); | 514 ASSERT_FALSE(m_layerTreeHost.get()); |
| 515 m_client.reset(); | 515 m_client.reset(); |
| 516 if (m_timedOut) { | 516 if (m_timedOut) { |
| 517 FAIL() << "Test timed out"; | 517 FAIL() << "Test timed out"; |
| 518 return; | 518 return; |
| 519 } | 519 } |
| 520 afterTest(); | 520 afterTest(); |
| 521 } | 521 } |
| 522 | 522 |
| 523 } // namespace cc | 523 } // namespace cc |
| OLD | NEW |