OLD | NEW |
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/tiles/picture_layer_tiling_set.h" | 5 #include "cc/tiles/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_raster_source.h" | 14 #include "cc/test/fake_raster_source.h" |
15 #include "cc/test/fake_resource_provider.h" | 15 #include "cc/test/fake_resource_provider.h" |
16 #include "cc/test/test_shared_bitmap_manager.h" | 16 #include "cc/test/test_shared_bitmap_manager.h" |
17 #include "cc/trees/layer_tree_settings.h" | 17 #include "cc/trees/layer_tree_settings.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/gfx/geometry/size_conversions.h" | 19 #include "ui/gfx/geometry/size_conversions.h" |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 namespace { | 22 namespace { |
23 | 23 |
24 scoped_ptr<PictureLayerTilingSet> CreateTilingSet( | 24 std::unique_ptr<PictureLayerTilingSet> CreateTilingSet( |
25 PictureLayerTilingClient* client) { | 25 PictureLayerTilingClient* client) { |
26 LayerTreeSettings defaults; | 26 LayerTreeSettings defaults; |
27 return PictureLayerTilingSet::Create( | 27 return PictureLayerTilingSet::Create( |
28 ACTIVE_TREE, client, defaults.tiling_interest_area_padding, | 28 ACTIVE_TREE, client, defaults.tiling_interest_area_padding, |
29 defaults.skewport_target_time_in_seconds, | 29 defaults.skewport_target_time_in_seconds, |
30 defaults.skewport_extrapolation_limit_in_content_pixels); | 30 defaults.skewport_extrapolation_limit_in_content_pixels); |
31 } | 31 } |
32 | 32 |
33 TEST(PictureLayerTilingSetTest, NoResources) { | 33 TEST(PictureLayerTilingSetTest, NoResources) { |
34 FakePictureLayerTilingClient client; | 34 FakePictureLayerTilingClient client; |
35 gfx::Size layer_bounds(1000, 800); | 35 gfx::Size layer_bounds(1000, 800); |
36 scoped_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client); | 36 std::unique_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client); |
37 client.SetTileSize(gfx::Size(256, 256)); | 37 client.SetTileSize(gfx::Size(256, 256)); |
38 | 38 |
39 scoped_refptr<FakeRasterSource> raster_source = | 39 scoped_refptr<FakeRasterSource> raster_source = |
40 FakeRasterSource::CreateEmpty(layer_bounds); | 40 FakeRasterSource::CreateEmpty(layer_bounds); |
41 | 41 |
42 set->AddTiling(1.0, raster_source); | 42 set->AddTiling(1.0, raster_source); |
43 set->AddTiling(1.5, raster_source); | 43 set->AddTiling(1.5, raster_source); |
44 set->AddTiling(2.0, raster_source); | 44 set->AddTiling(2.0, raster_source); |
45 | 45 |
46 float contents_scale = 2.0; | 46 float contents_scale = 2.0; |
(...skipping 23 matching lines...) Expand all Loading... |
70 PictureLayerTilingSet::TilingRange high_res_range(0, 0); | 70 PictureLayerTilingSet::TilingRange high_res_range(0, 0); |
71 PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0); | 71 PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0); |
72 PictureLayerTilingSet::TilingRange low_res_range(0, 0); | 72 PictureLayerTilingSet::TilingRange low_res_range(0, 0); |
73 PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0); | 73 PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0); |
74 PictureLayerTiling* high_res_tiling; | 74 PictureLayerTiling* high_res_tiling; |
75 PictureLayerTiling* low_res_tiling; | 75 PictureLayerTiling* low_res_tiling; |
76 | 76 |
77 scoped_refptr<FakeRasterSource> raster_source = | 77 scoped_refptr<FakeRasterSource> raster_source = |
78 FakeRasterSource::CreateFilled(layer_bounds); | 78 FakeRasterSource::CreateFilled(layer_bounds); |
79 | 79 |
80 scoped_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client); | 80 std::unique_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client); |
81 set->AddTiling(2.0, raster_source); | 81 set->AddTiling(2.0, raster_source); |
82 high_res_tiling = set->AddTiling(1.0, raster_source); | 82 high_res_tiling = set->AddTiling(1.0, raster_source); |
83 high_res_tiling->set_resolution(HIGH_RESOLUTION); | 83 high_res_tiling->set_resolution(HIGH_RESOLUTION); |
84 set->AddTiling(0.5, raster_source); | 84 set->AddTiling(0.5, raster_source); |
85 low_res_tiling = set->AddTiling(0.25, raster_source); | 85 low_res_tiling = set->AddTiling(0.25, raster_source); |
86 low_res_tiling->set_resolution(LOW_RESOLUTION); | 86 low_res_tiling->set_resolution(LOW_RESOLUTION); |
87 set->AddTiling(0.125, raster_source); | 87 set->AddTiling(0.125, raster_source); |
88 | 88 |
89 higher_than_high_res_range = | 89 higher_than_high_res_range = |
90 set->GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); | 90 set->GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); |
(...skipping 11 matching lines...) Expand all Loading... |
102 | 102 |
103 low_res_range = set->GetTilingRange(PictureLayerTilingSet::LOW_RES); | 103 low_res_range = set->GetTilingRange(PictureLayerTilingSet::LOW_RES); |
104 EXPECT_EQ(3u, low_res_range.start); | 104 EXPECT_EQ(3u, low_res_range.start); |
105 EXPECT_EQ(4u, low_res_range.end); | 105 EXPECT_EQ(4u, low_res_range.end); |
106 | 106 |
107 lower_than_low_res_range = | 107 lower_than_low_res_range = |
108 set->GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES); | 108 set->GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES); |
109 EXPECT_EQ(4u, lower_than_low_res_range.start); | 109 EXPECT_EQ(4u, lower_than_low_res_range.start); |
110 EXPECT_EQ(5u, lower_than_low_res_range.end); | 110 EXPECT_EQ(5u, lower_than_low_res_range.end); |
111 | 111 |
112 scoped_ptr<PictureLayerTilingSet> set_without_low_res = | 112 std::unique_ptr<PictureLayerTilingSet> set_without_low_res = |
113 CreateTilingSet(&client); | 113 CreateTilingSet(&client); |
114 set_without_low_res->AddTiling(2.0, raster_source); | 114 set_without_low_res->AddTiling(2.0, raster_source); |
115 high_res_tiling = set_without_low_res->AddTiling(1.0, raster_source); | 115 high_res_tiling = set_without_low_res->AddTiling(1.0, raster_source); |
116 high_res_tiling->set_resolution(HIGH_RESOLUTION); | 116 high_res_tiling->set_resolution(HIGH_RESOLUTION); |
117 set_without_low_res->AddTiling(0.5, raster_source); | 117 set_without_low_res->AddTiling(0.5, raster_source); |
118 set_without_low_res->AddTiling(0.25, raster_source); | 118 set_without_low_res->AddTiling(0.25, raster_source); |
119 | 119 |
120 higher_than_high_res_range = set_without_low_res->GetTilingRange( | 120 higher_than_high_res_range = set_without_low_res->GetTilingRange( |
121 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); | 121 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); |
122 EXPECT_EQ(0u, higher_than_high_res_range.start); | 122 EXPECT_EQ(0u, higher_than_high_res_range.start); |
(...skipping 10 matching lines...) Expand all Loading... |
133 EXPECT_EQ(4u, between_high_and_low_res_range.end); | 133 EXPECT_EQ(4u, between_high_and_low_res_range.end); |
134 | 134 |
135 low_res_range = | 135 low_res_range = |
136 set_without_low_res->GetTilingRange(PictureLayerTilingSet::LOW_RES); | 136 set_without_low_res->GetTilingRange(PictureLayerTilingSet::LOW_RES); |
137 EXPECT_EQ(0u, low_res_range.end - low_res_range.start); | 137 EXPECT_EQ(0u, low_res_range.end - low_res_range.start); |
138 | 138 |
139 lower_than_low_res_range = set_without_low_res->GetTilingRange( | 139 lower_than_low_res_range = set_without_low_res->GetTilingRange( |
140 PictureLayerTilingSet::LOWER_THAN_LOW_RES); | 140 PictureLayerTilingSet::LOWER_THAN_LOW_RES); |
141 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); | 141 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); |
142 | 142 |
143 scoped_ptr<PictureLayerTilingSet> set_with_only_high_and_low_res = | 143 std::unique_ptr<PictureLayerTilingSet> set_with_only_high_and_low_res = |
144 CreateTilingSet(&client); | 144 CreateTilingSet(&client); |
145 high_res_tiling = | 145 high_res_tiling = |
146 set_with_only_high_and_low_res->AddTiling(1.0, raster_source); | 146 set_with_only_high_and_low_res->AddTiling(1.0, raster_source); |
147 high_res_tiling->set_resolution(HIGH_RESOLUTION); | 147 high_res_tiling->set_resolution(HIGH_RESOLUTION); |
148 low_res_tiling = | 148 low_res_tiling = |
149 set_with_only_high_and_low_res->AddTiling(0.5, raster_source); | 149 set_with_only_high_and_low_res->AddTiling(0.5, raster_source); |
150 low_res_tiling->set_resolution(LOW_RESOLUTION); | 150 low_res_tiling->set_resolution(LOW_RESOLUTION); |
151 | 151 |
152 higher_than_high_res_range = set_with_only_high_and_low_res->GetTilingRange( | 152 higher_than_high_res_range = set_with_only_high_and_low_res->GetTilingRange( |
153 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); | 153 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); |
(...skipping 13 matching lines...) Expand all Loading... |
167 | 167 |
168 low_res_range = set_with_only_high_and_low_res->GetTilingRange( | 168 low_res_range = set_with_only_high_and_low_res->GetTilingRange( |
169 PictureLayerTilingSet::LOW_RES); | 169 PictureLayerTilingSet::LOW_RES); |
170 EXPECT_EQ(1u, low_res_range.start); | 170 EXPECT_EQ(1u, low_res_range.start); |
171 EXPECT_EQ(2u, low_res_range.end); | 171 EXPECT_EQ(2u, low_res_range.end); |
172 | 172 |
173 lower_than_low_res_range = set_with_only_high_and_low_res->GetTilingRange( | 173 lower_than_low_res_range = set_with_only_high_and_low_res->GetTilingRange( |
174 PictureLayerTilingSet::LOWER_THAN_LOW_RES); | 174 PictureLayerTilingSet::LOWER_THAN_LOW_RES); |
175 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); | 175 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); |
176 | 176 |
177 scoped_ptr<PictureLayerTilingSet> set_with_only_high_res = | 177 std::unique_ptr<PictureLayerTilingSet> set_with_only_high_res = |
178 CreateTilingSet(&client); | 178 CreateTilingSet(&client); |
179 high_res_tiling = set_with_only_high_res->AddTiling(1.0, raster_source); | 179 high_res_tiling = set_with_only_high_res->AddTiling(1.0, raster_source); |
180 high_res_tiling->set_resolution(HIGH_RESOLUTION); | 180 high_res_tiling->set_resolution(HIGH_RESOLUTION); |
181 | 181 |
182 higher_than_high_res_range = set_with_only_high_res->GetTilingRange( | 182 higher_than_high_res_range = set_with_only_high_res->GetTilingRange( |
183 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); | 183 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); |
184 EXPECT_EQ(0u, | 184 EXPECT_EQ(0u, |
185 higher_than_high_res_range.end - higher_than_high_res_range.start); | 185 higher_than_high_res_range.end - higher_than_high_res_range.start); |
186 | 186 |
187 high_res_range = | 187 high_res_range = |
(...skipping 16 matching lines...) Expand all Loading... |
204 } | 204 } |
205 | 205 |
206 class PictureLayerTilingSetTestWithResources : public testing::Test { | 206 class PictureLayerTilingSetTestWithResources : public testing::Test { |
207 public: | 207 public: |
208 void RunTest(int num_tilings, | 208 void RunTest(int num_tilings, |
209 float min_scale, | 209 float min_scale, |
210 float scale_increment, | 210 float scale_increment, |
211 float ideal_contents_scale, | 211 float ideal_contents_scale, |
212 float expected_scale) { | 212 float expected_scale) { |
213 FakeOutputSurfaceClient output_surface_client; | 213 FakeOutputSurfaceClient output_surface_client; |
214 scoped_ptr<FakeOutputSurface> output_surface = | 214 std::unique_ptr<FakeOutputSurface> output_surface = |
215 FakeOutputSurface::Create3d(); | 215 FakeOutputSurface::Create3d(); |
216 CHECK(output_surface->BindToClient(&output_surface_client)); | 216 CHECK(output_surface->BindToClient(&output_surface_client)); |
217 | 217 |
218 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 218 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
219 new TestSharedBitmapManager()); | 219 new TestSharedBitmapManager()); |
220 scoped_ptr<ResourceProvider> resource_provider = | 220 std::unique_ptr<ResourceProvider> resource_provider = |
221 FakeResourceProvider::Create(output_surface.get(), | 221 FakeResourceProvider::Create(output_surface.get(), |
222 shared_bitmap_manager.get()); | 222 shared_bitmap_manager.get()); |
223 | 223 |
224 FakePictureLayerTilingClient client(resource_provider.get()); | 224 FakePictureLayerTilingClient client(resource_provider.get()); |
225 client.SetTileSize(gfx::Size(256, 256)); | 225 client.SetTileSize(gfx::Size(256, 256)); |
226 gfx::Size layer_bounds(1000, 800); | 226 gfx::Size layer_bounds(1000, 800); |
227 scoped_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client); | 227 std::unique_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client); |
228 scoped_refptr<FakeRasterSource> raster_source = | 228 scoped_refptr<FakeRasterSource> raster_source = |
229 FakeRasterSource::CreateFilled(layer_bounds); | 229 FakeRasterSource::CreateFilled(layer_bounds); |
230 | 230 |
231 float scale = min_scale; | 231 float scale = min_scale; |
232 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) { | 232 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) { |
233 PictureLayerTiling* tiling = set->AddTiling(scale, raster_source); | 233 PictureLayerTiling* tiling = set->AddTiling(scale, raster_source); |
234 tiling->set_resolution(HIGH_RESOLUTION); | 234 tiling->set_resolution(HIGH_RESOLUTION); |
235 tiling->CreateAllTilesForTesting(); | 235 tiling->CreateAllTilesForTesting(); |
236 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); | 236 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); |
237 client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); | 237 client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 RunTest(10, 1.f, 1.f, 5.f, 5.f); | 292 RunTest(10, 1.f, 1.f, 5.f, 5.f); |
293 } | 293 } |
294 | 294 |
295 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_NotEqual) { | 295 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_NotEqual) { |
296 RunTest(10, 1.f, 1.f, 4.5f, 5.f); | 296 RunTest(10, 1.f, 1.f, 4.5f, 5.f); |
297 } | 297 } |
298 | 298 |
299 TEST(PictureLayerTilingSetTest, TileSizeChange) { | 299 TEST(PictureLayerTilingSetTest, TileSizeChange) { |
300 FakePictureLayerTilingClient pending_client; | 300 FakePictureLayerTilingClient pending_client; |
301 FakePictureLayerTilingClient active_client; | 301 FakePictureLayerTilingClient active_client; |
302 scoped_ptr<PictureLayerTilingSet> pending_set = PictureLayerTilingSet::Create( | 302 std::unique_ptr<PictureLayerTilingSet> pending_set = |
303 PENDING_TREE, &pending_client, 1000, 1.f, 1000); | 303 PictureLayerTilingSet::Create(PENDING_TREE, &pending_client, 1000, 1.f, |
304 scoped_ptr<PictureLayerTilingSet> active_set = PictureLayerTilingSet::Create( | 304 1000); |
305 ACTIVE_TREE, &active_client, 1000, 1.f, 1000); | 305 std::unique_ptr<PictureLayerTilingSet> active_set = |
| 306 PictureLayerTilingSet::Create(ACTIVE_TREE, &active_client, 1000, 1.f, |
| 307 1000); |
306 | 308 |
307 gfx::Size layer_bounds(100, 100); | 309 gfx::Size layer_bounds(100, 100); |
308 scoped_refptr<FakeRasterSource> raster_source = | 310 scoped_refptr<FakeRasterSource> raster_source = |
309 FakeRasterSource::CreateFilled(layer_bounds); | 311 FakeRasterSource::CreateFilled(layer_bounds); |
310 | 312 |
311 gfx::Size tile_size1(10, 10); | 313 gfx::Size tile_size1(10, 10); |
312 gfx::Size tile_size2(30, 30); | 314 gfx::Size tile_size2(30, 30); |
313 gfx::Size tile_size3(20, 20); | 315 gfx::Size tile_size3(20, 20); |
314 | 316 |
315 pending_client.SetTileSize(tile_size1); | 317 pending_client.SetTileSize(tile_size1); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 // And its tiles are resized. | 401 // And its tiles are resized. |
400 active_tiles = active_set->tiling_at(0)->AllTilesForTesting(); | 402 active_tiles = active_set->tiling_at(0)->AllTilesForTesting(); |
401 EXPECT_GT(active_tiles.size(), 0u); | 403 EXPECT_GT(active_tiles.size(), 0u); |
402 for (const auto& tile : active_tiles) | 404 for (const auto& tile : active_tiles) |
403 EXPECT_EQ(tile_size3, tile->content_rect().size()); | 405 EXPECT_EQ(tile_size3, tile->content_rect().size()); |
404 } | 406 } |
405 | 407 |
406 TEST(PictureLayerTilingSetTest, MaxContentScale) { | 408 TEST(PictureLayerTilingSetTest, MaxContentScale) { |
407 FakePictureLayerTilingClient pending_client; | 409 FakePictureLayerTilingClient pending_client; |
408 FakePictureLayerTilingClient active_client; | 410 FakePictureLayerTilingClient active_client; |
409 scoped_ptr<PictureLayerTilingSet> pending_set = PictureLayerTilingSet::Create( | 411 std::unique_ptr<PictureLayerTilingSet> pending_set = |
410 PENDING_TREE, &pending_client, 1000, 1.f, 1000); | 412 PictureLayerTilingSet::Create(PENDING_TREE, &pending_client, 1000, 1.f, |
411 scoped_ptr<PictureLayerTilingSet> active_set = PictureLayerTilingSet::Create( | 413 1000); |
412 ACTIVE_TREE, &active_client, 1000, 1.f, 1000); | 414 std::unique_ptr<PictureLayerTilingSet> active_set = |
| 415 PictureLayerTilingSet::Create(ACTIVE_TREE, &active_client, 1000, 1.f, |
| 416 1000); |
413 | 417 |
414 gfx::Size layer_bounds(100, 105); | 418 gfx::Size layer_bounds(100, 105); |
415 scoped_refptr<FakeRasterSource> raster_source = | 419 scoped_refptr<FakeRasterSource> raster_source = |
416 FakeRasterSource::CreateEmpty(layer_bounds); | 420 FakeRasterSource::CreateEmpty(layer_bounds); |
417 | 421 |
418 // Tilings can be added of any scale, the tiling client can controls this. | 422 // Tilings can be added of any scale, the tiling client can controls this. |
419 pending_set->AddTiling(1.f, raster_source); | 423 pending_set->AddTiling(1.f, raster_source); |
420 pending_set->AddTiling(2.f, raster_source); | 424 pending_set->AddTiling(2.f, raster_source); |
421 pending_set->AddTiling(3.f, raster_source); | 425 pending_set->AddTiling(3.f, raster_source); |
422 | 426 |
(...skipping 28 matching lines...) Expand all Loading... |
451 | 455 |
452 // Clone from the pending to the active tree with the same max content size. | 456 // Clone from the pending to the active tree with the same max content size. |
453 active_set->UpdateTilingsToCurrentRasterSourceForActivation( | 457 active_set->UpdateTilingsToCurrentRasterSourceForActivation( |
454 raster_source.get(), pending_set.get(), Region(), 1.f, max_content_scale); | 458 raster_source.get(), pending_set.get(), Region(), 1.f, max_content_scale); |
455 // All the tilings are on the active tree. | 459 // All the tilings are on the active tree. |
456 EXPECT_EQ(2u, active_set->num_tilings()); | 460 EXPECT_EQ(2u, active_set->num_tilings()); |
457 } | 461 } |
458 | 462 |
459 } // namespace | 463 } // namespace |
460 } // namespace cc | 464 } // namespace cc |
OLD | NEW |