Chromium Code Reviews| Index: cc/resources/picture_pile_unittest.cc |
| diff --git a/cc/resources/picture_pile_unittest.cc b/cc/resources/picture_pile_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..deda26030ead7e4f3d5488b30a3ff9f77d1e8656 |
| --- /dev/null |
| +++ b/cc/resources/picture_pile_unittest.cc |
| @@ -0,0 +1,202 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/resources/picture_pile.h" |
| +#include "cc/test/fake_content_layer_client.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/gfx/rect_conversions.h" |
| + |
| +namespace cc { |
| +namespace { |
| + |
| +class TestPicturePile : public PicturePile { |
| + public: |
| + using PicturePile::buffer_pixels; |
| + |
| + PictureListMap& picture_list_map() { return picture_list_map_; } |
| + |
| + typedef PicturePile::PictureList PictureList; |
| + typedef PicturePile::PictureListMapKey PictureListMapKey; |
| + typedef PicturePile::PictureListMap PictureListMap; |
| + |
| + protected: |
| + virtual ~TestPicturePile() {} |
| +}; |
| + |
| +// Update this if the implementation changes. |
| +const int kBasePictureSize = 3000; |
|
enne (OOO)
2013/05/09 22:55:44
Maybe make this configurable from the test so you
danakj
2013/05/09 23:11:53
Hummm..!
Actually, I can just use the tiling().ma
|
| + |
| +TEST(PicturePileTest, SmallInvalidateInflated) { |
| + FakeContentLayerClient client; |
| + scoped_refptr<TestPicturePile> pile = new TestPicturePile; |
| + SkColor background_color = SK_ColorBLUE; |
| + |
| + float min_scale = 0.125; |
| + |
| + gfx::Size layer_size(kBasePictureSize, kBasePictureSize); |
| + pile->Resize(layer_size); |
| + pile->SetTileGridSize(gfx::Size(kBasePictureSize, kBasePictureSize)); |
| + pile->SetMinContentsScale(min_scale); |
| + |
| + // Update the whole layer. |
| + pile->Update(&client, |
| + background_color, |
| + gfx::Rect(layer_size), |
| + gfx::Rect(layer_size), |
| + NULL); |
| + |
| + // Invalidate something inside a tile. |
| + gfx::Rect invalidate_rect(50, 50, 1, 1); |
| + pile->Update(&client, |
| + background_color, |
| + invalidate_rect, |
| + gfx::Rect(layer_size), |
| + NULL); |
| + |
| + EXPECT_EQ(1, pile->tiling().num_tiles_x()); |
| + EXPECT_EQ(1, pile->tiling().num_tiles_y()); |
| + |
| + TestPicturePile::PictureList& picture_list = |
| + pile->picture_list_map().find( |
| + TestPicturePile::PictureListMapKey(0, 0))->second; |
| + EXPECT_EQ(2u, picture_list.size()); |
| + for (TestPicturePile::PictureList::iterator it = picture_list.begin(); |
| + it != picture_list.end(); |
| + ++it) { |
| + scoped_refptr<Picture> picture = *it; |
| + gfx::Rect picture_rect = gfx::ToEnclosedRect( |
| + gfx::ScaleRect(picture->LayerRect(), min_scale)); |
| + |
| + // The invalidation in each tile should have been made large enough |
| + // that scaling it never makes a rect smaller than 1 px wide or tall. |
| + EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << |
| + picture_rect.ToString(); |
| + } |
| +} |
| + |
| +TEST(PicturePileTest, LargeInvalidateInflated) { |
| + FakeContentLayerClient client; |
| + scoped_refptr<TestPicturePile> pile = new TestPicturePile; |
| + SkColor background_color = SK_ColorBLUE; |
| + |
| + float min_scale = 0.125; |
| + |
| + gfx::Size layer_size(kBasePictureSize, kBasePictureSize); |
| + pile->Resize(layer_size); |
| + pile->SetTileGridSize(gfx::Size(kBasePictureSize, kBasePictureSize)); |
| + pile->SetMinContentsScale(min_scale); |
| + |
| + // Update the whole layer. |
| + pile->Update(&client, |
| + background_color, |
| + gfx::Rect(layer_size), |
| + gfx::Rect(layer_size), |
| + NULL); |
| + |
| + // Invalidate something inside a tile. |
| + gfx::Rect invalidate_rect(50, 50, 100, 100); |
| + pile->Update(&client, |
| + background_color, |
| + invalidate_rect, |
| + gfx::Rect(layer_size), |
| + NULL); |
| + |
| + EXPECT_EQ(1, pile->tiling().num_tiles_x()); |
| + EXPECT_EQ(1, pile->tiling().num_tiles_y()); |
| + |
| + TestPicturePile::PictureList& picture_list = |
| + pile->picture_list_map().find( |
| + TestPicturePile::PictureListMapKey(0, 0))->second; |
| + EXPECT_EQ(2u, picture_list.size()); |
| + |
| + int expected_inflation = ceil(1.f / min_scale) - 1; |
|
enne (OOO)
2013/05/09 22:55:44
Can you just ask for the buffer pixels?
danakj
2013/05/09 23:11:53
Done.
|
| + |
| + scoped_refptr<Picture> base_picture = *picture_list.begin(); |
| + gfx::Rect base_picture_rect(layer_size); |
| + base_picture_rect.Inset(-expected_inflation, -expected_inflation); |
| + EXPECT_EQ(base_picture_rect.ToString(), |
| + base_picture->LayerRect().ToString()); |
| + |
| + scoped_refptr<Picture> picture = *(++picture_list.begin()); |
| + gfx::Rect picture_rect(invalidate_rect); |
| + picture_rect.Inset(-expected_inflation, -expected_inflation); |
| + EXPECT_EQ(picture_rect.ToString(), |
| + picture->LayerRect().ToString()); |
| +} |
| + |
| +TEST(PicturePileTest, InvalidateOnTileBoundaryInflated) { |
| + FakeContentLayerClient client; |
| + scoped_refptr<TestPicturePile> pile = new TestPicturePile; |
| + SkColor background_color = SK_ColorBLUE; |
| + |
| + float min_scale = 0.125; |
| + |
| + gfx::Size layer_size(kBasePictureSize * 2, kBasePictureSize * 2); |
| + pile->Resize(layer_size); |
| + pile->SetTileGridSize(gfx::Size(kBasePictureSize, kBasePictureSize)); |
| + pile->SetMinContentsScale(min_scale); |
| + |
| + // Verify kBasePictureSize matches our expectations. Update kBasePictureSize |
| + // if these are wrong. |
| + EXPECT_EQ(3, pile->tiling().num_tiles_x()); |
| + EXPECT_EQ(3, pile->tiling().num_tiles_y()); |
| + EXPECT_EQ(kBasePictureSize, pile->tiling().max_texture_size().width()); |
| + EXPECT_EQ(kBasePictureSize, pile->tiling().max_texture_size().height()); |
| + |
| + // We should have 1/.125 - 1 = 7 border pixels. |
| + EXPECT_EQ(7, pile->buffer_pixels()); |
| + EXPECT_EQ(7, pile->tiling().border_texels()); |
| + |
| + // Update the whole layer. |
| + pile->Update(&client, |
| + background_color, |
| + gfx::Rect(layer_size), |
| + gfx::Rect(layer_size), |
| + NULL); |
| + |
| + // Invalidate something just over a tile boundary by a single pixel. |
| + // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). |
| + gfx::Rect invalidate_rect( |
| + pile->tiling().TileBoundsWithBorder(0, 0).right(), |
| + pile->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, |
| + 50, |
| + 50); |
| + pile->Update(&client, |
| + background_color, |
| + invalidate_rect, |
| + gfx::Rect(layer_size), |
| + NULL); |
| + |
| + for (int i = 0; i < pile->tiling().num_tiles_x(); ++i) { |
| + for (int j = 0; j < pile->tiling().num_tiles_y(); ++j) { |
| + // (1, 0) and (1, 1) should be invalidated partially. |
| + bool expect_invalidated = i == 1 && (j == 0 || j == 1); |
| + |
| + TestPicturePile::PictureList& picture_list = |
| + pile->picture_list_map().find( |
| + TestPicturePile::PictureListMapKey(i, j))->second; |
| + if (!expect_invalidated) { |
| + EXPECT_EQ(1u, picture_list.size()) << "For i,j " << i << "," << j; |
| + continue; |
| + } |
| + |
| + EXPECT_EQ(2u, picture_list.size()) << "For i,j " << i << "," << j; |
| + for (TestPicturePile::PictureList::iterator it = picture_list.begin(); |
| + it != picture_list.end(); |
| + ++it) { |
| + scoped_refptr<Picture> picture = *it; |
| + gfx::Rect picture_rect = gfx::ToEnclosedRect( |
| + gfx::ScaleRect(picture->LayerRect(), min_scale)); |
| + |
| + // The invalidation in each tile should have been made large enough |
| + // that scaling it never makes a rect smaller than 1 px wide or tall. |
| + EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << |
| + picture_rect.ToString(); |
| + } |
| + } |
| + } |
| +} |
| + |
| +} // namespace |
| +} // namespace cc |