OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include "cc/test/fake_picture_layer_tiling_client.h" | 7 #include "cc/test/fake_picture_layer_tiling_client.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/rect_conversions.h" | 9 #include "ui/gfx/rect_conversions.h" |
10 #include "ui/gfx/size_conversions.h" | 10 #include "ui/gfx/size_conversions.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 namespace { | 13 namespace { |
14 | 14 |
15 class TestablePictureLayerTiling : public PictureLayerTiling { | |
16 public: | |
17 using PictureLayerTiling::SetLiveTilesRect; | |
18 | |
19 static scoped_ptr<TestablePictureLayerTiling> Create( | |
20 float contents_scale, | |
21 gfx::Size layer_bounds, | |
22 PictureLayerTilingClient* client) { | |
23 return make_scoped_ptr(new TestablePictureLayerTiling( | |
24 contents_scale, | |
25 layer_bounds, | |
26 client)); | |
27 } | |
28 | |
29 protected: | |
30 TestablePictureLayerTiling(float contents_scale, | |
31 gfx::Size layer_bounds, | |
32 PictureLayerTilingClient* client) | |
33 : PictureLayerTiling(contents_scale, layer_bounds, client) { } | |
34 }; | |
35 | |
15 class PictureLayerTilingIteratorTest : public testing::Test { | 36 class PictureLayerTilingIteratorTest : public testing::Test { |
16 public: | 37 public: |
17 PictureLayerTilingIteratorTest() {} | 38 PictureLayerTilingIteratorTest() {} |
18 virtual ~PictureLayerTilingIteratorTest() {} | 39 virtual ~PictureLayerTilingIteratorTest() {} |
19 | 40 |
20 void Initialize(gfx::Size tile_size, | 41 void Initialize(gfx::Size tile_size, |
21 float contents_scale, | 42 float contents_scale, |
22 gfx::Size layer_bounds) { | 43 gfx::Size layer_bounds) { |
23 client_.SetTileSize(tile_size); | 44 client_.SetTileSize(tile_size); |
24 tiling_ = PictureLayerTiling::Create(contents_scale); | 45 tiling_ = TestablePictureLayerTiling::Create(contents_scale, |
25 tiling_->SetClient(&client_); | 46 layer_bounds, |
26 tiling_->SetLayerBounds(layer_bounds); | 47 &client_); |
48 tiling_->CreateAllTilesForTesting(); | |
49 } | |
50 | |
51 void SetLiveRectAndVerifyTiles(gfx::Rect live_tiles_rect) { | |
52 tiling_->SetLiveTilesRect(live_tiles_rect); // max tiles in tile manager | |
enne (OOO)
2013/04/11 00:16:02
I don't think this comment is true, and could just
| |
53 | |
54 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); | |
55 for (std::vector<Tile*>::iterator iter = tiles.begin(); | |
56 iter != tiles.end(); | |
enne (OOO)
2013/04/11 00:16:02
style nit: don't indent 5 spaces after a for loop
| |
57 ++iter) { | |
58 EXPECT_EQ(*iter != NULL, | |
enne (OOO)
2013/04/11 00:16:02
Now that the loop has changed, this is a little bi
| |
59 live_tiles_rect.Intersects((*iter)->content_rect())); | |
60 } | |
27 } | 61 } |
28 | 62 |
29 void VerifyTilesExactlyCoverRect( | 63 void VerifyTilesExactlyCoverRect( |
30 float rect_scale, | 64 float rect_scale, |
31 gfx::Rect request_rect, | 65 gfx::Rect request_rect, |
32 gfx::Rect expect_rect) { | 66 gfx::Rect expect_rect) { |
33 EXPECT_TRUE(request_rect.Contains(expect_rect)); | 67 EXPECT_TRUE(request_rect.Contains(expect_rect)); |
34 | 68 |
35 // Iterators are not valid if this ratio is too large (i.e. the | 69 // Iterators are not valid if this ratio is too large (i.e. the |
36 // tiling is too high-res for a low-res destination rect.) This is an | 70 // tiling is too high-res for a low-res destination rect.) This is an |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 void VerifyTilesCoverNonContainedRect(float rect_scale, gfx::Rect dest_rect) { | 119 void VerifyTilesCoverNonContainedRect(float rect_scale, gfx::Rect dest_rect) { |
86 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | 120 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; |
87 gfx::Rect clamped_rect(gfx::ToEnclosingRect(gfx::ScaleRect( | 121 gfx::Rect clamped_rect(gfx::ToEnclosingRect(gfx::ScaleRect( |
88 tiling_->ContentRect(), 1 / dest_to_contents_scale))); | 122 tiling_->ContentRect(), 1 / dest_to_contents_scale))); |
89 clamped_rect.Intersect(dest_rect); | 123 clamped_rect.Intersect(dest_rect); |
90 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); | 124 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); |
91 } | 125 } |
92 | 126 |
93 protected: | 127 protected: |
94 FakePictureLayerTilingClient client_; | 128 FakePictureLayerTilingClient client_; |
95 scoped_ptr<PictureLayerTiling> tiling_; | 129 scoped_ptr<TestablePictureLayerTiling> tiling_; |
96 | 130 |
97 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); | 131 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); |
98 }; | 132 }; |
99 | 133 |
134 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { | |
135 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | |
136 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100)); | |
137 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99)); | |
138 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1)); | |
139 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801)); | |
140 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1)); | |
141 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800)); | |
142 } | |
143 | |
100 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { | 144 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { |
101 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 145 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); |
102 VerifyTilesExactlyCoverRect(1, gfx::Rect()); | 146 VerifyTilesExactlyCoverRect(1, gfx::Rect()); |
103 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); | 147 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); |
104 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); | 148 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); |
105 | 149 |
106 // With borders, a size of 3x3 = 1 pixel of content. | 150 // With borders, a size of 3x3 = 1 pixel of content. |
107 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10)); | 151 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10)); |
108 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); | 152 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); |
109 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); | 153 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 layer_bounds, // last layer bounds | 485 layer_bounds, // last layer bounds |
442 layer_bounds, // current layer bounds | 486 layer_bounds, // current layer bounds |
443 1.f, // last contents scale | 487 1.f, // last contents scale |
444 1.f, // current contents scale | 488 1.f, // current contents scale |
445 gfx::Transform(), // last screen transform | 489 gfx::Transform(), // last screen transform |
446 gfx::Transform(), // current screen transform | 490 gfx::Transform(), // current screen transform |
447 2, // current frame number | 491 2, // current frame number |
448 2.0, // current frame time | 492 2.0, // current frame time |
449 false, // store screen space quads on tiles | 493 false, // store screen space quads on tiles |
450 10000); // max tiles in tile manager | 494 10000); // max tiles in tile manager |
451 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 495 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false)); |
452 } | 496 } |
453 | 497 |
454 } // namespace | 498 } // namespace |
455 } // namespace cc | 499 } // namespace cc |
OLD | NEW |