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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 2515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2526 // Set the tile priority rects such that only the tile with the second image | 2526 // Set the tile priority rects such that only the tile with the second image |
2527 // is scheduled for decodes, since it is checker-imaged. | 2527 // is scheduled for decodes, since it is checker-imaged. |
2528 gfx::Rect rect_to_raster(600, 0, 300, 900); | 2528 gfx::Rect rect_to_raster(600, 0, 300, 900); |
2529 active_tiling->SetTilePriorityRectsForTesting( | 2529 active_tiling->SetTilePriorityRectsForTesting( |
2530 gfx::Rect(rect_to_raster), // Visible rect. | 2530 gfx::Rect(rect_to_raster), // Visible rect. |
2531 gfx::Rect(rect_to_raster), // Skewport rect. | 2531 gfx::Rect(rect_to_raster), // Skewport rect. |
2532 gfx::Rect(rect_to_raster), // Soon rect. | 2532 gfx::Rect(rect_to_raster), // Soon rect. |
2533 gfx::Rect(rect_to_raster)); // Eventually rect. | 2533 gfx::Rect(rect_to_raster)); // Eventually rect. |
2534 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); | 2534 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
2535 | 2535 |
| 2536 // Finish all raster and dispatch completion callback so that the decode work |
| 2537 // for checkered images can be scheduled. |
| 2538 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner())->RunUntilIdle(); |
| 2539 base::RunLoop().RunUntilIdle(); |
| 2540 |
2536 // Run decode tasks to trigger completion of any pending decodes. | 2541 // Run decode tasks to trigger completion of any pending decodes. |
2537 FlushDecodeTasks(); | 2542 FlushDecodeTasks(); |
2538 | 2543 |
2539 // Create a new pending tree to invalidate tiles for decoded images and verify | 2544 // Create a new pending tree to invalidate tiles for decoded images and verify |
2540 // that only tiles for |image2| are invalidated. | 2545 // that only tiles for |image2| are invalidated. |
2541 EXPECT_TRUE(host_impl()->client()->did_request_impl_side_invalidation()); | 2546 EXPECT_TRUE(host_impl()->client()->did_request_impl_side_invalidation()); |
2542 PerformImplSideInvalidation(); | 2547 PerformImplSideInvalidation(); |
2543 for (int i = 0; i < 2; i++) { | 2548 for (int i = 0; i < 2; i++) { |
2544 for (int j = 0; j < 2; j++) { | 2549 for (int j = 0; j < 2; j++) { |
2545 const Tile* tile = pending_tiling->TileAt(i, j); | 2550 const Tile* tile = pending_tiling->TileAt(i, j); |
(...skipping 20 matching lines...) Expand all Loading... |
2566 gfx::Rect(layer_bounds)); // Eventually rect. | 2571 gfx::Rect(layer_bounds)); // Eventually rect. |
2567 host_impl()->SetVisible(false); | 2572 host_impl()->SetVisible(false); |
2568 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); | 2573 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
2569 FlushDecodeTasks(); | 2574 FlushDecodeTasks(); |
2570 EXPECT_FALSE(host_impl()->client()->did_request_impl_side_invalidation()); | 2575 EXPECT_FALSE(host_impl()->client()->did_request_impl_side_invalidation()); |
2571 } | 2576 } |
2572 | 2577 |
2573 TEST_F(CheckerImagingTileManagerTest, | 2578 TEST_F(CheckerImagingTileManagerTest, |
2574 TileManagerCleanupClearsCheckerImagedDecodes) { | 2579 TileManagerCleanupClearsCheckerImagedDecodes) { |
2575 const gfx::Size layer_bounds(512, 512); | 2580 const gfx::Size layer_bounds(512, 512); |
2576 SetupDefaultTrees(layer_bounds); | |
2577 | 2581 |
2578 std::unique_ptr<FakeRecordingSource> recording_source = | 2582 std::unique_ptr<FakeRecordingSource> recording_source = |
2579 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 2583 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
2580 recording_source->set_fill_with_nonsolid_color(true); | 2584 recording_source->set_fill_with_nonsolid_color(true); |
2581 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(512, 512)); | 2585 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(512, 512)); |
2582 recording_source->add_draw_image(image, gfx::Point(0, 0)); | 2586 recording_source->add_draw_image(image, gfx::Point(0, 0)); |
2583 recording_source->Rerecord(); | 2587 recording_source->Rerecord(); |
2584 scoped_refptr<RasterSource> raster_source = | 2588 scoped_refptr<RasterSource> raster_source = |
2585 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 2589 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
2586 | 2590 |
2587 std::unique_ptr<PictureLayerImpl> layer_impl = PictureLayerImpl::Create( | 2591 SetupPendingTree(raster_source, gfx::Size(100, 100), |
2588 host_impl()->active_tree(), 1, Layer::LayerMaskType::NOT_MASK); | 2592 Region(gfx::Rect(0, 0, 500, 500))); |
2589 layer_impl->set_contributes_to_drawn_render_surface(true); | |
2590 PictureLayerTilingSet* tiling_set = layer_impl->picture_layer_tiling_set(); | |
2591 | |
2592 PictureLayerTiling* tiling = | |
2593 tiling_set->AddTiling(gfx::AxisTransform2d(), raster_source); | |
2594 tiling->set_resolution(HIGH_RESOLUTION); | |
2595 tiling->CreateAllTilesForTesting(); | |
2596 tiling->SetTilePriorityRectsForTesting( | |
2597 gfx::Rect(layer_bounds), // Visible rect. | |
2598 gfx::Rect(layer_bounds), // Skewport rect. | |
2599 gfx::Rect(layer_bounds), // Soon rect. | |
2600 gfx::Rect(layer_bounds)); // Eventually rect. | |
2601 | 2593 |
2602 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); | 2594 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
| 2595 // Finish all raster and dispatch completion callback so that the decode work |
| 2596 // for checkered images can be scheduled. |
| 2597 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner())->RunUntilIdle(); |
| 2598 base::RunLoop().RunUntilIdle(); |
2603 FlushDecodeTasks(); | 2599 FlushDecodeTasks(); |
| 2600 |
2604 EXPECT_TRUE(host_impl() | 2601 EXPECT_TRUE(host_impl() |
2605 ->tile_manager() | 2602 ->tile_manager() |
2606 ->checker_image_tracker() | 2603 ->checker_image_tracker() |
2607 .has_locked_decodes_for_testing()); | 2604 .has_locked_decodes_for_testing()); |
| 2605 |
| 2606 host_impl()->pending_tree()->ReleaseTileResources(); |
2608 CleanUpTileManager(); | 2607 CleanUpTileManager(); |
| 2608 |
2609 EXPECT_FALSE(host_impl() | 2609 EXPECT_FALSE(host_impl() |
2610 ->tile_manager() | 2610 ->tile_manager() |
2611 ->checker_image_tracker() | 2611 ->checker_image_tracker() |
2612 .has_locked_decodes_for_testing()); | 2612 .has_locked_decodes_for_testing()); |
2613 EXPECT_TRUE( | 2613 EXPECT_TRUE( |
2614 host_impl()->tile_manager()->TakeImagesToInvalidateOnSyncTree().empty()); | 2614 host_impl()->tile_manager()->TakeImagesToInvalidateOnSyncTree().empty()); |
2615 } | 2615 } |
2616 | 2616 |
| 2617 TEST_F(CheckerImagingTileManagerTest, |
| 2618 TileManagerCorrectlyPrioritizesCheckerImagedDecodes) { |
| 2619 gfx::Size layer_bounds(500, 500); |
| 2620 |
| 2621 std::unique_ptr<FakeRecordingSource> recording_source = |
| 2622 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
| 2623 recording_source->set_fill_with_nonsolid_color(true); |
| 2624 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(512, 512)); |
| 2625 recording_source->add_draw_image(image, gfx::Point(0, 0)); |
| 2626 recording_source->Rerecord(); |
| 2627 scoped_refptr<RasterSource> raster_source = |
| 2628 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
| 2629 |
| 2630 // Required for activation tiles block checker-imaged decodes. |
| 2631 SetupPendingTree(raster_source, gfx::Size(100, 100), |
| 2632 Region(gfx::Rect(0, 0, 500, 500))); |
| 2633 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
| 2634 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); |
| 2635 EXPECT_TRUE(host_impl() |
| 2636 ->tile_manager() |
| 2637 ->checker_image_tracker() |
| 2638 .no_decodes_allowed_for_testing()); |
| 2639 while (!host_impl()->client()->ready_to_activate()) { |
| 2640 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner()) |
| 2641 ->RunSingleTaskForTesting(); |
| 2642 base::RunLoop().RunUntilIdle(); |
| 2643 } |
| 2644 EXPECT_EQ(host_impl() |
| 2645 ->tile_manager() |
| 2646 ->checker_image_tracker() |
| 2647 .decode_priority_allowed_for_testing(), |
| 2648 CheckerImageTracker::DecodeType::kRaster); |
| 2649 |
| 2650 // Finishing all tasks allows pre-decodes. |
| 2651 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner())->RunUntilIdle(); |
| 2652 base::RunLoop().RunUntilIdle(); |
| 2653 EXPECT_EQ(host_impl() |
| 2654 ->tile_manager() |
| 2655 ->checker_image_tracker() |
| 2656 .decode_priority_allowed_for_testing(), |
| 2657 CheckerImageTracker::DecodeType::kPreDecode); |
| 2658 |
| 2659 // Required for draw tiles block checker-imaged decodes. |
| 2660 // Free all tile resources and perform another PrepareTiles. |
| 2661 ActivateTree(); |
| 2662 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw()); |
| 2663 host_impl()->tile_manager()->PrepareTiles( |
| 2664 GlobalStateThatImpactsTilePriority()); |
| 2665 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToDraw()); |
| 2666 |
| 2667 host_impl()->client()->reset_ready_to_draw(); |
| 2668 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
| 2669 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); |
| 2670 EXPECT_TRUE(host_impl() |
| 2671 ->tile_manager() |
| 2672 ->checker_image_tracker() |
| 2673 .no_decodes_allowed_for_testing()); |
| 2674 while (!host_impl()->client()->ready_to_draw()) { |
| 2675 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner()) |
| 2676 ->RunSingleTaskForTesting(); |
| 2677 base::RunLoop().RunUntilIdle(); |
| 2678 } |
| 2679 EXPECT_EQ(host_impl() |
| 2680 ->tile_manager() |
| 2681 ->checker_image_tracker() |
| 2682 .decode_priority_allowed_for_testing(), |
| 2683 CheckerImageTracker::DecodeType::kRaster); |
| 2684 } |
| 2685 |
2617 class CheckerImagingTileManagerMemoryTest | 2686 class CheckerImagingTileManagerMemoryTest |
2618 : public CheckerImagingTileManagerTest { | 2687 : public CheckerImagingTileManagerTest { |
2619 public: | 2688 public: |
2620 std::unique_ptr<FakeLayerTreeHostImpl> CreateHostImpl( | 2689 std::unique_ptr<FakeLayerTreeHostImpl> CreateHostImpl( |
2621 const LayerTreeSettings& settings, | 2690 const LayerTreeSettings& settings, |
2622 TaskRunnerProvider* task_runner_provider, | 2691 TaskRunnerProvider* task_runner_provider, |
2623 TaskGraphRunner* task_graph_runner) override { | 2692 TaskGraphRunner* task_graph_runner) override { |
2624 LayerTreeSettings new_settings = settings; | 2693 LayerTreeSettings new_settings = settings; |
2625 new_settings.gpu_memory_policy.num_resources_limit = 4; | 2694 new_settings.gpu_memory_policy.num_resources_limit = 4; |
2626 return CheckerImagingTileManagerTest::CreateHostImpl( | 2695 return CheckerImagingTileManagerTest::CreateHostImpl( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2679 gfx::Rect complete_tiling_rect(layer_bounds); | 2748 gfx::Rect complete_tiling_rect(layer_bounds); |
2680 PictureLayerTiling* active_tiling = | 2749 PictureLayerTiling* active_tiling = |
2681 active_layer()->picture_layer_tiling_set()->tiling_at(0); | 2750 active_layer()->picture_layer_tiling_set()->tiling_at(0); |
2682 active_tiling->SetTilePriorityRectsForTesting( | 2751 active_tiling->SetTilePriorityRectsForTesting( |
2683 complete_tiling_rect, // Visible rect. | 2752 complete_tiling_rect, // Visible rect. |
2684 complete_tiling_rect, // Skewport rect. | 2753 complete_tiling_rect, // Skewport rect. |
2685 complete_tiling_rect, // Soon rect. | 2754 complete_tiling_rect, // Soon rect. |
2686 complete_tiling_rect); // Eventually rect. | 2755 complete_tiling_rect); // Eventually rect. |
2687 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); | 2756 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
2688 | 2757 |
| 2758 // Finish all raster work so the decode work for checkered images can be |
| 2759 // scheduled. |
| 2760 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner())->RunUntilIdle(); |
| 2761 base::RunLoop().RunUntilIdle(); |
| 2762 |
2689 // Flush all decode tasks. The tiles with checkered images should be | 2763 // Flush all decode tasks. The tiles with checkered images should be |
2690 // invalidated. | 2764 // invalidated. |
2691 FlushDecodeTasks(); | 2765 FlushDecodeTasks(); |
2692 EXPECT_TRUE(host_impl()->client()->did_request_impl_side_invalidation()); | 2766 EXPECT_TRUE(host_impl()->client()->did_request_impl_side_invalidation()); |
2693 PerformImplSideInvalidation(); | 2767 PerformImplSideInvalidation(); |
2694 for (int i = 0; i < 2; i++) { | 2768 for (int i = 0; i < 2; i++) { |
2695 for (int j = 0; j < 3; j++) { | 2769 for (int j = 0; j < 3; j++) { |
2696 const Tile* tile = pending_tiling->TileAt(i, j); | 2770 const Tile* tile = pending_tiling->TileAt(i, j); |
2697 if (j == 1) | 2771 if (j == 1) |
2698 EXPECT_TRUE(tile); | 2772 EXPECT_TRUE(tile); |
2699 else | 2773 else |
2700 EXPECT_FALSE(tile); | 2774 EXPECT_FALSE(tile); |
2701 } | 2775 } |
2702 } | 2776 } |
2703 host_impl()->client()->reset_did_request_impl_side_invalidation(); | 2777 host_impl()->client()->reset_did_request_impl_side_invalidation(); |
2704 } | 2778 } |
2705 | 2779 |
2706 } // namespace | 2780 } // namespace |
2707 } // namespace cc | 2781 } // namespace cc |
OLD | NEW |