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 |
| index d87f92840763978a03ac71b96ae2ece3007bc019..e89e140d127139c54bc59968af35c770926c8f0d 100644 |
| --- a/cc/resources/picture_pile_unittest.cc |
| +++ b/cc/resources/picture_pile_unittest.cc |
| @@ -18,8 +18,15 @@ namespace { |
| class TestPicturePile : public PicturePile { |
| public: |
| using PicturePile::buffer_pixels; |
| + using PicturePile::CanRasterSlowTileCheck; |
| + using PicturePile::Clear; |
| PictureMap& picture_map() { return picture_map_; } |
| + const gfx::Rect& recorded_viewport() const { return recorded_viewport_; } |
| + |
| + bool CanRasterLayerRect(const gfx::Rect& layer_rect) { |
| + return CanRaster(1.f, layer_rect); |
| + } |
| typedef PicturePile::PictureInfo PictureInfo; |
| typedef PicturePile::PictureMapKey PictureMapKey; |
| @@ -229,5 +236,85 @@ TEST_F(PicturePileTest, StopRecordingOffscreenInvalidations) { |
| } |
| } |
| +TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { |
| + UpdateWholeLayer(); |
| + |
| + gfx::Rect rect(0, 0, 5, 5); |
| + EXPECT_TRUE(pile_->CanRasterLayerRect(rect)); |
| + EXPECT_TRUE(pile_->CanRasterSlowTileCheck(rect)); |
| + |
| + pile_->Clear(); |
| + |
| + // Make sure both the cache-aware check (using recorded region) and the normal |
| + // check are both false after clearing. |
| + EXPECT_FALSE(pile_->CanRasterLayerRect(rect)); |
| + EXPECT_FALSE(pile_->CanRasterSlowTileCheck(rect)); |
| +} |
| + |
| +TEST_F(PicturePileTest, FrequentInvalidationCanRaster) { |
| + // This test makes sure that if part of the page is frequently invalidated |
| + // and doesn't get re-recorded, then CanRaster is not true for any |
| + // tiles touching it, but is true for adjacent tiles, even if it |
| + // overlaps on borders (edge case). |
| + gfx::Size layer_size = gfx::ToFlooredSize(gfx::ScaleSize(pile_->size(), 4.f)); |
| + pile_->Resize(layer_size); |
| + |
| + gfx::Rect tile01_borders = pile_->tiling().TileBoundsWithBorder(0, 1); |
| + gfx::Rect tile02_borders = pile_->tiling().TileBoundsWithBorder(0, 2); |
| + gfx::Rect tile01_noborders = pile_->tiling().TileBounds(0, 1); |
| + gfx::Rect tile02_noborders = pile_->tiling().TileBounds(0, 2); |
| + |
| + // Sanity check these two tiles are overlapping with borders, since this is |
| + // what the test is trying to repro. |
| + EXPECT_TRUE(tile01_borders.Intersects(tile02_borders)); |
| + EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders)); |
| + UpdateWholeLayer(); |
| + EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
| + EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
| + EXPECT_TRUE(pile_->CanRasterLayerRect(tile02_noborders)); |
| + EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
| + // Sanity check that an initial paint goes down the fast path of having |
| + // a valid recorded viewport. |
| + EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| + |
| + // Update the whole layer until the invalidation frequency is high. |
| + for (int frame = 0; frame < 33; ++frame) { |
| + UpdateWholeLayer(); |
| + } |
| + |
| + // Update once more with a small viewport. |
| + gfx::Rect viewport(0, 0, layer_size.width(), 1); |
| + Update(layer_rect(), viewport); |
| + |
| + // Sanity check some pictures exist and others don't. |
| + EXPECT_TRUE(pile_->picture_map() |
| + .find(TestPicturePile::PictureMapKey(0, 1)) |
| + ->second.GetPicture()); |
| + EXPECT_FALSE(pile_->picture_map() |
| + .find(TestPicturePile::PictureMapKey(0, 2)) |
| + ->second.GetPicture()); |
| + |
| + EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
| + EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
| + EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); |
| + EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
| +} |
| + |
| +TEST_F(PicturePileTest, NoInvalidationValidViewport) { |
| + // This test validates that the recorded_viewport cache of full tiles |
| + // is still valid for some use cases. If it's not, it's a performance |
| + // issue because CanRaster checks will go down the slow path. |
| + UpdateWholeLayer(); |
| + EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| + |
| + // No invalidation, same viewport. |
| + Update(gfx::Rect(), layer_rect()); |
| + EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| + |
| + // No invalidation, changing viewport. |
|
danakj
2014/03/18 21:01:37
For a single invalidation it should work also righ
enne (OOO)
2014/03/18 21:04:05
Sure. That's tested by the line on 308. The whol
danakj
2014/03/18 21:05:14
I was thinking a partial invalidation, so there's
enne (OOO)
2014/03/18 21:09:46
I guess I don't follow which piece of code you're
danakj
2014/03/18 21:44:19
My thought was with a partial invalidation, you'll
enne (OOO)
2014/03/18 22:02:03
Sure, but lines 312 and 316 test that still having
danakj
2014/03/18 22:04:56
Ya, it's the same code right now. I'm just trying
|
| + Update(gfx::Rect(), gfx::Rect(5, 5, 5, 5)); |
| + EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| +} |
| + |
| } // namespace |
| } // namespace cc |