1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/tiles/picture_layer_tiling_set.h"
10 #include "build/build_config.h"
11 #include "cc/test/fake_output_surface_client.h"
12 #include "cc/test/fake_picture_layer_tiling_client.h"
13 #include "cc/test/fake_raster_source.h"
14 #include "cc/trees/layer_tree_settings.h"
15 #include "components/viz/client/client_resource_provider.h"
16 #include "components/viz/test/fake_output_surface.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/geometry/size_conversions.h"
23 class TestablePictureLayerTilingSet : public PictureLayerTilingSet {
25 TestablePictureLayerTilingSet(
27 PictureLayerTilingClient* client,
28 int tiling_interest_area_padding,
29 float skewport_target_time_in_seconds,
30 int skewport_extrapolation_limit_in_screen_pixels,
31 float max_preraster_distance)
32 : PictureLayerTilingSet(tree,
34 tiling_interest_area_padding,
35 skewport_target_time_in_seconds,
36 skewport_extrapolation_limit_in_screen_pixels,
37 max_preraster_distance) {}
39 using PictureLayerTilingSet::ComputeSkewport;
40 using PictureLayerTilingSet::ComputeSoonBorderRect;
41 using PictureLayerTilingSet::TilingsNeedUpdate;
44 std::unique_ptr<TestablePictureLayerTilingSet> CreateTilingSetWithSettings(
45 PictureLayerTilingClient* client,
46 const LayerTreeSettings& settings) {
47 return std::make_unique<TestablePictureLayerTilingSet>(
48 ACTIVE_TREE, client, settings.tiling_interest_area_padding,
49 settings.skewport_target_time_in_seconds,
50 settings.skewport_extrapolation_limit_in_screen_pixels,
51 settings.max_preraster_distance_in_screen_pixels);
54 std::unique_ptr<TestablePictureLayerTilingSet> CreateTilingSet(
55 PictureLayerTilingClient* client) {
56 return CreateTilingSetWithSettings(client, LayerTreeSettings());
59 TEST(PictureLayerTilingSetTest, NoResources) {
60 FakePictureLayerTilingClient client;
61 gfx::Size layer_bounds(1000, 800);
62 std::unique_ptr<TestablePictureLayerTilingSet> set = CreateTilingSet(&client);
63 client.SetTileSize(gfx::Size(256, 256));
65 scoped_refptr<FakeRasterSource> raster_source =
66 FakeRasterSource::CreateEmpty(layer_bounds);
68 set->AddTiling(gfx::AxisTransform2d(), raster_source);
69 set->AddTiling(gfx::AxisTransform2d(1.5, gfx::Vector2dF()), raster_source);
70 set->AddTiling(gfx::AxisTransform2d(2.0, gfx::Vector2dF()), raster_source);
72 float contents_scale = 2.0;
73 gfx::Size content_bounds(
74 gfx::ScaleToCeiledSize(layer_bounds, contents_scale));
75 gfx::Rect content_rect(content_bounds);
77 Region remaining(content_rect);
78 PictureLayerTilingSet::CoverageIterator iter(set.get(), contents_scale,
79 content_rect, contents_scale);
80 for (; iter; ++iter) {
81 gfx::Rect geometry_rect = iter.geometry_rect();
82 EXPECT_TRUE(content_rect.Contains(geometry_rect));
83 ASSERT_TRUE(remaining.Contains(geometry_rect));
84 remaining.Subtract(geometry_rect);
86 // No tiles have resources, so no iter represents a real tile.
89 EXPECT_TRUE(remaining.IsEmpty());
92 TEST(PictureLayerTilingSetTest, TilingRange) {
93 FakePictureLayerTilingClient client;
94 gfx::Size layer_bounds(10, 10);
95 PictureLayerTilingSet::TilingRange higher_than_high_res_range(0, 0);
96 PictureLayerTilingSet::TilingRange high_res_range(0, 0);
97 PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0);
98 PictureLayerTilingSet::TilingRange low_res_range(0, 0);
99 PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0);
100 PictureLayerTiling* high_res_tiling;
101 PictureLayerTiling* low_res_tiling;
103 scoped_refptr<FakeRasterSource> raster_source =
104 FakeRasterSource::CreateFilled(layer_bounds);
106 std::unique_ptr<TestablePictureLayerTilingSet> set = CreateTilingSet(&client);
107 set->AddTiling(gfx::AxisTransform2d(2.0, gfx::Vector2dF()), raster_source);
108 high_res_tiling = set->AddTiling(gfx::AxisTransform2d(), raster_source);
109 high_res_tiling->set_resolution(HIGH_RESOLUTION);
110 set->AddTiling(gfx::AxisTransform2d(0.5, gfx::Vector2dF()), raster_source);
111 low_res_tiling = set->AddTiling(gfx::AxisTransform2d(0.25, gfx::Vector2dF()),
113 low_res_tiling->set_resolution(LOW_RESOLUTION);
114 set->AddTiling(gfx::AxisTransform2d(0.125, gfx::Vector2dF()), raster_source);
116 higher_than_high_res_range =
117 set->GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
118 EXPECT_EQ(0u, higher_than_high_res_range.start);
119 EXPECT_EQ(1u, higher_than_high_res_range.end);
121 high_res_range = set->GetTilingRange(PictureLayerTilingSet::HIGH_RES);
122 EXPECT_EQ(1u, high_res_range.start);
123 EXPECT_EQ(2u, high_res_range.end);
125 between_high_and_low_res_range =
126 set->GetTilingRange(PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
127 EXPECT_EQ(2u, between_high_and_low_res_range.start);
128 EXPECT_EQ(3u, between_high_and_low_res_range.end);
130 low_res_range = set->GetTilingRange(PictureLayerTilingSet::LOW_RES);
131 EXPECT_EQ(3u, low_res_range.start);
132 EXPECT_EQ(4u, low_res_range.end);
134 lower_than_low_res_range =
135 set->GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES);
136 EXPECT_EQ(4u, lower_than_low_res_range.start);
137 EXPECT_EQ(5u, lower_than_low_res_range.end);
139 std::unique_ptr<TestablePictureLayerTilingSet> set_without_low_res =
140 CreateTilingSet(&client);
141 set_without_low_res->AddTiling(gfx::AxisTransform2d(2.0, gfx::Vector2dF()),
144 set_without_low_res->AddTiling(gfx::AxisTransform2d(), raster_source);
145 high_res_tiling->set_resolution(HIGH_RESOLUTION);
146 set_without_low_res->AddTiling(gfx::AxisTransform2d(0.5, gfx::Vector2dF()),
148 set_without_low_res->AddTiling(gfx::AxisTransform2d(0.25, gfx::Vector2dF()),
151 higher_than_high_res_range = set_without_low_res->GetTilingRange(
152 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
153 EXPECT_EQ(0u, higher_than_high_res_range.start);
154 EXPECT_EQ(1u, higher_than_high_res_range.end);
157 set_without_low_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES);
158 EXPECT_EQ(1u, high_res_range.start);
159 EXPECT_EQ(2u, high_res_range.end);
161 between_high_and_low_res_range = set_without_low_res->GetTilingRange(
162 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
163 EXPECT_EQ(2u, between_high_and_low_res_range.start);
164 EXPECT_EQ(4u, between_high_and_low_res_range.end);
167 set_without_low_res->GetTilingRange(PictureLayerTilingSet::LOW_RES);
168 EXPECT_EQ(0u, low_res_range.end - low_res_range.start);
170 lower_than_low_res_range = set_without_low_res->GetTilingRange(
171 PictureLayerTilingSet::LOWER_THAN_LOW_RES);
172 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
174 std::unique_ptr<TestablePictureLayerTilingSet>
175 set_with_only_high_and_low_res = CreateTilingSet(&client);
176 high_res_tiling = set_with_only_high_and_low_res->AddTiling(
177 gfx::AxisTransform2d(), raster_source);
178 high_res_tiling->set_resolution(HIGH_RESOLUTION);
179 low_res_tiling = set_with_only_high_and_low_res->AddTiling(
180 gfx::AxisTransform2d(0.5, gfx::Vector2dF()), raster_source);
181 low_res_tiling->set_resolution(LOW_RESOLUTION);
183 higher_than_high_res_range = set_with_only_high_and_low_res->GetTilingRange(
184 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
186 higher_than_high_res_range.end - higher_than_high_res_range.start);
188 high_res_range = set_with_only_high_and_low_res->GetTilingRange(
189 PictureLayerTilingSet::HIGH_RES);
190 EXPECT_EQ(0u, high_res_range.start);
191 EXPECT_EQ(1u, high_res_range.end);
193 between_high_and_low_res_range =
194 set_with_only_high_and_low_res->GetTilingRange(
195 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
196 EXPECT_EQ(0u, between_high_and_low_res_range.end -
197 between_high_and_low_res_range.start);
199 low_res_range = set_with_only_high_and_low_res->GetTilingRange(
200 PictureLayerTilingSet::LOW_RES);
201 EXPECT_EQ(1u, low_res_range.start);
202 EXPECT_EQ(2u, low_res_range.end);
204 lower_than_low_res_range = set_with_only_high_and_low_res->GetTilingRange(
205 PictureLayerTilingSet::LOWER_THAN_LOW_RES);
206 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
208 std::unique_ptr<TestablePictureLayerTilingSet> set_with_only_high_res =
209 CreateTilingSet(&client);
211 set_with_only_high_res->AddTiling(gfx::AxisTransform2d(), raster_source);
212 high_res_tiling->set_resolution(HIGH_RESOLUTION);
214 higher_than_high_res_range = set_with_only_high_res->GetTilingRange(
215 PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
217 higher_than_high_res_range.end - higher_than_high_res_range.start);
220 set_with_only_high_res->GetTilingRange(PictureLayerTilingSet::HIGH_RES);
221 EXPECT_EQ(0u, high_res_range.start);
222 EXPECT_EQ(1u, high_res_range.end);
224 between_high_and_low_res_range = set_with_only_high_res->GetTilingRange(
225 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
226 EXPECT_EQ(0u, between_high_and_low_res_range.end -
227 between_high_and_low_res_range.start);
230 set_with_only_high_res->GetTilingRange(PictureLayerTilingSet::LOW_RES);
231 EXPECT_EQ(0u, low_res_range.end - low_res_range.start);
233 lower_than_low_res_range = set_with_only_high_res->GetTilingRange(
234 PictureLayerTilingSet::LOWER_THAN_LOW_RES);
235 EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
238 class PictureLayerTilingSetTestWithResources : public testing::Test {
240 void RunTest(int num_tilings,
242 float scale_increment,
243 float ideal_contents_scale,
244 float expected_scale) {
245 scoped_refptr<viz::TestContextProvider> context_provider =
246 viz::TestContextProvider::Create();
247 ASSERT_EQ(context_provider->BindToCurrentThread(),
248 gpu::ContextResult::kSuccess);
249 std::unique_ptr<viz::ClientResourceProvider> resource_provider =
250 std::make_unique<viz::ClientResourceProvider>();
252 FakePictureLayerTilingClient client(resource_provider.get(),
253 context_provider.get());
254 client.SetTileSize(gfx::Size(256, 256));
255 gfx::Size layer_bounds(1000, 800);
256 std::unique_ptr<TestablePictureLayerTilingSet> set =
257 CreateTilingSet(&client);
258 scoped_refptr<FakeRasterSource> raster_source =
259 FakeRasterSource::CreateFilled(layer_bounds);
261 float scale = min_scale;
262 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) {
263 PictureLayerTiling* tiling = set->AddTiling(
264 gfx::AxisTransform2d(scale, gfx::Vector2dF()), raster_source);
265 tiling->set_resolution(HIGH_RESOLUTION);
266 tiling->CreateAllTilesForTesting();
267 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
268 client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
271 float max_contents_scale = scale;
272 gfx::Size content_bounds(
273 gfx::ScaleToCeiledSize(layer_bounds, max_contents_scale));
274 gfx::Rect content_rect(content_bounds);
276 Region remaining(content_rect);
277 PictureLayerTilingSet::CoverageIterator iter(
278 set.get(), max_contents_scale, content_rect, ideal_contents_scale);
279 for (; iter; ++iter) {
280 gfx::Rect geometry_rect = iter.geometry_rect();
281 EXPECT_TRUE(content_rect.Contains(geometry_rect));
282 ASSERT_TRUE(remaining.Contains(geometry_rect));
283 remaining.Subtract(geometry_rect);
285 EXPECT_EQ(expected_scale, iter.CurrentTiling()->contents_scale_key());
292 EXPECT_TRUE(remaining.IsEmpty());
296 TEST_F(PictureLayerTilingSetTestWithResources, NoTilings) {
297 RunTest(0, 0.f, 0.f, 2.f, 0.f);
299 TEST_F(PictureLayerTilingSetTestWithResources, OneTiling_Smaller) {
300 RunTest(1, 1.f, 0.f, 2.f, 1.f);
302 TEST_F(PictureLayerTilingSetTestWithResources, OneTiling_Larger) {
303 RunTest(1, 3.f, 0.f, 2.f, 3.f);
305 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_Smaller) {
306 RunTest(2, 1.f, 1.f, 3.f, 2.f);
309 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_SmallerEqual) {
310 RunTest(2, 1.f, 1.f, 2.f, 2.f);
313 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_LargerEqual) {
314 RunTest(2, 1.f, 1.f, 1.f, 1.f);
317 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_Larger) {
318 RunTest(2, 2.f, 8.f, 1.f, 2.f);
321 // Test is flaky: https://crbug.com/1056828.
322 #if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
323 #define MAYBE_ManyTilings_Equal DISABLED_ManyTilings_Equal
325 #define MAYBE_ManyTilings_Equal ManyTilings_Equal
327 TEST_F(PictureLayerTilingSetTestWithResources, MAYBE_ManyTilings_Equal) {
328 RunTest(10, 1.f, 1.f, 5.f, 5.f);
331 // Test is flaky: https://crbug.com/1056828.
332 #if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
333 #define MAYBE_ManyTilings_NotEqual DISABLED_ManyTilings_NotEqual
335 #define MAYBE_ManyTilings_NotEqual ManyTilings_NotEqual
337 TEST_F(PictureLayerTilingSetTestWithResources, MAYBE_ManyTilings_NotEqual) {
338 RunTest(10, 1.f, 1.f, 4.5f, 5.f);
341 TEST(PictureLayerTilingSetTest, TileSizeChange) {
342 FakePictureLayerTilingClient pending_client;
343 FakePictureLayerTilingClient active_client;
344 std::unique_ptr<PictureLayerTilingSet> pending_set =
345 PictureLayerTilingSet::Create(PENDING_TREE, &pending_client, 1000, 1.f,
347 std::unique_ptr<PictureLayerTilingSet> active_set =
348 PictureLayerTilingSet::Create(ACTIVE_TREE, &active_client, 1000, 1.f,
351 gfx::Size layer_bounds(100, 100);
352 scoped_refptr<FakeRasterSource> raster_source =
353 FakeRasterSource::CreateFilled(layer_bounds);
355 gfx::Size tile_size1(10, 10);
356 gfx::Size tile_size2(30, 30);
357 gfx::Size tile_size3(20, 20);
359 pending_client.SetTileSize(tile_size1);
360 pending_set->AddTiling(gfx::AxisTransform2d(), raster_source);
361 // New tilings get the correct tile size.
362 EXPECT_EQ(tile_size1, pending_set->tiling_at(0)->tile_size());
364 // Set some expected things for the tiling set to function.
365 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
366 active_client.set_twin_tiling_set(pending_set.get());
368 // Set a priority rect so we get tiles.
369 pending_set->UpdateTilePriorities(gfx::Rect(layer_bounds), 1.f, 1.0,
371 EXPECT_EQ(tile_size1, pending_set->tiling_at(0)->tile_size());
373 // The tiles should get the correct size.
374 std::vector<Tile*> pending_tiles =
375 pending_set->tiling_at(0)->AllTilesForTesting();
376 EXPECT_GT(pending_tiles.size(), 0u);
377 for (auto* tile : pending_tiles)
378 EXPECT_EQ(tile_size1, tile->content_rect().size());
380 // Update to a new source frame with a new tile size.
381 // Note that setting a new raster source can typically only happen after
382 // activation, since we can't set the raster source twice on the pending tree
383 // without activating. For test, just remove and add a new tiling instead.
384 pending_set->RemoveAllTilings();
385 pending_set->AddTiling(gfx::AxisTransform2d(), raster_source);
386 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
387 pending_client.SetTileSize(tile_size2);
388 pending_set->UpdateTilingsToCurrentRasterSourceForCommit(raster_source.get(),
390 // The tiling should get the correct tile size.
391 EXPECT_EQ(tile_size2, pending_set->tiling_at(0)->tile_size());
393 // Set a priority rect so we get tiles.
394 pending_set->UpdateTilePriorities(gfx::Rect(layer_bounds), 1.f, 2.0,
396 EXPECT_EQ(tile_size2, pending_set->tiling_at(0)->tile_size());
398 // Tiles should have the new correct size.
399 pending_tiles = pending_set->tiling_at(0)->AllTilesForTesting();
400 EXPECT_GT(pending_tiles.size(), 0u);
401 for (auto* tile : pending_tiles)
402 EXPECT_EQ(tile_size2, tile->content_rect().size());
404 // Clone from the pending to the active tree.
405 active_client.SetTileSize(tile_size2);
406 active_set->UpdateTilingsToCurrentRasterSourceForActivation(
407 raster_source.get(), pending_set.get(), Region(), 1.f, 1.f);
408 // The active tiling should get the right tile size.
409 EXPECT_EQ(tile_size2, active_set->tiling_at(0)->tile_size());
411 // Cloned tiles should have the right size.
412 std::vector<Tile*> active_tiles =
413 active_set->tiling_at(0)->AllTilesForTesting();
414 EXPECT_GT(active_tiles.size(), 0u);
415 for (auto* tile : active_tiles)
416 EXPECT_EQ(tile_size2, tile->content_rect().size());
418 // A new source frame with a new tile size.
419 pending_client.SetTileSize(tile_size3);
420 pending_set->UpdateTilingsToCurrentRasterSourceForCommit(raster_source.get(),
422 // The tiling gets the new size correctly.
423 EXPECT_EQ(tile_size3, pending_set->tiling_at(0)->tile_size());
425 // Set a priority rect so we get tiles.
426 pending_set->UpdateTilePriorities(gfx::Rect(layer_bounds), 1.f, 3.0,
428 EXPECT_EQ(tile_size3, pending_set->tiling_at(0)->tile_size());
430 // Tiles are resized for the new size.
431 pending_tiles = pending_set->tiling_at(0)->AllTilesForTesting();
432 EXPECT_GT(pending_tiles.size(), 0u);
433 for (auto* tile : pending_tiles)
434 EXPECT_EQ(tile_size3, tile->content_rect().size());
436 // Now we activate with a different tile size for the active tiling.
437 active_client.SetTileSize(tile_size3);
438 active_set->UpdateTilingsToCurrentRasterSourceForActivation(
439 raster_source.get(), pending_set.get(), Region(), 1.f, 1.f);
440 // The active tiling changes its tile size.
441 EXPECT_EQ(tile_size3, active_set->tiling_at(0)->tile_size());
443 // And its tiles are resized.
444 active_tiles = active_set->tiling_at(0)->AllTilesForTesting();
445 EXPECT_GT(active_tiles.size(), 0u);
446 for (auto* tile : active_tiles)
447 EXPECT_EQ(tile_size3, tile->content_rect().size());
450 TEST(PictureLayerTilingSetTest, MaxContentScale) {
451 FakePictureLayerTilingClient pending_client;
452 FakePictureLayerTilingClient active_client;
453 std::unique_ptr<PictureLayerTilingSet> pending_set =
454 PictureLayerTilingSet::Create(PENDING_TREE, &pending_client, 1000, 1.f,
456 std::unique_ptr<PictureLayerTilingSet> active_set =
457 PictureLayerTilingSet::Create(ACTIVE_TREE, &active_client, 1000, 1.f,
460 gfx::Size layer_bounds(100, 105);
461 scoped_refptr<FakeRasterSource> raster_source =
462 FakeRasterSource::CreateEmpty(layer_bounds);
464 // Tilings can be added of any scale, the tiling client can controls this.
465 pending_set->AddTiling(gfx::AxisTransform2d(), raster_source);
466 pending_set->AddTiling(gfx::AxisTransform2d(2.f, gfx::Vector2dF()),
468 pending_set->AddTiling(gfx::AxisTransform2d(3.f, gfx::Vector2dF()),
471 // Set some expected things for the tiling set to function.
472 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
473 active_client.set_twin_tiling_set(pending_set.get());
475 // Update to a new source frame with a max content scale that is larger than
477 float max_content_scale = 3.f;
478 pending_set->UpdateTilingsToCurrentRasterSourceForCommit(
479 raster_source.get(), Region(), 1.f, max_content_scale);
481 // All the tilings are there still.
482 EXPECT_EQ(3u, pending_set->num_tilings());
484 // Clone from the pending to the active tree with the same max content size.
485 active_set->UpdateTilingsToCurrentRasterSourceForActivation(
486 raster_source.get(), pending_set.get(), Region(), 1.f, max_content_scale);
487 // All the tilings are on the active tree.
488 EXPECT_EQ(3u, active_set->num_tilings());
490 // Update to a new source frame with a max content scale that will drop one
492 max_content_scale = 2.9f;
493 pending_set->UpdateTilingsToCurrentRasterSourceForCommit(
494 raster_source.get(), Region(), 1.f, max_content_scale);
495 // All the tilings are there still.
496 EXPECT_EQ(2u, pending_set->num_tilings());
498 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
500 // Clone from the pending to the active tree with the same max content size.
501 active_set->UpdateTilingsToCurrentRasterSourceForActivation(
502 raster_source.get(), pending_set.get(), Region(), 1.f, max_content_scale);
503 // All the tilings are on the active tree.
504 EXPECT_EQ(2u, active_set->num_tilings());
507 TEST(PictureLayerTilingSetTest, SkewportLimits) {
508 FakePictureLayerTilingClient client;
510 gfx::Rect viewport(0, 0, 100, 100);
511 gfx::Size layer_bounds(200, 200);
513 client.SetTileSize(gfx::Size(100, 100));
514 LayerTreeSettings settings;
515 settings.skewport_extrapolation_limit_in_screen_pixels = 75;
516 settings.tiling_interest_area_padding = 1000000;
518 scoped_refptr<FakeRasterSource> raster_source =
519 FakeRasterSource::CreateFilled(layer_bounds);
520 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
521 CreateTilingSetWithSettings(&client, settings);
523 EXPECT_FALSE(tiling_set->TilingsNeedUpdate(viewport, 1.0));
524 tiling_set->AddTiling(gfx::AxisTransform2d(), raster_source);
525 EXPECT_TRUE(tiling_set->TilingsNeedUpdate(viewport, 1.0));
527 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
529 // Move viewport down 50 pixels in 0.5 seconds.
530 gfx::Rect down_skewport =
531 tiling_set->ComputeSkewport(gfx::Rect(0, 50, 100, 100), 1.5, 1.f);
533 EXPECT_EQ(0, down_skewport.x());
534 EXPECT_EQ(50, down_skewport.y());
535 EXPECT_EQ(100, down_skewport.width());
536 EXPECT_EQ(175, down_skewport.height());
537 EXPECT_TRUE(down_skewport.Contains(gfx::Rect(0, 50, 100, 100)));
539 // Move viewport down 50 and right 10 pixels.
540 gfx::Rect down_right_skewport =
541 tiling_set->ComputeSkewport(gfx::Rect(10, 50, 100, 100), 1.5, 1.f);
543 EXPECT_EQ(10, down_right_skewport.x());
544 EXPECT_EQ(50, down_right_skewport.y());
545 EXPECT_EQ(120, down_right_skewport.width());
546 EXPECT_EQ(175, down_right_skewport.height());
547 EXPECT_TRUE(down_right_skewport.Contains(gfx::Rect(10, 50, 100, 100)));
549 // Move viewport left.
550 gfx::Rect left_skewport =
551 tiling_set->ComputeSkewport(gfx::Rect(-50, 0, 100, 100), 1.5, 1.f);
553 EXPECT_EQ(-125, left_skewport.x());
554 EXPECT_EQ(0, left_skewport.y());
555 EXPECT_EQ(175, left_skewport.width());
556 EXPECT_EQ(100, left_skewport.height());
557 EXPECT_TRUE(left_skewport.Contains(gfx::Rect(-50, 0, 100, 100)));
560 gfx::Rect expand_skewport =
561 tiling_set->ComputeSkewport(gfx::Rect(-50, -50, 200, 200), 1.5, 1.f);
563 // x and y moved by -75 (-50 - 75 = -125).
564 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75].
565 EXPECT_EQ(-125, expand_skewport.x());
566 EXPECT_EQ(-125, expand_skewport.y());
567 EXPECT_EQ(350, expand_skewport.width());
568 EXPECT_EQ(350, expand_skewport.height());
569 EXPECT_TRUE(expand_skewport.Contains(gfx::Rect(-50, -50, 200, 200)));
571 // Expand the viewport past the limit in all directions.
572 gfx::Rect big_expand_skewport =
573 tiling_set->ComputeSkewport(gfx::Rect(-500, -500, 1500, 1500), 1.5, 1.f);
575 EXPECT_EQ(-575, big_expand_skewport.x());
576 EXPECT_EQ(-575, big_expand_skewport.y());
577 EXPECT_EQ(1650, big_expand_skewport.width());
578 EXPECT_EQ(1650, big_expand_skewport.height());
579 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500)));
581 // Shrink the skewport in all directions.
582 gfx::Rect shrink_viewport =
583 tiling_set->ComputeSkewport(gfx::Rect(0, 0, 100, 100), 1.5, 1.f);
584 EXPECT_EQ(0, shrink_viewport.x());
585 EXPECT_EQ(0, shrink_viewport.y());
586 EXPECT_EQ(100, shrink_viewport.width());
587 EXPECT_EQ(100, shrink_viewport.height());
589 // Move the skewport really far in one direction.
590 gfx::Rect move_skewport_far =
591 tiling_set->ComputeSkewport(gfx::Rect(0, 5000, 100, 100), 1.5, 1.f);
592 EXPECT_EQ(0, move_skewport_far.x());
593 EXPECT_EQ(5000, move_skewport_far.y());
594 EXPECT_EQ(100, move_skewport_far.width());
595 EXPECT_EQ(175, move_skewport_far.height());
596 EXPECT_TRUE(move_skewport_far.Contains(gfx::Rect(0, 5000, 100, 100)));
599 TEST(PictureLayerTilingSetTest, ComputeSkewportExtremeCases) {
600 FakePictureLayerTilingClient client;
602 gfx::Size layer_bounds(200, 200);
603 client.SetTileSize(gfx::Size(100, 100));
604 LayerTreeSettings settings;
605 settings.tiling_interest_area_padding = 1000000000;
606 scoped_refptr<FakeRasterSource> raster_source =
607 FakeRasterSource::CreateFilled(layer_bounds);
608 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
609 CreateTilingSetWithSettings(&client, settings);
610 tiling_set->AddTiling(gfx::AxisTransform2d(), raster_source);
612 gfx::Rect viewport1(-1918, 255860, 4010, 2356);
613 gfx::Rect viewport2(-7088, -91738, 14212, 8350);
614 gfx::Rect viewport3(-12730024, -158883296, 24607540, 14454512);
616 tiling_set->UpdateTilePriorities(viewport1, 1.f, time, Occlusion(), true);
619 tiling_set->ComputeSkewport(viewport2, time, 1.f).Contains(viewport2));
620 tiling_set->UpdateTilePriorities(viewport2, 1.f, time, Occlusion(), true);
623 tiling_set->ComputeSkewport(viewport3, time, 1.f).Contains(viewport3));
625 // Use a tiling with a large scale, so the viewport times the scale no longer
626 // fits into integers, and the viewport is not anywhere close to the tiling.
627 PictureLayerTiling* tiling = tiling_set->AddTiling(
628 gfx::AxisTransform2d(1000.f, gfx::Vector2dF()), raster_source);
629 EXPECT_TRUE(tiling_set->TilingsNeedUpdate(viewport3, time));
630 tiling_set->UpdateTilePriorities(viewport3, 1.f, time, Occlusion(), true);
631 EXPECT_TRUE(tiling->GetCurrentVisibleRectForTesting().IsEmpty());
634 TEST(PictureLayerTilingSetTest, ComputeSkewport) {
635 FakePictureLayerTilingClient client;
637 gfx::Rect viewport(0, 0, 100, 100);
638 gfx::Size layer_bounds(200, 200);
640 client.SetTileSize(gfx::Size(100, 100));
642 scoped_refptr<FakeRasterSource> raster_source =
643 FakeRasterSource::CreateFilled(layer_bounds);
644 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
645 CreateTilingSet(&client);
646 tiling_set->AddTiling(gfx::AxisTransform2d(), raster_source);
648 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
650 // Move viewport down 50 pixels in 0.5 seconds.
651 gfx::Rect down_skewport =
652 tiling_set->ComputeSkewport(gfx::Rect(0, 50, 100, 100), 1.5, 1.f);
654 EXPECT_EQ(0, down_skewport.x());
655 EXPECT_EQ(50, down_skewport.y());
656 EXPECT_EQ(100, down_skewport.width());
657 EXPECT_EQ(200, down_skewport.height());
660 gfx::Rect shrink_skewport =
661 tiling_set->ComputeSkewport(gfx::Rect(25, 25, 50, 50), 1.5, 1.f);
663 EXPECT_EQ(25, shrink_skewport.x());
664 EXPECT_EQ(25, shrink_skewport.y());
665 EXPECT_EQ(50, shrink_skewport.width());
666 EXPECT_EQ(50, shrink_skewport.height());
668 // Move viewport down 50 and right 10 pixels.
669 gfx::Rect down_right_skewport =
670 tiling_set->ComputeSkewport(gfx::Rect(10, 50, 100, 100), 1.5, 1.f);
672 EXPECT_EQ(10, down_right_skewport.x());
673 EXPECT_EQ(50, down_right_skewport.y());
674 EXPECT_EQ(120, down_right_skewport.width());
675 EXPECT_EQ(200, down_right_skewport.height());
677 // Move viewport left.
678 gfx::Rect left_skewport =
679 tiling_set->ComputeSkewport(gfx::Rect(-20, 0, 100, 100), 1.5, 1.f);
681 EXPECT_EQ(-60, left_skewport.x());
682 EXPECT_EQ(0, left_skewport.y());
683 EXPECT_EQ(140, left_skewport.width());
684 EXPECT_EQ(100, left_skewport.height());
686 // Expand viewport in 0.2 seconds.
687 gfx::Rect expanded_skewport =
688 tiling_set->ComputeSkewport(gfx::Rect(-5, -5, 110, 110), 1.2, 1.f);
690 EXPECT_EQ(-30, expanded_skewport.x());
691 EXPECT_EQ(-30, expanded_skewport.y());
692 EXPECT_EQ(160, expanded_skewport.width());
693 EXPECT_EQ(160, expanded_skewport.height());
696 TEST(PictureLayerTilingSetTest, SkewportThroughUpdateTilePriorities) {
697 FakePictureLayerTilingClient client;
699 gfx::Rect viewport(0, 0, 100, 100);
700 gfx::Size layer_bounds(200, 200);
702 client.SetTileSize(gfx::Size(100, 100));
704 scoped_refptr<FakeRasterSource> raster_source =
705 FakeRasterSource::CreateFilled(layer_bounds);
706 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
707 CreateTilingSet(&client);
708 tiling_set->AddTiling(gfx::AxisTransform2d(), raster_source);
710 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
712 // Move viewport down 50 pixels in 0.5 seconds.
713 gfx::Rect viewport_50 = gfx::Rect(0, 50, 100, 100);
714 gfx::Rect skewport_50 = tiling_set->ComputeSkewport(viewport_50, 1.5, 1.f);
716 EXPECT_EQ(gfx::Rect(0, 50, 100, 200), skewport_50);
717 tiling_set->UpdateTilePriorities(viewport_50, 1.f, 1.5, Occlusion(), true);
719 gfx::Rect viewport_100 = gfx::Rect(0, 100, 100, 100);
720 gfx::Rect skewport_100 = tiling_set->ComputeSkewport(viewport_100, 2.0, 1.f);
722 EXPECT_EQ(gfx::Rect(0, 100, 100, 200), skewport_100);
723 tiling_set->UpdateTilePriorities(viewport_100, 1.f, 2.0, Occlusion(), true);
725 // Advance time, but not the viewport.
726 gfx::Rect result = tiling_set->ComputeSkewport(viewport_100, 2.5, 1.f);
727 // Since the history did advance, we should still get a skewport but a smaller
729 EXPECT_EQ(gfx::Rect(0, 100, 100, 150), result);
730 tiling_set->UpdateTilePriorities(viewport_100, 1.f, 2.5, Occlusion(), true);
732 // Advance time again.
733 result = tiling_set->ComputeSkewport(viewport_100, 3.0, 1.f);
734 EXPECT_EQ(viewport_100, result);
735 tiling_set->UpdateTilePriorities(viewport_100, 1.f, 3.0, Occlusion(), true);
737 // Ensure we have a skewport.
738 gfx::Rect viewport_150 = gfx::Rect(0, 150, 100, 100);
739 gfx::Rect skewport_150 = tiling_set->ComputeSkewport(viewport_150, 3.5, 1.f);
740 EXPECT_EQ(gfx::Rect(0, 150, 100, 150), skewport_150);
741 tiling_set->UpdateTilePriorities(viewport_150, 1.f, 3.5, Occlusion(), true);
743 // Advance the viewport, but not the time.
744 gfx::Rect viewport_200 = gfx::Rect(0, 200, 100, 100);
745 gfx::Rect skewport_200 = tiling_set->ComputeSkewport(viewport_200, 3.5, 1.f);
746 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200);
748 // Ensure that continued calls with the same value, produce the same skewport.
749 tiling_set->UpdateTilePriorities(viewport_150, 1.f, 3.5, Occlusion(), true);
750 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200);
751 tiling_set->UpdateTilePriorities(viewport_150, 1.f, 3.5, Occlusion(), true);
752 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200);
754 tiling_set->UpdateTilePriorities(viewport_200, 1.f, 3.5, Occlusion(), true);
756 // This should never happen, but advance the viewport yet again keeping the
758 gfx::Rect viewport_250 = gfx::Rect(0, 250, 100, 100);
759 gfx::Rect skewport_250 = tiling_set->ComputeSkewport(viewport_250, 3.5, 1.f);
760 EXPECT_EQ(viewport_250, skewport_250);
761 tiling_set->UpdateTilePriorities(viewport_250, 1.f, 3.5, Occlusion(), true);
764 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) {
765 FakePictureLayerTilingClient client;
767 gfx::Rect viewport(0, 0, 100, 100);
768 gfx::Size layer_bounds(1500, 1500);
770 client.SetTileSize(gfx::Size(10, 10));
771 LayerTreeSettings settings;
773 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10.
774 // The reason is that each tile has a one pixel border, so tile at (1, 2)
775 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at
776 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the
778 scoped_refptr<FakeRasterSource> raster_source =
779 FakeRasterSource::CreateFilled(layer_bounds);
780 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
781 CreateTilingSet(&client);
782 auto* tiling = tiling_set->AddTiling(
783 gfx::AxisTransform2d(0.25f, gfx::Vector2dF()), raster_source);
784 tiling->set_resolution(HIGH_RESOLUTION);
785 gfx::Rect viewport_in_content_space =
786 gfx::ScaleToEnclosedRect(viewport, 0.25f);
788 tiling_set->UpdateTilePriorities(viewport, 1.f, 1.0, Occlusion(), true);
789 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
791 // Compute the soon border.
792 gfx::Rect soon_border_rect_in_content_space =
793 tiling_set->ComputeSoonBorderRect(viewport, 1.f);
794 soon_border_rect_in_content_space =
795 gfx::ScaleToEnclosedRect(soon_border_rect_in_content_space, 0.25f);
798 for (int i = 0; i < 47; ++i) {
799 for (int j = 0; j < 47; ++j) {
800 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j;
803 for (int i = 0; i < 47; ++i) {
804 EXPECT_FALSE(tiling->TileAt(i, 47)) << "i: " << i;
805 EXPECT_FALSE(tiling->TileAt(47, i)) << "i: " << i;
808 // No movement in the viewport implies that tiles will either be NOW
809 // or EVENTUALLY, with the exception of tiles that are between 0 and 312
810 // pixels away from the viewport, which will be in the SOON bin.
811 bool have_now = false;
812 bool have_eventually = false;
813 bool have_soon = false;
814 for (int i = 0; i < 47; ++i) {
815 for (int j = 0; j < 47; ++j) {
816 Tile* tile = tiling->TileAt(i, j);
817 PrioritizedTile prioritized_tile = prioritized_tiles[tile];
818 TilePriority priority = prioritized_tile.priority();
820 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j);
821 if (viewport_in_content_space.Intersects(tile_rect)) {
822 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
823 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
825 } else if (soon_border_rect_in_content_space.Intersects(tile_rect)) {
826 EXPECT_EQ(TilePriority::SOON, priority.priority_bin);
829 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin);
830 EXPECT_GT(priority.distance_to_visible, 0.f);
831 have_eventually = true;
836 EXPECT_TRUE(have_now);
837 EXPECT_TRUE(have_soon);
838 EXPECT_TRUE(have_eventually);
840 // Spot check some distances.
841 // Tile at 5, 1 should begin at 41x9 in content space (without borders),
842 // so the distance to a viewport that ends at 25x25 in content space
843 // should be 17 (41 - 25 + 1). In layer space, then that should be
844 // 17 / 0.25 = 68 pixels.
846 // We can verify that the content rect (with borders) is one pixel off
847 // 41,9 8x8 on all sides.
848 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10");
849 TilePriority priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
850 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
852 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
853 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
855 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
856 EXPECT_FLOAT_EQ(40.f, priority.distance_to_visible);
858 // Move the viewport down 40 pixels.
859 viewport = gfx::Rect(0, 40, 100, 100);
860 viewport_in_content_space = gfx::ScaleToEnclosedRect(viewport, 0.25f);
861 gfx::Rect skewport_in_content_space =
862 tiling_set->ComputeSkewport(viewport, 2.0, 1.f);
863 skewport_in_content_space =
864 gfx::ScaleToEnclosedRect(skewport_in_content_space, 0.25f);
866 // Compute the soon border.
867 soon_border_rect_in_content_space =
868 tiling_set->ComputeSoonBorderRect(viewport, 1.f);
869 soon_border_rect_in_content_space =
870 gfx::ScaleToEnclosedRect(soon_border_rect_in_content_space, 0.25f);
872 EXPECT_EQ(0, skewport_in_content_space.x());
873 EXPECT_EQ(10, skewport_in_content_space.y());
874 EXPECT_EQ(25, skewport_in_content_space.width());
875 EXPECT_EQ(35, skewport_in_content_space.height());
877 EXPECT_TRUE(tiling_set->TilingsNeedUpdate(viewport, 2.0));
878 tiling_set->UpdateTilePriorities(viewport, 1.f, 2.0, Occlusion(), true);
879 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
882 have_eventually = false;
885 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
886 // some EVENTUALLY tiles.
887 for (int i = 0; i < 47; ++i) {
888 for (int j = 0; j < 47; ++j) {
889 Tile* tile = tiling->TileAt(i, j);
890 priority = prioritized_tiles[tile].priority();
892 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j);
893 if (viewport_in_content_space.Intersects(tile_rect)) {
894 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i
896 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i
899 } else if (skewport_in_content_space.Intersects(tile_rect) ||
900 soon_border_rect_in_content_space.Intersects(tile_rect)) {
901 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i
903 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
907 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin)
908 << "i: " << i << " j: " << j;
909 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
911 have_eventually = true;
916 EXPECT_TRUE(have_now);
917 EXPECT_TRUE(have_soon);
918 EXPECT_TRUE(have_eventually);
920 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
921 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
923 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
924 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible);
926 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
927 EXPECT_FLOAT_EQ(4.f, priority.distance_to_visible);
929 // Change the underlying layer scale.
930 tiling_set->UpdateTilePriorities(viewport, 2.0f, 3.0, Occlusion(), true);
931 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
933 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
934 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible);
936 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
937 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible);
939 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
940 EXPECT_FLOAT_EQ(8.f, priority.distance_to_visible);
942 // Test additional scales.
943 tiling = tiling_set->AddTiling(gfx::AxisTransform2d(0.2f, gfx::Vector2dF()),
945 tiling->set_resolution(HIGH_RESOLUTION);
946 tiling_set->UpdateTilePriorities(viewport, 1.0f, 4.0, Occlusion(), true);
947 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
949 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
950 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible);
952 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
953 EXPECT_FLOAT_EQ(70.f, priority.distance_to_visible);
955 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
956 EXPECT_FLOAT_EQ(60.f, priority.distance_to_visible);
958 tiling_set->UpdateTilePriorities(viewport, 0.5f, 5.0, Occlusion(), true);
959 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting();
961 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority();
962 EXPECT_FLOAT_EQ(55.f, priority.distance_to_visible);
964 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority();
965 EXPECT_FLOAT_EQ(35.f, priority.distance_to_visible);
967 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority();
968 EXPECT_FLOAT_EQ(30.f, priority.distance_to_visible);
971 TEST(PictureLayerTilingTest, InvalidateAfterComputeTilePriorityRects) {
972 FakePictureLayerTilingClient pending_client;
973 pending_client.SetTileSize(gfx::Size(100, 100));
975 scoped_refptr<FakeRasterSource> raster_source =
976 FakeRasterSource::CreateFilled(gfx::Size(100, 100));
977 std::unique_ptr<TestablePictureLayerTilingSet> tiling_set =
978 CreateTilingSet(&pending_client);
979 auto* pending_tiling =
980 tiling_set->AddTiling(gfx::AxisTransform2d(), raster_source);
981 pending_tiling->set_resolution(HIGH_RESOLUTION);
983 // Ensure that we can compute tile priority rects, invalidate, and compute the
984 // rects again. It is important that the second compute tile priority rects
985 // return true, indicating that things have changed (since invalidation has
986 // changed things). This causes PrepareTiles to be properly scheduled. If the
987 // second ComputeTilePriorityRects returns false, then we assume that
988 // PrepareTiles isn't needed and we signal that we're ready to draw
989 // immediately, which can cause visual glitches.
991 // This can happen we if we process an impl frame deadline before processing a
992 // commit. That is, when we draw we ComputeTilePriorityRects. If we process
993 // the commit afterwards, it would use the same timestamp and sometimes would
994 // use the same viewport to compute tile priority rects again.
996 gfx::Rect viewport(0, 0, 100, 100);
998 tiling_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
1000 tiling_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
1002 // This will invalidate tilings.
1003 tiling_set->Invalidate(Region());
1006 tiling_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
1009 TEST(PictureLayerTilingTest, InvalidateAfterUpdateRasterSourceForCommit) {
1010 FakePictureLayerTilingClient pending_client;
1011 FakePictureLayerTilingClient active_client;
1012 std::unique_ptr<PictureLayerTilingSet> pending_set =
1013 PictureLayerTilingSet::Create(PENDING_TREE, &pending_client, 1000, 1.f,
1015 std::unique_ptr<PictureLayerTilingSet> active_set =
1016 PictureLayerTilingSet::Create(ACTIVE_TREE, &active_client, 1000, 1.f,
1019 gfx::Size layer_bounds(100, 100);
1020 scoped_refptr<FakeRasterSource> raster_source =
1021 FakeRasterSource::CreateFilled(layer_bounds);
1023 auto* pending_tiling =
1024 pending_set->AddTiling(gfx::AxisTransform2d(), raster_source);
1025 pending_tiling->set_resolution(HIGH_RESOLUTION);
1026 active_client.set_twin_tiling_set(pending_set.get());
1029 gfx::Rect viewport(0, 0, 100, 100);
1031 // The first commit will update the raster source for pending tilings.
1032 pending_set->UpdateTilingsToCurrentRasterSourceForCommit(raster_source,
1033 Region(), 1.f, 1.f);
1034 // UpdateTilePriorities for pending set gets called during UDP in commit.
1035 EXPECT_TRUE(pending_set->UpdateTilePriorities(viewport, 1.f, time,
1036 Occlusion(), true));
1037 // The active set doesn't have tilings yet.
1039 active_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
1041 // On activation tilings are copied from pending set to active set.
1042 active_set->UpdateTilingsToCurrentRasterSourceForActivation(
1043 raster_source, pending_set.get(), Region(), 1.f, 1.f);
1044 // Pending set doesn't have any tilings now.
1045 EXPECT_FALSE(pending_set->UpdateTilePriorities(viewport, 1.f, time,
1046 Occlusion(), true));
1047 // UpdateTilePriorities for active set gets called during UDP in draw.
1049 active_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
1051 // Even though frame time and viewport haven't changed since last commit we
1052 // update tile priorities because of potential invalidations.
1053 pending_set->UpdateTilingsToCurrentRasterSourceForCommit(raster_source,
1054 Region(), 1.f, 1.f);
1055 // UpdateTilePriorities for pending set gets called during UDP in commit.
1056 EXPECT_TRUE(pending_set->UpdateTilePriorities(viewport, 1.f, time,
1057 Occlusion(), true));
1058 // No changes for active set until activation.
1060 active_set->UpdateTilePriorities(viewport, 1.f, time, Occlusion(), true));
1063 TEST(PictureLayerTilingSetTest, TilingTranslationChanges) {
1064 gfx::Size tile_size(64, 64);
1065 FakePictureLayerTilingClient pending_client;
1066 FakePictureLayerTilingClient active_client;
1067 pending_client.SetTileSize(tile_size);
1068 active_client.SetTileSize(tile_size);
1069 std::unique_ptr<PictureLayerTilingSet> pending_set =
1070 PictureLayerTilingSet::Create(PENDING_TREE, &pending_client, 0, 1.f, 0,
1072 std::unique_ptr<PictureLayerTilingSet> active_set =
1073 PictureLayerTilingSet::Create(ACTIVE_TREE, &active_client, 0, 1.f, 0,
1075 active_client.set_twin_tiling_set(pending_set.get());
1077 gfx::Size layer_bounds(100, 100);
1078 scoped_refptr<FakeRasterSource> raster_source =
1079 FakeRasterSource::CreateFilled(layer_bounds);
1081 gfx::AxisTransform2d raster_transform1(1.f, gfx::Vector2dF(0.25f, 0.25f));
1082 pending_set->AddTiling(raster_transform1, raster_source);
1083 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
1085 // Set a priority rect so we get tiles.
1086 pending_set->UpdateTilePriorities(gfx::Rect(layer_bounds), 1.f, 1.0,
1087 Occlusion(), false);
1089 // Make sure all tiles are generated.
1090 EXPECT_EQ(4u, pending_set->tiling_at(0)->AllTilesForTesting().size());
1092 // Clone from the pending to the active tree.
1093 active_set->UpdateTilingsToCurrentRasterSourceForActivation(
1094 raster_source.get(), pending_set.get(), Region(), 1.f, 1.f);
1096 // Verifies active tree cloned the tiling correctly.
1097 ASSERT_EQ(1u, active_set->num_tilings());
1098 EXPECT_EQ(active_set->tiling_at(0)->raster_transform(), raster_transform1);
1099 EXPECT_EQ(4u, active_set->tiling_at(0)->AllTilesForTesting().size());
1101 // Change raster translation on the pending set.
1102 gfx::AxisTransform2d raster_transform2(1.f, gfx::Vector2dF(0.75f, 0.75f));
1103 pending_set->RemoveAllTilings();
1104 pending_set->AddTiling(raster_transform2, raster_source);
1105 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
1107 // Set a different priority rect to get one tile.
1108 pending_set->UpdateTilePriorities(gfx::Rect(1, 1), 1.f, 1.0, Occlusion(),
1110 EXPECT_EQ(1u, pending_set->tiling_at(0)->AllTilesForTesting().size());
1112 // Commit the pending to the active tree again.
1113 active_set->UpdateTilingsToCurrentRasterSourceForActivation(
1114 raster_source.get(), pending_set.get(), Region(), 1.f, 1.f);
1116 // Verifies the old tiling with a different translation is dropped.
1117 ASSERT_EQ(1u, active_set->num_tilings());
1118 EXPECT_EQ(active_set->tiling_at(0)->raster_transform(), raster_transform2);
1119 EXPECT_EQ(1u, active_set->tiling_at(0)->AllTilesForTesting().size());
1122 TEST(PictureLayerTilingSetTest, LcdChanges) {
1123 gfx::Size tile_size(64, 64);
1124 FakePictureLayerTilingClient pending_client;
1125 FakePictureLayerTilingClient active_client;
1126 pending_client.SetTileSize(tile_size);
1127 active_client.SetTileSize(tile_size);
1128 std::unique_ptr<PictureLayerTilingSet> pending_set =
1129 PictureLayerTilingSet::Create(PENDING_TREE, &pending_client, 0, 1.f, 0,
1131 std::unique_ptr<PictureLayerTilingSet> active_set =
1132 PictureLayerTilingSet::Create(ACTIVE_TREE, &active_client, 0, 1.f, 0,
1134 active_client.set_twin_tiling_set(pending_set.get());
1135 pending_client.set_twin_tiling_set(active_set.get());
1137 gfx::Size layer_bounds(100, 100);
1138 scoped_refptr<FakeRasterSource> raster_source =
1139 FakeRasterSource::CreateFilled(layer_bounds);
1141 const bool with_lcd_text = true;
1142 const bool without_lcd_text = false;
1144 gfx::AxisTransform2d raster_transform(1.f, gfx::Vector2dF());
1145 pending_set->AddTiling(raster_transform, raster_source, with_lcd_text);
1146 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
1148 // Set a priority rect so we get tiles.
1149 pending_set->UpdateTilePriorities(gfx::Rect(layer_bounds), 1.f, 1.0,
1150 Occlusion(), false);
1152 // Make sure all tiles are generated.
1153 EXPECT_EQ(4u, pending_set->tiling_at(0)->AllTilesForTesting().size());
1155 // Clone from the pending to the active tree.
1156 active_set->UpdateTilingsToCurrentRasterSourceForActivation(
1157 raster_source.get(), pending_set.get(), Region(), 1.f, 1.f);
1159 // Verifies active tree cloned the tiling correctly.
1160 ASSERT_EQ(1u, active_set->num_tilings());
1161 EXPECT_EQ(4u, active_set->tiling_at(0)->AllTilesForTesting().size());
1163 // Change LCD state on the pending tree
1164 pending_set->RemoveAllTilings();
1165 pending_set->AddTiling(raster_transform, raster_source, without_lcd_text);
1166 pending_set->tiling_at(0)->set_resolution(HIGH_RESOLUTION);
1168 // Set a priority rect so we get tiles.
1169 pending_set->UpdateTilePriorities(gfx::Rect(layer_bounds), 1.f, 1.0,
1170 Occlusion(), false);
1171 // We should have created all tiles because lcd state changed.
1172 EXPECT_EQ(4u, pending_set->tiling_at(0)->AllTilesForTesting().size());