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

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

Issue 1939963002: cc: Move prepaint region calculations to the tiling set. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « cc/tiles/picture_layer_tiling_set.cc ('k') | cc/tiles/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/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 std::unique_ptr<PictureLayerTilingSet> CreateTilingSet( 24 class TestablePictureLayerTilingSet : public PictureLayerTilingSet {
25 public:
26 TestablePictureLayerTilingSet(
27 WhichTree tree,
28 PictureLayerTilingClient* client,
29 int tiling_interest_area_padding,
30 float skewport_target_time_in_seconds,
31 int skewport_extrapolation_limit_in_screen_pixels)
32 : PictureLayerTilingSet(tree,
33 client,
34 tiling_interest_area_padding,
35 skewport_target_time_in_seconds,
36 skewport_extrapolation_limit_in_screen_pixels) {}
37
38 using PictureLayerTilingSet::ComputeSkewport;
39 using PictureLayerTilingSet::ComputeSoonBorderRect;
40 using PictureLayerTilingSet::TilingsNeedUpdate;
41 };
42
43 std::unique_ptr<TestablePictureLayerTilingSet> CreateTilingSetWithSettings(
44 PictureLayerTilingClient* client,
45 const LayerTreeSettings& settings) {
46 return base::WrapUnique(new TestablePictureLayerTilingSet(
47 ACTIVE_TREE, client, settings.tiling_interest_area_padding,
48 settings.skewport_target_time_in_seconds,
49 settings.skewport_extrapolation_limit_in_screen_pixels));
50 }
51
52 std::unique_ptr<TestablePictureLayerTilingSet> CreateTilingSet(
25 PictureLayerTilingClient* client) { 53 PictureLayerTilingClient* client) {
26 LayerTreeSettings defaults; 54 return CreateTilingSetWithSettings(client, LayerTreeSettings());
27 return PictureLayerTilingSet::Create(
28 ACTIVE_TREE, client, defaults.tiling_interest_area_padding,
29 defaults.skewport_target_time_in_seconds,
30 defaults.skewport_extrapolation_limit_in_content_pixels);
31 } 55 }
32 56
33 TEST(PictureLayerTilingSetTest, NoResources) { 57 TEST(PictureLayerTilingSetTest, NoResources) {
34 FakePictureLayerTilingClient client; 58 FakePictureLayerTilingClient client;
35 gfx::Size layer_bounds(1000, 800); 59 gfx::Size layer_bounds(1000, 800);
36 std::unique_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client); 60 std::unique_ptr<TestablePictureLayerTilingSet> set = CreateTilingSet(&client);
37 client.SetTileSize(gfx::Size(256, 256)); 61 client.SetTileSize(gfx::Size(256, 256));
38 62
39 scoped_refptr<FakeRasterSource> raster_source = 63 scoped_refptr<FakeRasterSource> raster_source =
40 FakeRasterSource::CreateEmpty(layer_bounds); 64 FakeRasterSource::CreateEmpty(layer_bounds);
41 65
42 set->AddTiling(1.0, raster_source); 66 set->AddTiling(1.0, raster_source);
43 set->AddTiling(1.5, raster_source); 67 set->AddTiling(1.5, raster_source);
44 set->AddTiling(2.0, raster_source); 68 set->AddTiling(2.0, raster_source);
45 69
46 float contents_scale = 2.0; 70 float contents_scale = 2.0;
(...skipping 23 matching lines...) Expand all
70 PictureLayerTilingSet::TilingRange high_res_range(0, 0); 94 PictureLayerTilingSet::TilingRange high_res_range(0, 0);
71 PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0); 95 PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0);
72 PictureLayerTilingSet::TilingRange low_res_range(0, 0); 96 PictureLayerTilingSet::TilingRange low_res_range(0, 0);
73 PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0); 97 PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0);
74 PictureLayerTiling* high_res_tiling; 98 PictureLayerTiling* high_res_tiling;
75 PictureLayerTiling* low_res_tiling; 99 PictureLayerTiling* low_res_tiling;
76 100
77 scoped_refptr<FakeRasterSource> raster_source = 101 scoped_refptr<FakeRasterSource> raster_source =
78 FakeRasterSource::CreateFilled(layer_bounds); 102 FakeRasterSource::CreateFilled(layer_bounds);
79 103
80 std::unique_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client); 104 std::unique_ptr<TestablePictureLayerTilingSet> set = CreateTilingSet(&client);
81 set->AddTiling(2.0, raster_source); 105 set->AddTiling(2.0, raster_source);
82 high_res_tiling = set->AddTiling(1.0, raster_source); 106 high_res_tiling = set->AddTiling(1.0, raster_source);
83 high_res_tiling->set_resolution(HIGH_RESOLUTION); 107 high_res_tiling->set_resolution(HIGH_RESOLUTION);
84 set->AddTiling(0.5, raster_source); 108 set->AddTiling(0.5, raster_source);
85 low_res_tiling = set->AddTiling(0.25, raster_source); 109 low_res_tiling = set->AddTiling(0.25, raster_source);
86 low_res_tiling->set_resolution(LOW_RESOLUTION); 110 low_res_tiling->set_resolution(LOW_RESOLUTION);
87 set->AddTiling(0.125, raster_source); 111 set->AddTiling(0.125, raster_source);
88 112
89 higher_than_high_res_range = 113 higher_than_high_res_range =
90 set->GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 114 set->GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
(...skipping 11 matching lines...) Expand all
102 126
103 low_res_range = set->GetTilingRange(PictureLayerTilingSet::LOW_RES); 127 low_res_range = set->GetTilingRange(PictureLayerTilingSet::LOW_RES);
104 EXPECT_EQ(3u, low_res_range.start); 128 EXPECT_EQ(3u, low_res_range.start);
105 EXPECT_EQ(4u, low_res_range.end); 129 EXPECT_EQ(4u, low_res_range.end);
106 130
107 lower_than_low_res_range = 131 lower_than_low_res_range =
108 set->GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES); 132 set->GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES);
109 EXPECT_EQ(4u, lower_than_low_res_range.start); 133 EXPECT_EQ(4u, lower_than_low_res_range.start);
110 EXPECT_EQ(5u, lower_than_low_res_range.end); 134 EXPECT_EQ(5u, lower_than_low_res_range.end);
111 135
112 std::unique_ptr<PictureLayerTilingSet> set_without_low_res = 136 std::unique_ptr<TestablePictureLayerTilingSet> set_without_low_res =
113 CreateTilingSet(&client); 137 CreateTilingSet(&client);
114 set_without_low_res->AddTiling(2.0, raster_source); 138 set_without_low_res->AddTiling(2.0, raster_source);
115 high_res_tiling = set_without_low_res->AddTiling(1.0, raster_source); 139 high_res_tiling = set_without_low_res->AddTiling(1.0, raster_source);
116 high_res_tiling->set_resolution(HIGH_RESOLUTION); 140 high_res_tiling->set_resolution(HIGH_RESOLUTION);
117 set_without_low_res->AddTiling(0.5, raster_source); 141 set_without_low_res->AddTiling(0.5, raster_source);
118 set_without_low_res->AddTiling(0.25, raster_source); 142 set_without_low_res->AddTiling(0.25, raster_source);
119 143
120 higher_than_high_res_range = set_without_low_res->GetTilingRange( 144 higher_than_high_res_range = set_without_low_res->GetTilingRange(
121 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 145 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
122 EXPECT_EQ(0u, higher_than_high_res_range.start); 146 EXPECT_EQ(0u, higher_than_high_res_range.start);
(...skipping 10 matching lines...) Expand all
133 EXPECT_EQ(4u, between_high_and_low_res_range.end); 157 EXPECT_EQ(4u, between_high_and_low_res_range.end);
134 158
135 low_res_range = 159 low_res_range =
136 set_without_low_res->GetTilingRange(PictureLayerTilingSet::LOW_RES); 160 set_without_low_res->GetTilingRange(PictureLayerTilingSet::LOW_RES);
137 EXPECT_EQ(0u, low_res_range.end - low_res_range.start); 161 EXPECT_EQ(0u, low_res_range.end - low_res_range.start);
138 162
139 lower_than_low_res_range = set_without_low_res->GetTilingRange( 163 lower_than_low_res_range = set_without_low_res->GetTilingRange(
140 PictureLayerTilingSet::LOWER_THAN_LOW_RES); 164 PictureLayerTilingSet::LOWER_THAN_LOW_RES);
141 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); 165 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
142 166
143 std::unique_ptr<PictureLayerTilingSet> set_with_only_high_and_low_res = 167 std::unique_ptr<TestablePictureLayerTilingSet>
144 CreateTilingSet(&client); 168 set_with_only_high_and_low_res = CreateTilingSet(&client);
145 high_res_tiling = 169 high_res_tiling =
146 set_with_only_high_and_low_res->AddTiling(1.0, raster_source); 170 set_with_only_high_and_low_res->AddTiling(1.0, raster_source);
147 high_res_tiling->set_resolution(HIGH_RESOLUTION); 171 high_res_tiling->set_resolution(HIGH_RESOLUTION);
148 low_res_tiling = 172 low_res_tiling =
149 set_with_only_high_and_low_res->AddTiling(0.5, raster_source); 173 set_with_only_high_and_low_res->AddTiling(0.5, raster_source);
150 low_res_tiling->set_resolution(LOW_RESOLUTION); 174 low_res_tiling->set_resolution(LOW_RESOLUTION);
151 175
152 higher_than_high_res_range = set_with_only_high_and_low_res->GetTilingRange( 176 higher_than_high_res_range = set_with_only_high_and_low_res->GetTilingRange(
153 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 177 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
154 EXPECT_EQ(0u, 178 EXPECT_EQ(0u,
(...skipping 12 matching lines...) Expand all
167 191
168 low_res_range = set_with_only_high_and_low_res->GetTilingRange( 192 low_res_range = set_with_only_high_and_low_res->GetTilingRange(
169 PictureLayerTilingSet::LOW_RES); 193 PictureLayerTilingSet::LOW_RES);
170 EXPECT_EQ(1u, low_res_range.start); 194 EXPECT_EQ(1u, low_res_range.start);
171 EXPECT_EQ(2u, low_res_range.end); 195 EXPECT_EQ(2u, low_res_range.end);
172 196
173 lower_than_low_res_range = set_with_only_high_and_low_res->GetTilingRange( 197 lower_than_low_res_range = set_with_only_high_and_low_res->GetTilingRange(
174 PictureLayerTilingSet::LOWER_THAN_LOW_RES); 198 PictureLayerTilingSet::LOWER_THAN_LOW_RES);
175 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start); 199 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
176 200
177 std::unique_ptr<PictureLayerTilingSet> set_with_only_high_res = 201 std::unique_ptr<TestablePictureLayerTilingSet> set_with_only_high_res =
178 CreateTilingSet(&client); 202 CreateTilingSet(&client);
179 high_res_tiling = set_with_only_high_res->AddTiling(1.0, raster_source); 203 high_res_tiling = set_with_only_high_res->AddTiling(1.0, raster_source);
180 high_res_tiling->set_resolution(HIGH_RESOLUTION); 204 high_res_tiling->set_resolution(HIGH_RESOLUTION);
181 205
182 higher_than_high_res_range = set_with_only_high_res->GetTilingRange( 206 higher_than_high_res_range = set_with_only_high_res->GetTilingRange(
183 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES); 207 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
184 EXPECT_EQ(0u, 208 EXPECT_EQ(0u,
185 higher_than_high_res_range.end - higher_than_high_res_range.start); 209 higher_than_high_res_range.end - higher_than_high_res_range.start);
186 210
187 high_res_range = 211 high_res_range =
(...skipping 29 matching lines...) Expand all
217 241
218 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( 242 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager(
219 new TestSharedBitmapManager()); 243 new TestSharedBitmapManager());
220 std::unique_ptr<ResourceProvider> resource_provider = 244 std::unique_ptr<ResourceProvider> resource_provider =
221 FakeResourceProvider::Create(output_surface.get(), 245 FakeResourceProvider::Create(output_surface.get(),
222 shared_bitmap_manager.get()); 246 shared_bitmap_manager.get());
223 247
224 FakePictureLayerTilingClient client(resource_provider.get()); 248 FakePictureLayerTilingClient client(resource_provider.get());
225 client.SetTileSize(gfx::Size(256, 256)); 249 client.SetTileSize(gfx::Size(256, 256));
226 gfx::Size layer_bounds(1000, 800); 250 gfx::Size layer_bounds(1000, 800);
227 std::unique_ptr<PictureLayerTilingSet> set = CreateTilingSet(&client); 251 std::unique_ptr<TestablePictureLayerTilingSet> set =
252 CreateTilingSet(&client);
228 scoped_refptr<FakeRasterSource> raster_source = 253 scoped_refptr<FakeRasterSource> raster_source =
229 FakeRasterSource::CreateFilled(layer_bounds); 254 FakeRasterSource::CreateFilled(layer_bounds);
230 255
231 float scale = min_scale; 256 float scale = min_scale;
232 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) { 257 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) {
233 PictureLayerTiling* tiling = set->AddTiling(scale, raster_source); 258 PictureLayerTiling* tiling = set->AddTiling(scale, raster_source);
234 tiling->set_resolution(HIGH_RESOLUTION); 259 tiling->set_resolution(HIGH_RESOLUTION);
235 tiling->CreateAllTilesForTesting(); 260 tiling->CreateAllTilesForTesting();
236 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 261 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
237 client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 262 client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 478
454 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION); 479 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
455 480
456 // Clone from the pending to the active tree with the same max content size. 481 // Clone from the pending to the active tree with the same max content size.
457 active_set->UpdateTilingsToCurrentRasterSourceForActivation( 482 active_set->UpdateTilingsToCurrentRasterSourceForActivation(
458 raster_source.get(), pending_set.get(), Region(), 1.f, max_content_scale); 483 raster_source.get(), pending_set.get(), Region(), 1.f, max_content_scale);
459 // All the tilings are on the active tree. 484 // All the tilings are on the active tree.
460 EXPECT_EQ(2u, active_set->num_tilings()); 485 EXPECT_EQ(2u, active_set->num_tilings());
461 } 486 }
462 487
488 TEST(PictureLayerTilingSetTest, SkewportLimits) {
489 FakePictureLayerTilingClient client;
490
491 gfx::Rect viewport(0, 0, 100, 100);
492 gfx::Size layer_bounds(200, 200);
493
494 client.SetTileSize(gfx::Size(100, 100));
495 LayerTreeSettings settings;
496 settings.skewport_extrapolation_limit_in_screen_pixels = 75;
497 settings.tiling_interest_area_padding = 1000000;
498
499 scoped_refptr<FakeRasterSource> raster_source =
500 FakeRasterSource::CreateFilled(layer_bounds);
501 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
502 CreateTilingSetWithSettings(&client, settings);
503
504 EXPECT_FALSE(tiling_set->TilingsNeedUpdate(viewport, 1.0));
505 tiling_set->AddTiling(1.f, raster_source);
506 EXPECT_TRUE(tiling_set->TilingsNeedUpdate(viewport, 1.0));
507
508 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
509
510 // Move viewport down 50 pixels in 0.5 seconds.
511 gfx::Rect down_skewport =
512 tiling_set->ComputeSkewport(gfx::Rect(0, 50, 100, 100), 1.5, 1.f);
513
514 EXPECT_EQ(0, down_skewport.x());
515 EXPECT_EQ(50, down_skewport.y());
516 EXPECT_EQ(100, down_skewport.width());
517 EXPECT_EQ(175, down_skewport.height());
518 EXPECT_TRUE(down_skewport.Contains(gfx::Rect(0, 50, 100, 100)));
519
520 // Move viewport down 50 and right 10 pixels.
521 gfx::Rect down_right_skewport =
522 tiling_set->ComputeSkewport(gfx::Rect(10, 50, 100, 100), 1.5, 1.f);
523
524 EXPECT_EQ(10, down_right_skewport.x());
525 EXPECT_EQ(50, down_right_skewport.y());
526 EXPECT_EQ(120, down_right_skewport.width());
527 EXPECT_EQ(175, down_right_skewport.height());
528 EXPECT_TRUE(down_right_skewport.Contains(gfx::Rect(10, 50, 100, 100)));
529
530 // Move viewport left.
531 gfx::Rect left_skewport =
532 tiling_set->ComputeSkewport(gfx::Rect(-50, 0, 100, 100), 1.5, 1.f);
533
534 EXPECT_EQ(-125, left_skewport.x());
535 EXPECT_EQ(0, left_skewport.y());
536 EXPECT_EQ(175, left_skewport.width());
537 EXPECT_EQ(100, left_skewport.height());
538 EXPECT_TRUE(left_skewport.Contains(gfx::Rect(-50, 0, 100, 100)));
539
540 // Expand viewport.
541 gfx::Rect expand_skewport =
542 tiling_set->ComputeSkewport(gfx::Rect(-50, -50, 200, 200), 1.5, 1.f);
543
544 // x and y moved by -75 (-50 - 75 = -125).
545 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75].
546 EXPECT_EQ(-125, expand_skewport.x());
547 EXPECT_EQ(-125, expand_skewport.y());
548 EXPECT_EQ(350, expand_skewport.width());
549 EXPECT_EQ(350, expand_skewport.height());
550 EXPECT_TRUE(expand_skewport.Contains(gfx::Rect(-50, -50, 200, 200)));
551
552 // Expand the viewport past the limit in all directions.
553 gfx::Rect big_expand_skewport =
554 tiling_set->ComputeSkewport(gfx::Rect(-500, -500, 1500, 1500), 1.5, 1.f);
555
556 EXPECT_EQ(-575, big_expand_skewport.x());
557 EXPECT_EQ(-575, big_expand_skewport.y());
558 EXPECT_EQ(1650, big_expand_skewport.width());
559 EXPECT_EQ(1650, big_expand_skewport.height());
560 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500)));
561
562 // Shrink the skewport in all directions.
563 gfx::Rect shrink_viewport =
564 tiling_set->ComputeSkewport(gfx::Rect(0, 0, 100, 100), 1.5, 1.f);
565 EXPECT_EQ(0, shrink_viewport.x());
566 EXPECT_EQ(0, shrink_viewport.y());
567 EXPECT_EQ(100, shrink_viewport.width());
568 EXPECT_EQ(100, shrink_viewport.height());
569
570 // Move the skewport really far in one direction.
571 gfx::Rect move_skewport_far =
572 tiling_set->ComputeSkewport(gfx::Rect(0, 5000, 100, 100), 1.5, 1.f);
573 EXPECT_EQ(0, move_skewport_far.x());
574 EXPECT_EQ(5000, move_skewport_far.y());
575 EXPECT_EQ(100, move_skewport_far.width());
576 EXPECT_EQ(175, move_skewport_far.height());
577 EXPECT_TRUE(move_skewport_far.Contains(gfx::Rect(0, 5000, 100, 100)));
578 }
579
580 TEST(PictureLayerTilingSetTest, ComputeSkewportExtremeCases) {
581 FakePictureLayerTilingClient client;
582
583 gfx::Size layer_bounds(200, 200);
584 client.SetTileSize(gfx::Size(100, 100));
585 LayerTreeSettings settings;
586 settings.tiling_interest_area_padding = 1000000000;
587 scoped_refptr<FakeRasterSource> raster_source =
588 FakeRasterSource::CreateFilled(layer_bounds);
589 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
590 CreateTilingSetWithSettings(&client, settings);
591 tiling_set->AddTiling(1.f, raster_source);
592
593 gfx::Rect viewport1(-1918, 255860, 4010, 2356);
594 gfx::Rect viewport2(-7088, -91738, 14212, 8350);
595 gfx::Rect viewport3(-12730024, -158883296, 24607540, 14454512);
596 double time = 1.0;
597 tiling_set->UpdateTilePriorities(viewport1, 1.f, time, Occlusion(), true);
598 time += 0.016;
599 EXPECT_TRUE(
600 tiling_set->ComputeSkewport(viewport2, time, 1.f).Contains(viewport2));
601 tiling_set->UpdateTilePriorities(viewport2, 1.f, time, Occlusion(), true);
602 time += 0.016;
603 EXPECT_TRUE(
604 tiling_set->ComputeSkewport(viewport3, time, 1.f).Contains(viewport3));
605
606 // Use a tiling with a large scale, so the viewport times the scale no longer
607 // fits into integers, and the viewport is not anywhere close to the tiling.
608 PictureLayerTiling* tiling = tiling_set->AddTiling(1000.f, raster_source);
609 EXPECT_TRUE(tiling_set->TilingsNeedUpdate(viewport3, time));
610 tiling_set->UpdateTilePriorities(viewport3, 1.f, time, Occlusion(), true);
611 EXPECT_TRUE(tiling->GetCurrentVisibleRectForTesting().IsEmpty());
612 }
613
614 TEST(PictureLayerTilingSetTest, ComputeSkewport) {
615 FakePictureLayerTilingClient client;
616
617 gfx::Rect viewport(0, 0, 100, 100);
618 gfx::Size layer_bounds(200, 200);
619
620 client.SetTileSize(gfx::Size(100, 100));
621
622 scoped_refptr<FakeRasterSource> raster_source =
623 FakeRasterSource::CreateFilled(layer_bounds);
624 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
625 CreateTilingSet(&client);
626 tiling_set->AddTiling(1.f, raster_source);
627
628 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
629
630 // Move viewport down 50 pixels in 0.5 seconds.
631 gfx::Rect down_skewport =
632 tiling_set->ComputeSkewport(gfx::Rect(0, 50, 100, 100), 1.5, 1.f);
633
634 EXPECT_EQ(0, down_skewport.x());
635 EXPECT_EQ(50, down_skewport.y());
636 EXPECT_EQ(100, down_skewport.width());
637 EXPECT_EQ(200, down_skewport.height());
638
639 // Shrink viewport.
640 gfx::Rect shrink_skewport =
641 tiling_set->ComputeSkewport(gfx::Rect(25, 25, 50, 50), 1.5, 1.f);
642
643 EXPECT_EQ(25, shrink_skewport.x());
644 EXPECT_EQ(25, shrink_skewport.y());
645 EXPECT_EQ(50, shrink_skewport.width());
646 EXPECT_EQ(50, shrink_skewport.height());
647
648 // Move viewport down 50 and right 10 pixels.
649 gfx::Rect down_right_skewport =
650 tiling_set->ComputeSkewport(gfx::Rect(10, 50, 100, 100), 1.5, 1.f);
651
652 EXPECT_EQ(10, down_right_skewport.x());
653 EXPECT_EQ(50, down_right_skewport.y());
654 EXPECT_EQ(120, down_right_skewport.width());
655 EXPECT_EQ(200, down_right_skewport.height());
656
657 // Move viewport left.
658 gfx::Rect left_skewport =
659 tiling_set->ComputeSkewport(gfx::Rect(-20, 0, 100, 100), 1.5, 1.f);
660
661 EXPECT_EQ(-60, left_skewport.x());
662 EXPECT_EQ(0, left_skewport.y());
663 EXPECT_EQ(140, left_skewport.width());
664 EXPECT_EQ(100, left_skewport.height());
665
666 // Expand viewport in 0.2 seconds.
667 gfx::Rect expanded_skewport =
668 tiling_set->ComputeSkewport(gfx::Rect(-5, -5, 110, 110), 1.2, 1.f);
669
670 EXPECT_EQ(-30, expanded_skewport.x());
671 EXPECT_EQ(-30, expanded_skewport.y());
672 EXPECT_EQ(160, expanded_skewport.width());
673 EXPECT_EQ(160, expanded_skewport.height());
674 }
675
676 TEST(PictureLayerTilingSetTest, SkewportThroughUpdateTilePriorities) {
677 FakePictureLayerTilingClient client;
678
679 gfx::Rect viewport(0, 0, 100, 100);
680 gfx::Size layer_bounds(200, 200);
681
682 client.SetTileSize(gfx::Size(100, 100));
683
684 scoped_refptr<FakeRasterSource> raster_source =
685 FakeRasterSource::CreateFilled(layer_bounds);
686 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
687 CreateTilingSet(&client);
688 tiling_set->AddTiling(1.f, raster_source);
689
690 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
691
692 // Move viewport down 50 pixels in 0.5 seconds.
693 gfx::Rect viewport_50 = gfx::Rect(0, 50, 100, 100);
694 gfx::Rect skewport_50 = tiling_set->ComputeSkewport(viewport_50, 1.5, 1.f);
695
696 EXPECT_EQ(gfx::Rect(0, 50, 100, 200), skewport_50);
697 tiling_set->UpdateTilePriorities(viewport_50, 1.f, 1.5, Occlusion(), true);
698
699 gfx::Rect viewport_100 = gfx::Rect(0, 100, 100, 100);
700 gfx::Rect skewport_100 = tiling_set->ComputeSkewport(viewport_100, 2.0, 1.f);
701
702 EXPECT_EQ(gfx::Rect(0, 100, 100, 200), skewport_100);
703 tiling_set->UpdateTilePriorities(viewport_100, 1.f, 2.0, Occlusion(), true);
704
705 // Advance time, but not the viewport.
706 gfx::Rect result = tiling_set->ComputeSkewport(viewport_100, 2.5, 1.f);
707 // Since the history did advance, we should still get a skewport but a smaller
708 // one.
709 EXPECT_EQ(gfx::Rect(0, 100, 100, 150), result);
710 tiling_set->UpdateTilePriorities(viewport_100, 1.f, 2.5, Occlusion(), true);
711
712 // Advance time again.
713 result = tiling_set->ComputeSkewport(viewport_100, 3.0, 1.f);
714 EXPECT_EQ(viewport_100, result);
715 tiling_set->UpdateTilePriorities(viewport_100, 1.f, 3.0, Occlusion(), true);
716
717 // Ensure we have a skewport.
718 gfx::Rect viewport_150 = gfx::Rect(0, 150, 100, 100);
719 gfx::Rect skewport_150 = tiling_set->ComputeSkewport(viewport_150, 3.5, 1.f);
720 EXPECT_EQ(gfx::Rect(0, 150, 100, 150), skewport_150);
721 tiling_set->UpdateTilePriorities(viewport_150, 1.f, 3.5, Occlusion(), true);
722
723 // Advance the viewport, but not the time.
724 gfx::Rect viewport_200 = gfx::Rect(0, 200, 100, 100);
725 gfx::Rect skewport_200 = tiling_set->ComputeSkewport(viewport_200, 3.5, 1.f);
726 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200);
727
728 // Ensure that continued calls with the same value, produce the same skewport.
729 tiling_set->UpdateTilePriorities(viewport_150, 1.f, 3.5, Occlusion(), true);
730 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200);
731 tiling_set->UpdateTilePriorities(viewport_150, 1.f, 3.5, Occlusion(), true);
732 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200);
733
734 tiling_set->UpdateTilePriorities(viewport_200, 1.f, 3.5, Occlusion(), true);
735
736 // This should never happen, but advance the viewport yet again keeping the
737 // time the same.
738 gfx::Rect viewport_250 = gfx::Rect(0, 250, 100, 100);
739 gfx::Rect skewport_250 = tiling_set->ComputeSkewport(viewport_250, 3.5, 1.f);
740 EXPECT_EQ(viewport_250, skewport_250);
741 tiling_set->UpdateTilePriorities(viewport_250, 1.f, 3.5, Occlusion(), true);
742 }
743
744 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) {
745 FakePictureLayerTilingClient client;
746
747 gfx::Rect viewport(0, 0, 100, 100);
748 gfx::Size layer_bounds(1500, 1500);
749
750 client.SetTileSize(gfx::Size(10, 10));
751 LayerTreeSettings settings;
752
753 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10.
754 // The reason is that each tile has a one pixel border, so tile at (1, 2)
755 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at
756 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the
757 // tiling.
758 scoped_refptr<FakeRasterSource> raster_source =
759 FakeRasterSource::CreateFilled(layer_bounds);
760 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
761 CreateTilingSet(&client);
762 auto* tiling = tiling_set->AddTiling(0.25f, raster_source);
763 tiling->set_resolution(HIGH_RESOLUTION);
764 gfx::Rect viewport_in_content_space =
765 gfx::ScaleToEnclosedRect(viewport, 0.25f);
766
767 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
768 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
769
770 // Compute the soon border.
771 gfx::Rect soon_border_rect_in_content_space =
772 tiling_set->ComputeSoonBorderRect(viewport, 1.f);
773 soon_border_rect_in_content_space =
774 gfx::ScaleToEnclosedRect(soon_border_rect_in_content_space, 0.25f);
775
776 // Sanity checks.
777 for (int i = 0; i < 47; ++i) {
778 for (int j = 0; j < 47; ++j) {
779 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j;
780 }
781 }
782 for (int i = 0; i < 47; ++i) {
783 EXPECT_FALSE(tiling->TileAt(i, 47)) << "i: " << i;
784 EXPECT_FALSE(tiling->TileAt(47, i)) << "i: " << i;
785 }
786
787 // No movement in the viewport implies that tiles will either be NOW
788 // or EVENTUALLY, with the exception of tiles that are between 0 and 312
789 // pixels away from the viewport, which will be in the SOON bin.
790 bool have_now = false;
791 bool have_eventually = false;
792 bool have_soon = false;
793 for (int i = 0; i < 47; ++i) {
794 for (int j = 0; j < 47; ++j) {
795 Tile* tile = tiling->TileAt(i, j);
796 PrioritizedTile prioritized_tile = prioritized_tiles[tile];
797 TilePriority priority = prioritized_tile.priority();
798
799 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j);
800 if (viewport_in_content_space.Intersects(tile_rect)) {
801 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
802 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
803 have_now = true;
804 } else if (soon_border_rect_in_content_space.Intersects(tile_rect)) {
805 EXPECT_EQ(TilePriority::SOON, priority.priority_bin);
806 have_soon = true;
807 } else {
808 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin);
809 EXPECT_GT(priority.distance_to_visible, 0.f);
810 have_eventually = true;
811 }
812 }
813 }
814
815 EXPECT_TRUE(have_now);
816 EXPECT_TRUE(have_soon);
817 EXPECT_TRUE(have_eventually);
818
819 // Spot check some distances.
820 // Tile at 5, 1 should begin at 41x9 in content space (without borders),
821 // so the distance to a viewport that ends at 25x25 in content space
822 // should be 17 (41 - 25 + 1). In layer space, then that should be
823 // 17 / 0.25 = 68 pixels.
824
825 // We can verify that the content rect (with borders) is one pixel off
826 // 41,9 8x8 on all sides.
827 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10");
828
829 TilePriority priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
830 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
831
832 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
833 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
834
835 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
836 EXPECT_FLOAT_EQ(40.f, priority.distance_to_visible);
837
838 // Move the viewport down 40 pixels.
839 viewport = gfx::Rect(0, 40, 100, 100);
840 viewport_in_content_space = gfx::ScaleToEnclosedRect(viewport, 0.25f);
841 gfx::Rect skewport_in_content_space =
842 tiling_set->ComputeSkewport(viewport, 2.0, 1.f);
843 skewport_in_content_space =
844 gfx::ScaleToEnclosedRect(skewport_in_content_space, 0.25f);
845
846 // Compute the soon border.
847 soon_border_rect_in_content_space =
848 tiling_set->ComputeSoonBorderRect(viewport, 1.f);
849 soon_border_rect_in_content_space =
850 gfx::ScaleToEnclosedRect(soon_border_rect_in_content_space, 0.25f);
851
852 EXPECT_EQ(0, skewport_in_content_space.x());
853 EXPECT_EQ(10, skewport_in_content_space.y());
854 EXPECT_EQ(25, skewport_in_content_space.width());
855 EXPECT_EQ(35, skewport_in_content_space.height());
856
857 EXPECT_TRUE(tiling_set->TilingsNeedUpdate(viewport, 2.0));
858 tiling_set->UpdateTilePriorities(viewport, 1.f, 2.0, Occlusion(), true);
859 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
860
861 have_now = false;
862 have_eventually = false;
863 have_soon = false;
864
865 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
866 // some EVENTUALLY tiles.
867 for (int i = 0; i < 47; ++i) {
868 for (int j = 0; j < 47; ++j) {
869 Tile* tile = tiling->TileAt(i, j);
870 TilePriority priority = prioritized_tiles[tile].priority();
871
872 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j);
873 if (viewport_in_content_space.Intersects(tile_rect)) {
874 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i
875 << " j: " << j;
876 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i
877 << " j: " << j;
878 have_now = true;
879 } else if (skewport_in_content_space.Intersects(tile_rect) ||
880 soon_border_rect_in_content_space.Intersects(tile_rect)) {
881 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i
882 << " j: " << j;
883 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
884 << " j: " << j;
885 have_soon = true;
886 } else {
887 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin)
888 << "i: " << i << " j: " << j;
889 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
890 << " j: " << j;
891 have_eventually = true;
892 }
893 }
894 }
895
896 EXPECT_TRUE(have_now);
897 EXPECT_TRUE(have_soon);
898 EXPECT_TRUE(have_eventually);
899
900 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
901 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
902
903 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
904 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible);
905
906 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
907 EXPECT_FLOAT_EQ(4.f, priority.distance_to_visible);
908
909 // Change the underlying layer scale.
910 tiling_set->UpdateTilePriorities(viewport, 2.0f, 3.0, Occlusion(), true);
911 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
912
913 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
914 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible);
915
916 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
917 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible);
918
919 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
920 EXPECT_FLOAT_EQ(8.f, priority.distance_to_visible);
921
922 // Test additional scales.
923 tiling = tiling_set->AddTiling(0.2f, raster_source);
924 tiling->set_resolution(HIGH_RESOLUTION);
925 tiling_set->UpdateTilePriorities(viewport, 1.0f, 4.0, Occlusion(), true);
926 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
927
928 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
929 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible);
930
931 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
932 EXPECT_FLOAT_EQ(70.f, priority.distance_to_visible);
933
934 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
935 EXPECT_FLOAT_EQ(60.f, priority.distance_to_visible);
936
937 tiling_set->UpdateTilePriorities(viewport, 0.5f, 5.0, Occlusion(), true);
938 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
939
940 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
941 EXPECT_FLOAT_EQ(55.f, priority.distance_to_visible);
942
943 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
944 EXPECT_FLOAT_EQ(35.f, priority.distance_to_visible);
945
946 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
947 EXPECT_FLOAT_EQ(30.f, priority.distance_to_visible);
948 }
949
950 TEST(PictureLayerTilingTest, InvalidateAfterComputeTilePriorityRects) {
951 FakePictureLayerTilingClient pending_client;
952 pending_client.SetTileSize(gfx::Size(100, 100));
953
954 scoped_refptr<FakeRasterSource> raster_source =
955 FakeRasterSource::CreateFilled(gfx::Size(100, 100));
956 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
957 CreateTilingSet(&pending_client);
958 auto* pending_tiling = tiling_set->AddTiling(1.f, raster_source);
959 pending_tiling->set_resolution(HIGH_RESOLUTION);
960
961 // Ensure that we can compute tile priority rects, invalidate, and compute the
962 // rects again. It is important that the second compute tile priority rects
963 // return true, indicating that things have changed (since invalidation has
964 // changed things). This causes PrepareTiles to be properly scheduled. If the
965 // second ComputeTilePriorityRects returns false, then we assume that
966 // PrepareTiles isn't needed and we signal that we're ready to draw
967 // immediately, which can cause visual glitches.
968 //
969 // This can happen we if we process an impl frame deadline before processing a
970 // commit. That is, when we draw we ComputeTilePriorityRects. If we process
971 // the commit afterwards, it would use the same timestamp and sometimes would
972 // use the same viewport to compute tile priority rects again.
973 double time = 1.;
974 gfx::Rect viewport(0, 0, 100, 100);
975 EXPECT_TRUE(
976 tiling_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
977 EXPECT_FALSE(
978 tiling_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
979
980 // This will invalidate tilings.
981 tiling_set->UpdateRasterSourceDueToLCDChange(raster_source, Region());
982
983 EXPECT_TRUE(
984 tiling_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
985 }
986
463 } // namespace 987 } // namespace
464 } // namespace cc 988 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/picture_layer_tiling_set.cc ('k') | cc/tiles/picture_layer_tiling_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698