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

Side by Side Diff: cc/layer_unittest.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ScaleAsVector 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 | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_host_unittest.cc ('k') | cc/math_util.h » ('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/layer.h" 7 #include "cc/layer.h"
8 8
9 #include "cc/keyframed_animation_curve.h" 9 #include "cc/keyframed_animation_curve.h"
10 #include "cc/layer_impl.h" 10 #include "cc/layer_impl.h"
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 TEST_F(LayerTest, checkSetNeedsDisplayCausesCorrectBehavior) 412 TEST_F(LayerTest, checkSetNeedsDisplayCausesCorrectBehavior)
413 { 413 {
414 // The semantics for setNeedsDisplay which are tested here: 414 // The semantics for setNeedsDisplay which are tested here:
415 // 1. sets needsDisplay flag appropriately. 415 // 1. sets needsDisplay flag appropriately.
416 // 2. indirectly calls setNeedsCommit, exactly once for each call to setNe edsDisplay. 416 // 2. indirectly calls setNeedsCommit, exactly once for each call to setNe edsDisplay.
417 417
418 scoped_refptr<Layer> testLayer = Layer::create(); 418 scoped_refptr<Layer> testLayer = Layer::create();
419 testLayer->setLayerTreeHost(m_layerTreeHost.get()); 419 testLayer->setLayerTreeHost(m_layerTreeHost.get());
420 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setIsDrawable(tru e)); 420 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setIsDrawable(tru e));
421 421
422 IntSize testBounds = IntSize(501, 508); 422 gfx::Size testBounds = gfx::Size(501, 508);
423 423
424 FloatRect dirty1 = FloatRect(10, 15, 1, 2); 424 gfx::RectF dirty1 = gfx::RectF(10, 15, 1, 2);
425 FloatRect dirty2 = FloatRect(20, 25, 3, 4); 425 gfx::RectF dirty2 = gfx::RectF(20, 25, 3, 4);
426 FloatRect emptyDirtyRect = FloatRect(40, 45, 0, 0); 426 gfx::RectF emptyDirtyRect = gfx::RectF(40, 45, 0, 0);
427 FloatRect outOfBoundsDirtyRect = FloatRect(400, 405, 500, 502); 427 gfx::RectF outOfBoundsDirtyRect = gfx::RectF(400, 405, 500, 502);
428 428
429 // Before anything, testLayer should not be dirty. 429 // Before anything, testLayer should not be dirty.
430 EXPECT_FALSE(testLayer->needsDisplay()); 430 EXPECT_FALSE(testLayer->needsDisplay());
431 431
432 // This is just initialization, but setNeedsCommit behavior is verified anyw ay to avoid warnings. 432 // This is just initialization, but setNeedsCommit behavior is verified anyw ay to avoid warnings.
433 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setBounds(testBou nds)); 433 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setBounds(testBou nds));
434 testLayer = Layer::create(); 434 testLayer = Layer::create();
435 testLayer->setLayerTreeHost(m_layerTreeHost.get()); 435 testLayer->setLayerTreeHost(m_layerTreeHost.get());
436 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setIsDrawable(tru e)); 436 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setIsDrawable(tru e));
437 EXPECT_FALSE(testLayer->needsDisplay()); 437 EXPECT_FALSE(testLayer->needsDisplay());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 scoped_refptr<Layer> testLayer = Layer::create(); 479 scoped_refptr<Layer> testLayer = Layer::create();
480 testLayer->setLayerTreeHost(m_layerTreeHost.get()); 480 testLayer->setLayerTreeHost(m_layerTreeHost.get());
481 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setIsDrawable(tru e)); 481 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setIsDrawable(tru e));
482 482
483 scoped_refptr<Layer> dummyLayer = Layer::create(); // just a dummy layer for this test case. 483 scoped_refptr<Layer> dummyLayer = Layer::create(); // just a dummy layer for this test case.
484 484
485 // sanity check of initial test condition 485 // sanity check of initial test condition
486 EXPECT_FALSE(testLayer->needsDisplay()); 486 EXPECT_FALSE(testLayer->needsDisplay());
487 487
488 // Test properties that should not call needsDisplay and needsCommit when ch anged. 488 // Test properties that should not call needsDisplay and needsCommit when ch anged.
489 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setVisibleContent Rect(IntRect(0, 0, 40, 50))); 489 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setVisibleContent Rect(gfx::Rect(0, 0, 40, 50)));
490 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setUseLCDText(tru e)); 490 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setUseLCDText(tru e));
491 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setDrawOpacity(0. 5)); 491 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setDrawOpacity(0. 5));
492 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setRenderTarget(0 )); 492 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setRenderTarget(0 ));
493 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setDrawTransform( WebTransformationMatrix())); 493 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setDrawTransform( WebTransformationMatrix()));
494 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setScreenSpaceTra nsform(WebTransformationMatrix())); 494 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setScreenSpaceTra nsform(WebTransformationMatrix()));
495 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setDrawableConten tRect(IntRect(4, 5, 6, 7))); 495 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(0, testLayer->setDrawableConten tRect(gfx::Rect(4, 5, 6, 7)));
496 EXPECT_FALSE(testLayer->needsDisplay()); 496 EXPECT_FALSE(testLayer->needsDisplay());
497 497
498 // Next, test properties that should call setNeedsCommit (but not setNeedsDi splay) 498 // Next, test properties that should call setNeedsCommit (but not setNeedsDi splay)
499 // All properties need to be set to new values in order for setNeedsCommit t o be called. 499 // All properties need to be set to new values in order for setNeedsCommit t o be called.
500 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setAnchorPoint(Fl oatPoint(1.23f, 4.56f))); 500 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setAnchorPoint(gf x::PointF(1.23f, 4.56f)));
501 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setAnchorPointZ(0 .7f)); 501 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setAnchorPointZ(0 .7f));
502 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setBackgroundColo r(SK_ColorLTGRAY)); 502 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setBackgroundColo r(SK_ColorLTGRAY));
503 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setMasksToBounds( true)); 503 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setMasksToBounds( true));
504 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setMaskLayer(dumm yLayer.get())); 504 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setMaskLayer(dumm yLayer.get()));
505 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setOpacity(0.5)); 505 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setOpacity(0.5));
506 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setContentsOpaque (true)); 506 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setContentsOpaque (true));
507 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setPosition(Float Point(4, 9))); 507 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setPosition(gfx:: PointF(4, 9)));
508 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setReplicaLayer(d ummyLayer.get())); 508 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setReplicaLayer(d ummyLayer.get()));
509 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setSublayerTransf orm(WebTransformationMatrix(0, 0, 0, 0, 0, 0))); 509 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setSublayerTransf orm(WebTransformationMatrix(0, 0, 0, 0, 0, 0)));
510 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setScrollable(tru e)); 510 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setScrollable(tru e));
511 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setShouldScrollOn MainThread(true)); 511 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setShouldScrollOn MainThread(true));
512 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setNonFastScrolla bleRegion(Region(IntRect(1, 1, 2, 2)))); 512 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setNonFastScrolla bleRegion(Region(IntRect(1, 1, 2, 2))));
513 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setHaveWheelEvent Handlers(true)); 513 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setHaveWheelEvent Handlers(true));
514 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setScrollPosition (IntPoint(10, 10))); 514 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setScrollPosition (IntPoint(10, 10)));
515 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setTransform(WebT ransformationMatrix(0, 0, 0, 0, 0, 0))); 515 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setTransform(WebT ransformationMatrix(0, 0, 0, 0, 0, 0)));
516 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setDoubleSided(fa lse)); 516 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setDoubleSided(fa lse));
517 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setDebugName("Tes t Layer")); 517 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setDebugName("Tes t Layer"));
518 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setDrawCheckerboa rdForMissingTiles(!testLayer->drawCheckerboardForMissingTiles())); 518 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setDrawCheckerboa rdForMissingTiles(!testLayer->drawCheckerboardForMissingTiles()));
519 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setForceRenderSur face(true)); 519 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setForceRenderSur face(true));
520 520
521 // The above tests should not have caused a change to the needsDisplay flag. 521 // The above tests should not have caused a change to the needsDisplay flag.
522 EXPECT_FALSE(testLayer->needsDisplay()); 522 EXPECT_FALSE(testLayer->needsDisplay());
523 523
524 // Test properties that should call setNeedsDisplay and setNeedsCommit 524 // Test properties that should call setNeedsDisplay and setNeedsCommit
525 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setBounds(IntSize (5, 10))); 525 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setBounds(gfx::Si ze(5, 10)));
526 EXPECT_TRUE(testLayer->needsDisplay()); 526 EXPECT_TRUE(testLayer->needsDisplay());
527 } 527 }
528 528
529 TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect) 529 TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect)
530 { 530 {
531 DebugScopedSetImplThread setImplThread; 531 DebugScopedSetImplThread setImplThread;
532 532
533 scoped_refptr<Layer> testLayer = Layer::create(); 533 scoped_refptr<Layer> testLayer = Layer::create();
534 scoped_ptr<LayerImpl> implLayer = LayerImpl::create(1); 534 scoped_ptr<LayerImpl> implLayer = LayerImpl::create(1);
535 535
536 testLayer->setNeedsDisplayRect(FloatRect(FloatPoint::zero(), FloatSize(5, 5) )); 536 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)));
537 testLayer->pushPropertiesTo(implLayer.get()); 537 testLayer->pushPropertiesTo(implLayer.get());
538 EXPECT_FLOAT_RECT_EQ(FloatRect(FloatPoint::zero(), FloatSize(5, 5)), implLay er->updateRect()); 538 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)), implLayer- >updateRect());
539 539
540 // The LayerImpl's updateRect should be accumulated here, since we did not d o anything to clear it. 540 // The LayerImpl's updateRect should be accumulated here, since we did not d o anything to clear it.
541 testLayer->setNeedsDisplayRect(FloatRect(FloatPoint(10, 10), FloatSize(5, 5) )); 541 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)));
542 testLayer->pushPropertiesTo(implLayer.get()); 542 testLayer->pushPropertiesTo(implLayer.get());
543 EXPECT_FLOAT_RECT_EQ(FloatRect(FloatPoint::zero(), FloatSize(15, 15)), implL ayer->updateRect()); 543 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(15, 15)), implLaye r->updateRect());
544 544
545 // If we do clear the LayerImpl side, then the next updateRect should be fre sh without accumulation. 545 // If we do clear the LayerImpl side, then the next updateRect should be fre sh without accumulation.
546 implLayer->resetAllChangeTrackingForSubtree(); 546 implLayer->resetAllChangeTrackingForSubtree();
547 testLayer->setNeedsDisplayRect(FloatRect(FloatPoint(10, 10), FloatSize(5, 5) )); 547 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)));
548 testLayer->pushPropertiesTo(implLayer.get()); 548 testLayer->pushPropertiesTo(implLayer.get());
549 EXPECT_FLOAT_RECT_EQ(FloatRect(FloatPoint(10, 10), FloatSize(5, 5)), implLay er->updateRect()); 549 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)), impl Layer->updateRect());
550 } 550 }
551 551
552 class FakeLayerImplTreeHost : public LayerTreeHost { 552 class FakeLayerImplTreeHost : public LayerTreeHost {
553 public: 553 public:
554 static scoped_ptr<FakeLayerImplTreeHost> create() 554 static scoped_ptr<FakeLayerImplTreeHost> create()
555 { 555 {
556 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost); 556 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost);
557 // The initialize call will fail, since our client doesn't provide a val id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i gnore the return value. 557 // The initialize call will fail, since our client doesn't provide a val id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i gnore the return value.
558 host->initialize(); 558 host->initialize();
559 return host.Pass(); 559 return host.Pass();
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 private: 785 private:
786 virtual ~MockLayer() 786 virtual ~MockLayer()
787 { 787 {
788 } 788 }
789 }; 789 };
790 790
791 TEST(LayerTestWithoutFixture, setBoundsTriggersSetNeedsRedrawAfterGettingNonEmpt yBounds) 791 TEST(LayerTestWithoutFixture, setBoundsTriggersSetNeedsRedrawAfterGettingNonEmpt yBounds)
792 { 792 {
793 scoped_refptr<MockLayer> layer(new MockLayer); 793 scoped_refptr<MockLayer> layer(new MockLayer);
794 EXPECT_FALSE(layer->needsDisplay()); 794 EXPECT_FALSE(layer->needsDisplay());
795 layer->setBounds(IntSize(0, 10)); 795 layer->setBounds(gfx::Size(0, 10));
796 EXPECT_FALSE(layer->needsDisplay()); 796 EXPECT_FALSE(layer->needsDisplay());
797 layer->setBounds(IntSize(10, 10)); 797 layer->setBounds(gfx::Size(10, 10));
798 EXPECT_TRUE(layer->needsDisplay()); 798 EXPECT_TRUE(layer->needsDisplay());
799 } 799 }
800 800
801 801
802 } // namespace 802 } // namespace
OLDNEW
« no previous file with comments | « cc/layer_tree_host_unittest.cc ('k') | cc/math_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698