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

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
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
498 scoped_refptr<FakeRasterSource> raster_source =
499 FakeRasterSource::CreateFilled(layer_bounds);
500 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
501 CreateTilingSetWithSettings(&client, settings);
502
503 EXPECT_FALSE(tiling_set->TilingsNeedUpdate(viewport, 1.0));
504 tiling_set->AddTiling(1.f, raster_source);
505 EXPECT_TRUE(tiling_set->TilingsNeedUpdate(viewport, 1.0));
506
507 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
508
509 // Move viewport down 50 pixels in 0.5 seconds.
510 gfx::Rect down_skewport =
511 tiling_set->ComputeSkewport(gfx::Rect(0, 50, 100, 100), 1.5, 1.f);
512
513 EXPECT_EQ(0, down_skewport.x());
514 EXPECT_EQ(50, down_skewport.y());
515 EXPECT_EQ(100, down_skewport.width());
516 EXPECT_EQ(175, down_skewport.height());
517 EXPECT_TRUE(down_skewport.Contains(gfx::Rect(0, 50, 100, 100)));
518
519 // Move viewport down 50 and right 10 pixels.
520 gfx::Rect down_right_skewport =
521 tiling_set->ComputeSkewport(gfx::Rect(10, 50, 100, 100), 1.5, 1.f);
522
523 EXPECT_EQ(10, down_right_skewport.x());
524 EXPECT_EQ(50, down_right_skewport.y());
525 EXPECT_EQ(120, down_right_skewport.width());
526 EXPECT_EQ(175, down_right_skewport.height());
527 EXPECT_TRUE(down_right_skewport.Contains(gfx::Rect(10, 50, 100, 100)));
528
529 // Move viewport left.
530 gfx::Rect left_skewport =
531 tiling_set->ComputeSkewport(gfx::Rect(-50, 0, 100, 100), 1.5, 1.f);
532
533 EXPECT_EQ(-125, left_skewport.x());
534 EXPECT_EQ(0, left_skewport.y());
535 EXPECT_EQ(175, left_skewport.width());
536 EXPECT_EQ(100, left_skewport.height());
537 EXPECT_TRUE(left_skewport.Contains(gfx::Rect(-50, 0, 100, 100)));
538
539 // Expand viewport.
540 gfx::Rect expand_skewport =
541 tiling_set->ComputeSkewport(gfx::Rect(-50, -50, 200, 200), 1.5, 1.f);
542
543 // x and y moved by -75 (-50 - 75 = -125).
544 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75].
545 EXPECT_EQ(-125, expand_skewport.x());
546 EXPECT_EQ(-125, expand_skewport.y());
547 EXPECT_EQ(350, expand_skewport.width());
548 EXPECT_EQ(350, expand_skewport.height());
549 EXPECT_TRUE(expand_skewport.Contains(gfx::Rect(-50, -50, 200, 200)));
550
551 // Expand the viewport past the limit in all directions.
552 gfx::Rect big_expand_skewport =
553 tiling_set->ComputeSkewport(gfx::Rect(-500, -500, 1500, 1500), 1.5, 1.f);
554
555 EXPECT_EQ(-575, big_expand_skewport.x());
556 EXPECT_EQ(-575, big_expand_skewport.y());
557 EXPECT_EQ(1650, big_expand_skewport.width());
558 EXPECT_EQ(1650, big_expand_skewport.height());
559 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500)));
560
561 // Shrink the skewport in all directions.
562 gfx::Rect shrink_viewport =
563 tiling_set->ComputeSkewport(gfx::Rect(0, 0, 100, 100), 1.5, 1.f);
564 EXPECT_EQ(0, shrink_viewport.x());
565 EXPECT_EQ(0, shrink_viewport.y());
566 EXPECT_EQ(100, shrink_viewport.width());
567 EXPECT_EQ(100, shrink_viewport.height());
568
569 // Move the skewport really far in one direction.
570 gfx::Rect move_skewport_far =
571 tiling_set->ComputeSkewport(gfx::Rect(0, 5000, 100, 100), 1.5, 1.f);
572 EXPECT_EQ(0, move_skewport_far.x());
573 EXPECT_EQ(5000, move_skewport_far.y());
574 EXPECT_EQ(100, move_skewport_far.width());
575 EXPECT_EQ(175, move_skewport_far.height());
576 EXPECT_TRUE(move_skewport_far.Contains(gfx::Rect(0, 5000, 100, 100)));
577 }
578
579 TEST(PictureLayerTilingSetTest, ComputeSkewportExtremeCases) {
580 FakePictureLayerTilingClient client;
581
582 gfx::Size layer_bounds(200, 200);
583 client.SetTileSize(gfx::Size(100, 100));
584 LayerTreeSettings settings;
585 scoped_refptr<FakeRasterSource> raster_source =
586 FakeRasterSource::CreateFilled(layer_bounds);
587 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
588 CreateTilingSet(&client);
589 tiling_set->AddTiling(1.f, raster_source);
590
591 gfx::Rect viewport1(-1918, 255860, 4010, 2356);
592 gfx::Rect viewport2(-7088, -91738, 14212, 8350);
593 gfx::Rect viewport3(-12730024, -158883296, 24607540, 14454512);
594 double time = 1.0;
595 tiling_set->UpdateTilePriorities(viewport1, 1.f, time, Occlusion(), true);
596 time += 0.016;
597 EXPECT_TRUE(
598 tiling_set->ComputeSkewport(viewport2, time, 1.f).Contains(viewport2));
599 tiling_set->UpdateTilePriorities(viewport2, 1.f, time, Occlusion(), true);
600 time += 0.016;
601 EXPECT_TRUE(
602 tiling_set->ComputeSkewport(viewport3, time, 1.f).Contains(viewport3));
603
604 // Use a tiling with a large scale, so the viewport times the scale no longer
605 // fits into integers, and the viewport is not anywhere close to the tiling.
606 PictureLayerTiling* tiling = tiling_set->AddTiling(1000.f, raster_source);
607 EXPECT_TRUE(tiling_set->TilingsNeedUpdate(viewport3, time));
608 tiling_set->UpdateTilePriorities(viewport3, 1.f, time, Occlusion(), true);
609 EXPECT_EQ(gfx::Rect(), tiling->GetCurrentVisibleRectForTesting());
610 }
611
612 TEST(PictureLayerTilingSetTest, ComputeSkewport) {
613 FakePictureLayerTilingClient client;
614
615 gfx::Rect viewport(0, 0, 100, 100);
616 gfx::Size layer_bounds(200, 200);
617
618 client.SetTileSize(gfx::Size(100, 100));
619
620 scoped_refptr<FakeRasterSource> raster_source =
621 FakeRasterSource::CreateFilled(layer_bounds);
622 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
623 CreateTilingSet(&client);
624 tiling_set->AddTiling(1.f, raster_source);
625
626 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
627
628 // Move viewport down 50 pixels in 0.5 seconds.
629 gfx::Rect down_skewport =
630 tiling_set->ComputeSkewport(gfx::Rect(0, 50, 100, 100), 1.5, 1.f);
631
632 EXPECT_EQ(0, down_skewport.x());
633 EXPECT_EQ(50, down_skewport.y());
634 EXPECT_EQ(100, down_skewport.width());
635 EXPECT_EQ(200, down_skewport.height());
636
637 // Shrink viewport.
638 gfx::Rect shrink_skewport =
639 tiling_set->ComputeSkewport(gfx::Rect(25, 25, 50, 50), 1.5, 1.f);
640
641 EXPECT_EQ(25, shrink_skewport.x());
642 EXPECT_EQ(25, shrink_skewport.y());
643 EXPECT_EQ(50, shrink_skewport.width());
644 EXPECT_EQ(50, shrink_skewport.height());
645
646 // Move viewport down 50 and right 10 pixels.
647 gfx::Rect down_right_skewport =
648 tiling_set->ComputeSkewport(gfx::Rect(10, 50, 100, 100), 1.5, 1.f);
649
650 EXPECT_EQ(10, down_right_skewport.x());
651 EXPECT_EQ(50, down_right_skewport.y());
652 EXPECT_EQ(120, down_right_skewport.width());
653 EXPECT_EQ(200, down_right_skewport.height());
654
655 // Move viewport left.
656 gfx::Rect left_skewport =
657 tiling_set->ComputeSkewport(gfx::Rect(-20, 0, 100, 100), 1.5, 1.f);
658
659 EXPECT_EQ(-60, left_skewport.x());
660 EXPECT_EQ(0, left_skewport.y());
661 EXPECT_EQ(140, left_skewport.width());
662 EXPECT_EQ(100, left_skewport.height());
663
664 // Expand viewport in 0.2 seconds.
665 gfx::Rect expanded_skewport =
666 tiling_set->ComputeSkewport(gfx::Rect(-5, -5, 110, 110), 1.2, 1.f);
667
668 EXPECT_EQ(-30, expanded_skewport.x());
669 EXPECT_EQ(-30, expanded_skewport.y());
670 EXPECT_EQ(160, expanded_skewport.width());
671 EXPECT_EQ(160, expanded_skewport.height());
672 }
673
674 TEST(PictureLayerTilingSetTest, SkewportThroughUpdateTilePriorities) {
675 FakePictureLayerTilingClient client;
676
677 gfx::Rect viewport(0, 0, 100, 100);
678 gfx::Size layer_bounds(200, 200);
679
680 client.SetTileSize(gfx::Size(100, 100));
681
682 scoped_refptr<FakeRasterSource> raster_source =
683 FakeRasterSource::CreateFilled(layer_bounds);
684 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
685 CreateTilingSet(&client);
686 tiling_set->AddTiling(1.f, raster_source);
687
688 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
689
690 // Move viewport down 50 pixels in 0.5 seconds.
691 gfx::Rect viewport_50 = gfx::Rect(0, 50, 100, 100);
692 gfx::Rect skewport_50 = tiling_set->ComputeSkewport(viewport_50, 1.5, 1.f);
693
694 EXPECT_EQ(gfx::Rect(0, 50, 100, 200), skewport_50);
695 tiling_set->UpdateTilePriorities(viewport_50, 1.f, 1.5, Occlusion(), true);
696
697 gfx::Rect viewport_100 = gfx::Rect(0, 100, 100, 100);
698 gfx::Rect skewport_100 = tiling_set->ComputeSkewport(viewport_100, 2.0, 1.f);
699
700 EXPECT_EQ(gfx::Rect(0, 100, 100, 200), skewport_100);
701 tiling_set->UpdateTilePriorities(viewport_100, 1.f, 2.0, Occlusion(), true);
702
703 // Advance time, but not the viewport.
704 gfx::Rect result = tiling_set->ComputeSkewport(viewport_100, 2.5, 1.f);
705 // Since the history did advance, we should still get a skewport but a smaller
706 // one.
707 EXPECT_EQ(gfx::Rect(0, 100, 100, 150), result);
708 tiling_set->UpdateTilePriorities(viewport_100, 1.f, 2.5, Occlusion(), true);
709
710 // Advance time again.
711 result = tiling_set->ComputeSkewport(viewport_100, 3.0, 1.f);
712 EXPECT_EQ(viewport_100, result);
713 tiling_set->UpdateTilePriorities(viewport_100, 1.f, 3.0, Occlusion(), true);
714
715 // Ensure we have a skewport.
716 gfx::Rect viewport_150 = gfx::Rect(0, 150, 100, 100);
717 gfx::Rect skewport_150 = tiling_set->ComputeSkewport(viewport_150, 3.5, 1.f);
718 EXPECT_EQ(gfx::Rect(0, 150, 100, 150), skewport_150);
719 tiling_set->UpdateTilePriorities(viewport_150, 1.f, 3.5, Occlusion(), true);
720
721 // Advance the viewport, but not the time.
722 gfx::Rect viewport_200 = gfx::Rect(0, 200, 100, 100);
723 gfx::Rect skewport_200 = tiling_set->ComputeSkewport(viewport_200, 3.5, 1.f);
724 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200);
725
726 // Ensure that continued calls with the same value, produce the same skewport.
727 tiling_set->UpdateTilePriorities(viewport_150, 1.f, 3.5, Occlusion(), true);
728 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200);
729 tiling_set->UpdateTilePriorities(viewport_150, 1.f, 3.5, Occlusion(), true);
730 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200);
731
732 tiling_set->UpdateTilePriorities(viewport_200, 1.f, 3.5, Occlusion(), true);
733
734 // This should never happen, but advance the viewport yet again keeping the
735 // time the same.
736 gfx::Rect viewport_250 = gfx::Rect(0, 250, 100, 100);
737 gfx::Rect skewport_250 = tiling_set->ComputeSkewport(viewport_250, 3.5, 1.f);
738 EXPECT_EQ(viewport_250, skewport_250);
739 tiling_set->UpdateTilePriorities(viewport_250, 1.f, 3.5, Occlusion(), true);
740 }
741
742 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) {
743 FakePictureLayerTilingClient client;
744
745 gfx::Rect viewport(0, 0, 100, 100);
746 gfx::Size layer_bounds(1500, 1500);
747
748 client.SetTileSize(gfx::Size(10, 10));
749 LayerTreeSettings settings;
750
751 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10.
752 // The reason is that each tile has a one pixel border, so tile at (1, 2)
753 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at
754 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the
755 // tiling.
756 scoped_refptr<FakeRasterSource> raster_source =
757 FakeRasterSource::CreateFilled(layer_bounds);
758 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
759 CreateTilingSet(&client);
760 auto* tiling = tiling_set->AddTiling(0.25f, raster_source);
761 tiling->set_resolution(HIGH_RESOLUTION);
762 gfx::Rect viewport_in_content_space =
763 gfx::ScaleToEnclosedRect(viewport, 0.25f);
764
765 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
766 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
767
768 // Compute the soon border.
769 gfx::Rect soon_border_rect_in_content_space =
770 tiling_set->ComputeSoonBorderRect(viewport, 1.f);
771 soon_border_rect_in_content_space =
772 gfx::ScaleToEnclosedRect(soon_border_rect_in_content_space, 0.25f);
773
774 // Sanity checks.
775 for (int i = 0; i < 47; ++i) {
776 for (int j = 0; j < 47; ++j) {
777 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j;
778 }
779 }
780 for (int i = 0; i < 47; ++i) {
781 EXPECT_FALSE(tiling->TileAt(i, 47)) << "i: " << i;
782 EXPECT_FALSE(tiling->TileAt(47, i)) << "i: " << i;
783 }
784
785 // No movement in the viewport implies that tiles will either be NOW
786 // or EVENTUALLY, with the exception of tiles that are between 0 and 312
787 // pixels away from the viewport, which will be in the SOON bin.
788 bool have_now = false;
789 bool have_eventually = false;
790 bool have_soon = false;
791 for (int i = 0; i < 47; ++i) {
792 for (int j = 0; j < 47; ++j) {
793 Tile* tile = tiling->TileAt(i, j);
794 PrioritizedTile prioritized_tile = prioritized_tiles[tile];
795 TilePriority priority = prioritized_tile.priority();
796
797 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j);
798 if (viewport_in_content_space.Intersects(tile_rect)) {
799 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
800 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
801 have_now = true;
802 } else if (soon_border_rect_in_content_space.Intersects(tile_rect)) {
803 EXPECT_EQ(TilePriority::SOON, priority.priority_bin);
804 have_soon = true;
805 } else {
806 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin);
807 EXPECT_GT(priority.distance_to_visible, 0.f);
808 have_eventually = true;
809 }
810 }
811 }
812
813 EXPECT_TRUE(have_now);
814 EXPECT_TRUE(have_soon);
815 EXPECT_TRUE(have_eventually);
816
817 // Spot check some distances.
818 // Tile at 5, 1 should begin at 41x9 in content space (without borders),
819 // so the distance to a viewport that ends at 25x25 in content space
820 // should be 17 (41 - 25 + 1). In layer space, then that should be
821 // 17 / 0.25 = 68 pixels.
822
823 // We can verify that the content rect (with borders) is one pixel off
824 // 41,9 8x8 on all sides.
825 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10");
826
827 TilePriority priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
828 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
829
830 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
831 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
832
833 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
834 EXPECT_FLOAT_EQ(40.f, priority.distance_to_visible);
835
836 // Move the viewport down 40 pixels.
837 viewport = gfx::Rect(0, 40, 100, 100);
838 viewport_in_content_space = gfx::ScaleToEnclosedRect(viewport, 0.25f);
839 gfx::Rect skewport_in_content_space =
840 tiling_set->ComputeSkewport(viewport, 2.0, 1.f);
841 skewport_in_content_space =
842 gfx::ScaleToEnclosedRect(skewport_in_content_space, 0.25f);
843
844 // Compute the soon border.
845 soon_border_rect_in_content_space =
846 tiling_set->ComputeSoonBorderRect(viewport, 1.f);
847 soon_border_rect_in_content_space =
848 gfx::ScaleToEnclosedRect(soon_border_rect_in_content_space, 0.25f);
849
850 EXPECT_EQ(0, skewport_in_content_space.x());
851 EXPECT_EQ(10, skewport_in_content_space.y());
852 EXPECT_EQ(25, skewport_in_content_space.width());
853 EXPECT_EQ(35, skewport_in_content_space.height());
854
855 EXPECT_TRUE(tiling_set->TilingsNeedUpdate(viewport, 2.0));
856 tiling_set->UpdateTilePriorities(viewport, 1.f, 2.0, Occlusion(), true);
857 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
858
859 have_now = false;
860 have_eventually = false;
861 have_soon = false;
862
863 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
864 // some EVENTUALLY tiles.
865 for (int i = 0; i < 47; ++i) {
866 for (int j = 0; j < 47; ++j) {
867 Tile* tile = tiling->TileAt(i, j);
868 TilePriority priority = prioritized_tiles[tile].priority();
869
870 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j);
871 if (viewport_in_content_space.Intersects(tile_rect)) {
872 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i
873 << " j: " << j;
874 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i
875 << " j: " << j;
876 have_now = true;
877 } else if (skewport_in_content_space.Intersects(tile_rect) ||
878 soon_border_rect_in_content_space.Intersects(tile_rect)) {
879 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i
880 << " j: " << j;
881 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
882 << " j: " << j;
883 have_soon = true;
884 } else {
885 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin)
886 << "i: " << i << " j: " << j;
887 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
888 << " j: " << j;
889 have_eventually = true;
890 }
891 }
892 }
893
894 EXPECT_TRUE(have_now);
895 EXPECT_TRUE(have_soon);
896 EXPECT_TRUE(have_eventually);
897
898 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
899 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
900
901 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
902 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible);
903
904 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
905 EXPECT_FLOAT_EQ(4.f, priority.distance_to_visible);
906
907 // Change the underlying layer scale.
908 tiling_set->UpdateTilePriorities(viewport, 2.0f, 3.0, Occlusion(), true);
909 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
910
911 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
912 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible);
913
914 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
915 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible);
916
917 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
918 EXPECT_FLOAT_EQ(8.f, priority.distance_to_visible);
919
920 // Test additional scales.
921 tiling = tiling_set->AddTiling(0.2f, raster_source);
922 tiling->set_resolution(HIGH_RESOLUTION);
923 tiling_set->UpdateTilePriorities(viewport, 1.0f, 4.0, Occlusion(), true);
924 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
925
926 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
927 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible);
928
929 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
930 EXPECT_FLOAT_EQ(70.f, priority.distance_to_visible);
931
932 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
933 EXPECT_FLOAT_EQ(60.f, priority.distance_to_visible);
934
935 tiling_set->UpdateTilePriorities(viewport, 0.5f, 5.0, Occlusion(), true);
936 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
937
938 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
939 EXPECT_FLOAT_EQ(55.f, priority.distance_to_visible);
940
941 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
942 EXPECT_FLOAT_EQ(35.f, priority.distance_to_visible);
943
944 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
945 EXPECT_FLOAT_EQ(30.f, priority.distance_to_visible);
946 }
947
948 TEST(PictureLayerTilingTest, InvalidateAfterComputeTilePriorityRects) {
949 FakePictureLayerTilingClient pending_client;
950 pending_client.SetTileSize(gfx::Size(100, 100));
951
952 scoped_refptr<FakeRasterSource> raster_source =
953 FakeRasterSource::CreateFilled(gfx::Size(100, 100));
954 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
955 CreateTilingSet(&pending_client);
956 auto* pending_tiling = tiling_set->AddTiling(1.f, raster_source);
957 pending_tiling->set_resolution(HIGH_RESOLUTION);
958
959 // Ensure that we can compute tile priority rects, invalidate, and compute the
960 // rects again. It is important that the second compute tile priority rects
961 // return true, indicating that things have changed (since invalidation has
962 // changed things). This causes PrepareTiles to be properly scheduled. If the
963 // second ComputeTilePriorityRects returns false, then we assume that
964 // PrepareTiles isn't needed and we signal that we're ready to draw
965 // immediately, which can cause visual glitches.
966 //
967 // This can happen we if we process an impl frame deadline before processing a
968 // commit. That is, when we draw we ComputeTilePriorityRects. If we process
969 // the commit afterwards, it would use the same timestamp and sometimes would
970 // use the same viewport to compute tile priority rects again.
971 double time = 1.;
972 gfx::Rect viewport(0, 0, 100, 100);
973 EXPECT_TRUE(
974 tiling_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
975 EXPECT_FALSE(
976 tiling_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
977
978 // This will invalidate tilings.
979 tiling_set->UpdateRasterSourceDueToLCDChange(raster_source, Region());
980
981 EXPECT_TRUE(
982 tiling_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
983 }
984
463 } // namespace 985 } // namespace
464 } // namespace cc 986 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698