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

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

Issue 12865017: Makes tile-creation lazy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing last round of feedback Created 7 years, 8 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
« no previous file with comments | « cc/resources/picture_layer_tiling_set_unittest.cc ('k') | cc/resources/picture_pile_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 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 "cc/resources/picture_layer_tiling.h" 5 #include "cc/resources/picture_layer_tiling.h"
6 6
7 #include "cc/test/fake_picture_layer_tiling_client.h" 7 #include "cc/test/fake_picture_layer_tiling_client.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/rect_conversions.h" 9 #include "ui/gfx/rect_conversions.h"
10 #include "ui/gfx/size_conversions.h" 10 #include "ui/gfx/size_conversions.h"
11 11
12 namespace cc { 12 namespace cc {
13 namespace { 13 namespace {
14 14
15 class TestablePictureLayerTiling : public PictureLayerTiling {
16 public:
17 using PictureLayerTiling::SetLiveTilesRect;
18
19 static scoped_ptr<TestablePictureLayerTiling> Create(
20 float contents_scale,
21 gfx::Size layer_bounds,
22 PictureLayerTilingClient* client) {
23 return make_scoped_ptr(new TestablePictureLayerTiling(
24 contents_scale,
25 layer_bounds,
26 client));
27 }
28
29 protected:
30 TestablePictureLayerTiling(float contents_scale,
31 gfx::Size layer_bounds,
32 PictureLayerTilingClient* client)
33 : PictureLayerTiling(contents_scale, layer_bounds, client) { }
34 };
35
15 class PictureLayerTilingIteratorTest : public testing::Test { 36 class PictureLayerTilingIteratorTest : public testing::Test {
16 public: 37 public:
17 PictureLayerTilingIteratorTest() {} 38 PictureLayerTilingIteratorTest() {}
18 virtual ~PictureLayerTilingIteratorTest() {} 39 virtual ~PictureLayerTilingIteratorTest() {}
19 40
20 void Initialize(gfx::Size tile_size, 41 void Initialize(gfx::Size tile_size,
21 float contents_scale, 42 float contents_scale,
22 gfx::Size layer_bounds) { 43 gfx::Size layer_bounds) {
23 client_.SetTileSize(tile_size); 44 client_.SetTileSize(tile_size);
24 tiling_ = PictureLayerTiling::Create(contents_scale); 45 tiling_ = TestablePictureLayerTiling::Create(contents_scale,
25 tiling_->SetClient(&client_); 46 layer_bounds,
26 tiling_->SetLayerBounds(layer_bounds); 47 &client_);
48 tiling_->CreateAllTilesForTesting();
49 }
50
51 void SetLiveRectAndVerifyTiles(gfx::Rect live_tiles_rect) {
52 tiling_->SetLiveTilesRect(live_tiles_rect);
53
54 std::vector<Tile*> tiles = tiling_->AllTilesForTesting();
55 for (std::vector<Tile*>::iterator iter = tiles.begin();
56 iter != tiles.end();
57 ++iter) {
58 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect()));
59 }
27 } 60 }
28 61
29 void VerifyTilesExactlyCoverRect( 62 void VerifyTilesExactlyCoverRect(
30 float rect_scale, 63 float rect_scale,
31 gfx::Rect request_rect, 64 gfx::Rect request_rect,
32 gfx::Rect expect_rect) { 65 gfx::Rect expect_rect) {
33 EXPECT_TRUE(request_rect.Contains(expect_rect)); 66 EXPECT_TRUE(request_rect.Contains(expect_rect));
34 67
35 // Iterators are not valid if this ratio is too large (i.e. the 68 // Iterators are not valid if this ratio is too large (i.e. the
36 // tiling is too high-res for a low-res destination rect.) This is an 69 // tiling is too high-res for a low-res destination rect.) This is an
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void VerifyTilesCoverNonContainedRect(float rect_scale, gfx::Rect dest_rect) { 118 void VerifyTilesCoverNonContainedRect(float rect_scale, gfx::Rect dest_rect) {
86 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; 119 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale;
87 gfx::Rect clamped_rect(gfx::ToEnclosingRect(gfx::ScaleRect( 120 gfx::Rect clamped_rect(gfx::ToEnclosingRect(gfx::ScaleRect(
88 tiling_->ContentRect(), 1 / dest_to_contents_scale))); 121 tiling_->ContentRect(), 1 / dest_to_contents_scale)));
89 clamped_rect.Intersect(dest_rect); 122 clamped_rect.Intersect(dest_rect);
90 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); 123 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect);
91 } 124 }
92 125
93 protected: 126 protected:
94 FakePictureLayerTilingClient client_; 127 FakePictureLayerTilingClient client_;
95 scoped_ptr<PictureLayerTiling> tiling_; 128 scoped_ptr<TestablePictureLayerTiling> tiling_;
96 129
97 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); 130 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest);
98 }; 131 };
99 132
133 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) {
134 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801));
135 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100));
136 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99));
137 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
138 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801));
139 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
140 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800));
141 }
142
100 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { 143 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) {
101 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); 144 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801));
102 VerifyTilesExactlyCoverRect(1, gfx::Rect()); 145 VerifyTilesExactlyCoverRect(1, gfx::Rect());
103 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); 146 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801));
104 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); 147 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412));
105 148
106 // With borders, a size of 3x3 = 1 pixel of content. 149 // With borders, a size of 3x3 = 1 pixel of content.
107 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10)); 150 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10));
108 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); 151 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
109 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); 152 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 layer_bounds, // last layer bounds 484 layer_bounds, // last layer bounds
442 layer_bounds, // current layer bounds 485 layer_bounds, // current layer bounds
443 1.f, // last contents scale 486 1.f, // last contents scale
444 1.f, // current contents scale 487 1.f, // current contents scale
445 gfx::Transform(), // last screen transform 488 gfx::Transform(), // last screen transform
446 gfx::Transform(), // current screen transform 489 gfx::Transform(), // current screen transform
447 2, // current frame number 490 2, // current frame number
448 2.0, // current frame time 491 2.0, // current frame time
449 false, // store screen space quads on tiles 492 false, // store screen space quads on tiles
450 10000); // max tiles in tile manager 493 10000); // max tiles in tile manager
451 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); 494 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false));
452 } 495 }
453 496
454 } // namespace 497 } // namespace
455 } // namespace cc 498 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_layer_tiling_set_unittest.cc ('k') | cc/resources/picture_pile_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698