OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/picture_layer_tiling.h" |
| 6 |
| 7 #include "cc/test/fake_picture_layer_tiling_client.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/size_conversions.h" |
| 10 |
| 11 namespace cc { |
| 12 |
| 13 class PictureLayerTilingIteratorTest : public testing::Test { |
| 14 public: |
| 15 PictureLayerTilingIteratorTest() {} |
| 16 virtual ~PictureLayerTilingIteratorTest() {} |
| 17 |
| 18 void Initialize(gfx::Size tile_size, |
| 19 float contents_scale, |
| 20 gfx::Size layer_bounds) { |
| 21 client_.SetTileSize(tile_size); |
| 22 tiling_ = PictureLayerTiling::Create(contents_scale, tile_size); |
| 23 tiling_->SetClient(&client_); |
| 24 tiling_->SetLayerBounds(layer_bounds); |
| 25 } |
| 26 |
| 27 void VerifyTilesExactlyCoverRect(float rect_scale, gfx::Rect rect) { |
| 28 // Iterators are not valid if this ratio is too large (i.e. the |
| 29 // tiling is too high-res for a low-res destination rect.) This is an |
| 30 // artifact of snapping geometry to integer coordinates and then mapping |
| 31 // back to floating point texture coordinates. |
| 32 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; |
| 33 ASSERT_LE(dest_to_contents_scale, 2.0); |
| 34 |
| 35 Region remaining = rect; |
| 36 for (PictureLayerTiling::Iterator iter(tiling_.get(), rect_scale, rect); |
| 37 iter; |
| 38 ++iter) { |
| 39 |
| 40 // Geometry cannot overlap previous geometry at all |
| 41 gfx::Rect geometry = iter.geometry_rect(); |
| 42 EXPECT_TRUE(rect.Contains(geometry)); |
| 43 EXPECT_TRUE(remaining.Contains(geometry)); |
| 44 remaining.Subtract(geometry); |
| 45 |
| 46 // Sanity check that texture coords are within the texture rect. |
| 47 gfx::RectF texture_rect = iter.texture_rect(); |
| 48 EXPECT_GE(texture_rect.x(), 0); |
| 49 EXPECT_GE(texture_rect.y(), 0); |
| 50 EXPECT_LE(texture_rect.right(), client_.TileSize().width()); |
| 51 EXPECT_LE(texture_rect.bottom(), client_.TileSize().height()); |
| 52 |
| 53 EXPECT_EQ(iter.texture_size(), client_.TileSize()); |
| 54 } |
| 55 |
| 56 // The entire rect must be filled by geometry from the tiling. |
| 57 EXPECT_TRUE(remaining.IsEmpty()); |
| 58 } |
| 59 |
| 60 protected: |
| 61 FakePictureLayerTilingClient client_; |
| 62 scoped_ptr<PictureLayerTiling> tiling_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); |
| 65 }; |
| 66 |
| 67 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { |
| 68 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); |
| 69 VerifyTilesExactlyCoverRect(1, gfx::Rect()); |
| 70 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); |
| 71 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); |
| 72 |
| 73 // With borders, a size of 3x3 = 1 pixel of content. |
| 74 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10)); |
| 75 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); |
| 76 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); |
| 77 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2)); |
| 78 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2)); |
| 79 } |
| 80 |
| 81 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsTilingScale) { |
| 82 Initialize(gfx::Size(200, 100), 2.0f, gfx::Size(1005, 2010)); |
| 83 VerifyTilesExactlyCoverRect(1, gfx::Rect()); |
| 84 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); |
| 85 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381)); |
| 86 |
| 87 Initialize(gfx::Size(3, 3), 2.0f, gfx::Size(10, 10)); |
| 88 VerifyTilesExactlyCoverRect(1, gfx::Rect()); |
| 89 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); |
| 90 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); |
| 91 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2)); |
| 92 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2)); |
| 93 |
| 94 Initialize(gfx::Size(100, 200), 0.5f, gfx::Size(1005, 2010)); |
| 95 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); |
| 96 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381)); |
| 97 |
| 98 Initialize(gfx::Size(150, 250), 0.37f, gfx::Size(1005, 2010)); |
| 99 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); |
| 100 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381)); |
| 101 |
| 102 Initialize(gfx::Size(312, 123), 0.01f, gfx::Size(1005, 2010)); |
| 103 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); |
| 104 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381)); |
| 105 } |
| 106 |
| 107 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsBothScale) { |
| 108 Initialize(gfx::Size(50, 50), 4.0f, gfx::Size(800, 600)); |
| 109 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect()); |
| 110 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect(0, 0, 1600, 1200)); |
| 111 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect(512, 365, 253, 182)); |
| 112 |
| 113 float scale = 6.7f; |
| 114 gfx::Size bounds(800, 600); |
| 115 gfx::Rect full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale))); |
| 116 Initialize(gfx::Size(256, 512), 5.2f, bounds); |
| 117 VerifyTilesExactlyCoverRect(scale, full_rect); |
| 118 VerifyTilesExactlyCoverRect(scale, gfx::Rect(2014, 1579, 867, 1033)); |
| 119 } |
| 120 |
| 121 } // namespace cc |
OLD | NEW |