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

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

Issue 822713002: Update from https://crrev.com/309415 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years 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
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_set.h" 5 #include "cc/resources/picture_layer_tiling_set.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "cc/resources/resource_provider.h" 10 #include "cc/resources/resource_provider.h"
11 #include "cc/test/fake_output_surface.h" 11 #include "cc/test/fake_output_surface.h"
12 #include "cc/test/fake_output_surface_client.h" 12 #include "cc/test/fake_output_surface_client.h"
13 #include "cc/test/fake_picture_layer_tiling_client.h" 13 #include "cc/test/fake_picture_layer_tiling_client.h"
14 #include "cc/test/fake_picture_pile_impl.h"
14 #include "cc/test/test_shared_bitmap_manager.h" 15 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/geometry/size_conversions.h" 17 #include "ui/gfx/geometry/size_conversions.h"
17 18
18 namespace cc { 19 namespace cc {
19 namespace { 20 namespace {
20 21
21 scoped_ptr<PictureLayerTilingSet> CreateTilingSet( 22 scoped_ptr<PictureLayerTilingSet> CreateTilingSet(
22 PictureLayerTilingClient* client) { 23 PictureLayerTilingClient* client) {
23 LayerTreeSettings defaults; 24 LayerTreeSettings defaults;
24 return PictureLayerTilingSet::Create( 25 return PictureLayerTilingSet::Create(
25 client, defaults.max_tiles_for_interest_area, 26 client, defaults.max_tiles_for_interest_area,
26 defaults.skewport_target_time_in_seconds, 27 defaults.skewport_target_time_in_seconds,
27 defaults.skewport_extrapolation_limit_in_content_pixels); 28 defaults.skewport_extrapolation_limit_in_content_pixels);
28 } 29 }
29 30
30 TEST(PictureLayerTilingSetTest, NoResources) { 31 TEST(PictureLayerTilingSetTest, NoResources) {
31 FakePictureLayerTilingClient client; 32 FakePictureLayerTilingClient client;
32 gfx::Size layer_bounds(1000, 800); 33 gfx::Size layer_bounds(1000, 800);
33 auto set = CreateTilingSet(&client); 34 scoped_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client);
34 client.SetTileSize(gfx::Size(256, 256)); 35 client.SetTileSize(gfx::Size(256, 256));
35 36
36 set->AddTiling(1.0, layer_bounds); 37 scoped_refptr<FakePicturePileImpl> pile =
37 set->AddTiling(1.5, layer_bounds); 38 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(layer_bounds);
38 set->AddTiling(2.0, layer_bounds); 39
40 set->AddTiling(1.0, pile);
41 set->AddTiling(1.5, pile);
42 set->AddTiling(2.0, pile);
39 43
40 float contents_scale = 2.0; 44 float contents_scale = 2.0;
41 gfx::Size content_bounds( 45 gfx::Size content_bounds(
42 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); 46 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
43 gfx::Rect content_rect(content_bounds); 47 gfx::Rect content_rect(content_bounds);
44 48
45 Region remaining(content_rect); 49 Region remaining(content_rect);
46 PictureLayerTilingSet::CoverageIterator iter(set.get(), contents_scale, 50 PictureLayerTilingSet::CoverageIterator iter(set.get(), contents_scale,
47 content_rect, contents_scale); 51 content_rect, contents_scale);
48 for (; iter; ++iter) { 52 for (; iter; ++iter) {
(...skipping 12 matching lines...) Expand all
61 FakePictureLayerTilingClient client; 65 FakePictureLayerTilingClient client;
62 gfx::Size layer_bounds(10, 10); 66 gfx::Size layer_bounds(10, 10);
63 PictureLayerTilingSet::TilingRange higher_than_high_res_range(0, 0); 67 PictureLayerTilingSet::TilingRange higher_than_high_res_range(0, 0);
64 PictureLayerTilingSet::TilingRange high_res_range(0, 0); 68 PictureLayerTilingSet::TilingRange high_res_range(0, 0);
65 PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0); 69 PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0);
66 PictureLayerTilingSet::TilingRange low_res_range(0, 0); 70 PictureLayerTilingSet::TilingRange low_res_range(0, 0);
67 PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0); 71 PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0);
68 PictureLayerTiling* high_res_tiling; 72 PictureLayerTiling* high_res_tiling;
69 PictureLayerTiling* low_res_tiling; 73 PictureLayerTiling* low_res_tiling;
70 74
71 auto set = CreateTilingSet(&client); 75 scoped_refptr<FakePicturePileImpl> pile =
72 set->AddTiling(2.0, layer_bounds); 76 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds);
73 high_res_tiling = set->AddTiling(1.0, layer_bounds); 77
78 scoped_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client);
79 set->AddTiling(2.0, pile);
80 high_res_tiling = set->AddTiling(1.0, pile);
74 high_res_tiling->set_resolution(HIGH_RESOLUTION); 81 high_res_tiling->set_resolution(HIGH_RESOLUTION);
75 set->AddTiling(0.5, layer_bounds); 82 set->AddTiling(0.5, pile);
76 low_res_tiling = set->AddTiling(0.25, layer_bounds); 83 low_res_tiling = set->AddTiling(0.25, pile);
77 low_res_tiling->set_resolution(LOW_RESOLUTION); 84 low_res_tiling->set_resolution(LOW_RESOLUTION);
78 set->AddTiling(0.125, layer_bounds); 85 set->AddTiling(0.125, pile);
79 86
80 higher_than_high_res_range = 87 higher_than_high_res_range =
81 set->GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 88 set->GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
82 EXPECT_EQ(0u, higher_than_high_res_range.start); 89 EXPECT_EQ(0u, higher_than_high_res_range.start);
83 EXPECT_EQ(1u, higher_than_high_res_range.end); 90 EXPECT_EQ(1u, higher_than_high_res_range.end);
84 91
85 high_res_range = set->GetTilingRange(PictureLayerTilingSet::HIGH_RES); 92 high_res_range = set->GetTilingRange(PictureLayerTilingSet::HIGH_RES);
86 EXPECT_EQ(1u, high_res_range.start); 93 EXPECT_EQ(1u, high_res_range.start);
87 EXPECT_EQ(2u, high_res_range.end); 94 EXPECT_EQ(2u, high_res_range.end);
88 95
89 between_high_and_low_res_range = 96 between_high_and_low_res_range =
90 set->GetTilingRange(PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES); 97 set->GetTilingRange(PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
91 EXPECT_EQ(2u, between_high_and_low_res_range.start); 98 EXPECT_EQ(2u, between_high_and_low_res_range.start);
92 EXPECT_EQ(3u, between_high_and_low_res_range.end); 99 EXPECT_EQ(3u, between_high_and_low_res_range.end);
93 100
94 low_res_range = set->GetTilingRange(PictureLayerTilingSet::LOW_RES); 101 low_res_range = set->GetTilingRange(PictureLayerTilingSet::LOW_RES);
95 EXPECT_EQ(3u, low_res_range.start); 102 EXPECT_EQ(3u, low_res_range.start);
96 EXPECT_EQ(4u, low_res_range.end); 103 EXPECT_EQ(4u, low_res_range.end);
97 104
98 lower_than_low_res_range = 105 lower_than_low_res_range =
99 set->GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES); 106 set->GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES);
100 EXPECT_EQ(4u, lower_than_low_res_range.start); 107 EXPECT_EQ(4u, lower_than_low_res_range.start);
101 EXPECT_EQ(5u, lower_than_low_res_range.end); 108 EXPECT_EQ(5u, lower_than_low_res_range.end);
102 109
103 auto set_without_low_res = CreateTilingSet(&client); 110 scoped_ptr<PictureLayerTilingSet> set_without_low_res =
104 set_without_low_res->AddTiling(2.0, layer_bounds); 111 CreateTilingSet(&client);
105 high_res_tiling = set_without_low_res->AddTiling(1.0, layer_bounds); 112 set_without_low_res->AddTiling(2.0, pile);
113 high_res_tiling = set_without_low_res->AddTiling(1.0, pile);
106 high_res_tiling->set_resolution(HIGH_RESOLUTION); 114 high_res_tiling->set_resolution(HIGH_RESOLUTION);
107 set_without_low_res->AddTiling(0.5, layer_bounds); 115 set_without_low_res->AddTiling(0.5, pile);
108 set_without_low_res->AddTiling(0.25, layer_bounds); 116 set_without_low_res->AddTiling(0.25, pile);
109 117
110 higher_than_high_res_range = set_without_low_res->GetTilingRange( 118 higher_than_high_res_range = set_without_low_res->GetTilingRange(
111 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 119 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
112 EXPECT_EQ(0u, higher_than_high_res_range.start); 120 EXPECT_EQ(0u, higher_than_high_res_range.start);
113 EXPECT_EQ(1u, higher_than_high_res_range.end); 121 EXPECT_EQ(1u, higher_than_high_res_range.end);
114 122
115 high_res_range = 123 high_res_range =
116 set_without_low_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES); 124 set_without_low_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES);
117 EXPECT_EQ(1u, high_res_range.start); 125 EXPECT_EQ(1u, high_res_range.start);
118 EXPECT_EQ(2u, high_res_range.end); 126 EXPECT_EQ(2u, high_res_range.end);
119 127
120 between_high_and_low_res_range = set_without_low_res->GetTilingRange( 128 between_high_and_low_res_range = set_without_low_res->GetTilingRange(
121 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES); 129 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
122 EXPECT_EQ(2u, between_high_and_low_res_range.start); 130 EXPECT_EQ(2u, between_high_and_low_res_range.start);
123 EXPECT_EQ(4u, between_high_and_low_res_range.end); 131 EXPECT_EQ(4u, between_high_and_low_res_range.end);
124 132
125 low_res_range = 133 low_res_range =
126 set_without_low_res->GetTilingRange(PictureLayerTilingSet::LOW_RES); 134 set_without_low_res->GetTilingRange(PictureLayerTilingSet::LOW_RES);
127 EXPECT_EQ(0u, low_res_range.end - low_res_range.start); 135 EXPECT_EQ(0u, low_res_range.end - low_res_range.start);
128 136
129 lower_than_low_res_range = set_without_low_res->GetTilingRange( 137 lower_than_low_res_range = set_without_low_res->GetTilingRange(
130 PictureLayerTilingSet::LOWER_THAN_LOW_RES); 138 PictureLayerTilingSet::LOWER_THAN_LOW_RES);
131 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); 139 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
132 140
133 auto set_with_only_high_and_low_res = CreateTilingSet(&client); 141 scoped_ptr<PictureLayerTilingSet> set_with_only_high_and_low_res =
134 high_res_tiling = 142 CreateTilingSet(&client);
135 set_with_only_high_and_low_res->AddTiling(1.0, layer_bounds); 143 high_res_tiling = set_with_only_high_and_low_res->AddTiling(1.0, pile);
136 high_res_tiling->set_resolution(HIGH_RESOLUTION); 144 high_res_tiling->set_resolution(HIGH_RESOLUTION);
137 low_res_tiling = set_with_only_high_and_low_res->AddTiling(0.5, layer_bounds); 145 low_res_tiling = set_with_only_high_and_low_res->AddTiling(0.5, pile);
138 low_res_tiling->set_resolution(LOW_RESOLUTION); 146 low_res_tiling->set_resolution(LOW_RESOLUTION);
139 147
140 higher_than_high_res_range = set_with_only_high_and_low_res->GetTilingRange( 148 higher_than_high_res_range = set_with_only_high_and_low_res->GetTilingRange(
141 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 149 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
142 EXPECT_EQ(0u, 150 EXPECT_EQ(0u,
143 higher_than_high_res_range.end - higher_than_high_res_range.start); 151 higher_than_high_res_range.end - higher_than_high_res_range.start);
144 152
145 high_res_range = set_with_only_high_and_low_res->GetTilingRange( 153 high_res_range = set_with_only_high_and_low_res->GetTilingRange(
146 PictureLayerTilingSet::HIGH_RES); 154 PictureLayerTilingSet::HIGH_RES);
147 EXPECT_EQ(0u, high_res_range.start); 155 EXPECT_EQ(0u, high_res_range.start);
148 EXPECT_EQ(1u, high_res_range.end); 156 EXPECT_EQ(1u, high_res_range.end);
149 157
150 between_high_and_low_res_range = 158 between_high_and_low_res_range =
151 set_with_only_high_and_low_res->GetTilingRange( 159 set_with_only_high_and_low_res->GetTilingRange(
152 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES); 160 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
153 EXPECT_EQ(0u, between_high_and_low_res_range.end - 161 EXPECT_EQ(0u, between_high_and_low_res_range.end -
154 between_high_and_low_res_range.start); 162 between_high_and_low_res_range.start);
155 163
156 low_res_range = set_with_only_high_and_low_res->GetTilingRange( 164 low_res_range = set_with_only_high_and_low_res->GetTilingRange(
157 PictureLayerTilingSet::LOW_RES); 165 PictureLayerTilingSet::LOW_RES);
158 EXPECT_EQ(1u, low_res_range.start); 166 EXPECT_EQ(1u, low_res_range.start);
159 EXPECT_EQ(2u, low_res_range.end); 167 EXPECT_EQ(2u, low_res_range.end);
160 168
161 lower_than_low_res_range = set_with_only_high_and_low_res->GetTilingRange( 169 lower_than_low_res_range = set_with_only_high_and_low_res->GetTilingRange(
162 PictureLayerTilingSet::LOWER_THAN_LOW_RES); 170 PictureLayerTilingSet::LOWER_THAN_LOW_RES);
163 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); 171 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
164 172
165 auto set_with_only_high_res = CreateTilingSet(&client); 173 scoped_ptr<PictureLayerTilingSet> set_with_only_high_res =
166 high_res_tiling = set_with_only_high_res->AddTiling(1.0, layer_bounds); 174 CreateTilingSet(&client);
175 high_res_tiling = set_with_only_high_res->AddTiling(1.0, pile);
167 high_res_tiling->set_resolution(HIGH_RESOLUTION); 176 high_res_tiling->set_resolution(HIGH_RESOLUTION);
168 177
169 higher_than_high_res_range = set_with_only_high_res->GetTilingRange( 178 higher_than_high_res_range = set_with_only_high_res->GetTilingRange(
170 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 179 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
171 EXPECT_EQ(0u, 180 EXPECT_EQ(0u,
172 higher_than_high_res_range.end - higher_than_high_res_range.start); 181 higher_than_high_res_range.end - higher_than_high_res_range.start);
173 182
174 high_res_range = 183 high_res_range =
175 set_with_only_high_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES); 184 set_with_only_high_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES);
176 EXPECT_EQ(0u, high_res_range.start); 185 EXPECT_EQ(0u, high_res_range.start);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 NULL, 220 NULL,
212 NULL, 221 NULL,
213 0, 222 0,
214 false, 223 false,
215 1); 224 1);
216 225
217 FakePictureLayerTilingClient client(resource_provider.get()); 226 FakePictureLayerTilingClient client(resource_provider.get());
218 client.SetTileSize(gfx::Size(256, 256)); 227 client.SetTileSize(gfx::Size(256, 256));
219 client.set_tree(PENDING_TREE); 228 client.set_tree(PENDING_TREE);
220 gfx::Size layer_bounds(1000, 800); 229 gfx::Size layer_bounds(1000, 800);
221 auto set = CreateTilingSet(&client); 230 scoped_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client);
231 scoped_refptr<FakePicturePileImpl> pile =
232 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds);
222 233
223 float scale = min_scale; 234 float scale = min_scale;
224 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) { 235 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) {
225 PictureLayerTiling* tiling = set->AddTiling(scale, layer_bounds); 236 PictureLayerTiling* tiling = set->AddTiling(scale, pile);
226 tiling->CreateAllTilesForTesting(); 237 tiling->CreateAllTilesForTesting();
227 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 238 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
228 client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 239 client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
229 } 240 }
230 241
231 float max_contents_scale = scale; 242 float max_contents_scale = scale;
232 gfx::Size content_bounds( 243 gfx::Size content_bounds(
233 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, max_contents_scale))); 244 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, max_contents_scale)));
234 gfx::Rect content_rect(content_bounds); 245 gfx::Rect content_rect(content_bounds);
235 246
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 291 }
281 292
282 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_Equal) { 293 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_Equal) {
283 runTest(10, 1.f, 1.f, 5.f, 5.f); 294 runTest(10, 1.f, 1.f, 5.f, 5.f);
284 } 295 }
285 296
286 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_NotEqual) { 297 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_NotEqual) {
287 runTest(10, 1.f, 1.f, 4.5f, 5.f); 298 runTest(10, 1.f, 1.f, 4.5f, 5.f);
288 } 299 }
289 300
290 class PictureLayerTilingSetSyncTest : public testing::Test { 301 TEST(PictureLayerTilingSetTest, TileSizeChange) {
291 public: 302 FakePictureLayerTilingClient pending_client;
292 PictureLayerTilingSetSyncTest() 303 FakePictureLayerTilingClient active_client;
293 : tile_size_(gfx::Size(10, 10)), 304 scoped_ptr<PictureLayerTilingSet> pending_set =
294 source_bounds_(gfx::Size(30, 20)), 305 PictureLayerTilingSet::Create(&pending_client, 1000, 1.f, 1000);
295 target_bounds_(gfx::Size(30, 30)) { 306 scoped_ptr<PictureLayerTilingSet> active_set =
296 source_client_.SetTileSize(tile_size_); 307 PictureLayerTilingSet::Create(&active_client, 1000, 1.f, 1000);
297 source_client_.set_tree(PENDING_TREE);
298 target_client_.SetTileSize(tile_size_);
299 target_client_.set_tree(PENDING_TREE);
300 source_ = CreateTilingSet(&source_client_);
301 target_ = CreateTilingSet(&target_client_);
302 }
303 308
304 // Sync from source to target. 309 gfx::Size layer_bounds(100, 100);
305 void SyncTilings(const gfx::Size& new_bounds, 310 scoped_refptr<FakePicturePileImpl> pile =
306 const Region& invalidation, 311 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds);
307 float minimum_scale) {
308 for (size_t i = 0; i < source_->num_tilings(); ++i)
309 source_->tiling_at(i)->CreateAllTilesForTesting();
310 for (size_t i = 0; i < target_->num_tilings(); ++i)
311 target_->tiling_at(i)->CreateAllTilesForTesting();
312 312
313 target_->SyncTilingsForTesting(*source_.get(), new_bounds, invalidation, 313 gfx::Size tile_size1(10, 10);
314 minimum_scale, 314 gfx::Size tile_size2(30, 30);
315 target_client_.raster_source()); 315 gfx::Size tile_size3(20, 20);
316 }
317 void SyncTilings(const gfx::Size& new_bounds) {
318 Region invalidation;
319 SyncTilings(new_bounds, invalidation, 0.f);
320 }
321 void SyncTilings(const gfx::Size& new_bounds, const Region& invalidation) {
322 SyncTilings(new_bounds, invalidation, 0.f);
323 }
324 void SyncTilings(const gfx::Size& new_bounds, float minimum_scale) {
325 Region invalidation;
326 SyncTilings(new_bounds, invalidation, minimum_scale);
327 }
328 316
329 void VerifyTargetEqualsSource(const gfx::Size& new_bounds) { 317 pending_client.SetTileSize(tile_size1);
330 ASSERT_FALSE(new_bounds.IsEmpty()); 318 pending_set->AddTiling(1.f, pile);
331 EXPECT_EQ(target_->num_tilings(), source_->num_tilings()); 319 // New tilings get the correct tile size.
320 EXPECT_EQ(tile_size1, pending_set->tiling_at(0)->tile_size());
332 321
333 for (size_t i = 0; i < target_->num_tilings(); ++i) { 322 // Set some expected things for the tiling set to function.
334 ASSERT_GT(source_->num_tilings(), i); 323 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
335 const PictureLayerTiling* source_tiling = source_->tiling_at(i); 324 active_client.set_twin_tiling_set(pending_set.get());
336 const PictureLayerTiling* target_tiling = target_->tiling_at(i);
337 EXPECT_EQ(target_tiling->layer_bounds().ToString(),
338 new_bounds.ToString());
339 EXPECT_EQ(source_tiling->contents_scale(),
340 target_tiling->contents_scale());
341 }
342 325
343 EXPECT_EQ(source_->client(), &source_client_); 326 // Set a priority rect so we get tiles.
344 EXPECT_EQ(target_->client(), &target_client_); 327 pending_set->UpdateTilePriorities(gfx::Rect(layer_bounds), 1.f, 1.0,
345 ValidateTargetTilingSet(); 328 Occlusion(), false);
346 } 329 EXPECT_EQ(tile_size1, pending_set->tiling_at(0)->tile_size());
347 330
348 void ValidateTargetTilingSet() { 331 // The tiles should get the correct size.
349 // Tilings should be sorted largest to smallest. 332 std::vector<Tile*> pending_tiles =
350 if (target_->num_tilings() > 0) { 333 pending_set->tiling_at(0)->AllTilesForTesting();
351 float last_scale = target_->tiling_at(0)->contents_scale(); 334 EXPECT_GT(pending_tiles.size(), 0u);
352 for (size_t i = 1; i < target_->num_tilings(); ++i) { 335 for (const auto& tile : pending_tiles)
353 const PictureLayerTiling* target_tiling = target_->tiling_at(i); 336 EXPECT_EQ(tile_size1, tile->content_rect().size());
354 EXPECT_LT(target_tiling->contents_scale(), last_scale);
355 last_scale = target_tiling->contents_scale();
356 }
357 }
358 337
359 for (size_t i = 0; i < target_->num_tilings(); ++i) 338 // Update to a new source frame with a new tile size.
360 ValidateTiling(target_->tiling_at(i), target_client_.raster_source()); 339 pending_client.SetTileSize(tile_size2);
361 } 340 pending_set->UpdateTilingsToCurrentRasterSource(pile.get(), nullptr, Region(),
341 1.f, 1.f);
342 // The tiling should get the correct tile size.
343 EXPECT_EQ(tile_size2, pending_set->tiling_at(0)->tile_size());
362 344
363 void ValidateTiling(const PictureLayerTiling* tiling, 345 // Set a priority rect so we get tiles.
364 const RasterSource* raster_source) { 346 pending_set->UpdateTilePriorities(gfx::Rect(layer_bounds), 1.f, 2.0,
365 if (tiling->tiling_size().IsEmpty()) { 347 Occlusion(), false);
366 EXPECT_TRUE(tiling->live_tiles_rect().IsEmpty()); 348 EXPECT_EQ(tile_size2, pending_set->tiling_at(0)->tile_size());
367 } else if (!tiling->live_tiles_rect().IsEmpty()) {
368 gfx::Rect tiling_rect(tiling->tiling_size());
369 EXPECT_TRUE(tiling_rect.Contains(tiling->live_tiles_rect()));
370 }
371 349
372 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 350 // Tiles should have the new correct size.
373 for (size_t i = 0; i < tiles.size(); ++i) { 351 pending_tiles = pending_set->tiling_at(0)->AllTilesForTesting();
374 const Tile* tile = tiles[i]; 352 EXPECT_GT(pending_tiles.size(), 0u);
375 ASSERT_TRUE(!!tile); 353 for (const auto& tile : pending_tiles)
376 EXPECT_EQ(tile->raster_source(), raster_source); 354 EXPECT_EQ(tile_size2, tile->content_rect().size());
377 EXPECT_TRUE(tile->content_rect().Intersects(tiling->live_tiles_rect()))
378 << "All tiles must be inside the live tiles rect."
379 << " Tile rect: " << tile->content_rect().ToString()
380 << " Live rect: " << tiling->live_tiles_rect().ToString()
381 << " Scale: " << tiling->contents_scale();
382 }
383 355
384 for (PictureLayerTiling::CoverageIterator iter( 356 // Clone from the pending to the active tree.
385 tiling, tiling->contents_scale(), tiling->live_tiles_rect()); 357 active_client.SetTileSize(tile_size2);
386 iter; 358 active_set->UpdateTilingsToCurrentRasterSource(pile.get(), pending_set.get(),
387 ++iter) { 359 Region(), 1.f, 1.f);
388 EXPECT_TRUE(*iter) << "The live tiles rect must be full."; 360 // The active tiling should get the right tile size.
389 } 361 EXPECT_EQ(tile_size2, active_set->tiling_at(0)->tile_size());
390 }
391 362
392 gfx::Size tile_size_; 363 // Cloned tiles should have the right size.
364 std::vector<Tile*> active_tiles =
365 active_set->tiling_at(0)->AllTilesForTesting();
366 EXPECT_GT(active_tiles.size(), 0u);
367 for (const auto& tile : active_tiles)
368 EXPECT_EQ(tile_size2, tile->content_rect().size());
393 369
394 FakePictureLayerTilingClient source_client_; 370 // A new source frame with a new tile size.
395 gfx::Size source_bounds_; 371 pending_client.SetTileSize(tile_size3);
396 scoped_ptr<PictureLayerTilingSet> source_; 372 pending_set->UpdateTilingsToCurrentRasterSource(pile.get(), nullptr, Region(),
373 1.f, 1.f);
374 // The tiling gets the new size correctly.
375 EXPECT_EQ(tile_size3, pending_set->tiling_at(0)->tile_size());
397 376
398 FakePictureLayerTilingClient target_client_; 377 // Set a priority rect so we get tiles.
399 gfx::Size target_bounds_; 378 pending_set->UpdateTilePriorities(gfx::Rect(layer_bounds), 1.f, 3.0,
400 scoped_ptr<PictureLayerTilingSet> target_; 379 Occlusion(), false);
401 }; 380 EXPECT_EQ(tile_size3, pending_set->tiling_at(0)->tile_size());
402 381
403 TEST_F(PictureLayerTilingSetSyncTest, EmptyBounds) { 382 // Tiles are resized for the new size.
404 float source_scales[] = {1.f, 1.2f}; 383 pending_tiles = pending_set->tiling_at(0)->AllTilesForTesting();
405 for (size_t i = 0; i < arraysize(source_scales); ++i) 384 EXPECT_GT(pending_tiles.size(), 0u);
406 source_->AddTiling(source_scales[i], source_bounds_); 385 for (const auto& tile : pending_tiles)
386 EXPECT_EQ(tile_size3, tile->content_rect().size());
407 387
408 gfx::Size empty_bounds; 388 // Now we activate with a different tile size for the active tiling.
409 SyncTilings(empty_bounds); 389 active_client.SetTileSize(tile_size3);
410 EXPECT_EQ(target_->num_tilings(), 0u); 390 active_set->UpdateTilingsToCurrentRasterSource(pile.get(), pending_set.get(),
391 Region(), 1.f, 1.f);
392 // The active tiling changes its tile size.
393 EXPECT_EQ(tile_size3, active_set->tiling_at(0)->tile_size());
394
395 // And its tiles are resized.
396 active_tiles = active_set->tiling_at(0)->AllTilesForTesting();
397 EXPECT_GT(active_tiles.size(), 0u);
398 for (const auto& tile : active_tiles)
399 EXPECT_EQ(tile_size3, tile->content_rect().size());
411 } 400 }
412 401
413 TEST_F(PictureLayerTilingSetSyncTest, AllNew) { 402 TEST(PictureLayerTilingSetTest, MaxContentScale) {
414 float source_scales[] = {0.5f, 1.f, 1.2f}; 403 FakePictureLayerTilingClient pending_client;
415 for (size_t i = 0; i < arraysize(source_scales); ++i) 404 FakePictureLayerTilingClient active_client;
416 source_->AddTiling(source_scales[i], source_bounds_); 405 scoped_ptr<PictureLayerTilingSet> pending_set =
417 float target_scales[] = {0.75f, 1.4f, 3.f}; 406 PictureLayerTilingSet::Create(&pending_client, 1000, 1.f, 1000);
418 for (size_t i = 0; i < arraysize(target_scales); ++i) 407 scoped_ptr<PictureLayerTilingSet> active_set =
419 target_->AddTiling(target_scales[i], target_bounds_); 408 PictureLayerTilingSet::Create(&active_client, 1000, 1.f, 1000);
420 409
421 gfx::Size new_bounds(15, 40); 410 gfx::Size layer_bounds(100, 105);
422 SyncTilings(new_bounds); 411 scoped_refptr<FakePicturePileImpl> pile =
423 VerifyTargetEqualsSource(new_bounds); 412 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(layer_bounds);
424 }
425 413
426 Tile* FindTileAtOrigin(PictureLayerTiling* tiling) { 414 // Tilings can be added of any scale, the tiling client can controls this.
427 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 415 pending_set->AddTiling(1.f, pile);
428 for (size_t i = 0; i < tiles.size(); ++i) { 416 pending_set->AddTiling(2.f, pile);
429 if (tiles[i]->content_rect().origin() == gfx::Point()) 417 pending_set->AddTiling(3.f, pile);
430 return tiles[i];
431 }
432 return NULL;
433 }
434 418
435 TEST_F(PictureLayerTilingSetSyncTest, KeepExisting) { 419 // Set some expected things for the tiling set to function.
436 float source_scales[] = {0.7f, 1.f, 1.1f, 2.f}; 420 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
437 for (size_t i = 0; i < arraysize(source_scales); ++i) 421 active_client.set_twin_tiling_set(pending_set.get());
438 source_->AddTiling(source_scales[i], source_bounds_);
439 float target_scales[] = {0.5f, 1.f, 2.f};
440 for (size_t i = 0; i < arraysize(target_scales); ++i)
441 target_->AddTiling(target_scales[i], target_bounds_);
442 422
443 PictureLayerTiling* tiling1 = source_->FindTilingWithScale(1.f); 423 // Update to a new source frame with a max content scale that is larger than
444 ASSERT_TRUE(tiling1); 424 // everything.
445 tiling1->CreateAllTilesForTesting(); 425 float max_content_scale = 3.f;
446 EXPECT_EQ(tiling1->contents_scale(), 1.f); 426 pending_set->UpdateTilingsToCurrentRasterSource(pile.get(), nullptr, Region(),
447 Tile* tile1 = FindTileAtOrigin(tiling1); 427 1.f, max_content_scale);
448 ASSERT_TRUE(tile1); 428 // All the tilings are there still.
429 EXPECT_EQ(3u, pending_set->num_tilings());
449 430
450 PictureLayerTiling* tiling2 = source_->FindTilingWithScale(2.f); 431 // Clone from the pending to the active tree with the same max content size.
451 tiling2->CreateAllTilesForTesting(); 432 active_set->UpdateTilingsToCurrentRasterSource(
452 ASSERT_TRUE(tiling2); 433 pile.get(), pending_set.get(), Region(), 1.f, max_content_scale);
453 EXPECT_EQ(tiling2->contents_scale(), 2.f); 434 // All the tilings are on the active tree.
454 Tile* tile2 = FindTileAtOrigin(tiling2); 435 EXPECT_EQ(3u, active_set->num_tilings());
455 ASSERT_TRUE(tile2);
456 436
457 gfx::Size new_bounds(15, 40); 437 // Update to a new source frame with a max content scale that will drop one
458 SyncTilings(new_bounds); 438 // tiling.
459 VerifyTargetEqualsSource(new_bounds); 439 max_content_scale = 2.9f;
440 pending_set->UpdateTilingsToCurrentRasterSource(pile.get(), nullptr, Region(),
441 1.f, max_content_scale);
442 // All the tilings are there still.
443 EXPECT_EQ(2u, pending_set->num_tilings());
460 444
461 EXPECT_EQ(tiling1, source_->FindTilingWithScale(1.f)); 445 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
462 EXPECT_EQ(tile1, FindTileAtOrigin(tiling1));
463 EXPECT_FALSE(tiling1->live_tiles_rect().IsEmpty());
464 446
465 EXPECT_EQ(tiling2, source_->FindTilingWithScale(2.f)); 447 // Clone from the pending to the active tree with the same max content size.
466 EXPECT_EQ(tile2, FindTileAtOrigin(tiling2)); 448 active_set->UpdateTilingsToCurrentRasterSource(
467 EXPECT_FALSE(tiling2->live_tiles_rect().IsEmpty()); 449 pile.get(), pending_set.get(), Region(), 1.f, max_content_scale);
468 } 450 // All the tilings are on the active tree.
469 451 EXPECT_EQ(2u, active_set->num_tilings());
470 TEST_F(PictureLayerTilingSetSyncTest, EmptySet) {
471 float target_scales[] = {0.2f, 1.f};
472 for (size_t i = 0; i < arraysize(target_scales); ++i)
473 target_->AddTiling(target_scales[i], target_bounds_);
474
475 gfx::Size new_bounds(15, 40);
476 SyncTilings(new_bounds);
477 VerifyTargetEqualsSource(new_bounds);
478 }
479
480 TEST_F(PictureLayerTilingSetSyncTest, MinimumScale) {
481 float source_scales[] = {0.7f, 1.f, 1.1f, 2.f};
482 for (size_t i = 0; i < arraysize(source_scales); ++i)
483 source_->AddTiling(source_scales[i], source_bounds_);
484 float target_scales[] = {0.5f, 0.7f, 1.f, 1.1f, 2.f};
485 for (size_t i = 0; i < arraysize(target_scales); ++i)
486 target_->AddTiling(target_scales[i], target_bounds_);
487
488 gfx::Size new_bounds(15, 40);
489 float minimum_scale = 1.5f;
490 SyncTilings(new_bounds, minimum_scale);
491
492 EXPECT_EQ(target_->num_tilings(), 1u);
493 EXPECT_EQ(target_->tiling_at(0)->contents_scale(), 2.f);
494 ValidateTargetTilingSet();
495 }
496
497 TEST_F(PictureLayerTilingSetSyncTest, Invalidation) {
498 source_->AddTiling(2.f, source_bounds_);
499 target_->AddTiling(2.f, target_bounds_);
500 target_->tiling_at(0)->CreateAllTilesForTesting();
501
502 Region layer_invalidation;
503 layer_invalidation.Union(gfx::Rect(0, 0, 1, 1));
504 layer_invalidation.Union(gfx::Rect(0, 15, 1, 1));
505 // Out of bounds layer_invalidation.
506 layer_invalidation.Union(gfx::Rect(100, 100, 1, 1));
507
508 Region content_invalidation;
509 for (Region::Iterator iter(layer_invalidation); iter.has_rect();
510 iter.next()) {
511 gfx::Rect content_rect = gfx::ScaleToEnclosingRect(iter.rect(), 2.f);
512 content_invalidation.Union(content_rect);
513 }
514
515 std::vector<Tile*> old_tiles = target_->tiling_at(0)->AllTilesForTesting();
516 std::map<gfx::Point, scoped_refptr<Tile>> old_tile_map;
517 for (size_t i = 0; i < old_tiles.size(); ++i)
518 old_tile_map[old_tiles[i]->content_rect().origin()] = old_tiles[i];
519
520 SyncTilings(target_bounds_, layer_invalidation);
521 VerifyTargetEqualsSource(target_bounds_);
522
523 std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting();
524 for (size_t i = 0; i < new_tiles.size(); ++i) {
525 const Tile* tile = new_tiles[i];
526 std::map<gfx::Point, scoped_refptr<Tile>>::iterator find =
527 old_tile_map.find(tile->content_rect().origin());
528 if (content_invalidation.Intersects(tile->content_rect()))
529 EXPECT_NE(tile, find->second.get());
530 else
531 EXPECT_EQ(tile, find->second.get());
532 }
533 }
534
535 TEST_F(PictureLayerTilingSetSyncTest, TileSizeChange) {
536 source_->AddTiling(1.f, source_bounds_);
537 target_->AddTiling(1.f, target_bounds_);
538
539 target_->tiling_at(0)->CreateAllTilesForTesting();
540 std::vector<Tile*> original_tiles =
541 target_->tiling_at(0)->AllTilesForTesting();
542 EXPECT_GT(original_tiles.size(), 0u);
543 gfx::Size new_tile_size(100, 100);
544 target_client_.SetTileSize(new_tile_size);
545 EXPECT_NE(target_->tiling_at(0)->tile_size().ToString(),
546 new_tile_size.ToString());
547
548 gfx::Size new_bounds(15, 40);
549 SyncTilings(new_bounds);
550 VerifyTargetEqualsSource(new_bounds);
551
552 EXPECT_EQ(target_->tiling_at(0)->tile_size().ToString(),
553 new_tile_size.ToString());
554
555 // All old tiles should not be present in new tiles.
556 std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting();
557 for (size_t i = 0; i < original_tiles.size(); ++i) {
558 std::vector<Tile*>::iterator find =
559 std::find(new_tiles.begin(), new_tiles.end(), original_tiles[i]);
560 EXPECT_TRUE(find == new_tiles.end());
561 }
562 } 452 }
563 453
564 } // namespace 454 } // namespace
565 } // namespace cc 455 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698