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

Side by Side Diff: cc/CCThreadedTest.cpp

Issue 10905231: Enable cc_unittests in component build (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mark WebThreadImplForMessageLoop ctor/dtor as exported Created 8 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « cc/CCThreadedTest.h ('k') | cc/DEPS » ('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 "CCThreadedTest.h" 7 #include "CCThreadedTest.h"
8 8
9 #include "CCActiveAnimation.h" 9 #include "CCActiveAnimation.h"
10 #include "CCAnimationTestCommon.h" 10 #include "CCAnimationTestCommon.h"
(...skipping 12 matching lines...) Expand all
23 #include "FakeWebCompositorOutputSurface.h" 23 #include "FakeWebCompositorOutputSurface.h"
24 #include "FakeWebGraphicsContext3D.h" 24 #include "FakeWebGraphicsContext3D.h"
25 #include "LayerChromium.h" 25 #include "LayerChromium.h"
26 #include <gmock/gmock.h> 26 #include <gmock/gmock.h>
27 #include <public/Platform.h> 27 #include <public/Platform.h>
28 #include <public/WebCompositorSupport.h> 28 #include <public/WebCompositorSupport.h>
29 #include <public/WebFilterOperation.h> 29 #include <public/WebFilterOperation.h>
30 #include <public/WebFilterOperations.h> 30 #include <public/WebFilterOperations.h>
31 #include <public/WebThread.h> 31 #include <public/WebThread.h>
32 #include <wtf/Locker.h> 32 #include <wtf/Locker.h>
33 #include <wtf/MainThread.h>
34 #include <wtf/PassRefPtr.h> 33 #include <wtf/PassRefPtr.h>
35 #include <wtf/ThreadingPrimitives.h>
36 #include <wtf/Vector.h> 34 #include <wtf/Vector.h>
37 35
38 using namespace WebCore; 36 using namespace WebCore;
39 using namespace WebKit; 37 using namespace WebKit;
40 38
41 namespace WebKitTests { 39 namespace WebKitTests {
42 40
43 PassOwnPtr<CompositorFakeWebGraphicsContext3DWithTextureTracking> CompositorFake WebGraphicsContext3DWithTextureTracking::create(Attributes attrs) 41 PassOwnPtr<CompositorFakeWebGraphicsContext3DWithTextureTracking> CompositorFake WebGraphicsContext3DWithTextureTracking::create(Attributes attrs)
44 { 42 {
45 return adoptPtr(new CompositorFakeWebGraphicsContext3DWithTextureTracking(at trs)); 43 return adoptPtr(new CompositorFakeWebGraphicsContext3DWithTextureTracking(at trs));
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 282
285 virtual ~BeginTask() { } 283 virtual ~BeginTask() { }
286 virtual void run() 284 virtual void run()
287 { 285 {
288 m_test->doBeginTest(); 286 m_test->doBeginTest();
289 } 287 }
290 private: 288 private:
291 CCThreadedTest* m_test; 289 CCThreadedTest* m_test;
292 }; 290 };
293 291
294 class EndTestTask : public WebThread::Task {
295 public:
296 explicit EndTestTask(CCThreadedTest* test)
297 : m_test(test)
298 {
299 }
300
301 virtual ~EndTestTask()
302 {
303 if (m_test)
304 m_test->clearEndTestTask();
305 }
306
307 void clearTest()
308 {
309 m_test = 0;
310 }
311
312 virtual void run()
313 {
314 if (m_test)
315 m_test->endTest();
316 }
317
318 private:
319 CCThreadedTest* m_test;
320 };
321
322 CCThreadedTest::CCThreadedTest() 292 CCThreadedTest::CCThreadedTest()
323 : m_beginning(false) 293 : m_beginning(false)
324 , m_endWhenBeginReturns(false) 294 , m_endWhenBeginReturns(false)
325 , m_timedOut(false) 295 , m_timedOut(false)
326 , m_finished(false) 296 , m_finished(false)
327 , m_scheduled(false) 297 , m_scheduled(false)
328 , m_started(false) 298 , m_started(false)
329 , m_endTestTask(0)
330 { } 299 { }
331 300
332 void CCThreadedTest::endTest() 301 void CCThreadedTest::endTest()
333 { 302 {
334 m_finished = true; 303 m_finished = true;
335 304
336 // If we are called from the CCThread, re-call endTest on the main thread. 305 // For the case where we endTest during beginTest(), set a flag to indicate that
337 if (!isMainThread()) 306 // the test should end the second beginTest regains control.
338 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::en dTest)); 307 if (m_beginning)
339 else { 308 m_endWhenBeginReturns = true;
340 // For the case where we endTest during beginTest(), set a flag to indic ate that 309 else
341 // the test should end the second beginTest regains control. 310 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::re alEndTest));
342 if (m_beginning)
343 m_endWhenBeginReturns = true;
344 else
345 onEndTest(static_cast<void*>(this));
346 }
347 } 311 }
348 312
349 void CCThreadedTest::endTestAfterDelay(int delayMilliseconds) 313 void CCThreadedTest::endTestAfterDelay(int delayMilliseconds)
350 { 314 {
351 // If we are called from the CCThread, re-call endTest on the main thread. 315 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::endTes t));
352 if (!isMainThread())
353 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::en dTestAfterDelay, delayMilliseconds));
354 else {
355 m_endTestTask = new EndTestTask(this);
356 WebKit::Platform::current()->currentThread()->postDelayedTask(m_endTestT ask, delayMilliseconds);
357 }
358 } 316 }
359 317
360 void CCThreadedTest::postSetNeedsAnimateToMainThread() 318 void CCThreadedTest::postSetNeedsAnimateToMainThread()
361 { 319 {
362 callOnMainThread(CCThreadedTest::dispatchSetNeedsAnimate, this); 320 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chSetNeedsAnimate));
363 } 321 }
364 322
365 void CCThreadedTest::postAddAnimationToMainThread() 323 void CCThreadedTest::postAddAnimationToMainThread()
366 { 324 {
367 callOnMainThread(CCThreadedTest::dispatchAddAnimation, this); 325 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chAddAnimation));
368 } 326 }
369 327
370 void CCThreadedTest::postAddInstantAnimationToMainThread() 328 void CCThreadedTest::postAddInstantAnimationToMainThread()
371 { 329 {
372 callOnMainThread(CCThreadedTest::dispatchAddInstantAnimation, this); 330 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chAddInstantAnimation));
373 } 331 }
374 332
375 void CCThreadedTest::postSetNeedsCommitToMainThread() 333 void CCThreadedTest::postSetNeedsCommitToMainThread()
376 { 334 {
377 callOnMainThread(CCThreadedTest::dispatchSetNeedsCommit, this); 335 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chSetNeedsCommit));
378 } 336 }
379 337
380 void CCThreadedTest::postAcquireLayerTextures() 338 void CCThreadedTest::postAcquireLayerTextures()
381 { 339 {
382 callOnMainThread(CCThreadedTest::dispatchAcquireLayerTextures, this); 340 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chAcquireLayerTextures));
383 } 341 }
384 342
385 void CCThreadedTest::postSetNeedsRedrawToMainThread() 343 void CCThreadedTest::postSetNeedsRedrawToMainThread()
386 { 344 {
387 callOnMainThread(CCThreadedTest::dispatchSetNeedsRedraw, this); 345 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chSetNeedsRedraw));
388 } 346 }
389 347
390 void CCThreadedTest::postSetNeedsAnimateAndCommitToMainThread() 348 void CCThreadedTest::postSetNeedsAnimateAndCommitToMainThread()
391 { 349 {
392 callOnMainThread(CCThreadedTest::dispatchSetNeedsAnimateAndCommit, this); 350 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chSetNeedsAnimateAndCommit));
393 } 351 }
394 352
395 void CCThreadedTest::postSetVisibleToMainThread(bool visible) 353 void CCThreadedTest::postSetVisibleToMainThread(bool visible)
396 { 354 {
397 callOnMainThread(visible ? CCThreadedTest::dispatchSetVisible : CCThreadedTe st::dispatchSetInvisible, this); 355 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chSetVisible, visible));
398 } 356 }
399 357
400 void CCThreadedTest::postDidAddAnimationToMainThread() 358 void CCThreadedTest::postDidAddAnimationToMainThread()
401 { 359 {
402 callOnMainThread(CCThreadedTest::dispatchDidAddAnimation, this); 360 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chDidAddAnimation));
403 } 361 }
404 362
405 void CCThreadedTest::doBeginTest() 363 void CCThreadedTest::doBeginTest()
406 { 364 {
407 ASSERT(isMainThread()); 365 ASSERT(CCProxy::isMainThread());
408 m_client = MockLayerTreeHostClient::create(this); 366 m_client = MockLayerTreeHostClient::create(this);
409 367
410 RefPtr<LayerChromium> rootLayer = LayerChromium::create(); 368 RefPtr<LayerChromium> rootLayer = LayerChromium::create();
411 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings); 369 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings);
412 ASSERT_TRUE(m_layerTreeHost); 370 ASSERT_TRUE(m_layerTreeHost);
413 rootLayer->setLayerTreeHost(m_layerTreeHost.get()); 371 rootLayer->setLayerTreeHost(m_layerTreeHost.get());
414 m_layerTreeHost->setSurfaceReady(); 372 m_layerTreeHost->setSurfaceReady();
415 373
416 m_started = true; 374 m_started = true;
417 m_beginning = true; 375 m_beginning = true;
418 beginTest(); 376 beginTest();
419 m_beginning = false; 377 m_beginning = false;
420 if (m_endWhenBeginReturns) 378 if (m_endWhenBeginReturns)
421 onEndTest(static_cast<void*>(this)); 379 realEndTest();
422 } 380 }
423 381
424 void CCThreadedTest::timeout() 382 void CCThreadedTest::timeout()
425 { 383 {
426 m_timedOut = true; 384 m_timedOut = true;
427 endTest(); 385 endTest();
428 } 386 }
429 387
430 void CCThreadedTest::scheduleComposite() 388 void CCThreadedTest::scheduleComposite()
431 { 389 {
432 if (!m_started || m_scheduled || m_finished) 390 if (!m_started || m_scheduled || m_finished)
433 return; 391 return;
434 m_scheduled = true; 392 m_scheduled = true;
435 callOnMainThread(&CCThreadedTest::dispatchComposite, this); 393 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadedTest::dispat chComposite));
436 } 394 }
437 395
438 void CCThreadedTest::onEndTest(void* self) 396 void CCThreadedTest::realEndTest()
439 { 397 {
440 ASSERT(isMainThread()); 398 ASSERT(CCProxy::isMainThread());
441 WebKit::Platform::current()->currentThread()->exitRunLoop(); 399 WebKit::Platform::current()->currentThread()->exitRunLoop();
442 } 400 }
443 401
444 void CCThreadedTest::dispatchSetNeedsAnimate(void* self) 402 void CCThreadedTest::dispatchSetNeedsAnimate()
445 { 403 {
446 ASSERT(isMainThread()); 404 ASSERT(CCProxy::isMainThread());
447 405
448 CCThreadedTest* test = static_cast<CCThreadedTest*>(self); 406 if (m_finished)
449 ASSERT(test);
450 if (test->m_finished)
451 return; 407 return;
452 408
453 if (test->m_layerTreeHost) 409 if (m_layerTreeHost)
454 test->m_layerTreeHost->setNeedsAnimate(); 410 m_layerTreeHost->setNeedsAnimate();
455 } 411 }
456 412
457 void CCThreadedTest::dispatchAddInstantAnimation(void* self) 413 void CCThreadedTest::dispatchAddInstantAnimation()
458 { 414 {
459 ASSERT(isMainThread()); 415 ASSERT(CCProxy::isMainThread());
460 416
461 CCThreadedTest* test = static_cast<CCThreadedTest*>(self); 417 if (m_finished)
462 ASSERT(test);
463 if (test->m_finished)
464 return; 418 return;
465 419
466 if (test->m_layerTreeHost && test->m_layerTreeHost->rootLayer()) 420 if (m_layerTreeHost && m_layerTreeHost->rootLayer())
467 addOpacityTransitionToLayer(*test->m_layerTreeHost->rootLayer(), 0, 0, 0 .5, false); 421 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 0, 0, 0.5, fa lse);
468 } 422 }
469 423
470 void CCThreadedTest::dispatchAddAnimation(void* self) 424 void CCThreadedTest::dispatchAddAnimation()
471 { 425 {
472 ASSERT(isMainThread()); 426 ASSERT(CCProxy::isMainThread());
473 427
474 CCThreadedTest* test = static_cast<CCThreadedTest*>(self); 428 if (m_finished)
475 ASSERT(test);
476 if (test->m_finished)
477 return; 429 return;
478 430
479 if (test->m_layerTreeHost && test->m_layerTreeHost->rootLayer()) 431 if (m_layerTreeHost && m_layerTreeHost->rootLayer())
480 addOpacityTransitionToLayer(*test->m_layerTreeHost->rootLayer(), 10, 0, 0.5, true); 432 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 10, 0, 0.5, t rue);
481 } 433 }
482 434
483 void CCThreadedTest::dispatchSetNeedsAnimateAndCommit(void* self) 435 void CCThreadedTest::dispatchSetNeedsAnimateAndCommit()
484 { 436 {
485 ASSERT(isMainThread()); 437 ASSERT(CCProxy::isMainThread());
486 438
487 CCThreadedTest* test = static_cast<CCThreadedTest*>(self); 439 if (m_finished)
488 ASSERT(test);
489 if (test->m_finished)
490 return; 440 return;
491 441
492 if (test->m_layerTreeHost) { 442 if (m_layerTreeHost) {
493 test->m_layerTreeHost->setNeedsAnimate(); 443 m_layerTreeHost->setNeedsAnimate();
494 test->m_layerTreeHost->setNeedsCommit(); 444 m_layerTreeHost->setNeedsCommit();
495 } 445 }
496 } 446 }
497 447
498 void CCThreadedTest::dispatchSetNeedsCommit(void* self) 448 void CCThreadedTest::dispatchSetNeedsCommit()
499 { 449 {
500 ASSERT(isMainThread()); 450 ASSERT(CCProxy::isMainThread());
501 451
502 CCThreadedTest* test = static_cast<CCThreadedTest*>(self); 452 if (m_finished)
503 ASSERT_TRUE(test);
504 if (test->m_finished)
505 return; 453 return;
506 454
507 if (test->m_layerTreeHost) 455 if (m_layerTreeHost)
508 test->m_layerTreeHost->setNeedsCommit(); 456 m_layerTreeHost->setNeedsCommit();
509 } 457 }
510 458
511 void CCThreadedTest::dispatchAcquireLayerTextures(void* self) 459 void CCThreadedTest::dispatchAcquireLayerTextures()
512 { 460 {
513 ASSERT(isMainThread()); 461 ASSERT(CCProxy::isMainThread());
514 462
515 CCThreadedTest* test = static_cast<CCThreadedTest*>(self); 463 if (m_finished)
516 ASSERT_TRUE(test);
517 if (test->m_finished)
518 return; 464 return;
519 465
520 if (test->m_layerTreeHost) 466 if (m_layerTreeHost)
521 test->m_layerTreeHost->acquireLayerTextures(); 467 m_layerTreeHost->acquireLayerTextures();
522 } 468 }
523 469
524 void CCThreadedTest::dispatchSetNeedsRedraw(void* self) 470 void CCThreadedTest::dispatchSetNeedsRedraw()
525 { 471 {
526 ASSERT(isMainThread()); 472 ASSERT(CCProxy::isMainThread());
527 473
528 CCThreadedTest* test = static_cast<CCThreadedTest*>(self); 474 if (m_finished)
529 ASSERT_TRUE(test);
530 if (test->m_finished)
531 return; 475 return;
532 476
533 if (test->m_layerTreeHost) 477 if (m_layerTreeHost)
534 test->m_layerTreeHost->setNeedsRedraw(); 478 m_layerTreeHost->setNeedsRedraw();
535 } 479 }
536 480
537 void CCThreadedTest::dispatchSetVisible(void* self) 481 void CCThreadedTest::dispatchSetVisible(bool visible)
538 { 482 {
539 ASSERT(isMainThread()); 483 ASSERT(CCProxy::isMainThread());
540 484
541 CCThreadedTest* test = static_cast<CCThreadedTest*>(self); 485 if (m_finished)
542 ASSERT(test);
543 if (test->m_finished)
544 return; 486 return;
545 487
546 if (test->m_layerTreeHost) 488 if (m_layerTreeHost)
547 test->m_layerTreeHost->setVisible(true); 489 m_layerTreeHost->setVisible(visible);
548 } 490 }
549 491
550 void CCThreadedTest::dispatchSetInvisible(void* self) 492 void CCThreadedTest::dispatchComposite()
551 { 493 {
552 ASSERT(isMainThread()); 494 m_scheduled = false;
495 if (m_layerTreeHost && !m_finished)
496 m_layerTreeHost->composite();
497 }
553 498
554 CCThreadedTest* test = static_cast<CCThreadedTest*>(self); 499 void CCThreadedTest::dispatchDidAddAnimation()
555 ASSERT(test); 500 {
556 if (test->m_finished) 501 ASSERT(CCProxy::isMainThread());
502
503 if (m_finished)
557 return; 504 return;
558 505
559 if (test->m_layerTreeHost) 506 if (m_layerTreeHost)
560 test->m_layerTreeHost->setVisible(false); 507 m_layerTreeHost->didAddAnimation();
561 }
562
563 void CCThreadedTest::dispatchComposite(void* self)
564 {
565 CCThreadedTest* test = static_cast<CCThreadedTest*>(self);
566 ASSERT(isMainThread());
567 ASSERT(test);
568 test->m_scheduled = false;
569 if (test->m_layerTreeHost && !test->m_finished)
570 test->m_layerTreeHost->composite();
571 }
572
573 void CCThreadedTest::dispatchDidAddAnimation(void* self)
574 {
575 ASSERT(isMainThread());
576
577 CCThreadedTest* test = static_cast<CCThreadedTest*>(self);
578 ASSERT(test);
579 if (test->m_finished)
580 return;
581
582 if (test->m_layerTreeHost)
583 test->m_layerTreeHost->didAddAnimation();
584 } 508 }
585 509
586 void CCThreadedTest::runTest(bool threaded) 510 void CCThreadedTest::runTest(bool threaded)
587 { 511 {
588 // For these tests, we will enable threaded animations. 512 // For these tests, we will enable threaded animations.
589 Platform::current()->compositorSupport()->setAcceleratedAnimationEnabled(tru e); 513 Platform::current()->compositorSupport()->setAcceleratedAnimationEnabled(tru e);
590 514
591 if (threaded) { 515 if (threaded) {
592 m_webThread = adoptPtr(WebKit::Platform::current()->createThread("CCThre adedTest")); 516 m_webThread = adoptPtr(WebKit::Platform::current()->createThread("CCThre adedTest"));
593 Platform::current()->compositorSupport()->initialize(m_webThread.get()); 517 Platform::current()->compositorSupport()->initialize(m_webThread.get());
(...skipping 11 matching lines...) Expand all
605 WebKit::Platform::current()->currentThread()->postDelayedTask(m_timeoutTask, 5000); 529 WebKit::Platform::current()->currentThread()->postDelayedTask(m_timeoutTask, 5000);
606 WebKit::Platform::current()->currentThread()->enterRunLoop(); 530 WebKit::Platform::current()->currentThread()->enterRunLoop();
607 531
608 if (m_layerTreeHost && m_layerTreeHost->rootLayer()) 532 if (m_layerTreeHost && m_layerTreeHost->rootLayer())
609 m_layerTreeHost->rootLayer()->setLayerTreeHost(0); 533 m_layerTreeHost->rootLayer()->setLayerTreeHost(0);
610 m_layerTreeHost.clear(); 534 m_layerTreeHost.clear();
611 535
612 if (m_timeoutTask) 536 if (m_timeoutTask)
613 m_timeoutTask->clearTest(); 537 m_timeoutTask->clearTest();
614 538
615 if (m_endTestTask)
616 m_endTestTask->clearTest();
617
618 ASSERT_FALSE(m_layerTreeHost.get()); 539 ASSERT_FALSE(m_layerTreeHost.get());
619 m_client.clear(); 540 m_client.clear();
620 if (m_timedOut) { 541 if (m_timedOut) {
621 FAIL() << "Test timed out"; 542 FAIL() << "Test timed out";
622 Platform::current()->compositorSupport()->shutdown(); 543 Platform::current()->compositorSupport()->shutdown();
623 return; 544 return;
624 } 545 }
625 afterTest(); 546 afterTest();
626 Platform::current()->compositorSupport()->shutdown(); 547 Platform::current()->compositorSupport()->shutdown();
627 } 548 }
628 549
629 } // namespace WebKitTests 550 } // namespace WebKitTests
OLDNEW
« no previous file with comments | « cc/CCThreadedTest.h ('k') | cc/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698