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

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: Address code review comments and fix all cc_unittests 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"
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());
danakj 2012/10/25 05:06:06 Why not call proxy()->isMainThread() etc for all t
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());
438
439 if (m_finished) 437 if (m_finished)
440 return; 438 return;
441 439
442 if (m_layerTreeHost.get()) 440 if (m_layerTreeHost.get())
443 m_layerTreeHost->setNeedsAnimate(); 441 m_layerTreeHost->setNeedsAnimate();
444 } 442 }
445 443
446 void ThreadedTest::dispatchAddInstantAnimation() 444 void ThreadedTest::dispatchAddInstantAnimation()
447 { 445 {
448 DCHECK(Proxy::isMainThread());
449
450 if (m_finished) 446 if (m_finished)
451 return; 447 return;
452 448
453 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) 449 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer())
454 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 0, 0, 0.5, fa lse); 450 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 0, 0, 0.5, fa lse);
455 } 451 }
456 452
457 void ThreadedTest::dispatchAddAnimation() 453 void ThreadedTest::dispatchAddAnimation()
458 { 454 {
459 DCHECK(Proxy::isMainThread());
460
461 if (m_finished) 455 if (m_finished)
462 return; 456 return;
463 457
464 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) 458 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer())
465 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 10, 0, 0.5, t rue); 459 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 10, 0, 0.5, t rue);
466 } 460 }
467 461
468 void ThreadedTest::dispatchSetNeedsAnimateAndCommit() 462 void ThreadedTest::dispatchSetNeedsAnimateAndCommit()
469 { 463 {
470 DCHECK(Proxy::isMainThread());
471
472 if (m_finished) 464 if (m_finished)
473 return; 465 return;
474 466
475 if (m_layerTreeHost.get()) { 467 if (m_layerTreeHost.get()) {
476 m_layerTreeHost->setNeedsAnimate(); 468 m_layerTreeHost->setNeedsAnimate();
477 m_layerTreeHost->setNeedsCommit(); 469 m_layerTreeHost->setNeedsCommit();
478 } 470 }
479 } 471 }
480 472
481 void ThreadedTest::dispatchSetNeedsCommit() 473 void ThreadedTest::dispatchSetNeedsCommit()
482 { 474 {
483 DCHECK(Proxy::isMainThread());
484
485 if (m_finished) 475 if (m_finished)
486 return; 476 return;
487 477
488 if (m_layerTreeHost.get()) 478 if (m_layerTreeHost.get())
489 m_layerTreeHost->setNeedsCommit(); 479 m_layerTreeHost->setNeedsCommit();
490 } 480 }
491 481
492 void ThreadedTest::dispatchAcquireLayerTextures() 482 void ThreadedTest::dispatchAcquireLayerTextures()
493 { 483 {
494 DCHECK(Proxy::isMainThread());
495
496 if (m_finished) 484 if (m_finished)
497 return; 485 return;
498 486
499 if (m_layerTreeHost.get()) 487 if (m_layerTreeHost.get())
500 m_layerTreeHost->acquireLayerTextures(); 488 m_layerTreeHost->acquireLayerTextures();
501 } 489 }
502 490
503 void ThreadedTest::dispatchSetNeedsRedraw() 491 void ThreadedTest::dispatchSetNeedsRedraw()
504 { 492 {
505 DCHECK(Proxy::isMainThread());
506
507 if (m_finished) 493 if (m_finished)
508 return; 494 return;
509 495
510 if (m_layerTreeHost.get()) 496 if (m_layerTreeHost.get())
511 m_layerTreeHost->setNeedsRedraw(); 497 m_layerTreeHost->setNeedsRedraw();
512 } 498 }
513 499
514 void ThreadedTest::dispatchSetVisible(bool visible) 500 void ThreadedTest::dispatchSetVisible(bool visible)
515 { 501 {
516 DCHECK(Proxy::isMainThread());
517
518 if (m_finished) 502 if (m_finished)
519 return; 503 return;
520 504
521 if (m_layerTreeHost.get()) 505 if (m_layerTreeHost.get())
522 m_layerTreeHost->setVisible(visible); 506 m_layerTreeHost->setVisible(visible);
523 } 507 }
524 508
525 void ThreadedTest::dispatchComposite() 509 void ThreadedTest::dispatchComposite()
526 { 510 {
527 m_scheduled = false; 511 m_scheduled = false;
528 if (m_layerTreeHost.get() && !m_finished) 512 if (m_layerTreeHost.get() && !m_finished)
529 m_layerTreeHost->composite(); 513 m_layerTreeHost->composite();
530 } 514 }
531 515
532 void ThreadedTest::dispatchDidAddAnimation() 516 void ThreadedTest::dispatchDidAddAnimation()
533 { 517 {
534 DCHECK(Proxy::isMainThread());
535
536 if (m_finished) 518 if (m_finished)
537 return; 519 return;
538 520
539 if (m_layerTreeHost.get()) 521 if (m_layerTreeHost.get())
540 m_layerTreeHost->didAddAnimation(); 522 m_layerTreeHost->didAddAnimation();
541 } 523 }
542 524
543 void ThreadedTest::runTest(bool threaded) 525 void ThreadedTest::runTest(bool threaded)
544 { 526 {
545 // For these tests, we will enable threaded animations. 527 // For these tests, we will enable threaded animations.
546 ScopedSettings scopedSettings; 528 ScopedSettings scopedSettings;
547 Settings::setAcceleratedAnimationEnabled(true); 529 Settings::setAcceleratedAnimationEnabled(true);
548 530
549 if (threaded) { 531 if (threaded) {
550 m_webThread.reset(WebKit::Platform::current()->createThread("ThreadedTes t")); 532 m_webImplThread.reset(WebKit::Platform::current()->createThread("Threade dTest"));
551 Platform::current()->compositorSupport()->initialize(m_webThread.get()); 533 m_implThread = CCThreadImpl::createForDifferentThread(m_webImplThread.ge t()).release();
552 } else 534 }
553 Platform::current()->compositorSupport()->initialize(0);
554 535
555 DCHECK(Proxy::isMainThread()); 536 m_mainThreadProxy = ScopedThreadProxy::create(WebKit::CCThreadImpl::createFo rCurrentThread().release());
556 m_mainThreadProxy = ScopedThreadProxy::create(Proxy::mainThread());
557 537
558 initializeSettings(m_settings); 538 initializeSettings(m_settings);
559 539
560 m_beginTask = new BeginTask(this); 540 m_beginTask = new BeginTask(this);
561 WebKit::Platform::current()->currentThread()->postDelayedTask(m_beginTask, 0 ); // postDelayedTask takes ownership of the task 541 WebKit::Platform::current()->currentThread()->postDelayedTask(m_beginTask, 0 ); // postDelayedTask takes ownership of the task
562 m_timeoutTask = new TimeoutTask(this); 542 m_timeoutTask = new TimeoutTask(this);
563 WebKit::Platform::current()->currentThread()->postDelayedTask(m_timeoutTask, 5000); 543 WebKit::Platform::current()->currentThread()->postDelayedTask(m_timeoutTask, 5000);
564 WebKit::Platform::current()->currentThread()->enterRunLoop(); 544 WebKit::Platform::current()->currentThread()->enterRunLoop();
565 545
566 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) 546 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer())
567 m_layerTreeHost->rootLayer()->setLayerTreeHost(0); 547 m_layerTreeHost->rootLayer()->setLayerTreeHost(0);
568 m_layerTreeHost.reset(); 548 m_layerTreeHost.reset();
569 549
570 if (m_timeoutTask) 550 if (m_timeoutTask)
571 m_timeoutTask->clearTest(); 551 m_timeoutTask->clearTest();
572 552
573 ASSERT_FALSE(m_layerTreeHost.get()); 553 ASSERT_FALSE(m_layerTreeHost.get());
574 m_client.reset(); 554 m_client.reset();
575 if (m_timedOut) { 555 if (m_timedOut) {
576 FAIL() << "Test timed out"; 556 FAIL() << "Test timed out";
577 Platform::current()->compositorSupport()->shutdown();
578 return; 557 return;
579 } 558 }
580 afterTest(); 559 afterTest();
581 Platform::current()->compositorSupport()->shutdown();
582 } 560 }
583 561
584 } // namespace WebKitTests 562 } // namespace WebKitTests
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698