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> |
(...skipping 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 | 2440 |
2441 // High-res tiles should not be enough. | 2441 // High-res tiles should not be enough. |
2442 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | 2442 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); |
2443 | 2443 |
2444 // Initialize remaining tiles. | 2444 // Initialize remaining tiles. |
2445 pending_layer_->SetAllTilesReady(); | 2445 pending_layer_->SetAllTilesReady(); |
2446 | 2446 |
2447 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | 2447 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); |
2448 } | 2448 } |
2449 | 2449 |
| 2450 class NoLowResTilingsSettings : public ImplSidePaintingSettings { |
| 2451 public: |
| 2452 NoLowResTilingsSettings() { create_low_res_tiling = false; } |
| 2453 }; |
| 2454 |
| 2455 class NoLowResPictureLayerImplTest : public PictureLayerImplTest { |
| 2456 public: |
| 2457 NoLowResPictureLayerImplTest() |
| 2458 : PictureLayerImplTest(NoLowResTilingsSettings()) {} |
| 2459 }; |
| 2460 |
| 2461 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) { |
| 2462 gfx::Size tile_size(400, 400); |
| 2463 gfx::Size layer_bounds(1300, 1900); |
| 2464 |
| 2465 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 2466 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2467 scoped_refptr<FakePicturePileImpl> active_pile = |
| 2468 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2469 |
| 2470 float result_scale_x, result_scale_y; |
| 2471 gfx::Size result_bounds; |
| 2472 |
| 2473 SetupTrees(pending_pile, active_pile); |
| 2474 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 2475 |
| 2476 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
| 2477 EXPECT_LT(low_res_factor, 1.f); |
| 2478 |
| 2479 pending_layer_->CalculateContentsScale(6.f, // ideal contents scale |
| 2480 3.f, // device scale |
| 2481 2.f, // page scale |
| 2482 1.f, // maximum animation scale |
| 2483 false, |
| 2484 &result_scale_x, |
| 2485 &result_scale_y, |
| 2486 &result_bounds); |
| 2487 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 2488 EXPECT_FLOAT_EQ(6.f, |
| 2489 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 2490 |
| 2491 // If we change the page scale factor, then we should get new tilings. |
| 2492 pending_layer_->CalculateContentsScale(6.6f, // ideal contents scale |
| 2493 3.f, // device scale |
| 2494 2.2f, // page scale |
| 2495 1.f, // maximum animation scale |
| 2496 false, |
| 2497 &result_scale_x, |
| 2498 &result_scale_y, |
| 2499 &result_bounds); |
| 2500 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
| 2501 EXPECT_FLOAT_EQ(6.6f, |
| 2502 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 2503 |
| 2504 // If we change the device scale factor, then we should get new tilings. |
| 2505 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale |
| 2506 3.3f, // device scale |
| 2507 2.2f, // page scale |
| 2508 1.f, // maximum animation scale |
| 2509 false, |
| 2510 &result_scale_x, |
| 2511 &result_scale_y, |
| 2512 &result_bounds); |
| 2513 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); |
| 2514 EXPECT_FLOAT_EQ(7.26f, |
| 2515 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 2516 |
| 2517 // If we change the device scale factor, but end up at the same total scale |
| 2518 // factor somehow, then we don't get new tilings. |
| 2519 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale |
| 2520 2.2f, // device scale |
| 2521 3.3f, // page scale |
| 2522 1.f, // maximum animation scale |
| 2523 false, |
| 2524 &result_scale_x, |
| 2525 &result_scale_y, |
| 2526 &result_bounds); |
| 2527 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); |
| 2528 EXPECT_FLOAT_EQ(7.26f, |
| 2529 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 2530 } |
| 2531 |
| 2532 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredNullTiles) { |
| 2533 gfx::Size tile_size(100, 100); |
| 2534 gfx::Size layer_bounds(1000, 1000); |
| 2535 |
| 2536 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 2537 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
| 2538 // Layers with entirely empty piles can't get tilings. |
| 2539 pending_pile->AddRecordingAt(0, 0); |
| 2540 |
| 2541 SetupPendingTree(pending_pile); |
| 2542 |
| 2543 ASSERT_TRUE(pending_layer_->CanHaveTilings()); |
| 2544 pending_layer_->AddTiling(1.0f); |
| 2545 pending_layer_->AddTiling(2.0f); |
| 2546 |
| 2547 // It should be safe to call this (and MarkVisibleResourcesAsRequired) |
| 2548 // on a layer with no recordings. |
| 2549 host_impl_.pending_tree()->UpdateDrawProperties(); |
| 2550 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 2551 } |
| 2552 |
| 2553 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) { |
| 2554 gfx::Size layer_bounds(400, 400); |
| 2555 gfx::Size tile_size(100, 100); |
| 2556 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
| 2557 |
| 2558 CreateHighLowResAndSetAllTilesVisible(); |
| 2559 |
| 2560 Tile* some_active_tile = |
| 2561 active_layer_->HighResTiling()->AllTilesForTesting()[0]; |
| 2562 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); |
| 2563 |
| 2564 // All tiles shared (no invalidation), so even though the active tree's |
| 2565 // tiles aren't ready, there is nothing required. |
| 2566 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 2567 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
| 2568 if (host_impl_.settings().create_low_res_tiling) { |
| 2569 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
| 2570 } |
| 2571 } |
| 2572 |
| 2573 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { |
| 2574 gfx::Size layer_bounds(400, 400); |
| 2575 gfx::Size tile_size(100, 100); |
| 2576 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 2577 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2578 // This pile will create tilings, but has no recordings so will not create any |
| 2579 // tiles. This is attempting to simulate scrolling past the end of recorded |
| 2580 // content on the active layer, where the recordings are so far away that |
| 2581 // no tiles are created. |
| 2582 scoped_refptr<FakePicturePileImpl> active_pile = |
| 2583 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( |
| 2584 tile_size, layer_bounds); |
| 2585 SetupTrees(pending_pile, active_pile); |
| 2586 pending_layer_->set_fixed_tile_size(tile_size); |
| 2587 active_layer_->set_fixed_tile_size(tile_size); |
| 2588 |
| 2589 CreateHighLowResAndSetAllTilesVisible(); |
| 2590 |
| 2591 // Active layer has tilings, but no tiles due to missing recordings. |
| 2592 EXPECT_TRUE(active_layer_->CanHaveTilings()); |
| 2593 EXPECT_EQ(active_layer_->tilings()->num_tilings(), |
| 2594 host_impl_.settings().create_low_res_tiling ? 2u : 1u); |
| 2595 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); |
| 2596 |
| 2597 // Since the active layer has no tiles at all, the pending layer doesn't |
| 2598 // need content in order to activate. |
| 2599 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 2600 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
| 2601 if (host_impl_.settings().create_low_res_tiling) |
| 2602 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
| 2603 } |
| 2604 |
| 2605 TEST_F(NoLowResPictureLayerImplTest, TileManagerRegisterUnregister) { |
| 2606 gfx::Size tile_size(100, 100); |
| 2607 gfx::Size layer_bounds(400, 400); |
| 2608 |
| 2609 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 2610 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2611 scoped_refptr<FakePicturePileImpl> active_pile = |
| 2612 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2613 |
| 2614 SetupTrees(pending_pile, active_pile); |
| 2615 |
| 2616 std::vector<TileManager::PairedPictureLayer> paired_layers; |
| 2617 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); |
| 2618 EXPECT_EQ(0u, paired_layers.size()); |
| 2619 |
| 2620 // Update tile priorities will force the layer to register itself. |
| 2621 float dummy_contents_scale_x; |
| 2622 float dummy_contents_scale_y; |
| 2623 gfx::Size dummy_content_bounds; |
| 2624 active_layer_->CalculateContentsScale(1.f, |
| 2625 1.f, |
| 2626 1.f, |
| 2627 1.f, |
| 2628 false, |
| 2629 &dummy_contents_scale_x, |
| 2630 &dummy_contents_scale_y, |
| 2631 &dummy_content_bounds); |
| 2632 active_layer_->UpdateTilePriorities(); |
| 2633 host_impl_.pending_tree()->UpdateDrawProperties(); |
| 2634 pending_layer_->CalculateContentsScale(1.f, |
| 2635 1.f, |
| 2636 1.f, |
| 2637 1.f, |
| 2638 false, |
| 2639 &dummy_contents_scale_x, |
| 2640 &dummy_contents_scale_y, |
| 2641 &dummy_content_bounds); |
| 2642 pending_layer_->UpdateTilePriorities(); |
| 2643 |
| 2644 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); |
| 2645 EXPECT_EQ(1u, paired_layers.size()); |
| 2646 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); |
| 2647 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); |
| 2648 |
| 2649 // Destroy and recreate tile manager. |
| 2650 host_impl_.DidLoseOutputSurface(); |
| 2651 scoped_ptr<TestWebGraphicsContext3D> context = |
| 2652 TestWebGraphicsContext3D::Create(); |
| 2653 host_impl_.InitializeRenderer( |
| 2654 FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>()); |
| 2655 |
| 2656 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); |
| 2657 EXPECT_EQ(0u, paired_layers.size()); |
| 2658 |
| 2659 active_layer_->CalculateContentsScale(1.f, |
| 2660 1.f, |
| 2661 1.f, |
| 2662 1.f, |
| 2663 false, |
| 2664 &dummy_contents_scale_x, |
| 2665 &dummy_contents_scale_y, |
| 2666 &dummy_content_bounds); |
| 2667 active_layer_->UpdateTilePriorities(); |
| 2668 host_impl_.pending_tree()->UpdateDrawProperties(); |
| 2669 pending_layer_->CalculateContentsScale(1.f, |
| 2670 1.f, |
| 2671 1.f, |
| 2672 1.f, |
| 2673 false, |
| 2674 &dummy_contents_scale_x, |
| 2675 &dummy_contents_scale_y, |
| 2676 &dummy_content_bounds); |
| 2677 pending_layer_->UpdateTilePriorities(); |
| 2678 |
| 2679 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); |
| 2680 EXPECT_EQ(1u, paired_layers.size()); |
| 2681 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); |
| 2682 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); |
| 2683 } |
| 2684 |
| 2685 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { |
| 2686 base::TimeTicks time_ticks; |
| 2687 host_impl_.SetCurrentFrameTimeTicks(time_ticks); |
| 2688 |
| 2689 gfx::Size tile_size(100, 100); |
| 2690 gfx::Size layer_bounds(400, 400); |
| 2691 |
| 2692 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 2693 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2694 scoped_refptr<FakePicturePileImpl> active_pile = |
| 2695 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2696 |
| 2697 SetupTrees(pending_pile, active_pile); |
| 2698 |
| 2699 Region invalidation; |
| 2700 AddDefaultTilingsWithInvalidation(invalidation); |
| 2701 float dummy_contents_scale_x; |
| 2702 float dummy_contents_scale_y; |
| 2703 gfx::Size dummy_content_bounds; |
| 2704 active_layer_->CalculateContentsScale(1.f, |
| 2705 1.f, |
| 2706 1.f, |
| 2707 1.f, |
| 2708 false, |
| 2709 &dummy_contents_scale_x, |
| 2710 &dummy_contents_scale_y, |
| 2711 &dummy_content_bounds); |
| 2712 |
| 2713 // UpdateTilePriorities with valid viewport. Should update tile viewport. |
| 2714 bool valid_for_tile_management = true; |
| 2715 gfx::Rect viewport = gfx::Rect(layer_bounds); |
| 2716 gfx::Transform transform; |
| 2717 host_impl_.SetExternalDrawConstraints( |
| 2718 transform, viewport, viewport, valid_for_tile_management); |
| 2719 active_layer_->draw_properties().visible_content_rect = viewport; |
| 2720 active_layer_->draw_properties().screen_space_transform = transform; |
| 2721 active_layer_->UpdateTilePriorities(); |
| 2722 |
| 2723 gfx::Rect visible_rect_for_tile_priority = |
| 2724 active_layer_->visible_rect_for_tile_priority(); |
| 2725 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); |
| 2726 gfx::Size viewport_size_for_tile_priority = |
| 2727 active_layer_->viewport_size_for_tile_priority(); |
| 2728 EXPECT_FALSE(viewport_size_for_tile_priority.IsEmpty()); |
| 2729 gfx::Transform screen_space_transform_for_tile_priority = |
| 2730 active_layer_->screen_space_transform_for_tile_priority(); |
| 2731 |
| 2732 // Expand viewport and set it as invalid for prioritizing tiles. |
| 2733 // Should not update tile viewport. |
| 2734 time_ticks += base::TimeDelta::FromMilliseconds(200); |
| 2735 host_impl_.SetCurrentFrameTimeTicks(time_ticks); |
| 2736 valid_for_tile_management = false; |
| 2737 viewport = gfx::ScaleToEnclosingRect(viewport, 2); |
| 2738 transform.Translate(1.f, 1.f); |
| 2739 active_layer_->draw_properties().visible_content_rect = viewport; |
| 2740 active_layer_->draw_properties().screen_space_transform = transform; |
| 2741 host_impl_.SetExternalDrawConstraints( |
| 2742 transform, viewport, viewport, valid_for_tile_management); |
| 2743 active_layer_->UpdateTilePriorities(); |
| 2744 |
| 2745 EXPECT_RECT_EQ(visible_rect_for_tile_priority, |
| 2746 active_layer_->visible_rect_for_tile_priority()); |
| 2747 EXPECT_SIZE_EQ(viewport_size_for_tile_priority, |
| 2748 active_layer_->viewport_size_for_tile_priority()); |
| 2749 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 2750 screen_space_transform_for_tile_priority, |
| 2751 active_layer_->screen_space_transform_for_tile_priority()); |
| 2752 |
| 2753 // Keep expanded viewport but mark it valid. Should update tile viewport. |
| 2754 time_ticks += base::TimeDelta::FromMilliseconds(200); |
| 2755 host_impl_.SetCurrentFrameTimeTicks(time_ticks); |
| 2756 valid_for_tile_management = true; |
| 2757 host_impl_.SetExternalDrawConstraints( |
| 2758 transform, viewport, viewport, valid_for_tile_management); |
| 2759 active_layer_->UpdateTilePriorities(); |
| 2760 |
| 2761 EXPECT_FALSE(visible_rect_for_tile_priority == |
| 2762 active_layer_->visible_rect_for_tile_priority()); |
| 2763 EXPECT_FALSE(viewport_size_for_tile_priority == |
| 2764 active_layer_->viewport_size_for_tile_priority()); |
| 2765 EXPECT_FALSE(screen_space_transform_for_tile_priority == |
| 2766 active_layer_->screen_space_transform_for_tile_priority()); |
| 2767 } |
| 2768 |
| 2769 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportAfterReleaseResources) { |
| 2770 base::TimeTicks time_ticks; |
| 2771 host_impl_.SetCurrentFrameTimeTicks(time_ticks); |
| 2772 |
| 2773 gfx::Size tile_size(100, 100); |
| 2774 gfx::Size layer_bounds(400, 400); |
| 2775 |
| 2776 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 2777 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2778 scoped_refptr<FakePicturePileImpl> active_pile = |
| 2779 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2780 |
| 2781 SetupTrees(pending_pile, active_pile); |
| 2782 |
| 2783 Region invalidation; |
| 2784 AddDefaultTilingsWithInvalidation(invalidation); |
| 2785 |
| 2786 bool valid_for_tile_management = false; |
| 2787 gfx::Rect viewport = gfx::Rect(layer_bounds); |
| 2788 host_impl_.SetExternalDrawConstraints( |
| 2789 gfx::Transform(), viewport, viewport, valid_for_tile_management); |
| 2790 ResetTilingsAndRasterScales(); |
| 2791 host_impl_.pending_tree()->UpdateDrawProperties(); |
| 2792 host_impl_.active_tree()->UpdateDrawProperties(); |
| 2793 EXPECT_TRUE(active_layer_->HighResTiling()); |
| 2794 |
| 2795 size_t num_tilings = active_layer_->num_tilings(); |
| 2796 active_layer_->UpdateTilePriorities(); |
| 2797 pending_layer_->AddTiling(0.5f); |
| 2798 EXPECT_EQ(num_tilings + 1, active_layer_->num_tilings()); |
| 2799 } |
| 2800 |
| 2801 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { |
| 2802 gfx::Size tile_size(400, 400); |
| 2803 gfx::Size layer_bounds(1300, 1900); |
| 2804 |
| 2805 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 2806 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2807 scoped_refptr<FakePicturePileImpl> active_pile = |
| 2808 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2809 |
| 2810 float result_scale_x, result_scale_y; |
| 2811 gfx::Size result_bounds; |
| 2812 std::vector<PictureLayerTiling*> used_tilings; |
| 2813 |
| 2814 SetupTrees(pending_pile, active_pile); |
| 2815 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 2816 |
| 2817 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
| 2818 EXPECT_LT(low_res_factor, 1.f); |
| 2819 |
| 2820 float device_scale = 1.7f; |
| 2821 float page_scale = 3.2f; |
| 2822 float scale = 1.f; |
| 2823 |
| 2824 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false); |
| 2825 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
| 2826 |
| 2827 // We only have ideal tilings, so they aren't removed. |
| 2828 used_tilings.clear(); |
| 2829 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 2830 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
| 2831 |
| 2832 host_impl_.PinchGestureBegin(); |
| 2833 |
| 2834 // Changing the ideal but not creating new tilings. |
| 2835 scale *= 1.5f; |
| 2836 page_scale *= 1.5f; |
| 2837 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false); |
| 2838 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
| 2839 |
| 2840 // The tilings are still our target scale, so they aren't removed. |
| 2841 used_tilings.clear(); |
| 2842 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 2843 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
| 2844 |
| 2845 host_impl_.PinchGestureEnd(); |
| 2846 |
| 2847 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2. |
| 2848 scale /= 4.f; |
| 2849 page_scale /= 4.f; |
| 2850 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false); |
| 2851 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
| 2852 EXPECT_FLOAT_EQ(1.f, |
| 2853 active_layer_->tilings()->tiling_at(1)->contents_scale()); |
| 2854 |
| 2855 // Mark the non-ideal tilings as used. They won't be removed. |
| 2856 used_tilings.clear(); |
| 2857 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); |
| 2858 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 2859 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
| 2860 |
| 2861 // Now move the ideal scale to 0.5. Our target stays 1.2. |
| 2862 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false); |
| 2863 |
| 2864 // The high resolution tiling is between target and ideal, so is not |
| 2865 // removed. The low res tiling for the old ideal=1.0 scale is removed. |
| 2866 used_tilings.clear(); |
| 2867 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 2868 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
| 2869 |
| 2870 // Now move the ideal scale to 1.0. Our target stays 1.2. |
| 2871 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); |
| 2872 |
| 2873 // All the tilings are between are target and the ideal, so they are not |
| 2874 // removed. |
| 2875 used_tilings.clear(); |
| 2876 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 2877 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
| 2878 |
| 2879 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. |
| 2880 active_layer_->CalculateContentsScale(1.1f, |
| 2881 device_scale, |
| 2882 page_scale, |
| 2883 1.f, |
| 2884 false, |
| 2885 &result_scale_x, |
| 2886 &result_scale_y, |
| 2887 &result_bounds); |
| 2888 |
| 2889 // Because the pending layer's ideal scale is still 1.0, our tilings fall |
| 2890 // in the range [1.0,1.2] and are kept. |
| 2891 used_tilings.clear(); |
| 2892 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 2893 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
| 2894 |
| 2895 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays |
| 2896 // 1.2 still. |
| 2897 pending_layer_->CalculateContentsScale(1.1f, |
| 2898 device_scale, |
| 2899 page_scale, |
| 2900 1.f, |
| 2901 false, |
| 2902 &result_scale_x, |
| 2903 &result_scale_y, |
| 2904 &result_bounds); |
| 2905 |
| 2906 // Our 1.0 tiling now falls outside the range between our ideal scale and our |
| 2907 // target raster scale. But it is in our used tilings set, so nothing is |
| 2908 // deleted. |
| 2909 used_tilings.clear(); |
| 2910 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); |
| 2911 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 2912 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
| 2913 |
| 2914 // If we remove it from our used tilings set, it is outside the range to keep |
| 2915 // so it is deleted. |
| 2916 used_tilings.clear(); |
| 2917 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 2918 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
| 2919 } |
| 2920 |
| 2921 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) { |
| 2922 gfx::Size tile_size(400, 400); |
| 2923 gfx::Size layer_bounds(1300, 1900); |
| 2924 |
| 2925 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 2926 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2927 scoped_refptr<FakePicturePileImpl> active_pile = |
| 2928 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2929 |
| 2930 float result_scale_x, result_scale_y; |
| 2931 gfx::Size result_bounds; |
| 2932 |
| 2933 SetupTrees(pending_pile, active_pile); |
| 2934 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 2935 |
| 2936 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale |
| 2937 2.7f, // device scale |
| 2938 3.2f, // page scale |
| 2939 1.f, // maximum animation scale |
| 2940 false, |
| 2941 &result_scale_x, |
| 2942 &result_scale_y, |
| 2943 &result_bounds); |
| 2944 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 2945 |
| 2946 // All tilings should be removed when losing output surface. |
| 2947 active_layer_->ReleaseResources(); |
| 2948 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
| 2949 pending_layer_->ReleaseResources(); |
| 2950 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 2951 |
| 2952 // This should create new tilings. |
| 2953 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale |
| 2954 2.7f, // device scale |
| 2955 3.2f, // page scale |
| 2956 1.f, // maximum animation scale |
| 2957 false, |
| 2958 &result_scale_x, |
| 2959 &result_scale_y, |
| 2960 &result_bounds); |
| 2961 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 2962 } |
| 2963 |
2450 } // namespace | 2964 } // namespace |
2451 } // namespace cc | 2965 } // namespace cc |
OLD | NEW |