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

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

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@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
« no previous file with comments | « cc/resources/picture_layer_tiling_set.cc ('k') | cc/resources/picture_layer_tiling_unittest.cc » ('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_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/test_shared_bitmap_manager.h" 14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/geometry/size_conversions.h" 16 #include "ui/gfx/geometry/size_conversions.h"
17 17
18 namespace cc { 18 namespace cc {
19 namespace { 19 namespace {
20 20
21 scoped_ptr<PictureLayerTilingSet> CreateTilingSet(
22 PictureLayerTilingClient* client) {
23 LayerTreeSettings defaults;
24 return PictureLayerTilingSet::Create(
25 client, defaults.max_tiles_for_interest_area,
26 defaults.skewport_target_time_in_seconds,
27 defaults.skewport_extrapolation_limit_in_content_pixels);
28 }
29
21 TEST(PictureLayerTilingSetTest, NoResources) { 30 TEST(PictureLayerTilingSetTest, NoResources) {
22 FakePictureLayerTilingClient client; 31 FakePictureLayerTilingClient client;
23 gfx::Size layer_bounds(1000, 800); 32 gfx::Size layer_bounds(1000, 800);
24 auto set = PictureLayerTilingSet::Create(&client); 33 auto set = CreateTilingSet(&client);
25 client.SetTileSize(gfx::Size(256, 256)); 34 client.SetTileSize(gfx::Size(256, 256));
26 35
27 set->AddTiling(1.0, layer_bounds); 36 set->AddTiling(1.0, layer_bounds);
28 set->AddTiling(1.5, layer_bounds); 37 set->AddTiling(1.5, layer_bounds);
29 set->AddTiling(2.0, layer_bounds); 38 set->AddTiling(2.0, layer_bounds);
30 39
31 float contents_scale = 2.0; 40 float contents_scale = 2.0;
32 gfx::Size content_bounds( 41 gfx::Size content_bounds(
33 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); 42 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
34 gfx::Rect content_rect(content_bounds); 43 gfx::Rect content_rect(content_bounds);
(...skipping 17 matching lines...) Expand all
52 FakePictureLayerTilingClient client; 61 FakePictureLayerTilingClient client;
53 gfx::Size layer_bounds(10, 10); 62 gfx::Size layer_bounds(10, 10);
54 PictureLayerTilingSet::TilingRange higher_than_high_res_range(0, 0); 63 PictureLayerTilingSet::TilingRange higher_than_high_res_range(0, 0);
55 PictureLayerTilingSet::TilingRange high_res_range(0, 0); 64 PictureLayerTilingSet::TilingRange high_res_range(0, 0);
56 PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0); 65 PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0);
57 PictureLayerTilingSet::TilingRange low_res_range(0, 0); 66 PictureLayerTilingSet::TilingRange low_res_range(0, 0);
58 PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0); 67 PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0);
59 PictureLayerTiling* high_res_tiling; 68 PictureLayerTiling* high_res_tiling;
60 PictureLayerTiling* low_res_tiling; 69 PictureLayerTiling* low_res_tiling;
61 70
62 auto set = PictureLayerTilingSet::Create(&client); 71 auto set = CreateTilingSet(&client);
63 set->AddTiling(2.0, layer_bounds); 72 set->AddTiling(2.0, layer_bounds);
64 high_res_tiling = set->AddTiling(1.0, layer_bounds); 73 high_res_tiling = set->AddTiling(1.0, layer_bounds);
65 high_res_tiling->set_resolution(HIGH_RESOLUTION); 74 high_res_tiling->set_resolution(HIGH_RESOLUTION);
66 set->AddTiling(0.5, layer_bounds); 75 set->AddTiling(0.5, layer_bounds);
67 low_res_tiling = set->AddTiling(0.25, layer_bounds); 76 low_res_tiling = set->AddTiling(0.25, layer_bounds);
68 low_res_tiling->set_resolution(LOW_RESOLUTION); 77 low_res_tiling->set_resolution(LOW_RESOLUTION);
69 set->AddTiling(0.125, layer_bounds); 78 set->AddTiling(0.125, layer_bounds);
70 79
71 higher_than_high_res_range = 80 higher_than_high_res_range =
72 set->GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 81 set->GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
(...skipping 11 matching lines...) Expand all
84 93
85 low_res_range = set->GetTilingRange(PictureLayerTilingSet::LOW_RES); 94 low_res_range = set->GetTilingRange(PictureLayerTilingSet::LOW_RES);
86 EXPECT_EQ(3u, low_res_range.start); 95 EXPECT_EQ(3u, low_res_range.start);
87 EXPECT_EQ(4u, low_res_range.end); 96 EXPECT_EQ(4u, low_res_range.end);
88 97
89 lower_than_low_res_range = 98 lower_than_low_res_range =
90 set->GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES); 99 set->GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES);
91 EXPECT_EQ(4u, lower_than_low_res_range.start); 100 EXPECT_EQ(4u, lower_than_low_res_range.start);
92 EXPECT_EQ(5u, lower_than_low_res_range.end); 101 EXPECT_EQ(5u, lower_than_low_res_range.end);
93 102
94 auto set_without_low_res = PictureLayerTilingSet::Create(&client); 103 auto set_without_low_res = CreateTilingSet(&client);
95 set_without_low_res->AddTiling(2.0, layer_bounds); 104 set_without_low_res->AddTiling(2.0, layer_bounds);
96 high_res_tiling = set_without_low_res->AddTiling(1.0, layer_bounds); 105 high_res_tiling = set_without_low_res->AddTiling(1.0, layer_bounds);
97 high_res_tiling->set_resolution(HIGH_RESOLUTION); 106 high_res_tiling->set_resolution(HIGH_RESOLUTION);
98 set_without_low_res->AddTiling(0.5, layer_bounds); 107 set_without_low_res->AddTiling(0.5, layer_bounds);
99 set_without_low_res->AddTiling(0.25, layer_bounds); 108 set_without_low_res->AddTiling(0.25, layer_bounds);
100 109
101 higher_than_high_res_range = set_without_low_res->GetTilingRange( 110 higher_than_high_res_range = set_without_low_res->GetTilingRange(
102 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 111 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
103 EXPECT_EQ(0u, higher_than_high_res_range.start); 112 EXPECT_EQ(0u, higher_than_high_res_range.start);
104 EXPECT_EQ(1u, higher_than_high_res_range.end); 113 EXPECT_EQ(1u, higher_than_high_res_range.end);
105 114
106 high_res_range = 115 high_res_range =
107 set_without_low_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES); 116 set_without_low_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES);
108 EXPECT_EQ(1u, high_res_range.start); 117 EXPECT_EQ(1u, high_res_range.start);
109 EXPECT_EQ(2u, high_res_range.end); 118 EXPECT_EQ(2u, high_res_range.end);
110 119
111 between_high_and_low_res_range = set_without_low_res->GetTilingRange( 120 between_high_and_low_res_range = set_without_low_res->GetTilingRange(
112 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES); 121 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
113 EXPECT_EQ(2u, between_high_and_low_res_range.start); 122 EXPECT_EQ(2u, between_high_and_low_res_range.start);
114 EXPECT_EQ(4u, between_high_and_low_res_range.end); 123 EXPECT_EQ(4u, between_high_and_low_res_range.end);
115 124
116 low_res_range = 125 low_res_range =
117 set_without_low_res->GetTilingRange(PictureLayerTilingSet::LOW_RES); 126 set_without_low_res->GetTilingRange(PictureLayerTilingSet::LOW_RES);
118 EXPECT_EQ(0u, low_res_range.end - low_res_range.start); 127 EXPECT_EQ(0u, low_res_range.end - low_res_range.start);
119 128
120 lower_than_low_res_range = set_without_low_res->GetTilingRange( 129 lower_than_low_res_range = set_without_low_res->GetTilingRange(
121 PictureLayerTilingSet::LOWER_THAN_LOW_RES); 130 PictureLayerTilingSet::LOWER_THAN_LOW_RES);
122 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); 131 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
123 132
124 auto set_with_only_high_and_low_res = PictureLayerTilingSet::Create(&client); 133 auto set_with_only_high_and_low_res = CreateTilingSet(&client);
125 high_res_tiling = 134 high_res_tiling =
126 set_with_only_high_and_low_res->AddTiling(1.0, layer_bounds); 135 set_with_only_high_and_low_res->AddTiling(1.0, layer_bounds);
127 high_res_tiling->set_resolution(HIGH_RESOLUTION); 136 high_res_tiling->set_resolution(HIGH_RESOLUTION);
128 low_res_tiling = set_with_only_high_and_low_res->AddTiling(0.5, layer_bounds); 137 low_res_tiling = set_with_only_high_and_low_res->AddTiling(0.5, layer_bounds);
129 low_res_tiling->set_resolution(LOW_RESOLUTION); 138 low_res_tiling->set_resolution(LOW_RESOLUTION);
130 139
131 higher_than_high_res_range = set_with_only_high_and_low_res->GetTilingRange( 140 higher_than_high_res_range = set_with_only_high_and_low_res->GetTilingRange(
132 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 141 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
133 EXPECT_EQ(0u, 142 EXPECT_EQ(0u,
134 higher_than_high_res_range.end - higher_than_high_res_range.start); 143 higher_than_high_res_range.end - higher_than_high_res_range.start);
(...skipping 11 matching lines...) Expand all
146 155
147 low_res_range = set_with_only_high_and_low_res->GetTilingRange( 156 low_res_range = set_with_only_high_and_low_res->GetTilingRange(
148 PictureLayerTilingSet::LOW_RES); 157 PictureLayerTilingSet::LOW_RES);
149 EXPECT_EQ(1u, low_res_range.start); 158 EXPECT_EQ(1u, low_res_range.start);
150 EXPECT_EQ(2u, low_res_range.end); 159 EXPECT_EQ(2u, low_res_range.end);
151 160
152 lower_than_low_res_range = set_with_only_high_and_low_res->GetTilingRange( 161 lower_than_low_res_range = set_with_only_high_and_low_res->GetTilingRange(
153 PictureLayerTilingSet::LOWER_THAN_LOW_RES); 162 PictureLayerTilingSet::LOWER_THAN_LOW_RES);
154 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); 163 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
155 164
156 auto set_with_only_high_res = PictureLayerTilingSet::Create(&client); 165 auto set_with_only_high_res = CreateTilingSet(&client);
157 high_res_tiling = set_with_only_high_res->AddTiling(1.0, layer_bounds); 166 high_res_tiling = set_with_only_high_res->AddTiling(1.0, layer_bounds);
158 high_res_tiling->set_resolution(HIGH_RESOLUTION); 167 high_res_tiling->set_resolution(HIGH_RESOLUTION);
159 168
160 higher_than_high_res_range = set_with_only_high_res->GetTilingRange( 169 higher_than_high_res_range = set_with_only_high_res->GetTilingRange(
161 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 170 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
162 EXPECT_EQ(0u, 171 EXPECT_EQ(0u,
163 higher_than_high_res_range.end - higher_than_high_res_range.start); 172 higher_than_high_res_range.end - higher_than_high_res_range.start);
164 173
165 high_res_range = 174 high_res_range =
166 set_with_only_high_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES); 175 set_with_only_high_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 NULL, 211 NULL,
203 NULL, 212 NULL,
204 0, 213 0,
205 false, 214 false,
206 1); 215 1);
207 216
208 FakePictureLayerTilingClient client(resource_provider.get()); 217 FakePictureLayerTilingClient client(resource_provider.get());
209 client.SetTileSize(gfx::Size(256, 256)); 218 client.SetTileSize(gfx::Size(256, 256));
210 client.set_tree(PENDING_TREE); 219 client.set_tree(PENDING_TREE);
211 gfx::Size layer_bounds(1000, 800); 220 gfx::Size layer_bounds(1000, 800);
212 auto set = PictureLayerTilingSet::Create(&client); 221 auto set = CreateTilingSet(&client);
213 222
214 float scale = min_scale; 223 float scale = min_scale;
215 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) { 224 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) {
216 PictureLayerTiling* tiling = set->AddTiling(scale, layer_bounds); 225 PictureLayerTiling* tiling = set->AddTiling(scale, layer_bounds);
217 tiling->CreateAllTilesForTesting(); 226 tiling->CreateAllTilesForTesting();
218 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 227 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
219 client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 228 client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
220 } 229 }
221 230
222 float max_contents_scale = scale; 231 float max_contents_scale = scale;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 class PictureLayerTilingSetSyncTest : public testing::Test { 290 class PictureLayerTilingSetSyncTest : public testing::Test {
282 public: 291 public:
283 PictureLayerTilingSetSyncTest() 292 PictureLayerTilingSetSyncTest()
284 : tile_size_(gfx::Size(10, 10)), 293 : tile_size_(gfx::Size(10, 10)),
285 source_bounds_(gfx::Size(30, 20)), 294 source_bounds_(gfx::Size(30, 20)),
286 target_bounds_(gfx::Size(30, 30)) { 295 target_bounds_(gfx::Size(30, 30)) {
287 source_client_.SetTileSize(tile_size_); 296 source_client_.SetTileSize(tile_size_);
288 source_client_.set_tree(PENDING_TREE); 297 source_client_.set_tree(PENDING_TREE);
289 target_client_.SetTileSize(tile_size_); 298 target_client_.SetTileSize(tile_size_);
290 target_client_.set_tree(PENDING_TREE); 299 target_client_.set_tree(PENDING_TREE);
291 source_ = PictureLayerTilingSet::Create(&source_client_); 300 source_ = CreateTilingSet(&source_client_);
292 target_ = PictureLayerTilingSet::Create(&target_client_); 301 target_ = CreateTilingSet(&target_client_);
293 } 302 }
294 303
295 // Sync from source to target. 304 // Sync from source to target.
296 void SyncTilings(const gfx::Size& new_bounds, 305 void SyncTilings(const gfx::Size& new_bounds,
297 const Region& invalidation, 306 const Region& invalidation,
298 float minimum_scale) { 307 float minimum_scale) {
299 for (size_t i = 0; i < source_->num_tilings(); ++i) 308 for (size_t i = 0; i < source_->num_tilings(); ++i)
300 source_->tiling_at(i)->CreateAllTilesForTesting(); 309 source_->tiling_at(i)->CreateAllTilesForTesting();
301 for (size_t i = 0; i < target_->num_tilings(); ++i) 310 for (size_t i = 0; i < target_->num_tilings(); ++i)
302 target_->tiling_at(i)->CreateAllTilesForTesting(); 311 target_->tiling_at(i)->CreateAllTilesForTesting();
303 312
304 target_->SyncTilings(*source_.get(), new_bounds, invalidation, 313 target_->SyncTilingsForTesting(*source_.get(), new_bounds, invalidation,
305 minimum_scale, target_client_.raster_source()); 314 minimum_scale,
315 target_client_.raster_source());
306 } 316 }
307 void SyncTilings(const gfx::Size& new_bounds) { 317 void SyncTilings(const gfx::Size& new_bounds) {
308 Region invalidation; 318 Region invalidation;
309 SyncTilings(new_bounds, invalidation, 0.f); 319 SyncTilings(new_bounds, invalidation, 0.f);
310 } 320 }
311 void SyncTilings(const gfx::Size& new_bounds, const Region& invalidation) { 321 void SyncTilings(const gfx::Size& new_bounds, const Region& invalidation) {
312 SyncTilings(new_bounds, invalidation, 0.f); 322 SyncTilings(new_bounds, invalidation, 0.f);
313 } 323 }
314 void SyncTilings(const gfx::Size& new_bounds, float minimum_scale) { 324 void SyncTilings(const gfx::Size& new_bounds, float minimum_scale) {
315 Region invalidation; 325 Region invalidation;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting(); 556 std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting();
547 for (size_t i = 0; i < original_tiles.size(); ++i) { 557 for (size_t i = 0; i < original_tiles.size(); ++i) {
548 std::vector<Tile*>::iterator find = 558 std::vector<Tile*>::iterator find =
549 std::find(new_tiles.begin(), new_tiles.end(), original_tiles[i]); 559 std::find(new_tiles.begin(), new_tiles.end(), original_tiles[i]);
550 EXPECT_TRUE(find == new_tiles.end()); 560 EXPECT_TRUE(find == new_tiles.end());
551 } 561 }
552 } 562 }
553 563
554 } // namespace 564 } // namespace
555 } // namespace cc 565 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_layer_tiling_set.cc ('k') | cc/resources/picture_layer_tiling_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698