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

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 Dana's code review suggestions 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 "CCThreadedTest.h" 7 #include "CCThreadedTest.h"
8 8
9 #include "CCActiveAnimation.h" 9 #include "CCActiveAnimation.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "cc/content_layer.h" 11 #include "cc/content_layer.h"
12 #include "cc/input_handler.h" 12 #include "cc/input_handler.h"
13 #include "cc/layer.h" 13 #include "cc/layer.h"
14 #include "cc/layer_animation_controller.h" 14 #include "cc/layer_animation_controller.h"
15 #include "cc/layer_impl.h" 15 #include "cc/layer_impl.h"
16 #include "cc/layer_tree_host_impl.h" 16 #include "cc/layer_tree_host_impl.h"
17 #include "cc/scoped_thread_proxy.h" 17 #include "cc/scoped_thread_proxy.h"
18 #include "cc/settings.h" 18 #include "cc/settings.h"
19 #include "cc/single_thread_proxy.h" 19 #include "cc/single_thread_proxy.h"
20 #include "cc/test/animation_test_common.h" 20 #include "cc/test/animation_test_common.h"
21 #include "cc/test/fake_web_compositor_output_surface.h" 21 #include "cc/test/fake_web_compositor_output_surface.h"
22 #include "cc/test/fake_web_graphics_context_3d.h" 22 #include "cc/test/fake_web_graphics_context_3d.h"
23 #include "cc/test/occlusion_tracker_test_common.h" 23 #include "cc/test/occlusion_tracker_test_common.h"
24 #include "cc/test/test_common.h" 24 #include "cc/test/test_common.h"
25 #include "cc/test/tiled_layer_test_common.h" 25 #include "cc/test/tiled_layer_test_common.h"
26 #include "cc/thread_task.h" 26 #include "cc/thread_task.h"
27 #include "cc/timing_function.h" 27 #include "cc/timing_function.h"
28 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
29 #include "webkit/compositor_bindings/ccthread_impl.h"
jamesr 2012/10/25 19:42:39 this is also not good
29 #include <public/Platform.h> 30 #include <public/Platform.h>
30 #include <public/WebCompositorSupport.h> 31 #include <public/WebCompositorSupport.h>
31 #include <public/WebFilterOperation.h> 32 #include <public/WebFilterOperation.h>
32 #include <public/WebFilterOperations.h> 33 #include <public/WebFilterOperations.h>
33 #include <public/WebThread.h> 34 #include <public/WebThread.h>
34 35
35 using namespace cc; 36 using namespace cc;
36 using namespace WebKit; 37 using namespace WebKit;
37 38
38 namespace WebKitTests { 39 namespace WebKitTests {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 bool TestHooks::prepareToDrawOnThread(cc::LayerTreeHostImpl*) 88 bool TestHooks::prepareToDrawOnThread(cc::LayerTreeHostImpl*)
88 { 89 {
89 return true; 90 return true;
90 } 91 }
91 92
92 scoped_ptr<WebCompositorOutputSurface> TestHooks::createOutputSurface() 93 scoped_ptr<WebCompositorOutputSurface> TestHooks::createOutputSurface()
93 { 94 {
94 return FakeWebCompositorOutputSurface::create(CompositorFakeWebGraphicsConte xt3DWithTextureTracking::create(WebGraphicsContext3D::Attributes()).PassAs<WebKi t::WebGraphicsContext3D>()).PassAs<WebKit::WebCompositorOutputSurface>(); 95 return FakeWebCompositorOutputSurface::create(CompositorFakeWebGraphicsConte xt3DWithTextureTracking::create(WebGraphicsContext3D::Attributes()).PassAs<WebKi t::WebGraphicsContext3D>()).PassAs<WebKit::WebCompositorOutputSurface>();
95 } 96 }
96 97
97 scoped_ptr<MockLayerTreeHostImpl> MockLayerTreeHostImpl::create(TestHooks* testH ooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client) 98 scoped_ptr<MockLayerTreeHostImpl> MockLayerTreeHostImpl::create(TestHooks* testH ooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy)
98 { 99 {
99 return make_scoped_ptr(new MockLayerTreeHostImpl(testHooks, settings, client )); 100 return make_scoped_ptr(new MockLayerTreeHostImpl(testHooks, settings, client , proxy));
100 } 101 }
101 102
102 void MockLayerTreeHostImpl::beginCommit() 103 void MockLayerTreeHostImpl::beginCommit()
103 { 104 {
104 LayerTreeHostImpl::beginCommit(); 105 LayerTreeHostImpl::beginCommit();
105 m_testHooks->beginCommitOnThread(this); 106 m_testHooks->beginCommitOnThread(this);
106 } 107 }
107 108
108 void MockLayerTreeHostImpl::commitComplete() 109 void MockLayerTreeHostImpl::commitComplete()
109 { 110 {
(...skipping 20 matching lines...) Expand all
130 m_testHooks->willAnimateLayers(this, monotonicTime); 131 m_testHooks->willAnimateLayers(this, monotonicTime);
131 LayerTreeHostImpl::animateLayers(monotonicTime, wallClockTime); 132 LayerTreeHostImpl::animateLayers(monotonicTime, wallClockTime);
132 m_testHooks->animateLayers(this, monotonicTime); 133 m_testHooks->animateLayers(this, monotonicTime);
133 } 134 }
134 135
135 base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const 136 base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const
136 { 137 {
137 return base::TimeDelta::FromMilliseconds(16); 138 return base::TimeDelta::FromMilliseconds(16);
138 } 139 }
139 140
140 MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr eeSettings& settings, LayerTreeHostImplClient* client) 141 MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr eeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy)
141 : LayerTreeHostImpl(settings, client) 142 : LayerTreeHostImpl(settings, client, proxy)
142 , m_testHooks(testHooks) 143 , m_testHooks(testHooks)
143 { 144 {
144 } 145 }
145 146
146 // Adapts LayerTreeHost for test. Injects MockLayerTreeHostImpl. 147 // Adapts LayerTreeHost for test. Injects MockLayerTreeHostImpl.
147 class MockLayerTreeHost : public cc::LayerTreeHost { 148 class MockLayerTreeHost : public cc::LayerTreeHost {
148 public: 149 public:
149 static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerT reeHostClient* client, scoped_refptr<cc::Layer> rootLayer, const cc::LayerTreeSe ttings& settings) 150 static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerT reeHostClient* client, scoped_refptr<cc::Layer> rootLayer, const cc::LayerTreeSe ttings& settings, cc::Thread* implThread)
150 { 151 {
151 scoped_ptr<MockLayerTreeHost> layerTreeHost(new MockLayerTreeHost(testHo oks, client, settings)); 152 scoped_ptr<MockLayerTreeHost> layerTreeHost(new MockLayerTreeHost(testHo oks, client, settings));
152 bool success = layerTreeHost->initialize(); 153 bool success = layerTreeHost->initialize(implThread);
153 EXPECT_TRUE(success); 154 EXPECT_TRUE(success);
154 layerTreeHost->setRootLayer(rootLayer); 155 layerTreeHost->setRootLayer(rootLayer);
155 156
156 // LayerTreeHostImpl won't draw if it has 1x1 viewport. 157 // LayerTreeHostImpl won't draw if it has 1x1 viewport.
157 layerTreeHost->setViewportSize(IntSize(1, 1), IntSize(1, 1)); 158 layerTreeHost->setViewportSize(IntSize(1, 1), IntSize(1, 1));
158 159
159 layerTreeHost->rootLayer()->setLayerAnimationDelegate(testHooks); 160 layerTreeHost->rootLayer()->setLayerAnimationDelegate(testHooks);
160 161
161 return layerTreeHost.Pass(); 162 return layerTreeHost.Pass();
162 } 163 }
163 164
164 virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerT reeHostImplClient* client) 165 virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerT reeHostImplClient* client)
165 { 166 {
166 return MockLayerTreeHostImpl::create(m_testHooks, settings(), client).Pa ssAs<cc::LayerTreeHostImpl>(); 167 return MockLayerTreeHostImpl::create(m_testHooks, settings(), client, pr oxy()).PassAs<cc::LayerTreeHostImpl>();
167 } 168 }
168 169
169 virtual void didAddAnimation() OVERRIDE 170 virtual void didAddAnimation() OVERRIDE
170 { 171 {
171 LayerTreeHost::didAddAnimation(); 172 LayerTreeHost::didAddAnimation();
172 m_testHooks->didAddAnimation(); 173 m_testHooks->didAddAnimation();
173 } 174 }
174 175
175 virtual void setNeedsCommit() OVERRIDE 176 virtual void setNeedsCommit() OVERRIDE
176 { 177 {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 ThreadedTest* m_test; 313 ThreadedTest* m_test;
313 }; 314 };
314 315
315 ThreadedTest::ThreadedTest() 316 ThreadedTest::ThreadedTest()
316 : m_beginning(false) 317 : m_beginning(false)
317 , m_endWhenBeginReturns(false) 318 , m_endWhenBeginReturns(false)
318 , m_timedOut(false) 319 , m_timedOut(false)
319 , m_finished(false) 320 , m_finished(false)
320 , m_scheduled(false) 321 , m_scheduled(false)
321 , m_started(false) 322 , m_started(false)
323 , m_implThread(0)
322 { 324 {
323 } 325 }
324 326
325 ThreadedTest::~ThreadedTest() 327 ThreadedTest::~ThreadedTest()
326 { 328 {
327 } 329 }
328 330
329 void ThreadedTest::endTest() 331 void ThreadedTest::endTest()
330 { 332 {
331 m_finished = true; 333 m_finished = true;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSe tVisible, visible)); 385 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSe tVisible, visible));
384 } 386 }
385 387
386 void ThreadedTest::postDidAddAnimationToMainThread() 388 void ThreadedTest::postDidAddAnimationToMainThread()
387 { 389 {
388 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchDi dAddAnimation)); 390 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchDi dAddAnimation));
389 } 391 }
390 392
391 void ThreadedTest::doBeginTest() 393 void ThreadedTest::doBeginTest()
392 { 394 {
393 DCHECK(Proxy::isMainThread());
394 m_client = ThreadedMockLayerTreeHostClient::create(this); 395 m_client = ThreadedMockLayerTreeHostClient::create(this);
395 396
396 scoped_refptr<Layer> rootLayer = Layer::create(); 397 scoped_refptr<Layer> rootLayer = Layer::create();
397 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings); 398 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings, m_implThread);
398 ASSERT_TRUE(m_layerTreeHost.get()); 399 ASSERT_TRUE(m_layerTreeHost.get());
399 rootLayer->setLayerTreeHost(m_layerTreeHost.get()); 400 rootLayer->setLayerTreeHost(m_layerTreeHost.get());
400 m_layerTreeHost->setSurfaceReady(); 401 m_layerTreeHost->setSurfaceReady();
401 402
402 m_started = true; 403 m_started = true;
403 m_beginning = true; 404 m_beginning = true;
404 beginTest(); 405 beginTest();
405 m_beginning = false; 406 m_beginning = false;
406 if (m_endWhenBeginReturns) 407 if (m_endWhenBeginReturns)
407 realEndTest(); 408 realEndTest();
(...skipping 13 matching lines...) Expand all
421 void ThreadedTest::scheduleComposite() 422 void ThreadedTest::scheduleComposite()
422 { 423 {
423 if (!m_started || m_scheduled || m_finished) 424 if (!m_started || m_scheduled || m_finished)
424 return; 425 return;
425 m_scheduled = true; 426 m_scheduled = true;
426 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchCo mposite)); 427 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchCo mposite));
427 } 428 }
428 429
429 void ThreadedTest::realEndTest() 430 void ThreadedTest::realEndTest()
430 { 431 {
431 DCHECK(Proxy::isMainThread());
432 WebKit::Platform::current()->currentThread()->exitRunLoop(); 432 WebKit::Platform::current()->currentThread()->exitRunLoop();
433 } 433 }
434 434
435 void ThreadedTest::dispatchSetNeedsAnimate() 435 void ThreadedTest::dispatchSetNeedsAnimate()
436 { 436 {
437 DCHECK(Proxy::isMainThread()); 437 DCHECK(!proxy() || proxy()->isMainThread());
438 438
439 if (m_finished) 439 if (m_finished)
440 return; 440 return;
441 441
442 if (m_layerTreeHost.get()) 442 if (m_layerTreeHost.get())
443 m_layerTreeHost->setNeedsAnimate(); 443 m_layerTreeHost->setNeedsAnimate();
444 } 444 }
445 445
446 void ThreadedTest::dispatchAddInstantAnimation() 446 void ThreadedTest::dispatchAddInstantAnimation()
447 { 447 {
448 DCHECK(Proxy::isMainThread()); 448 DCHECK(!proxy() || proxy()->isMainThread());
449 449
450 if (m_finished) 450 if (m_finished)
451 return; 451 return;
452 452
453 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) 453 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer())
454 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 0, 0, 0.5, fa lse); 454 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 0, 0, 0.5, fa lse);
455 } 455 }
456 456
457 void ThreadedTest::dispatchAddAnimation() 457 void ThreadedTest::dispatchAddAnimation()
458 { 458 {
459 DCHECK(Proxy::isMainThread()); 459 DCHECK(!proxy() || proxy()->isMainThread());
460 460
461 if (m_finished) 461 if (m_finished)
462 return; 462 return;
463 463
464 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) 464 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer())
465 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 10, 0, 0.5, t rue); 465 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 10, 0, 0.5, t rue);
466 } 466 }
467 467
468 void ThreadedTest::dispatchSetNeedsAnimateAndCommit() 468 void ThreadedTest::dispatchSetNeedsAnimateAndCommit()
469 { 469 {
470 DCHECK(Proxy::isMainThread()); 470 DCHECK(!proxy() || proxy()->isMainThread());
471 471
472 if (m_finished) 472 if (m_finished)
473 return; 473 return;
474 474
475 if (m_layerTreeHost.get()) { 475 if (m_layerTreeHost.get()) {
476 m_layerTreeHost->setNeedsAnimate(); 476 m_layerTreeHost->setNeedsAnimate();
477 m_layerTreeHost->setNeedsCommit(); 477 m_layerTreeHost->setNeedsCommit();
478 } 478 }
479 } 479 }
480 480
481 void ThreadedTest::dispatchSetNeedsCommit() 481 void ThreadedTest::dispatchSetNeedsCommit()
482 { 482 {
483 DCHECK(Proxy::isMainThread()); 483 DCHECK(!proxy() || proxy()->isMainThread());
484 484
485 if (m_finished) 485 if (m_finished)
486 return; 486 return;
487 487
488 if (m_layerTreeHost.get()) 488 if (m_layerTreeHost.get())
489 m_layerTreeHost->setNeedsCommit(); 489 m_layerTreeHost->setNeedsCommit();
490 } 490 }
491 491
492 void ThreadedTest::dispatchAcquireLayerTextures() 492 void ThreadedTest::dispatchAcquireLayerTextures()
493 { 493 {
494 DCHECK(Proxy::isMainThread()); 494 DCHECK(!proxy() || proxy()->isMainThread());
495 495
496 if (m_finished) 496 if (m_finished)
497 return; 497 return;
498 498
499 if (m_layerTreeHost.get()) 499 if (m_layerTreeHost.get())
500 m_layerTreeHost->acquireLayerTextures(); 500 m_layerTreeHost->acquireLayerTextures();
501 } 501 }
502 502
503 void ThreadedTest::dispatchSetNeedsRedraw() 503 void ThreadedTest::dispatchSetNeedsRedraw()
504 { 504 {
505 DCHECK(Proxy::isMainThread()); 505 DCHECK(!proxy() || proxy()->isMainThread());
506 506
507 if (m_finished) 507 if (m_finished)
508 return; 508 return;
509 509
510 if (m_layerTreeHost.get()) 510 if (m_layerTreeHost.get())
511 m_layerTreeHost->setNeedsRedraw(); 511 m_layerTreeHost->setNeedsRedraw();
512 } 512 }
513 513
514 void ThreadedTest::dispatchSetVisible(bool visible) 514 void ThreadedTest::dispatchSetVisible(bool visible)
515 { 515 {
516 DCHECK(Proxy::isMainThread()); 516 DCHECK(!proxy() || proxy()->isMainThread());
517 517
518 if (m_finished) 518 if (m_finished)
519 return; 519 return;
520 520
521 if (m_layerTreeHost.get()) 521 if (m_layerTreeHost.get())
522 m_layerTreeHost->setVisible(visible); 522 m_layerTreeHost->setVisible(visible);
523 } 523 }
524 524
525 void ThreadedTest::dispatchComposite() 525 void ThreadedTest::dispatchComposite()
526 { 526 {
527 m_scheduled = false; 527 m_scheduled = false;
528 if (m_layerTreeHost.get() && !m_finished) 528 if (m_layerTreeHost.get() && !m_finished)
529 m_layerTreeHost->composite(); 529 m_layerTreeHost->composite();
530 } 530 }
531 531
532 void ThreadedTest::dispatchDidAddAnimation() 532 void ThreadedTest::dispatchDidAddAnimation()
533 { 533 {
534 DCHECK(Proxy::isMainThread()); 534 DCHECK(!proxy() || proxy()->isMainThread());
535 535
536 if (m_finished) 536 if (m_finished)
537 return; 537 return;
538 538
539 if (m_layerTreeHost.get()) 539 if (m_layerTreeHost.get())
540 m_layerTreeHost->didAddAnimation(); 540 m_layerTreeHost->didAddAnimation();
541 } 541 }
542 542
543 void ThreadedTest::runTest(bool threaded) 543 void ThreadedTest::runTest(bool threaded)
544 { 544 {
545 // For these tests, we will enable threaded animations. 545 // For these tests, we will enable threaded animations.
546 ScopedSettings scopedSettings; 546 ScopedSettings scopedSettings;
547 Settings::setAcceleratedAnimationEnabled(true); 547 Settings::setAcceleratedAnimationEnabled(true);
548 548
549 if (threaded) { 549 if (threaded) {
550 m_webThread.reset(WebKit::Platform::current()->createThread("ThreadedTes t")); 550 m_webImplThread.reset(WebKit::Platform::current()->createThread("Threade dTest"));
551 Platform::current()->compositorSupport()->initialize(m_webThread.get()); 551 m_implThread = CCThreadImpl::createForDifferentThread(m_webImplThread.ge t()).release();
jamesr 2012/10/25 19:42:39 instead of relying on WebKit::Platform to get a We
552 } else 552 }
553 Platform::current()->compositorSupport()->initialize(0);
554 553
555 DCHECK(Proxy::isMainThread()); 554 m_mainThreadProxy = ScopedThreadProxy::create(WebKit::CCThreadImpl::createFo rCurrentThread().release());
556 m_mainThreadProxy = ScopedThreadProxy::create(Proxy::mainThread());
557 555
558 initializeSettings(m_settings); 556 initializeSettings(m_settings);
559 557
560 m_beginTask = new BeginTask(this); 558 m_beginTask = new BeginTask(this);
561 WebKit::Platform::current()->currentThread()->postDelayedTask(m_beginTask, 0 ); // postDelayedTask takes ownership of the task 559 WebKit::Platform::current()->currentThread()->postDelayedTask(m_beginTask, 0 ); // postDelayedTask takes ownership of the task
562 m_timeoutTask = new TimeoutTask(this); 560 m_timeoutTask = new TimeoutTask(this);
563 WebKit::Platform::current()->currentThread()->postDelayedTask(m_timeoutTask, 5000); 561 WebKit::Platform::current()->currentThread()->postDelayedTask(m_timeoutTask, 5000);
564 WebKit::Platform::current()->currentThread()->enterRunLoop(); 562 WebKit::Platform::current()->currentThread()->enterRunLoop();
565 563
566 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) 564 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer())
567 m_layerTreeHost->rootLayer()->setLayerTreeHost(0); 565 m_layerTreeHost->rootLayer()->setLayerTreeHost(0);
568 m_layerTreeHost.reset(); 566 m_layerTreeHost.reset();
569 567
570 if (m_timeoutTask) 568 if (m_timeoutTask)
571 m_timeoutTask->clearTest(); 569 m_timeoutTask->clearTest();
572 570
573 ASSERT_FALSE(m_layerTreeHost.get()); 571 ASSERT_FALSE(m_layerTreeHost.get());
574 m_client.reset(); 572 m_client.reset();
575 if (m_timedOut) { 573 if (m_timedOut) {
576 FAIL() << "Test timed out"; 574 FAIL() << "Test timed out";
577 Platform::current()->compositorSupport()->shutdown();
578 return; 575 return;
579 } 576 }
580 afterTest(); 577 afterTest();
581 Platform::current()->compositorSupport()->shutdown();
582 } 578 }
583 579
584 } // namespace WebKitTests 580 } // namespace WebKitTests
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698