Chromium Code Reviews| 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 PictureLayerTilingIteratorTest : public testing::Test { | 15 class PictureLayerTilingIteratorTest : public testing::Test { |
| 16 public: | 16 public: |
| 17 PictureLayerTilingIteratorTest() {} | 17 PictureLayerTilingIteratorTest() {} |
| 18 virtual ~PictureLayerTilingIteratorTest() {} | 18 virtual ~PictureLayerTilingIteratorTest() {} |
| 19 | 19 |
| 20 void Initialize(gfx::Size tile_size, | 20 void Initialize(gfx::Size tile_size, |
| 21 float contents_scale, | 21 float contents_scale, |
| 22 gfx::Size layer_bounds) { | 22 gfx::Size layer_bounds) { |
| 23 client_.SetTileSize(tile_size); | 23 client_.SetTileSize(tile_size); |
| 24 tiling_ = PictureLayerTiling::Create(contents_scale); | 24 tiling_ = PictureLayerTiling::Create(contents_scale, |
| 25 tiling_->SetClient(&client_); | 25 layer_bounds, |
| 26 tiling_->SetLayerBounds(layer_bounds); | 26 &client_); |
| 27 } | |
| 28 | |
| 29 void VerifyTilesExistOnlyInLiveRect(gfx::Rect live_tiles_rect) { | |
|
enne (OOO)
2013/04/10 20:25:30
This function is named oddly. Maybe SetLiveRectAn
whunt
2013/04/10 20:52:30
sure.
| |
| 30 | |
| 31 tiling_->SetLiveTilesRect(live_tiles_rect); | |
| 32 for (TilingData::Iterator iter(&tiling_->tiling_data(), | |
|
enne (OOO)
2013/04/10 20:25:30
Shouldn't you iterate over all tiles and not just
whunt
2013/04/10 20:52:30
Yes, it should be iterating over the content rect,
enne (OOO)
2013/04/10 21:21:24
No, it's more than that. I'm saying that you need
| |
| 33 live_tiles_rect); | |
| 34 iter; | |
| 35 ++iter) { | |
| 36 Tile* tile = tiling_->TileAt(iter.index_x(), iter.index_y()); | |
| 37 EXPECT_EQ(tile != NULL, | |
| 38 live_tiles_rect.Intersects(tile->content_rect())); | |
| 39 } | |
| 27 } | 40 } |
| 28 | 41 |
| 29 void VerifyTilesExactlyCoverRect( | 42 void VerifyTilesExactlyCoverRect( |
| 30 float rect_scale, | 43 float rect_scale, |
| 31 gfx::Rect request_rect, | 44 gfx::Rect request_rect, |
| 32 gfx::Rect expect_rect) { | 45 gfx::Rect expect_rect) { |
| 33 EXPECT_TRUE(request_rect.Contains(expect_rect)); | 46 EXPECT_TRUE(request_rect.Contains(expect_rect)); |
| 34 | 47 |
| 35 // Iterators are not valid if this ratio is too large (i.e. the | 48 // 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 | 49 // tiling is too high-res for a low-res destination rect.) This is an |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); | 89 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); |
| 77 } | 90 } |
| 78 | 91 |
| 79 protected: | 92 protected: |
| 80 FakePictureLayerTilingClient client_; | 93 FakePictureLayerTilingClient client_; |
| 81 scoped_ptr<PictureLayerTiling> tiling_; | 94 scoped_ptr<PictureLayerTiling> tiling_; |
| 82 | 95 |
| 83 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); | 96 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); |
| 84 }; | 97 }; |
| 85 | 98 |
| 99 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { | |
| 100 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | |
| 101 VerifyTilesExistOnlyInLiveRect(gfx::Rect(100, 100)); | |
| 102 VerifyTilesExistOnlyInLiveRect(gfx::Rect(101, 99)); | |
| 103 VerifyTilesExistOnlyInLiveRect(gfx::Rect(1099, 1)); | |
| 104 VerifyTilesExistOnlyInLiveRect(gfx::Rect(1, 801)); | |
| 105 VerifyTilesExistOnlyInLiveRect(gfx::Rect(1099, 1)); | |
| 106 VerifyTilesExistOnlyInLiveRect(gfx::Rect(201, 800)); | |
| 107 } | |
| 108 | |
| 86 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { | 109 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { |
| 87 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 110 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); |
| 88 VerifyTilesExactlyCoverRect(1, gfx::Rect()); | 111 VerifyTilesExactlyCoverRect(1, gfx::Rect()); |
| 89 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); | 112 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); |
| 90 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); | 113 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); |
| 91 | 114 |
| 92 // With borders, a size of 3x3 = 1 pixel of content. | 115 // With borders, a size of 3x3 = 1 pixel of content. |
| 93 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10)); | 116 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10)); |
| 94 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); | 117 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); |
| 95 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); | 118 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 gfx::Rect in(40, 50, 100, 200); | 376 gfx::Rect in(40, 50, 100, 200); |
| 354 gfx::Rect bounds(0, 0, 10, 10); | 377 gfx::Rect bounds(0, 0, 10, 10); |
| 355 int64 target_area = 400 * 400; | 378 int64 target_area = 400 * 400; |
| 356 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 379 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
| 357 in, target_area, bounds); | 380 in, target_area, bounds); |
| 358 EXPECT_TRUE(out.IsEmpty()); | 381 EXPECT_TRUE(out.IsEmpty()); |
| 359 } | 382 } |
| 360 | 383 |
| 361 } // namespace | 384 } // namespace |
| 362 } // namespace cc | 385 } // namespace cc |
| OLD | NEW |