OLD | NEW |
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 "cc/layers/layer.h" | 5 #include "cc/layers/layer.h" |
6 | 6 |
7 #include "cc/animation/keyframed_animation_curve.h" | 7 #include "cc/animation/keyframed_animation_curve.h" |
8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
9 #include "cc/layers/layer_impl.h" | 9 #include "cc/layers/layer_impl.h" |
10 #include "cc/resources/layer_painter.h" | 10 #include "cc/resources/layer_painter.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 namespace { | 37 namespace { |
38 | 38 |
39 class MockLayerTreeHost : public LayerTreeHost { | 39 class MockLayerTreeHost : public LayerTreeHost { |
40 public: | 40 public: |
41 explicit MockLayerTreeHost(LayerTreeHostClient* client) | 41 explicit MockLayerTreeHost(LayerTreeHostClient* client) |
42 : LayerTreeHost(client, LayerTreeSettings()) { | 42 : LayerTreeHost(client, LayerTreeSettings()) { |
43 Initialize(NULL); | 43 Initialize(NULL); |
44 } | 44 } |
45 | 45 |
46 MOCK_METHOD0(SetNeedsCommit, void()); | 46 MOCK_METHOD0(SetNeedsCommit, void()); |
| 47 MOCK_METHOD0(SetNeedsUpdateLayers, void()); |
47 MOCK_METHOD0(SetNeedsFullTreeSync, void()); | 48 MOCK_METHOD0(SetNeedsFullTreeSync, void()); |
48 }; | 49 }; |
49 | 50 |
50 class MockLayerPainter : public LayerPainter { | 51 class MockLayerPainter : public LayerPainter { |
51 public: | 52 public: |
52 virtual void Paint(SkCanvas* canvas, | 53 virtual void Paint(SkCanvas* canvas, |
53 gfx::Rect content_rect, | 54 gfx::Rect content_rect, |
54 gfx::RectF* opaque) OVERRIDE {} | 55 gfx::RectF* opaque) OVERRIDE {} |
55 }; | 56 }; |
56 | 57 |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 EXPECT_EQ(parent_.get(), child3_->RootLayer()); | 440 EXPECT_EQ(parent_.get(), child3_->RootLayer()); |
440 EXPECT_EQ(grand_child3_.get(), child4->RootLayer()); | 441 EXPECT_EQ(grand_child3_.get(), child4->RootLayer()); |
441 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); | 442 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); |
442 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); | 443 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); |
443 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); | 444 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); |
444 } | 445 } |
445 | 446 |
446 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { | 447 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { |
447 // The semantics for SetNeedsDisplay which are tested here: | 448 // The semantics for SetNeedsDisplay which are tested here: |
448 // 1. sets NeedsDisplay flag appropriately. | 449 // 1. sets NeedsDisplay flag appropriately. |
449 // 2. indirectly calls SetNeedsCommit, exactly once for each call to | 450 // 2. indirectly calls SetNeedsUpdate, exactly once for each call to |
450 // SetNeedsDisplay. | 451 // SetNeedsDisplay. |
451 | 452 |
452 scoped_refptr<Layer> test_layer = Layer::Create(); | 453 scoped_refptr<Layer> test_layer = Layer::Create(); |
453 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 454 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
454 1, layer_tree_host_->SetRootLayer(test_layer)); | 455 1, layer_tree_host_->SetRootLayer(test_layer)); |
455 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 456 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
456 | 457 |
457 gfx::Size test_bounds = gfx::Size(501, 508); | 458 gfx::Size test_bounds = gfx::Size(501, 508); |
458 | 459 |
459 gfx::RectF dirty1 = gfx::RectF(10.f, 15.f, 1.f, 2.f); | 460 gfx::RectF dirty1 = gfx::RectF(10.f, 15.f, 1.f, 2.f); |
460 gfx::RectF dirty2 = gfx::RectF(20.f, 25.f, 3.f, 4.f); | 461 gfx::RectF dirty2 = gfx::RectF(20.f, 25.f, 3.f, 4.f); |
461 gfx::RectF empty_dirty_rect = gfx::RectF(40.f, 45.f, 0.f, 0.f); | 462 gfx::RectF empty_dirty_rect = gfx::RectF(40.f, 45.f, 0.f, 0.f); |
462 gfx::RectF out_of_bounds_dirty_rect = gfx::RectF(400.f, 405.f, 500.f, 502.f); | 463 gfx::RectF out_of_bounds_dirty_rect = gfx::RectF(400.f, 405.f, 500.f, 502.f); |
463 | 464 |
464 // Before anything, test_layer should not be dirty. | 465 // Before anything, test_layer should not be dirty. |
465 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 466 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
466 | 467 |
467 // This is just initialization, but SetNeedsCommit behavior is verified anyway | 468 // This is just initialization, but SetNeedsCommit behavior is verified anyway |
468 // to avoid warnings. | 469 // to avoid warnings. |
469 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(test_bounds)); | 470 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(test_bounds)); |
470 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 471 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
471 | 472 |
472 // The real test begins here. | 473 // The real test begins here. |
473 test_layer->ResetNeedsDisplayForTesting(); | 474 test_layer->ResetNeedsDisplayForTesting(); |
474 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 475 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
475 | 476 |
476 // Case 1: Layer should accept dirty rects that go beyond its bounds. | 477 // Case 1: Layer should accept dirty rects that go beyond its bounds. |
477 test_layer->ResetNeedsDisplayForTesting(); | 478 test_layer->ResetNeedsDisplayForTesting(); |
478 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 479 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
479 EXPECT_SET_NEEDS_COMMIT( | 480 EXPECT_SET_NEEDS_UPDATE( |
480 1, test_layer->SetNeedsDisplayRect(out_of_bounds_dirty_rect)); | 481 1, test_layer->SetNeedsDisplayRect(out_of_bounds_dirty_rect)); |
481 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); | 482 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
482 test_layer->ResetNeedsDisplayForTesting(); | 483 test_layer->ResetNeedsDisplayForTesting(); |
483 | 484 |
484 // Case 2: SetNeedsDisplay() without the dirty rect arg. | 485 // Case 2: SetNeedsDisplay() without the dirty rect arg. |
485 test_layer->ResetNeedsDisplayForTesting(); | 486 test_layer->ResetNeedsDisplayForTesting(); |
486 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 487 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
487 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNeedsDisplay()); | 488 EXPECT_SET_NEEDS_UPDATE(1, test_layer->SetNeedsDisplay()); |
488 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); | 489 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
489 test_layer->ResetNeedsDisplayForTesting(); | 490 test_layer->ResetNeedsDisplayForTesting(); |
490 | 491 |
491 // Case 3: SetNeedsDisplay() with a non-drawable layer | 492 // Case 3: SetNeedsDisplay() with a non-drawable layer |
492 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false)); | 493 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false)); |
493 test_layer->ResetNeedsDisplayForTesting(); | 494 test_layer->ResetNeedsDisplayForTesting(); |
494 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 495 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
495 EXPECT_SET_NEEDS_COMMIT(0, test_layer->SetNeedsDisplayRect(dirty1)); | 496 EXPECT_SET_NEEDS_UPDATE(0, test_layer->SetNeedsDisplayRect(dirty1)); |
496 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); | 497 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
497 } | 498 } |
498 | 499 |
499 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { | 500 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
500 scoped_refptr<Layer> test_layer = Layer::Create(); | 501 scoped_refptr<Layer> test_layer = Layer::Create(); |
501 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 502 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
502 1, layer_tree_host_->SetRootLayer(test_layer)); | 503 1, layer_tree_host_->SetRootLayer(test_layer)); |
503 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 504 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
504 | 505 |
505 scoped_refptr<Layer> dummy_layer1 = Layer::Create(); | 506 scoped_refptr<Layer> dummy_layer1 = Layer::Create(); |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " | 986 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " |
986 << host_opaque << "\n"; | 987 << host_opaque << "\n"; |
987 } | 988 } |
988 } | 989 } |
989 } | 990 } |
990 } | 991 } |
991 } | 992 } |
992 | 993 |
993 } // namespace | 994 } // namespace |
994 } // namespace cc | 995 } // namespace cc |
OLD | NEW |