OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <map> | 5 #include <map> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "cc/resources/picture_pile.h" | 8 #include "cc/resources/picture_pile.h" |
9 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
10 #include "cc/test/fake_rendering_stats_instrumentation.h" | 10 #include "cc/test/fake_rendering_stats_instrumentation.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/gfx/rect_conversions.h" | 12 #include "ui/gfx/rect_conversions.h" |
13 #include "ui/gfx/size_conversions.h" | 13 #include "ui/gfx/size_conversions.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 namespace { | 16 namespace { |
17 | 17 |
18 class TestPicturePile : public PicturePile { | 18 class TestPicturePile : public PicturePile { |
19 public: | 19 public: |
20 using PicturePile::buffer_pixels; | 20 using PicturePile::buffer_pixels; |
| 21 using PicturePile::CanRasterSlowTileCheck; |
| 22 using PicturePile::Clear; |
21 | 23 |
22 PictureMap& picture_map() { return picture_map_; } | 24 PictureMap& picture_map() { return picture_map_; } |
| 25 const gfx::Rect& recorded_viewport() const { return recorded_viewport_; } |
| 26 |
| 27 bool CanRasterLayerRect(const gfx::Rect& layer_rect) { |
| 28 return CanRaster(1.f, layer_rect); |
| 29 } |
23 | 30 |
24 typedef PicturePile::PictureInfo PictureInfo; | 31 typedef PicturePile::PictureInfo PictureInfo; |
25 typedef PicturePile::PictureMapKey PictureMapKey; | 32 typedef PicturePile::PictureMapKey PictureMapKey; |
26 typedef PicturePile::PictureMap PictureMap; | 33 typedef PicturePile::PictureMap PictureMap; |
27 | 34 |
28 protected: | 35 protected: |
29 virtual ~TestPicturePile() {} | 36 virtual ~TestPicturePile() {} |
30 }; | 37 }; |
31 | 38 |
32 class PicturePileTest : public testing::Test { | 39 class PicturePileTest : public testing::Test { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 229 |
223 EXPECT_FLOAT_EQ(expected_frequency, | 230 EXPECT_FLOAT_EQ(expected_frequency, |
224 picture_info.GetInvalidationFrequencyForTesting()); | 231 picture_info.GetInvalidationFrequencyForTesting()); |
225 | 232 |
226 // We expect that there are pictures everywhere now. | 233 // We expect that there are pictures everywhere now. |
227 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 234 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
228 } | 235 } |
229 } | 236 } |
230 } | 237 } |
231 | 238 |
| 239 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { |
| 240 UpdateWholeLayer(); |
| 241 |
| 242 gfx::Rect rect(0, 0, 5, 5); |
| 243 EXPECT_TRUE(pile_->CanRasterLayerRect(rect)); |
| 244 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(rect)); |
| 245 |
| 246 pile_->Clear(); |
| 247 |
| 248 // Make sure both the cache-aware check (using recorded region) and the normal |
| 249 // check are both false after clearing. |
| 250 EXPECT_FALSE(pile_->CanRasterLayerRect(rect)); |
| 251 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(rect)); |
| 252 } |
| 253 |
| 254 TEST_F(PicturePileTest, FrequentInvalidationCanRaster) { |
| 255 // This test makes sure that if part of the page is frequently invalidated |
| 256 // and doesn't get re-recorded, then CanRaster is not true for any |
| 257 // tiles touching it, but is true for adjacent tiles, even if it |
| 258 // overlaps on borders (edge case). |
| 259 gfx::Size layer_size = gfx::ToFlooredSize(gfx::ScaleSize(pile_->size(), 4.f)); |
| 260 pile_->Resize(layer_size); |
| 261 |
| 262 gfx::Rect tile01_borders = pile_->tiling().TileBoundsWithBorder(0, 1); |
| 263 gfx::Rect tile02_borders = pile_->tiling().TileBoundsWithBorder(0, 2); |
| 264 gfx::Rect tile01_noborders = pile_->tiling().TileBounds(0, 1); |
| 265 gfx::Rect tile02_noborders = pile_->tiling().TileBounds(0, 2); |
| 266 |
| 267 // Sanity check these two tiles are overlapping with borders, since this is |
| 268 // what the test is trying to repro. |
| 269 EXPECT_TRUE(tile01_borders.Intersects(tile02_borders)); |
| 270 EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders)); |
| 271 UpdateWholeLayer(); |
| 272 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
| 273 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
| 274 EXPECT_TRUE(pile_->CanRasterLayerRect(tile02_noborders)); |
| 275 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
| 276 // Sanity check that an initial paint goes down the fast path of having |
| 277 // a valid recorded viewport. |
| 278 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 279 |
| 280 // Update the whole layer until the invalidation frequency is high. |
| 281 for (int frame = 0; frame < 33; ++frame) { |
| 282 UpdateWholeLayer(); |
| 283 } |
| 284 |
| 285 // Update once more with a small viewport. |
| 286 gfx::Rect viewport(0, 0, layer_size.width(), 1); |
| 287 Update(layer_rect(), viewport); |
| 288 |
| 289 // Sanity check some pictures exist and others don't. |
| 290 EXPECT_TRUE(pile_->picture_map() |
| 291 .find(TestPicturePile::PictureMapKey(0, 1)) |
| 292 ->second.GetPicture()); |
| 293 EXPECT_FALSE(pile_->picture_map() |
| 294 .find(TestPicturePile::PictureMapKey(0, 2)) |
| 295 ->second.GetPicture()); |
| 296 |
| 297 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
| 298 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
| 299 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); |
| 300 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
| 301 } |
| 302 |
| 303 TEST_F(PicturePileTest, NoInvalidationValidViewport) { |
| 304 // This test validates that the recorded_viewport cache of full tiles |
| 305 // is still valid for some use cases. If it's not, it's a performance |
| 306 // issue because CanRaster checks will go down the slow path. |
| 307 UpdateWholeLayer(); |
| 308 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 309 |
| 310 // No invalidation, same viewport. |
| 311 Update(gfx::Rect(), layer_rect()); |
| 312 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 313 |
| 314 // Partial invalidation, same viewport. |
| 315 Update(gfx::Rect(gfx::Rect(0, 0, 1, 1)), layer_rect()); |
| 316 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 317 |
| 318 // No invalidation, changing viewport. |
| 319 Update(gfx::Rect(), gfx::Rect(5, 5, 5, 5)); |
| 320 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 321 } |
| 322 |
232 } // namespace | 323 } // namespace |
233 } // namespace cc | 324 } // namespace cc |
OLD | NEW |