| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "cc/base/math_util.h" | 17 #include "cc/base/math_util.h" |
| 18 #include "cc/layers/append_quads_data.h" | 18 #include "cc/layers/append_quads_data.h" |
| 19 #include "cc/layers/picture_layer.h" | 19 #include "cc/layers/picture_layer.h" |
| 20 #include "cc/output/buffer_to_texture_target_map.h" |
| 20 #include "cc/quads/draw_quad.h" | 21 #include "cc/quads/draw_quad.h" |
| 21 #include "cc/quads/tile_draw_quad.h" | 22 #include "cc/quads/tile_draw_quad.h" |
| 22 #include "cc/test/begin_frame_args_test.h" | 23 #include "cc/test/begin_frame_args_test.h" |
| 23 #include "cc/test/fake_content_layer_client.h" | 24 #include "cc/test/fake_content_layer_client.h" |
| 24 #include "cc/test/fake_impl_task_runner_provider.h" | 25 #include "cc/test/fake_impl_task_runner_provider.h" |
| 25 #include "cc/test/fake_layer_tree_host.h" | 26 #include "cc/test/fake_layer_tree_host.h" |
| 26 #include "cc/test/fake_layer_tree_host_client.h" | 27 #include "cc/test/fake_layer_tree_host_client.h" |
| 27 #include "cc/test/fake_layer_tree_host_impl.h" | 28 #include "cc/test/fake_layer_tree_host_impl.h" |
| 28 #include "cc/test/fake_output_surface.h" | 29 #include "cc/test/fake_output_surface.h" |
| 29 #include "cc/test/fake_picture_layer_impl.h" | 30 #include "cc/test/fake_picture_layer_impl.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 host_impl()->SetViewportSize(gfx::Size(10000, 10000)); | 90 host_impl()->SetViewportSize(gfx::Size(10000, 10000)); |
| 90 } | 91 } |
| 91 | 92 |
| 92 LayerTreeSettings CreateSettings() override { | 93 LayerTreeSettings CreateSettings() override { |
| 93 LayerTreeSettings settings; | 94 LayerTreeSettings settings; |
| 94 settings.gpu_rasterization_enabled = true; | 95 settings.gpu_rasterization_enabled = true; |
| 95 settings.layer_transforms_should_scale_layer_contents = true; | 96 settings.layer_transforms_should_scale_layer_contents = true; |
| 96 settings.create_low_res_tiling = true; | 97 settings.create_low_res_tiling = true; |
| 97 settings.verify_clip_tree_calculations = true; | 98 settings.verify_clip_tree_calculations = true; |
| 98 settings.verify_transform_tree_calculations = true; | 99 settings.verify_transform_tree_calculations = true; |
| 100 settings.renderer_settings.buffer_to_texture_target_map = |
| 101 DefaultBufferToTextureTargetMapForTesting(); |
| 99 return settings; | 102 return settings; |
| 100 } | 103 } |
| 101 | 104 |
| 102 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds, | 105 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds, |
| 103 const gfx::Size& tile_size, | 106 const gfx::Size& tile_size, |
| 104 const Region& invalidation) { | 107 const Region& invalidation) { |
| 105 scoped_refptr<FakeRasterSource> pending_raster_source = | 108 scoped_refptr<FakeRasterSource> pending_raster_source = |
| 106 FakeRasterSource::CreateFilled(layer_bounds); | 109 FakeRasterSource::CreateFilled(layer_bounds); |
| 107 scoped_refptr<FakeRasterSource> active_raster_source = | 110 scoped_refptr<FakeRasterSource> active_raster_source = |
| 108 FakeRasterSource::CreateFilled(layer_bounds); | 111 FakeRasterSource::CreateFilled(layer_bounds); |
| (...skipping 2210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2319 scoped_refptr<FakeRasterSource> active_raster_source = | 2322 scoped_refptr<FakeRasterSource> active_raster_source = |
| 2320 FakeRasterSource::CreateFilled(layer_bounds); | 2323 FakeRasterSource::CreateFilled(layer_bounds); |
| 2321 | 2324 |
| 2322 SetupTrees(pending_raster_source, active_raster_source); | 2325 SetupTrees(pending_raster_source, active_raster_source); |
| 2323 | 2326 |
| 2324 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(1.f)); | 2327 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(1.f)); |
| 2325 EXPECT_TRUE(active_layer()->tilings()->FindTilingWithScale(1.f)); | 2328 EXPECT_TRUE(active_layer()->tilings()->FindTilingWithScale(1.f)); |
| 2326 | 2329 |
| 2327 // Gpu rasterization is disabled by default. | 2330 // Gpu rasterization is disabled by default. |
| 2328 EXPECT_FALSE(host_impl()->use_gpu_rasterization()); | 2331 EXPECT_FALSE(host_impl()->use_gpu_rasterization()); |
| 2332 EXPECT_EQ(0u, pending_layer()->release_resources_count()); |
| 2333 EXPECT_EQ(0u, active_layer()->release_resources_count()); |
| 2329 // Toggling the gpu rasterization clears all tilings on both trees. | 2334 // Toggling the gpu rasterization clears all tilings on both trees. |
| 2330 host_impl()->SetHasGpuRasterizationTrigger(true); | 2335 host_impl()->SetHasGpuRasterizationTrigger(true); |
| 2331 host_impl()->SetContentIsSuitableForGpuRasterization(true); | 2336 host_impl()->SetContentIsSuitableForGpuRasterization(true); |
| 2332 host_impl()->UpdateTreeResourcesForGpuRasterizationIfNeeded(); | 2337 host_impl()->CommitComplete(); |
| 2333 EXPECT_EQ(0u, pending_layer()->tilings()->num_tilings()); | 2338 EXPECT_EQ(1u, pending_layer()->release_resources_count()); |
| 2339 EXPECT_EQ(1u, active_layer()->release_resources_count()); |
| 2340 |
| 2341 // But the pending layer gets a tiling back, and can activate it. |
| 2342 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(1.f)); |
| 2334 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); | 2343 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); |
| 2335 | 2344 |
| 2336 // Make sure that we can still add tiling to the pending layer, | |
| 2337 // that gets synced to the active layer. | |
| 2338 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); | |
| 2339 bool update_lcd_text = false; | |
| 2340 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); | |
| 2341 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(1.f)); | |
| 2342 | |
| 2343 ActivateTree(); | 2345 ActivateTree(); |
| 2344 EXPECT_TRUE(active_layer()->tilings()->FindTilingWithScale(1.f)); | 2346 EXPECT_TRUE(active_layer()->tilings()->FindTilingWithScale(1.f)); |
| 2345 | 2347 |
| 2346 SetupPendingTree(pending_raster_source); | 2348 SetupPendingTree(pending_raster_source); |
| 2347 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(1.f)); | 2349 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(1.f)); |
| 2348 | 2350 |
| 2349 // Toggling the gpu rasterization clears all tilings on both trees. | 2351 // Toggling the gpu rasterization clears all tilings on both trees. |
| 2350 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); | 2352 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); |
| 2351 host_impl()->SetHasGpuRasterizationTrigger(false); | 2353 host_impl()->SetHasGpuRasterizationTrigger(false); |
| 2352 host_impl()->UpdateTreeResourcesForGpuRasterizationIfNeeded(); | 2354 host_impl()->CommitComplete(); |
| 2353 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, | 2355 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, |
| 2354 host_impl()->gpu_rasterization_status()); | 2356 host_impl()->gpu_rasterization_status()); |
| 2355 EXPECT_EQ(0u, pending_layer()->tilings()->num_tilings()); | 2357 EXPECT_EQ(2u, pending_layer()->release_resources_count()); |
| 2356 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); | 2358 EXPECT_EQ(2u, active_layer()->release_resources_count()); |
| 2357 | 2359 |
| 2358 host_impl()->SetHasGpuRasterizationTrigger(true); | 2360 host_impl()->SetHasGpuRasterizationTrigger(true); |
| 2359 host_impl()->SetContentIsSuitableForGpuRasterization(false); | 2361 host_impl()->SetContentIsSuitableForGpuRasterization(false); |
| 2362 host_impl()->CommitComplete(); |
| 2360 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, | 2363 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, |
| 2361 host_impl()->gpu_rasterization_status()); | 2364 host_impl()->gpu_rasterization_status()); |
| 2362 } | 2365 } |
| 2363 | 2366 |
| 2364 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { | 2367 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { |
| 2365 // Put 0.5 as high res. | 2368 // Put 0.5 as high res. |
| 2366 SetInitialDeviceScaleFactor(0.5f); | 2369 SetInitialDeviceScaleFactor(0.5f); |
| 2367 | 2370 |
| 2368 scoped_refptr<FakeRasterSource> pending_raster_source = | 2371 scoped_refptr<FakeRasterSource> pending_raster_source = |
| 2369 FakeRasterSource::CreateFilled(gfx::Size(10, 10)); | 2372 FakeRasterSource::CreateFilled(gfx::Size(10, 10)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings()); | 2410 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings()); |
| 2408 } | 2411 } |
| 2409 | 2412 |
| 2410 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { | 2413 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { |
| 2411 gfx::Size default_tile_size(host_impl()->settings().default_tile_size); | 2414 gfx::Size default_tile_size(host_impl()->settings().default_tile_size); |
| 2412 gfx::Size layer_bounds(default_tile_size.width() * 4, | 2415 gfx::Size layer_bounds(default_tile_size.width() * 4, |
| 2413 default_tile_size.height() * 4); | 2416 default_tile_size.height() * 4); |
| 2414 | 2417 |
| 2415 host_impl()->SetHasGpuRasterizationTrigger(true); | 2418 host_impl()->SetHasGpuRasterizationTrigger(true); |
| 2416 host_impl()->SetContentIsSuitableForGpuRasterization(true); | 2419 host_impl()->SetContentIsSuitableForGpuRasterization(true); |
| 2420 host_impl()->CommitComplete(); |
| 2417 | 2421 |
| 2418 SetupDefaultTrees(layer_bounds); | 2422 SetupDefaultTrees(layer_bounds); |
| 2419 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); | 2423 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); |
| 2420 // Should only have the high-res tiling. | 2424 // Should only have the high-res tiling. |
| 2421 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); | 2425 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); |
| 2422 ActivateTree(); | 2426 ActivateTree(); |
| 2423 // Should only have the high-res tiling. | 2427 // Should only have the high-res tiling. |
| 2424 EXPECT_EQ(1u, active_layer()->tilings()->num_tilings()); | 2428 EXPECT_EQ(1u, active_layer()->tilings()->num_tilings()); |
| 2425 } | 2429 } |
| 2426 | 2430 |
| 2427 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) { | 2431 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) { |
| 2428 host_impl()->SetHasGpuRasterizationTrigger(true); | 2432 host_impl()->SetHasGpuRasterizationTrigger(true); |
| 2429 host_impl()->SetContentIsSuitableForGpuRasterization(true); | 2433 host_impl()->SetContentIsSuitableForGpuRasterization(true); |
| 2434 host_impl()->CommitComplete(); |
| 2430 | 2435 |
| 2431 gfx::Size viewport_size(1000, 1000); | 2436 gfx::Size viewport_size(1000, 1000); |
| 2432 host_impl()->SetViewportSize(viewport_size); | 2437 host_impl()->SetViewportSize(viewport_size); |
| 2433 | 2438 |
| 2434 gfx::Size layer_bounds(4000, 4000); | 2439 gfx::Size layer_bounds(4000, 4000); |
| 2435 SetupDefaultTrees(layer_bounds); | 2440 SetupDefaultTrees(layer_bounds); |
| 2436 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); | 2441 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); |
| 2437 | 2442 |
| 2438 // Should only have the high-res tiling. | 2443 // Should only have the high-res tiling. |
| 2439 EXPECT_EQ(1u, active_layer()->tilings()->num_tilings()); | 2444 EXPECT_EQ(1u, active_layer()->tilings()->num_tilings()); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2723 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f); | 2728 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f); |
| 2724 } | 2729 } |
| 2725 | 2730 |
| 2726 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) { | 2731 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) { |
| 2727 gfx::Size layer_bounds(100, 100); | 2732 gfx::Size layer_bounds(100, 100); |
| 2728 gfx::Size viewport_size(1000, 1000); | 2733 gfx::Size viewport_size(1000, 1000); |
| 2729 SetupDefaultTrees(layer_bounds); | 2734 SetupDefaultTrees(layer_bounds); |
| 2730 host_impl()->SetViewportSize(viewport_size); | 2735 host_impl()->SetViewportSize(viewport_size); |
| 2731 host_impl()->SetHasGpuRasterizationTrigger(true); | 2736 host_impl()->SetHasGpuRasterizationTrigger(true); |
| 2732 host_impl()->SetContentIsSuitableForGpuRasterization(true); | 2737 host_impl()->SetContentIsSuitableForGpuRasterization(true); |
| 2733 host_impl()->UpdateTreeResourcesForGpuRasterizationIfNeeded(); | 2738 host_impl()->CommitComplete(); |
| 2734 | 2739 |
| 2735 float contents_scale = 1.f; | 2740 float contents_scale = 1.f; |
| 2736 float device_scale = 1.3f; | 2741 float device_scale = 1.3f; |
| 2737 float page_scale = 1.4f; | 2742 float page_scale = 1.4f; |
| 2738 float maximum_animation_scale = 1.f; | 2743 float maximum_animation_scale = 1.f; |
| 2739 float starting_animation_scale = 0.f; | 2744 float starting_animation_scale = 0.f; |
| 2740 bool animating_transform = false; | 2745 bool animating_transform = false; |
| 2741 | 2746 |
| 2742 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, | 2747 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, |
| 2743 maximum_animation_scale, | 2748 maximum_animation_scale, |
| (...skipping 1990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4734 | 4739 |
| 4735 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); | 4740 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); |
| 4736 std::unique_ptr<FakePictureLayerImpl> layer = | 4741 std::unique_ptr<FakePictureLayerImpl> layer = |
| 4737 FakePictureLayerImpl::Create(pending_tree, layer_id()); | 4742 FakePictureLayerImpl::Create(pending_tree, layer_id()); |
| 4738 | 4743 |
| 4739 host_impl()->SetViewportSize(gfx::Size(1000, 1000)); | 4744 host_impl()->SetViewportSize(gfx::Size(1000, 1000)); |
| 4740 gfx::Size result; | 4745 gfx::Size result; |
| 4741 | 4746 |
| 4742 host_impl()->SetContentIsSuitableForGpuRasterization(true); | 4747 host_impl()->SetContentIsSuitableForGpuRasterization(true); |
| 4743 host_impl()->SetHasGpuRasterizationTrigger(false); | 4748 host_impl()->SetHasGpuRasterizationTrigger(false); |
| 4749 host_impl()->CommitComplete(); |
| 4744 EXPECT_EQ(host_impl()->gpu_rasterization_status(), | 4750 EXPECT_EQ(host_impl()->gpu_rasterization_status(), |
| 4745 GpuRasterizationStatus::OFF_VIEWPORT); | 4751 GpuRasterizationStatus::OFF_VIEWPORT); |
| 4746 | 4752 |
| 4747 // Default tile-size for large layers. | 4753 // Default tile-size for large layers. |
| 4748 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); | 4754 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); |
| 4749 EXPECT_EQ(result.width(), 100); | 4755 EXPECT_EQ(result.width(), 100); |
| 4750 EXPECT_EQ(result.height(), 100); | 4756 EXPECT_EQ(result.height(), 100); |
| 4751 // Don't tile and round-up, when under max_untiled_layer_size. | 4757 // Don't tile and round-up, when under max_untiled_layer_size. |
| 4752 result = layer->CalculateTileSize(gfx::Size(42, 42)); | 4758 result = layer->CalculateTileSize(gfx::Size(42, 42)); |
| 4753 EXPECT_EQ(result.width(), 64); | 4759 EXPECT_EQ(result.width(), 64); |
| 4754 EXPECT_EQ(result.height(), 64); | 4760 EXPECT_EQ(result.height(), 64); |
| 4755 result = layer->CalculateTileSize(gfx::Size(191, 191)); | 4761 result = layer->CalculateTileSize(gfx::Size(191, 191)); |
| 4756 EXPECT_EQ(result.width(), 192); | 4762 EXPECT_EQ(result.width(), 192); |
| 4757 EXPECT_EQ(result.height(), 192); | 4763 EXPECT_EQ(result.height(), 192); |
| 4758 result = layer->CalculateTileSize(gfx::Size(199, 199)); | 4764 result = layer->CalculateTileSize(gfx::Size(199, 199)); |
| 4759 EXPECT_EQ(result.width(), 200); | 4765 EXPECT_EQ(result.width(), 200); |
| 4760 EXPECT_EQ(result.height(), 200); | 4766 EXPECT_EQ(result.height(), 200); |
| 4761 | 4767 |
| 4762 // Gpu-rasterization uses 25% viewport-height tiles. | 4768 // Gpu-rasterization uses 25% viewport-height tiles. |
| 4763 // The +2's below are for border texels. | 4769 // The +2's below are for border texels. |
| 4764 host_impl()->SetHasGpuRasterizationTrigger(true); | 4770 host_impl()->SetHasGpuRasterizationTrigger(true); |
| 4771 host_impl()->CommitComplete(); |
| 4765 EXPECT_EQ(host_impl()->gpu_rasterization_status(), | 4772 EXPECT_EQ(host_impl()->gpu_rasterization_status(), |
| 4766 GpuRasterizationStatus::ON); | 4773 GpuRasterizationStatus::ON); |
| 4767 host_impl()->SetViewportSize(gfx::Size(2000, 2000)); | 4774 host_impl()->SetViewportSize(gfx::Size(2000, 2000)); |
| 4768 | 4775 |
| 4769 layer->set_gpu_raster_max_texture_size(host_impl()->device_viewport_size()); | 4776 layer->set_gpu_raster_max_texture_size(host_impl()->device_viewport_size()); |
| 4770 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); | 4777 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); |
| 4771 EXPECT_EQ(result.width(), | 4778 EXPECT_EQ(result.width(), |
| 4772 MathUtil::UncheckedRoundUp( | 4779 MathUtil::UncheckedRoundUp( |
| 4773 2000 + 2 * PictureLayerTiling::kBorderTexels, 4)); | 4780 2000 + 2 * PictureLayerTiling::kBorderTexels, 4)); |
| 4774 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned. | 4781 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned. |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5016 EXPECT_FLOAT_EQ(expected_contents_scale, | 5023 EXPECT_FLOAT_EQ(expected_contents_scale, |
| 5017 pending_layer_ptr->picture_layer_tiling_set() | 5024 pending_layer_ptr->picture_layer_tiling_set() |
| 5018 ->FindTilingWithResolution(HIGH_RESOLUTION) | 5025 ->FindTilingWithResolution(HIGH_RESOLUTION) |
| 5019 ->contents_scale()) | 5026 ->contents_scale()) |
| 5020 << "ideal_contents_scale: " << ideal_contents_scale; | 5027 << "ideal_contents_scale: " << ideal_contents_scale; |
| 5021 } | 5028 } |
| 5022 } | 5029 } |
| 5023 | 5030 |
| 5024 } // namespace | 5031 } // namespace |
| 5025 } // namespace cc | 5032 } // namespace cc |
| OLD | NEW |