Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Side by Side Diff: cc/resources/picture_pile_unittest.cc

Issue 196343005: cc: Replace recorded region with direct map lookup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: vmpstr bugfix Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_; }
23 25
26 bool CanRasterLayerRect(const gfx::Rect& layer_rect) {
27 return CanRaster(1.f, layer_rect);
28 }
29
24 typedef PicturePile::PictureInfo PictureInfo; 30 typedef PicturePile::PictureInfo PictureInfo;
25 typedef PicturePile::PictureMapKey PictureMapKey; 31 typedef PicturePile::PictureMapKey PictureMapKey;
26 typedef PicturePile::PictureMap PictureMap; 32 typedef PicturePile::PictureMap PictureMap;
27 33
28 protected: 34 protected:
29 virtual ~TestPicturePile() {} 35 virtual ~TestPicturePile() {}
30 }; 36 };
31 37
32 class PicturePileTest : public testing::Test { 38 class PicturePileTest : public testing::Test {
33 public: 39 public:
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 228
223 EXPECT_FLOAT_EQ(expected_frequency, 229 EXPECT_FLOAT_EQ(expected_frequency,
224 picture_info.GetInvalidationFrequencyForTesting()); 230 picture_info.GetInvalidationFrequencyForTesting());
225 231
226 // We expect that there are pictures everywhere now. 232 // We expect that there are pictures everywhere now.
227 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; 233 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j;
228 } 234 }
229 } 235 }
230 } 236 }
231 237
238 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) {
239 UpdateWholeLayer();
240
241 gfx::Rect rect(0, 0, 5, 5);
242 EXPECT_TRUE(pile_->CanRasterLayerRect(rect));
243 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(rect));
244
245 pile_->Clear();
246
247 // Make sure both the cache-aware check (using recorded region) and the normal
248 // check are both false after clearing.
249 EXPECT_FALSE(pile_->CanRasterLayerRect(rect));
250 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(rect));
251 }
252
253 TEST_F(PicturePileTest, FrequentInvalidationCanRaster) {
254 // This test makes sure that if part of the page is frequently invalidated
255 // and doesn't get re-recorded, then CanRaster is not true for any
256 // tiles touching it, but is true for adjacent tiles, even if it
257 // overlaps on borders (edge case).
258 gfx::Size layer_size = gfx::ToFlooredSize(gfx::ScaleSize(pile_->size(), 4.f));
259 pile_->Resize(layer_size);
260
261 gfx::Rect tile01_borders = pile_->tiling().TileBoundsWithBorder(0, 1);
262 gfx::Rect tile02_borders = pile_->tiling().TileBoundsWithBorder(0, 2);
263 gfx::Rect tile01_noborders = pile_->tiling().TileBounds(0, 1);
264 gfx::Rect tile02_noborders = pile_->tiling().TileBounds(0, 2);
265
266 // Sanity check these two tiles are overlapping with borders, since this is
267 // what the test is trying to repro.
268 EXPECT_TRUE(tile01_borders.Intersects(tile02_borders));
269 EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders));
270 UpdateWholeLayer();
271 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders));
272 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders));
273 EXPECT_TRUE(pile_->CanRasterLayerRect(tile02_noborders));
274 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile02_noborders));
275
276 // Update the whole layer until the invalidation frequency is high.
277 for (int frame = 0; frame < 33; ++frame) {
278 UpdateWholeLayer();
279 }
280
281 // Update once more with a small viewport.
282 gfx::Rect viewport(0, 0, layer_size.width(), 1);
283 Update(layer_rect(), viewport);
284
285 // Sanity check some pictures exist and others don't.
286 EXPECT_TRUE(pile_->picture_map()
287 .find(TestPicturePile::PictureMapKey(0, 1))
288 ->second.GetPicture());
289 EXPECT_FALSE(pile_->picture_map()
290 .find(TestPicturePile::PictureMapKey(0, 2))
291 ->second.GetPicture());
292
293 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders));
294 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders));
295 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders));
296 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders));
297 }
298
232 } // namespace 299 } // namespace
233 } // namespace cc 300 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698