OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "cc/layers/append_quads_data.h" | 12 #include "cc/layers/append_quads_data.h" |
13 #include "cc/layers/picture_layer.h" | 13 #include "cc/layers/picture_layer.h" |
14 #include "cc/test/fake_content_layer_client.h" | 14 #include "cc/test/fake_content_layer_client.h" |
15 #include "cc/test/fake_impl_proxy.h" | 15 #include "cc/test/fake_impl_proxy.h" |
16 #include "cc/test/fake_layer_tree_host_impl.h" | 16 #include "cc/test/fake_layer_tree_host_impl.h" |
17 #include "cc/test/fake_output_surface.h" | 17 #include "cc/test/fake_output_surface.h" |
18 #include "cc/test/fake_picture_layer_impl.h" | 18 #include "cc/test/fake_picture_layer_impl.h" |
19 #include "cc/test/fake_picture_pile_impl.h" | 19 #include "cc/test/fake_picture_pile_impl.h" |
20 #include "cc/test/geometry_test_utils.h" | 20 #include "cc/test/geometry_test_utils.h" |
21 #include "cc/test/impl_side_painting_settings.h" | |
22 #include "cc/test/layer_test_common.h" | 21 #include "cc/test/layer_test_common.h" |
23 #include "cc/test/mock_quad_culler.h" | 22 #include "cc/test/mock_quad_culler.h" |
24 #include "cc/test/test_shared_bitmap_manager.h" | 23 #include "cc/test/test_shared_bitmap_manager.h" |
25 #include "cc/test/test_web_graphics_context_3d.h" | 24 #include "cc/test/test_web_graphics_context_3d.h" |
26 #include "cc/trees/layer_tree_impl.h" | 25 #include "cc/trees/layer_tree_impl.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "ui/gfx/rect_conversions.h" | 27 #include "ui/gfx/rect_conversions.h" |
29 | 28 |
30 namespace cc { | 29 namespace cc { |
31 namespace { | 30 namespace { |
32 | 31 |
33 class MockCanvas : public SkCanvas { | 32 class MockCanvas : public SkCanvas { |
34 public: | 33 public: |
35 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} | 34 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} |
36 | 35 |
37 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { | 36 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { |
38 // Capture calls before SkCanvas quickReject() kicks in. | 37 // Capture calls before SkCanvas quickReject() kicks in. |
39 rects_.push_back(rect); | 38 rects_.push_back(rect); |
40 } | 39 } |
41 | 40 |
42 std::vector<SkRect> rects_; | 41 std::vector<SkRect> rects_; |
43 }; | 42 }; |
44 | 43 |
45 class PictureLayerImplTest : public testing::Test { | 44 class PictureLayerImplTest : public testing::Test { |
46 public: | 45 public: |
47 PictureLayerImplTest() | 46 PictureLayerImplTest() |
48 : proxy_(base::MessageLoopProxy::current()), | 47 : proxy_(base::MessageLoopProxy::current()), |
49 host_impl_(ImplSidePaintingSettings(), | 48 host_impl_(LayerTreeSettings(true), |
50 &proxy_, | 49 &proxy_, |
51 &shared_bitmap_manager_), | 50 &shared_bitmap_manager_), |
52 id_(7) {} | 51 id_(7) {} |
53 | 52 |
54 explicit PictureLayerImplTest(const LayerTreeSettings& settings) | 53 explicit PictureLayerImplTest(const LayerTreeSettings& settings) |
55 : proxy_(base::MessageLoopProxy::current()), | 54 : proxy_(base::MessageLoopProxy::current()), |
56 host_impl_(settings, &proxy_, &shared_bitmap_manager_), | 55 host_impl_(settings, &proxy_, &shared_bitmap_manager_), |
57 id_(7) {} | 56 id_(7) {} |
58 | 57 |
59 virtual ~PictureLayerImplTest() { | 58 virtual ~PictureLayerImplTest() { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 void AssertNoTilesRequired(PictureLayerTiling* tiling) { | 189 void AssertNoTilesRequired(PictureLayerTiling* tiling) { |
191 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); | 190 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); |
192 for (size_t i = 0; i < tiles.size(); ++i) | 191 for (size_t i = 0; i < tiles.size(); ++i) |
193 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i; | 192 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i; |
194 EXPECT_GT(tiles.size(), 0u); | 193 EXPECT_GT(tiles.size(), 0u); |
195 } | 194 } |
196 | 195 |
197 protected: | 196 protected: |
198 void TestTileGridAlignmentCommon() { | 197 void TestTileGridAlignmentCommon() { |
199 // Layer to span 4 raster tiles in x and in y | 198 // Layer to span 4 raster tiles in x and in y |
200 ImplSidePaintingSettings settings; | 199 LayerTreeSettings settings(true); |
201 gfx::Size layer_size( | 200 gfx::Size layer_size( |
202 settings.default_tile_size.width() * 7 / 2, | 201 settings.default_tile_size.width() * 7 / 2, |
203 settings.default_tile_size.height() * 7 / 2); | 202 settings.default_tile_size.height() * 7 / 2); |
204 | 203 |
205 scoped_refptr<FakePicturePileImpl> pending_pile = | 204 scoped_refptr<FakePicturePileImpl> pending_pile = |
206 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); | 205 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); |
207 scoped_refptr<FakePicturePileImpl> active_pile = | 206 scoped_refptr<FakePicturePileImpl> active_pile = |
208 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); | 207 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); |
209 | 208 |
210 SetupTrees(pending_pile, active_pile); | 209 SetupTrees(pending_pile, active_pile); |
(...skipping 2061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2272 impl.quad_list(), | 2271 impl.quad_list(), |
2273 gfx::Rect(layer_bounds), | 2272 gfx::Rect(layer_bounds), |
2274 occluded, | 2273 occluded, |
2275 &partially_occluded_count); | 2274 &partially_occluded_count); |
2276 // The layer outputs one quad, which is partially occluded. | 2275 // The layer outputs one quad, which is partially occluded. |
2277 EXPECT_EQ(100u - 10u, impl.quad_list().size()); | 2276 EXPECT_EQ(100u - 10u, impl.quad_list().size()); |
2278 EXPECT_EQ(10u + 10u, partially_occluded_count); | 2277 EXPECT_EQ(10u + 10u, partially_occluded_count); |
2279 } | 2278 } |
2280 } | 2279 } |
2281 | 2280 |
2281 class NoLowResPictureLayerImplTest : public PictureLayerImplTest { | |
2282 public: | |
2283 NoLowResPictureLayerImplTest() | |
2284 : PictureLayerImplTest(LayerTreeSettings(true, false)) | |
reveman
2014/05/13 15:38:05
You could just add a NoLowResTilingsSettings class
Sergey
2014/05/14 05:53:35
Done.
| |
2285 {} | |
2286 }; | |
2287 | |
2288 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) { | |
2289 gfx::Size tile_size(400, 400); | |
2290 gfx::Size layer_bounds(1300, 1900); | |
2291 | |
2292 scoped_refptr<FakePicturePileImpl> pending_pile = | |
2293 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2294 scoped_refptr<FakePicturePileImpl> active_pile = | |
2295 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2296 | |
2297 float result_scale_x, result_scale_y; | |
2298 gfx::Size result_bounds; | |
2299 | |
2300 SetupTrees(pending_pile, active_pile); | |
2301 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
2302 | |
2303 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | |
2304 EXPECT_LT(low_res_factor, 1.f); | |
2305 | |
2306 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale | |
2307 1.7f, // device scale | |
2308 3.2f, // page scale | |
2309 1.f, // maximum animation scale | |
2310 false, | |
2311 &result_scale_x, | |
2312 &result_scale_y, | |
2313 &result_bounds); | |
2314 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
2315 EXPECT_FLOAT_EQ( | |
2316 1.3f, | |
2317 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | |
2318 | |
2319 // If we change the layer's CSS scale factor, then we should not get new | |
2320 // tilings. | |
2321 pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale | |
2322 1.7f, // device scale | |
2323 3.2f, // page scale | |
2324 1.f, // maximum animation scale | |
2325 false, | |
2326 &result_scale_x, | |
2327 &result_scale_y, | |
2328 &result_bounds); | |
2329 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
2330 EXPECT_FLOAT_EQ( | |
2331 1.3f, | |
2332 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | |
2333 | |
2334 // If we change the page scale factor, then we should get new tilings. | |
2335 pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale | |
2336 1.7f, // device scale | |
2337 2.2f, // page scale | |
2338 1.f, // maximum animation scale | |
2339 false, | |
2340 &result_scale_x, | |
2341 &result_scale_y, | |
2342 &result_bounds); | |
2343 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | |
2344 EXPECT_FLOAT_EQ( | |
2345 1.8f, | |
2346 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | |
2347 | |
2348 // If we change the device scale factor, then we should get new tilings. | |
2349 pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale | |
2350 1.4f, // device scale | |
2351 2.2f, // page scale | |
2352 1.f, // maximum animation scale | |
2353 false, | |
2354 &result_scale_x, | |
2355 &result_scale_y, | |
2356 &result_bounds); | |
2357 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); | |
2358 EXPECT_FLOAT_EQ( | |
2359 1.9f, | |
2360 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | |
2361 | |
2362 // If we change the device scale factor, but end up at the same total scale | |
2363 // factor somehow, then we don't get new tilings. | |
2364 pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale | |
2365 2.2f, // device scale | |
2366 1.4f, // page scale | |
2367 1.f, // maximum animation scale | |
2368 false, | |
2369 &result_scale_x, | |
2370 &result_scale_y, | |
2371 &result_bounds); | |
2372 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); | |
2373 EXPECT_FLOAT_EQ( | |
2374 1.9f, | |
2375 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | |
2376 } | |
2377 | |
2378 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredNullTiles) { | |
2379 gfx::Size tile_size(100, 100); | |
2380 gfx::Size layer_bounds(1000, 1000); | |
2381 | |
2382 scoped_refptr<FakePicturePileImpl> pending_pile = | |
2383 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | |
2384 // Layers with entirely empty piles can't get tilings. | |
2385 pending_pile->AddRecordingAt(0, 0); | |
2386 | |
2387 SetupPendingTree(pending_pile); | |
2388 | |
2389 ASSERT_TRUE(pending_layer_->CanHaveTilings()); | |
2390 pending_layer_->AddTiling(1.0f); | |
2391 pending_layer_->AddTiling(2.0f); | |
2392 | |
2393 // It should be safe to call this (and MarkVisibleResourcesAsRequired) | |
2394 // on a layer with no recordings. | |
2395 host_impl_.pending_tree()->UpdateDrawProperties(); | |
2396 pending_layer_->MarkVisibleResourcesAsRequired(); | |
2397 } | |
2398 | |
2399 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) { | |
2400 gfx::Size layer_bounds(400, 400); | |
2401 gfx::Size tile_size(100, 100); | |
2402 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | |
2403 | |
2404 CreateHighLowResAndSetAllTilesVisible(); | |
2405 | |
2406 Tile* some_active_tile = | |
2407 active_layer_->HighResTiling()->AllTilesForTesting()[0]; | |
2408 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); | |
2409 | |
2410 // All tiles shared (no invalidation), so even though the active tree's | |
2411 // tiles aren't ready, there is nothing required. | |
2412 pending_layer_->MarkVisibleResourcesAsRequired(); | |
2413 AssertNoTilesRequired(pending_layer_->HighResTiling()); | |
2414 if (host_impl_.settings().create_low_res_tiling) { | |
2415 AssertNoTilesRequired(pending_layer_->LowResTiling()); | |
2416 } | |
2417 } | |
2418 | |
2419 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { | |
2420 gfx::Size layer_bounds(400, 400); | |
2421 gfx::Size tile_size(100, 100); | |
2422 scoped_refptr<FakePicturePileImpl> pending_pile = | |
2423 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2424 // This pile will create tilings, but has no recordings so will not create any | |
2425 // tiles. This is attempting to simulate scrolling past the end of recorded | |
2426 // content on the active layer, where the recordings are so far away that | |
2427 // no tiles are created. | |
2428 scoped_refptr<FakePicturePileImpl> active_pile = | |
2429 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( | |
2430 tile_size, layer_bounds); | |
2431 SetupTrees(pending_pile, active_pile); | |
2432 pending_layer_->set_fixed_tile_size(tile_size); | |
2433 active_layer_->set_fixed_tile_size(tile_size); | |
2434 | |
2435 CreateHighLowResAndSetAllTilesVisible(); | |
2436 | |
2437 // Active layer has tilings, but no tiles due to missing recordings. | |
2438 EXPECT_TRUE(active_layer_->CanHaveTilings()); | |
2439 EXPECT_EQ( | |
2440 active_layer_->tilings()->num_tilings(), | |
2441 host_impl_.settings().create_low_res_tiling ? 2u : 1u); | |
2442 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); | |
2443 | |
2444 // Since the active layer has no tiles at all, the pending layer doesn't | |
2445 // need content in order to activate. | |
2446 pending_layer_->MarkVisibleResourcesAsRequired(); | |
2447 AssertNoTilesRequired(pending_layer_->HighResTiling()); | |
2448 if (host_impl_.settings().create_low_res_tiling) | |
2449 AssertNoTilesRequired(pending_layer_->LowResTiling()); | |
2450 } | |
2451 | |
2452 TEST_F(NoLowResPictureLayerImplTest, TileManagerRegisterUnregister) { | |
2453 gfx::Size tile_size(100, 100); | |
2454 gfx::Size layer_bounds(400, 400); | |
2455 | |
2456 scoped_refptr<FakePicturePileImpl> pending_pile = | |
2457 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2458 scoped_refptr<FakePicturePileImpl> active_pile = | |
2459 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2460 | |
2461 SetupTrees(pending_pile, active_pile); | |
2462 | |
2463 std::vector<TileManager::PairedPictureLayer> paired_layers; | |
2464 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); | |
2465 EXPECT_EQ(0u, paired_layers.size()); | |
2466 | |
2467 // Update tile priorities will force the layer to register itself. | |
2468 float dummy_contents_scale_x; | |
2469 float dummy_contents_scale_y; | |
2470 gfx::Size dummy_content_bounds; | |
2471 active_layer_->CalculateContentsScale(1.f, | |
2472 1.f, | |
2473 1.f, | |
2474 1.f, | |
2475 false, | |
2476 &dummy_contents_scale_x, | |
2477 &dummy_contents_scale_y, | |
2478 &dummy_content_bounds); | |
2479 active_layer_->UpdateTilePriorities(); | |
2480 host_impl_.pending_tree()->UpdateDrawProperties(); | |
2481 pending_layer_->CalculateContentsScale(1.f, | |
2482 1.f, | |
2483 1.f, | |
2484 1.f, | |
2485 false, | |
2486 &dummy_contents_scale_x, | |
2487 &dummy_contents_scale_y, | |
2488 &dummy_content_bounds); | |
2489 pending_layer_->UpdateTilePriorities(); | |
2490 | |
2491 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); | |
2492 EXPECT_EQ(1u, paired_layers.size()); | |
2493 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); | |
2494 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); | |
2495 | |
2496 // Destroy and recreate tile manager. | |
2497 host_impl_.DidLoseOutputSurface(); | |
2498 scoped_ptr<TestWebGraphicsContext3D> context = | |
2499 TestWebGraphicsContext3D::Create(); | |
2500 host_impl_.InitializeRenderer( | |
2501 FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>()); | |
2502 | |
2503 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); | |
2504 EXPECT_EQ(0u, paired_layers.size()); | |
2505 | |
2506 active_layer_->CalculateContentsScale(1.f, | |
2507 1.f, | |
2508 1.f, | |
2509 1.f, | |
2510 false, | |
2511 &dummy_contents_scale_x, | |
2512 &dummy_contents_scale_y, | |
2513 &dummy_content_bounds); | |
2514 active_layer_->UpdateTilePriorities(); | |
2515 host_impl_.pending_tree()->UpdateDrawProperties(); | |
2516 pending_layer_->CalculateContentsScale(1.f, | |
2517 1.f, | |
2518 1.f, | |
2519 1.f, | |
2520 false, | |
2521 &dummy_contents_scale_x, | |
2522 &dummy_contents_scale_y, | |
2523 &dummy_content_bounds); | |
2524 pending_layer_->UpdateTilePriorities(); | |
2525 | |
2526 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); | |
2527 EXPECT_EQ(1u, paired_layers.size()); | |
2528 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); | |
2529 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); | |
2530 } | |
2531 | |
2532 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { | |
2533 base::TimeTicks time_ticks; | |
2534 host_impl_.SetCurrentFrameTimeTicks(time_ticks); | |
2535 | |
2536 gfx::Size tile_size(100, 100); | |
2537 gfx::Size layer_bounds(400, 400); | |
2538 | |
2539 scoped_refptr<FakePicturePileImpl> pending_pile = | |
2540 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2541 scoped_refptr<FakePicturePileImpl> active_pile = | |
2542 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2543 | |
2544 SetupTrees(pending_pile, active_pile); | |
2545 | |
2546 Region invalidation; | |
2547 AddDefaultTilingsWithInvalidation(invalidation); | |
2548 float dummy_contents_scale_x; | |
2549 float dummy_contents_scale_y; | |
2550 gfx::Size dummy_content_bounds; | |
2551 active_layer_->CalculateContentsScale(1.f, | |
2552 1.f, | |
2553 1.f, | |
2554 1.f, | |
2555 false, | |
2556 &dummy_contents_scale_x, | |
2557 &dummy_contents_scale_y, | |
2558 &dummy_content_bounds); | |
2559 | |
2560 // UpdateTilePriorities with valid viewport. Should update tile viewport. | |
2561 bool valid_for_tile_management = true; | |
2562 gfx::Rect viewport = gfx::Rect(layer_bounds); | |
2563 gfx::Transform transform; | |
2564 host_impl_.SetExternalDrawConstraints( | |
2565 transform, viewport, viewport, valid_for_tile_management); | |
2566 active_layer_->draw_properties().visible_content_rect = viewport; | |
2567 active_layer_->draw_properties().screen_space_transform = transform; | |
2568 active_layer_->UpdateTilePriorities(); | |
2569 | |
2570 gfx::Rect visible_rect_for_tile_priority = | |
2571 active_layer_->visible_rect_for_tile_priority(); | |
2572 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); | |
2573 gfx::Size viewport_size_for_tile_priority = | |
2574 active_layer_->viewport_size_for_tile_priority(); | |
2575 EXPECT_FALSE(viewport_size_for_tile_priority.IsEmpty()); | |
2576 gfx::Transform screen_space_transform_for_tile_priority = | |
2577 active_layer_->screen_space_transform_for_tile_priority(); | |
2578 | |
2579 // Expand viewport and set it as invalid for prioritizing tiles. | |
2580 // Should not update tile viewport. | |
2581 time_ticks += base::TimeDelta::FromMilliseconds(200); | |
2582 host_impl_.SetCurrentFrameTimeTicks(time_ticks); | |
2583 valid_for_tile_management = false; | |
2584 viewport = gfx::ScaleToEnclosingRect(viewport, 2); | |
2585 transform.Translate(1.f, 1.f); | |
2586 active_layer_->draw_properties().visible_content_rect = viewport; | |
2587 active_layer_->draw_properties().screen_space_transform = transform; | |
2588 host_impl_.SetExternalDrawConstraints( | |
2589 transform, viewport, viewport, valid_for_tile_management); | |
2590 active_layer_->UpdateTilePriorities(); | |
2591 | |
2592 EXPECT_RECT_EQ(visible_rect_for_tile_priority, | |
2593 active_layer_->visible_rect_for_tile_priority()); | |
2594 EXPECT_SIZE_EQ(viewport_size_for_tile_priority, | |
2595 active_layer_->viewport_size_for_tile_priority()); | |
2596 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
2597 screen_space_transform_for_tile_priority, | |
2598 active_layer_->screen_space_transform_for_tile_priority()); | |
2599 | |
2600 // Keep expanded viewport but mark it valid. Should update tile viewport. | |
2601 time_ticks += base::TimeDelta::FromMilliseconds(200); | |
2602 host_impl_.SetCurrentFrameTimeTicks(time_ticks); | |
2603 valid_for_tile_management = true; | |
2604 host_impl_.SetExternalDrawConstraints( | |
2605 transform, viewport, viewport, valid_for_tile_management); | |
2606 active_layer_->UpdateTilePriorities(); | |
2607 | |
2608 EXPECT_FALSE(visible_rect_for_tile_priority == | |
2609 active_layer_->visible_rect_for_tile_priority()); | |
2610 EXPECT_FALSE(viewport_size_for_tile_priority == | |
2611 active_layer_->viewport_size_for_tile_priority()); | |
2612 EXPECT_FALSE(screen_space_transform_for_tile_priority == | |
2613 active_layer_->screen_space_transform_for_tile_priority()); | |
2614 } | |
2615 | |
2616 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportAfterReleaseResources) { | |
2617 base::TimeTicks time_ticks; | |
2618 host_impl_.SetCurrentFrameTimeTicks(time_ticks); | |
2619 | |
2620 gfx::Size tile_size(100, 100); | |
2621 gfx::Size layer_bounds(400, 400); | |
2622 | |
2623 scoped_refptr<FakePicturePileImpl> pending_pile = | |
2624 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2625 scoped_refptr<FakePicturePileImpl> active_pile = | |
2626 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2627 | |
2628 SetupTrees(pending_pile, active_pile); | |
2629 | |
2630 Region invalidation; | |
2631 AddDefaultTilingsWithInvalidation(invalidation); | |
2632 | |
2633 bool valid_for_tile_management = false; | |
2634 gfx::Rect viewport = gfx::Rect(layer_bounds); | |
2635 host_impl_.SetExternalDrawConstraints( | |
2636 gfx::Transform(), viewport, viewport, valid_for_tile_management); | |
2637 ResetTilingsAndRasterScales(); | |
2638 host_impl_.pending_tree()->UpdateDrawProperties(); | |
2639 host_impl_.active_tree()->UpdateDrawProperties(); | |
2640 EXPECT_TRUE(active_layer_->HighResTiling()); | |
2641 | |
2642 size_t num_tilings = active_layer_->num_tilings(); | |
2643 active_layer_->UpdateTilePriorities(); | |
2644 pending_layer_->AddTiling(0.5f); | |
2645 EXPECT_EQ(num_tilings + 1, active_layer_->num_tilings()); | |
2646 } | |
2647 | |
2648 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { | |
2649 gfx::Size tile_size(400, 400); | |
2650 gfx::Size layer_bounds(1300, 1900); | |
2651 | |
2652 scoped_refptr<FakePicturePileImpl> pending_pile = | |
2653 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2654 scoped_refptr<FakePicturePileImpl> active_pile = | |
2655 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2656 | |
2657 float result_scale_x, result_scale_y; | |
2658 gfx::Size result_bounds; | |
2659 std::vector<PictureLayerTiling*> used_tilings; | |
2660 | |
2661 SetupTrees(pending_pile, active_pile); | |
2662 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
2663 | |
2664 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | |
2665 EXPECT_LT(low_res_factor, 1.f); | |
2666 | |
2667 float device_scale = 1.7f; | |
2668 float page_scale = 3.2f; | |
2669 | |
2670 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); | |
2671 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); | |
2672 | |
2673 // We only have ideal tilings, so they aren't removed. | |
2674 used_tilings.clear(); | |
2675 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | |
2676 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); | |
2677 | |
2678 // Changing the ideal but not creating new tilings. | |
2679 SetContentsScaleOnBothLayers(1.5f, device_scale, page_scale, 1.f, false); | |
2680 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); | |
2681 | |
2682 // The tilings are still our target scale, so they aren't removed. | |
2683 used_tilings.clear(); | |
2684 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | |
2685 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); | |
2686 | |
2687 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2. | |
2688 page_scale = 1.2f; | |
2689 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false); | |
2690 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | |
2691 EXPECT_FLOAT_EQ( | |
2692 1.f, | |
2693 active_layer_->tilings()->tiling_at(1)->contents_scale()); | |
2694 | |
2695 // Mark the non-ideal tilings as used. They won't be removed. | |
2696 used_tilings.clear(); | |
2697 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); | |
2698 used_tilings.push_back(active_layer_->tilings()->tiling_at(3)); | |
2699 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | |
2700 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | |
2701 | |
2702 // Now move the ideal scale to 0.5. Our target stays 1.2. | |
2703 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false); | |
2704 | |
2705 // The high resolution tiling is between target and ideal, so is not | |
2706 // removed. The low res tiling for the old ideal=1.0 scale is removed. | |
2707 used_tilings.clear(); | |
2708 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | |
2709 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | |
2710 | |
2711 // Now move the ideal scale to 1.0. Our target stays 1.2. | |
2712 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); | |
2713 | |
2714 // All the tilings are between are target and the ideal, so they are not | |
2715 // removed. | |
2716 used_tilings.clear(); | |
2717 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | |
2718 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | |
2719 | |
2720 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. | |
2721 active_layer_->CalculateContentsScale(1.1f, | |
2722 device_scale, | |
2723 page_scale, | |
2724 1.f, | |
2725 false, | |
2726 &result_scale_x, | |
2727 &result_scale_y, | |
2728 &result_bounds); | |
2729 | |
2730 // Because the pending layer's ideal scale is still 1.0, our tilings fall | |
2731 // in the range [1.0,1.2] and are kept. | |
2732 used_tilings.clear(); | |
2733 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | |
2734 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | |
2735 | |
2736 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays | |
2737 // 1.2 still. | |
2738 pending_layer_->CalculateContentsScale(1.1f, | |
2739 device_scale, | |
2740 page_scale, | |
2741 1.f, | |
2742 false, | |
2743 &result_scale_x, | |
2744 &result_scale_y, | |
2745 &result_bounds); | |
2746 | |
2747 // Our 1.0 tiling now falls outside the range between our ideal scale and our | |
2748 // target raster scale. But it is in our used tilings set, so nothing is | |
2749 // deleted. | |
2750 used_tilings.clear(); | |
2751 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); | |
2752 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | |
2753 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | |
2754 | |
2755 // If we remove it from our used tilings set, it is outside the range to keep | |
2756 // so it is deleted. | |
2757 used_tilings.clear(); | |
2758 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | |
2759 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); | |
2760 } | |
2761 | |
2762 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) { | |
2763 gfx::Size tile_size(400, 400); | |
2764 gfx::Size layer_bounds(1300, 1900); | |
2765 | |
2766 scoped_refptr<FakePicturePileImpl> pending_pile = | |
2767 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2768 scoped_refptr<FakePicturePileImpl> active_pile = | |
2769 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
2770 | |
2771 float result_scale_x, result_scale_y; | |
2772 gfx::Size result_bounds; | |
2773 | |
2774 SetupTrees(pending_pile, active_pile); | |
2775 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
2776 | |
2777 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale | |
2778 2.7f, // device scale | |
2779 3.2f, // page scale | |
2780 1.f, // maximum animation scale | |
2781 false, | |
2782 &result_scale_x, | |
2783 &result_scale_y, | |
2784 &result_bounds); | |
2785 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
2786 | |
2787 // All tilings should be removed when losing output surface. | |
2788 active_layer_->ReleaseResources(); | |
2789 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | |
2790 pending_layer_->ReleaseResources(); | |
2791 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
2792 | |
2793 // This should create new tilings. | |
2794 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale | |
2795 2.7f, // device scale | |
2796 3.2f, // page scale | |
2797 1.f, // maximum animation scale | |
2798 false, | |
2799 &result_scale_x, | |
2800 &result_scale_y, | |
2801 &result_bounds); | |
2802 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
2803 } | |
2804 | |
2282 } // namespace | 2805 } // namespace |
2283 } // namespace cc | 2806 } // namespace cc |
OLD | NEW |