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

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

Powered by Google App Engine
This is Rietveld 408576698