Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1091)

Side by Side Diff: cc/test/layer_tree_test_common.cc

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase to 165064 Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/test/layer_tree_test_common.h" 7 #include "cc/test/layer_tree_test_common.h"
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "cc/active_animation.h" 10 #include "cc/active_animation.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 bool TestHooks::prepareToDrawOnThread(cc::LayerTreeHostImpl*) 82 bool TestHooks::prepareToDrawOnThread(cc::LayerTreeHostImpl*)
83 { 83 {
84 return true; 84 return true;
85 } 85 }
86 86
87 scoped_ptr<WebCompositorOutputSurface> TestHooks::createOutputSurface() 87 scoped_ptr<WebCompositorOutputSurface> TestHooks::createOutputSurface()
88 { 88 {
89 return FakeWebCompositorOutputSurface::create(CompositorFakeWebGraphicsConte xt3DWithTextureTracking::create(WebGraphicsContext3D::Attributes()).PassAs<WebKi t::WebGraphicsContext3D>()).PassAs<WebKit::WebCompositorOutputSurface>(); 89 return FakeWebCompositorOutputSurface::create(CompositorFakeWebGraphicsConte xt3DWithTextureTracking::create(WebGraphicsContext3D::Attributes()).PassAs<WebKi t::WebGraphicsContext3D>()).PassAs<WebKit::WebCompositorOutputSurface>();
90 } 90 }
91 91
92 scoped_ptr<MockLayerTreeHostImpl> MockLayerTreeHostImpl::create(TestHooks* testH ooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client) 92 scoped_ptr<MockLayerTreeHostImpl> MockLayerTreeHostImpl::create(TestHooks* testH ooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy)
93 { 93 {
94 return make_scoped_ptr(new MockLayerTreeHostImpl(testHooks, settings, client )); 94 return make_scoped_ptr(new MockLayerTreeHostImpl(testHooks, settings, client , proxy));
95 } 95 }
96 96
97 void MockLayerTreeHostImpl::beginCommit() 97 void MockLayerTreeHostImpl::beginCommit()
98 { 98 {
99 LayerTreeHostImpl::beginCommit(); 99 LayerTreeHostImpl::beginCommit();
100 m_testHooks->beginCommitOnThread(this); 100 m_testHooks->beginCommitOnThread(this);
101 } 101 }
102 102
103 void MockLayerTreeHostImpl::commitComplete() 103 void MockLayerTreeHostImpl::commitComplete()
104 { 104 {
(...skipping 20 matching lines...) Expand all
125 m_testHooks->willAnimateLayers(this, monotonicTime); 125 m_testHooks->willAnimateLayers(this, monotonicTime);
126 LayerTreeHostImpl::animateLayers(monotonicTime, wallClockTime); 126 LayerTreeHostImpl::animateLayers(monotonicTime, wallClockTime);
127 m_testHooks->animateLayers(this, monotonicTime); 127 m_testHooks->animateLayers(this, monotonicTime);
128 } 128 }
129 129
130 base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const 130 base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const
131 { 131 {
132 return base::TimeDelta::FromMilliseconds(16); 132 return base::TimeDelta::FromMilliseconds(16);
133 } 133 }
134 134
135 MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr eeSettings& settings, LayerTreeHostImplClient* client) 135 MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr eeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy)
136 : LayerTreeHostImpl(settings, client) 136 : LayerTreeHostImpl(settings, client, proxy)
137 , m_testHooks(testHooks) 137 , m_testHooks(testHooks)
138 { 138 {
139 } 139 }
140 140
141 // Adapts LayerTreeHost for test. Injects MockLayerTreeHostImpl. 141 // Adapts LayerTreeHost for test. Injects MockLayerTreeHostImpl.
142 class MockLayerTreeHost : public cc::LayerTreeHost { 142 class MockLayerTreeHost : public cc::LayerTreeHost {
143 public: 143 public:
144 static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerT reeHostClient* client, scoped_refptr<cc::Layer> rootLayer, const cc::LayerTreeSe ttings& settings) 144 static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerT reeHostClient* client, scoped_refptr<cc::Layer> rootLayer, const cc::LayerTreeSe ttings& settings, cc::Thread* implThread)
145 { 145 {
146 scoped_ptr<MockLayerTreeHost> layerTreeHost(new MockLayerTreeHost(testHo oks, client, settings)); 146 scoped_ptr<MockLayerTreeHost> layerTreeHost(new MockLayerTreeHost(testHo oks, client, settings));
147 bool success = layerTreeHost->initialize(); 147 bool success = layerTreeHost->initialize(implThread);
148 EXPECT_TRUE(success); 148 EXPECT_TRUE(success);
149 layerTreeHost->setRootLayer(rootLayer); 149 layerTreeHost->setRootLayer(rootLayer);
150 150
151 // LayerTreeHostImpl won't draw if it has 1x1 viewport. 151 // LayerTreeHostImpl won't draw if it has 1x1 viewport.
152 layerTreeHost->setViewportSize(IntSize(1, 1), IntSize(1, 1)); 152 layerTreeHost->setViewportSize(IntSize(1, 1), IntSize(1, 1));
153 153
154 layerTreeHost->rootLayer()->setLayerAnimationDelegate(testHooks); 154 layerTreeHost->rootLayer()->setLayerAnimationDelegate(testHooks);
155 155
156 return layerTreeHost.Pass(); 156 return layerTreeHost.Pass();
157 } 157 }
158 158
159 virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerT reeHostImplClient* client) 159 virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerT reeHostImplClient* client)
160 { 160 {
161 return MockLayerTreeHostImpl::create(m_testHooks, settings(), client).Pa ssAs<cc::LayerTreeHostImpl>(); 161 return MockLayerTreeHostImpl::create(m_testHooks, settings(), client, pr oxy()).PassAs<cc::LayerTreeHostImpl>();
162 } 162 }
163 163
164 virtual void didAddAnimation() OVERRIDE 164 virtual void didAddAnimation() OVERRIDE
165 { 165 {
166 LayerTreeHost::didAddAnimation(); 166 LayerTreeHost::didAddAnimation();
167 m_testHooks->didAddAnimation(); 167 m_testHooks->didAddAnimation();
168 } 168 }
169 169
170 virtual void setNeedsCommit() OVERRIDE 170 virtual void setNeedsCommit() OVERRIDE
171 { 171 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 TestHooks* m_testHooks; 268 TestHooks* m_testHooks;
269 }; 269 };
270 270
271 ThreadedTest::ThreadedTest() 271 ThreadedTest::ThreadedTest()
272 : m_beginning(false) 272 : m_beginning(false)
273 , m_endWhenBeginReturns(false) 273 , m_endWhenBeginReturns(false)
274 , m_timedOut(false) 274 , m_timedOut(false)
275 , m_finished(false) 275 , m_finished(false)
276 , m_scheduled(false) 276 , m_scheduled(false)
277 , m_started(false) 277 , m_started(false)
278 , m_implThread(0)
278 { 279 {
279 } 280 }
280 281
281 ThreadedTest::~ThreadedTest() 282 ThreadedTest::~ThreadedTest()
282 { 283 {
283 } 284 }
284 285
285 void ThreadedTest::endTest() 286 void ThreadedTest::endTest()
286 { 287 {
287 m_finished = true; 288 m_finished = true;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet Visible, base::Unretained(this), visible)); 340 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet Visible, base::Unretained(this), visible));
340 } 341 }
341 342
342 void ThreadedTest::postDidAddAnimationToMainThread() 343 void ThreadedTest::postDidAddAnimationToMainThread()
343 { 344 {
344 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchDid AddAnimation, base::Unretained(this))); 345 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchDid AddAnimation, base::Unretained(this)));
345 } 346 }
346 347
347 void ThreadedTest::doBeginTest() 348 void ThreadedTest::doBeginTest()
348 { 349 {
349 DCHECK(Proxy::isMainThread());
350 m_client = ThreadedMockLayerTreeHostClient::create(this); 350 m_client = ThreadedMockLayerTreeHostClient::create(this);
351 351
352 scoped_refptr<Layer> rootLayer = Layer::create(); 352 scoped_refptr<Layer> rootLayer = Layer::create();
353 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings); 353 cc::Thread* implCCThread = 0;
354 if (m_implThread.get())
jamesr 2012/10/31 04:42:13 if (m_implThread)
355 implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->me ssage_loop_proxy()).release();
356 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings, implCCThread);
354 ASSERT_TRUE(m_layerTreeHost.get()); 357 ASSERT_TRUE(m_layerTreeHost.get());
355 rootLayer->setLayerTreeHost(m_layerTreeHost.get()); 358 rootLayer->setLayerTreeHost(m_layerTreeHost.get());
356 m_layerTreeHost->setSurfaceReady(); 359 m_layerTreeHost->setSurfaceReady();
357 360
358 m_started = true; 361 m_started = true;
359 m_beginning = true; 362 m_beginning = true;
360 beginTest(); 363 beginTest();
361 m_beginning = false; 364 m_beginning = false;
362 if (m_endWhenBeginReturns) 365 if (m_endWhenBeginReturns)
363 realEndTest(); 366 realEndTest();
(...skipping 13 matching lines...) Expand all
377 void ThreadedTest::scheduleComposite() 380 void ThreadedTest::scheduleComposite()
378 { 381 {
379 if (!m_started || m_scheduled || m_finished) 382 if (!m_started || m_scheduled || m_finished)
380 return; 383 return;
381 m_scheduled = true; 384 m_scheduled = true;
382 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchCom posite, base::Unretained(this))); 385 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchCom posite, base::Unretained(this)));
383 } 386 }
384 387
385 void ThreadedTest::realEndTest() 388 void ThreadedTest::realEndTest()
386 { 389 {
387 DCHECK(Proxy::isMainThread());
388 MessageLoop::current()->Quit(); 390 MessageLoop::current()->Quit();
389 } 391 }
390 392
391 void ThreadedTest::dispatchSetNeedsAnimate() 393 void ThreadedTest::dispatchSetNeedsAnimate()
392 { 394 {
393 DCHECK(Proxy::isMainThread()); 395 DCHECK(!proxy() || proxy()->isMainThread());
394 396
395 if (m_finished) 397 if (m_finished)
396 return; 398 return;
397 399
398 if (m_layerTreeHost.get()) 400 if (m_layerTreeHost.get())
399 m_layerTreeHost->setNeedsAnimate(); 401 m_layerTreeHost->setNeedsAnimate();
400 } 402 }
401 403
402 void ThreadedTest::dispatchAddInstantAnimation() 404 void ThreadedTest::dispatchAddInstantAnimation()
403 { 405 {
404 DCHECK(Proxy::isMainThread()); 406 DCHECK(!proxy() || proxy()->isMainThread());
405 407
406 if (m_finished) 408 if (m_finished)
407 return; 409 return;
408 410
409 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) 411 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer())
410 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 0, 0, 0.5, fa lse); 412 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 0, 0, 0.5, fa lse);
411 } 413 }
412 414
413 void ThreadedTest::dispatchAddAnimation(Layer* layerToReceiveAnimation) 415 void ThreadedTest::dispatchAddAnimation(Layer* layerToReceiveAnimation)
414 { 416 {
415 DCHECK(Proxy::isMainThread()); 417 DCHECK(!proxy() || proxy()->isMainThread());
416 418
417 if (m_finished) 419 if (m_finished)
418 return; 420 return;
419 421
420 if (layerToReceiveAnimation) 422 if (layerToReceiveAnimation)
421 addOpacityTransitionToLayer(*layerToReceiveAnimation, 10, 0, 0.5, true); 423 addOpacityTransitionToLayer(*layerToReceiveAnimation, 10, 0, 0.5, true);
422 } 424 }
423 425
424 void ThreadedTest::dispatchSetNeedsAnimateAndCommit() 426 void ThreadedTest::dispatchSetNeedsAnimateAndCommit()
425 { 427 {
426 DCHECK(Proxy::isMainThread()); 428 DCHECK(!proxy() || proxy()->isMainThread());
427 429
428 if (m_finished) 430 if (m_finished)
429 return; 431 return;
430 432
431 if (m_layerTreeHost.get()) { 433 if (m_layerTreeHost.get()) {
432 m_layerTreeHost->setNeedsAnimate(); 434 m_layerTreeHost->setNeedsAnimate();
433 m_layerTreeHost->setNeedsCommit(); 435 m_layerTreeHost->setNeedsCommit();
434 } 436 }
435 } 437 }
436 438
437 void ThreadedTest::dispatchSetNeedsCommit() 439 void ThreadedTest::dispatchSetNeedsCommit()
438 { 440 {
439 DCHECK(Proxy::isMainThread()); 441 DCHECK(!proxy() || proxy()->isMainThread());
440 442
441 if (m_finished) 443 if (m_finished)
442 return; 444 return;
443 445
444 if (m_layerTreeHost.get()) 446 if (m_layerTreeHost.get())
445 m_layerTreeHost->setNeedsCommit(); 447 m_layerTreeHost->setNeedsCommit();
446 } 448 }
447 449
448 void ThreadedTest::dispatchAcquireLayerTextures() 450 void ThreadedTest::dispatchAcquireLayerTextures()
449 { 451 {
450 DCHECK(Proxy::isMainThread()); 452 DCHECK(!proxy() || proxy()->isMainThread());
451 453
452 if (m_finished) 454 if (m_finished)
453 return; 455 return;
454 456
455 if (m_layerTreeHost.get()) 457 if (m_layerTreeHost.get())
456 m_layerTreeHost->acquireLayerTextures(); 458 m_layerTreeHost->acquireLayerTextures();
457 } 459 }
458 460
459 void ThreadedTest::dispatchSetNeedsRedraw() 461 void ThreadedTest::dispatchSetNeedsRedraw()
460 { 462 {
461 DCHECK(Proxy::isMainThread()); 463 DCHECK(!proxy() || proxy()->isMainThread());
462 464
463 if (m_finished) 465 if (m_finished)
464 return; 466 return;
465 467
466 if (m_layerTreeHost.get()) 468 if (m_layerTreeHost.get())
467 m_layerTreeHost->setNeedsRedraw(); 469 m_layerTreeHost->setNeedsRedraw();
468 } 470 }
469 471
470 void ThreadedTest::dispatchSetVisible(bool visible) 472 void ThreadedTest::dispatchSetVisible(bool visible)
471 { 473 {
472 DCHECK(Proxy::isMainThread()); 474 DCHECK(!proxy() || proxy()->isMainThread());
473 475
474 if (m_finished) 476 if (m_finished)
475 return; 477 return;
476 478
477 if (m_layerTreeHost.get()) 479 if (m_layerTreeHost.get())
478 m_layerTreeHost->setVisible(visible); 480 m_layerTreeHost->setVisible(visible);
479 } 481 }
480 482
481 void ThreadedTest::dispatchComposite() 483 void ThreadedTest::dispatchComposite()
482 { 484 {
483 m_scheduled = false; 485 m_scheduled = false;
484 if (m_layerTreeHost.get() && !m_finished) 486 if (m_layerTreeHost.get() && !m_finished)
485 m_layerTreeHost->composite(); 487 m_layerTreeHost->composite();
486 } 488 }
487 489
488 void ThreadedTest::dispatchDidAddAnimation() 490 void ThreadedTest::dispatchDidAddAnimation()
489 { 491 {
490 DCHECK(Proxy::isMainThread()); 492 DCHECK(!proxy() || proxy()->isMainThread());
491 493
492 if (m_finished) 494 if (m_finished)
493 return; 495 return;
494 496
495 if (m_layerTreeHost.get()) 497 if (m_layerTreeHost.get())
496 m_layerTreeHost->didAddAnimation(); 498 m_layerTreeHost->didAddAnimation();
497 } 499 }
498 500
499 void ThreadedTest::runTest(bool threaded) 501 void ThreadedTest::runTest(bool threaded)
500 { 502 {
501 // For these tests, we will enable threaded animations. 503 // For these tests, we will enable threaded animations.
502 ScopedSettings scopedSettings; 504 ScopedSettings scopedSettings;
503 Settings::setAcceleratedAnimationEnabled(true); 505 Settings::setAcceleratedAnimationEnabled(true);
504 506
505 if (threaded) { 507 if (threaded) {
506 m_implThread.reset(new base::Thread("ThreadedTest")); 508 m_implThread.reset(new base::Thread("ThreadedTest"));
507 ASSERT_TRUE(m_implThread->Start()); 509 ASSERT_TRUE(m_implThread->Start());
508 m_implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread-> message_loop_proxy());
509 cc::Proxy::setImplThread(m_implCCThread.get());
510 } 510 }
511 511
512 DCHECK(Proxy::isMainThread()); 512 m_mainCCThread = cc::ThreadImpl::createForCurrentThread();
513 m_mainThreadProxy = ScopedThreadProxy::create(Proxy::mainThread()); 513 m_mainThreadProxy = ScopedThreadProxy::create(m_mainCCThread.get());
514 514
515 initializeSettings(m_settings); 515 initializeSettings(m_settings);
516 516
517 cc::Proxy::mainThread()->postTask(base::Bind(&ThreadedTest::doBeginTest, bas e::Unretained(this))); 517 m_mainCCThread->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unreta ined(this)));
518 m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this))); 518 m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this)));
519 cc::Proxy::mainThread()->postDelayedTask(m_timeout.callback(), 5000); 519 m_mainCCThread->postDelayedTask(m_timeout.callback(), 5000);
520 MessageLoop::current()->Run(); 520 MessageLoop::current()->Run();
521 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) 521 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer())
522 m_layerTreeHost->rootLayer()->setLayerTreeHost(0); 522 m_layerTreeHost->rootLayer()->setLayerTreeHost(0);
523 m_layerTreeHost.reset(); 523 m_layerTreeHost.reset();
524 524
525 cc::Proxy::setImplThread(0);
526
527 m_timeout.Cancel(); 525 m_timeout.Cancel();
528 526
529 ASSERT_FALSE(m_layerTreeHost.get()); 527 ASSERT_FALSE(m_layerTreeHost.get());
530 m_client.reset(); 528 m_client.reset();
531 if (m_timedOut) { 529 if (m_timedOut) {
532 FAIL() << "Test timed out"; 530 FAIL() << "Test timed out";
533 return; 531 return;
534 } 532 }
535 afterTest(); 533 afterTest();
536 } 534 }
537 535
538 } // namespace WebKitTests 536 } // namespace WebKitTests
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698