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

Side by Side Diff: cc/layers/layer_unittest.cc

Issue 19106007: cc: Allow the main thread to cancel commits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add more comments Created 7 years, 4 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/layers/layer_impl_unittest.cc ('k') | cc/layers/texture_layer_unittest.cc » ('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 "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
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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 EXPECT_EQ(parent_.get(), child3_->RootLayer()); 461 EXPECT_EQ(parent_.get(), child3_->RootLayer());
461 EXPECT_EQ(grand_child3_.get(), child4->RootLayer()); 462 EXPECT_EQ(grand_child3_.get(), child4->RootLayer());
462 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); 463 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer());
463 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); 464 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer());
464 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); 465 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer());
465 } 466 }
466 467
467 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { 468 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) {
468 // The semantics for SetNeedsDisplay which are tested here: 469 // The semantics for SetNeedsDisplay which are tested here:
469 // 1. sets NeedsDisplay flag appropriately. 470 // 1. sets NeedsDisplay flag appropriately.
470 // 2. indirectly calls SetNeedsCommit, exactly once for each call to 471 // 2. indirectly calls SetNeedsUpdate, exactly once for each call to
471 // SetNeedsDisplay. 472 // SetNeedsDisplay.
472 473
473 scoped_refptr<Layer> test_layer = Layer::Create(); 474 scoped_refptr<Layer> test_layer = Layer::Create();
474 EXPECT_SET_NEEDS_FULL_TREE_SYNC( 475 EXPECT_SET_NEEDS_FULL_TREE_SYNC(
475 1, layer_tree_host_->SetRootLayer(test_layer)); 476 1, layer_tree_host_->SetRootLayer(test_layer));
476 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); 477 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true));
477 478
478 gfx::Size test_bounds = gfx::Size(501, 508); 479 gfx::Size test_bounds = gfx::Size(501, 508);
479 480
480 gfx::RectF dirty1 = gfx::RectF(10.f, 15.f, 1.f, 2.f); 481 gfx::RectF dirty1 = gfx::RectF(10.f, 15.f, 1.f, 2.f);
481 gfx::RectF dirty2 = gfx::RectF(20.f, 25.f, 3.f, 4.f); 482 gfx::RectF dirty2 = gfx::RectF(20.f, 25.f, 3.f, 4.f);
482 gfx::RectF empty_dirty_rect = gfx::RectF(40.f, 45.f, 0.f, 0.f); 483 gfx::RectF empty_dirty_rect = gfx::RectF(40.f, 45.f, 0.f, 0.f);
483 gfx::RectF out_of_bounds_dirty_rect = gfx::RectF(400.f, 405.f, 500.f, 502.f); 484 gfx::RectF out_of_bounds_dirty_rect = gfx::RectF(400.f, 405.f, 500.f, 502.f);
484 485
485 // Before anything, test_layer should not be dirty. 486 // Before anything, test_layer should not be dirty.
486 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); 487 EXPECT_FALSE(test_layer->NeedsDisplayForTesting());
487 488
488 // This is just initialization, but SetNeedsCommit behavior is verified anyway 489 // This is just initialization, but SetNeedsCommit behavior is verified anyway
489 // to avoid warnings. 490 // to avoid warnings.
490 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(test_bounds)); 491 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(test_bounds));
491 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); 492 EXPECT_FALSE(test_layer->NeedsDisplayForTesting());
492 493
493 // The real test begins here. 494 // The real test begins here.
494 test_layer->ResetNeedsDisplayForTesting(); 495 test_layer->ResetNeedsDisplayForTesting();
495 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); 496 EXPECT_FALSE(test_layer->NeedsDisplayForTesting());
496 497
497 // Case 1: Layer should accept dirty rects that go beyond its bounds. 498 // Case 1: Layer should accept dirty rects that go beyond its bounds.
498 test_layer->ResetNeedsDisplayForTesting(); 499 test_layer->ResetNeedsDisplayForTesting();
499 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); 500 EXPECT_FALSE(test_layer->NeedsDisplayForTesting());
500 EXPECT_SET_NEEDS_COMMIT( 501 EXPECT_SET_NEEDS_UPDATE(
501 1, test_layer->SetNeedsDisplayRect(out_of_bounds_dirty_rect)); 502 1, test_layer->SetNeedsDisplayRect(out_of_bounds_dirty_rect));
502 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); 503 EXPECT_TRUE(test_layer->NeedsDisplayForTesting());
503 test_layer->ResetNeedsDisplayForTesting(); 504 test_layer->ResetNeedsDisplayForTesting();
504 505
505 // Case 2: SetNeedsDisplay() without the dirty rect arg. 506 // Case 2: SetNeedsDisplay() without the dirty rect arg.
506 test_layer->ResetNeedsDisplayForTesting(); 507 test_layer->ResetNeedsDisplayForTesting();
507 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); 508 EXPECT_FALSE(test_layer->NeedsDisplayForTesting());
508 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNeedsDisplay()); 509 EXPECT_SET_NEEDS_UPDATE(1, test_layer->SetNeedsDisplay());
509 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); 510 EXPECT_TRUE(test_layer->NeedsDisplayForTesting());
510 test_layer->ResetNeedsDisplayForTesting(); 511 test_layer->ResetNeedsDisplayForTesting();
511 512
512 // Case 3: SetNeedsDisplay() with a non-drawable layer 513 // Case 3: SetNeedsDisplay() with a non-drawable layer
513 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false)); 514 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false));
514 test_layer->ResetNeedsDisplayForTesting(); 515 test_layer->ResetNeedsDisplayForTesting();
515 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); 516 EXPECT_FALSE(test_layer->NeedsDisplayForTesting());
516 EXPECT_SET_NEEDS_COMMIT(0, test_layer->SetNeedsDisplayRect(dirty1)); 517 EXPECT_SET_NEEDS_UPDATE(0, test_layer->SetNeedsDisplayRect(dirty1));
517 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); 518 EXPECT_TRUE(test_layer->NeedsDisplayForTesting());
518 } 519 }
519 520
520 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { 521 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) {
521 scoped_refptr<Layer> test_layer = Layer::Create(); 522 scoped_refptr<Layer> test_layer = Layer::Create();
522 EXPECT_SET_NEEDS_FULL_TREE_SYNC( 523 EXPECT_SET_NEEDS_FULL_TREE_SYNC(
523 1, layer_tree_host_->SetRootLayer(test_layer)); 524 1, layer_tree_host_->SetRootLayer(test_layer));
524 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); 525 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true));
525 526
526 scoped_refptr<Layer> dummy_layer1 = Layer::Create(); 527 scoped_refptr<Layer> dummy_layer1 = Layer::Create();
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " 1007 << "Flags: " << contents_opaque << ", " << layer_opaque << ", "
1007 << host_opaque << "\n"; 1008 << host_opaque << "\n";
1008 } 1009 }
1009 } 1010 }
1010 } 1011 }
1011 } 1012 }
1012 } 1013 }
1013 1014
1014 } // namespace 1015 } // namespace
1015 } // namespace cc 1016 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_impl_unittest.cc ('k') | cc/layers/texture_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698