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 2425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2436 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 2436 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
2437 | 2437 |
2438 SetupTrees(pending_pile, active_pile); | 2438 SetupTrees(pending_pile, active_pile); |
2439 | 2439 |
2440 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f)); | 2440 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f)); |
2441 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f)); | 2441 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f)); |
2442 | 2442 |
2443 // Gpu rasterization is disabled by default. | 2443 // Gpu rasterization is disabled by default. |
2444 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); | 2444 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); |
2445 // Toggling the gpu rasterization clears all tilings on both trees. | 2445 // Toggling the gpu rasterization clears all tilings on both trees. |
2446 host_impl_.set_has_gpu_rasterization_trigger(true); | 2446 host_impl_.SetHasGpuRasterizationTrigger(true); |
2447 host_impl_.set_content_is_suitable_for_gpu_rasterization(true); | 2447 host_impl_.SetContentIsSuitableForGpuRasterization(true); |
2448 host_impl_.UpdateGpuRasterizationStatus(); | 2448 host_impl_.UpdateTreeResourcesForGpuRasterizationIfNeeded(); |
2449 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 2449 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
2450 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 2450 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
2451 | 2451 |
2452 // Make sure that we can still add tiling to the pending layer, | 2452 // Make sure that we can still add tiling to the pending layer, |
2453 // that gets synced to the active layer. | 2453 // that gets synced to the active layer. |
2454 time_ticks += base::TimeDelta::FromMilliseconds(1); | 2454 time_ticks += base::TimeDelta::FromMilliseconds(1); |
2455 host_impl_.SetCurrentBeginFrameArgs( | 2455 host_impl_.SetCurrentBeginFrameArgs( |
2456 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); | 2456 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); |
2457 bool update_lcd_text = false; | 2457 bool update_lcd_text = false; |
2458 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); | 2458 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); |
2459 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f)); | 2459 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f)); |
2460 | 2460 |
2461 ActivateTree(); | 2461 ActivateTree(); |
2462 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f)); | 2462 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f)); |
2463 | 2463 |
2464 SetupPendingTree(pending_pile); | 2464 SetupPendingTree(pending_pile); |
2465 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f)); | 2465 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f)); |
2466 | 2466 |
2467 // Toggling the gpu rasterization clears all tilings on both trees. | 2467 // Toggling the gpu rasterization clears all tilings on both trees. |
2468 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); | 2468 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); |
2469 host_impl_.set_has_gpu_rasterization_trigger(false); | 2469 host_impl_.SetHasGpuRasterizationTrigger(false); |
2470 host_impl_.UpdateGpuRasterizationStatus(); | 2470 host_impl_.UpdateTreeResourcesForGpuRasterizationIfNeeded(); |
2471 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, | 2471 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, |
2472 host_impl_.gpu_rasterization_status()); | 2472 host_impl_.gpu_rasterization_status()); |
2473 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 2473 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
2474 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 2474 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
2475 | 2475 |
2476 host_impl_.set_has_gpu_rasterization_trigger(true); | 2476 host_impl_.SetHasGpuRasterizationTrigger(true); |
2477 host_impl_.set_content_is_suitable_for_gpu_rasterization(false); | 2477 host_impl_.SetContentIsSuitableForGpuRasterization(false); |
2478 host_impl_.UpdateGpuRasterizationStatus(); | |
2479 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, | 2478 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, |
2480 host_impl_.gpu_rasterization_status()); | 2479 host_impl_.gpu_rasterization_status()); |
2481 } | 2480 } |
2482 | 2481 |
2483 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { | 2482 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { |
2484 gfx::Size tile_size(100, 100); | 2483 gfx::Size tile_size(100, 100); |
2485 | 2484 |
2486 // Put 0.5 as high res. | 2485 // Put 0.5 as high res. |
2487 host_impl_.SetDeviceScaleFactor(0.5f); | 2486 host_impl_.SetDeviceScaleFactor(0.5f); |
2488 | 2487 |
(...skipping 25 matching lines...) Expand all Loading... |
2514 pending_layer_->tilings()->FindTilingWithScale(1.0f); | 2513 pending_layer_->tilings()->FindTilingWithScale(1.0f); |
2515 ASSERT_TRUE(tiling); | 2514 ASSERT_TRUE(tiling); |
2516 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution()); | 2515 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution()); |
2517 } | 2516 } |
2518 | 2517 |
2519 TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) { | 2518 TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) { |
2520 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | 2519 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
2521 gfx::Size layer_bounds(default_tile_size.width() * 4, | 2520 gfx::Size layer_bounds(default_tile_size.width() * 4, |
2522 default_tile_size.height() * 4); | 2521 default_tile_size.height() * 4); |
2523 | 2522 |
2524 host_impl_.set_has_gpu_rasterization_trigger(false); | 2523 host_impl_.SetHasGpuRasterizationTrigger(false); |
2525 host_impl_.UpdateGpuRasterizationStatus(); | |
2526 | 2524 |
2527 SetupDefaultTrees(layer_bounds); | 2525 SetupDefaultTrees(layer_bounds); |
2528 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); | 2526 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); |
2529 // Should have a low-res and a high-res tiling. | 2527 // Should have a low-res and a high-res tiling. |
2530 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 2528 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
2531 } | 2529 } |
2532 | 2530 |
2533 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { | 2531 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { |
2534 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | 2532 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
2535 gfx::Size layer_bounds(default_tile_size.width() * 4, | 2533 gfx::Size layer_bounds(default_tile_size.width() * 4, |
2536 default_tile_size.height() * 4); | 2534 default_tile_size.height() * 4); |
2537 | 2535 |
2538 host_impl_.set_has_gpu_rasterization_trigger(true); | 2536 host_impl_.SetHasGpuRasterizationTrigger(true); |
2539 host_impl_.set_content_is_suitable_for_gpu_rasterization(true); | 2537 host_impl_.SetContentIsSuitableForGpuRasterization(true); |
2540 host_impl_.UpdateGpuRasterizationStatus(); | |
2541 | 2538 |
2542 SetupDefaultTrees(layer_bounds); | 2539 SetupDefaultTrees(layer_bounds); |
2543 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); | 2540 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); |
2544 // Should only have the high-res tiling. | 2541 // Should only have the high-res tiling. |
2545 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); | 2542 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
2546 } | 2543 } |
2547 | 2544 |
2548 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) { | 2545 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) { |
2549 host_impl_.set_has_gpu_rasterization_trigger(true); | 2546 host_impl_.SetHasGpuRasterizationTrigger(true); |
2550 host_impl_.set_content_is_suitable_for_gpu_rasterization(true); | 2547 host_impl_.SetContentIsSuitableForGpuRasterization(true); |
2551 host_impl_.UpdateGpuRasterizationStatus(); | |
2552 | 2548 |
2553 gfx::Size viewport_size(1000, 1000); | 2549 gfx::Size viewport_size(1000, 1000); |
2554 host_impl_.SetViewportSize(viewport_size); | 2550 host_impl_.SetViewportSize(viewport_size); |
2555 | 2551 |
2556 gfx::Size layer_bounds(4000, 4000); | 2552 gfx::Size layer_bounds(4000, 4000); |
2557 SetupDefaultTrees(layer_bounds); | 2553 SetupDefaultTrees(layer_bounds); |
2558 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); | 2554 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); |
2559 | 2555 |
2560 // Should only have the high-res tiling. | 2556 // Should only have the high-res tiling. |
2561 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings()); | 2557 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings()); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2841 maximum_animation_scale, | 2837 maximum_animation_scale, |
2842 starting_animation_scale, animating_transform); | 2838 starting_animation_scale, animating_transform); |
2843 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f); | 2839 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f); |
2844 } | 2840 } |
2845 | 2841 |
2846 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) { | 2842 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) { |
2847 gfx::Size layer_bounds(100, 100); | 2843 gfx::Size layer_bounds(100, 100); |
2848 gfx::Size viewport_size(1000, 1000); | 2844 gfx::Size viewport_size(1000, 1000); |
2849 SetupDefaultTrees(layer_bounds); | 2845 SetupDefaultTrees(layer_bounds); |
2850 host_impl_.SetViewportSize(viewport_size); | 2846 host_impl_.SetViewportSize(viewport_size); |
2851 host_impl_.set_has_gpu_rasterization_trigger(true); | 2847 host_impl_.SetHasGpuRasterizationTrigger(true); |
2852 host_impl_.set_content_is_suitable_for_gpu_rasterization(true); | 2848 host_impl_.SetContentIsSuitableForGpuRasterization(true); |
2853 host_impl_.UpdateGpuRasterizationStatus(); | 2849 host_impl_.UpdateTreeResourcesForGpuRasterizationIfNeeded(); |
2854 | 2850 |
2855 float contents_scale = 1.f; | 2851 float contents_scale = 1.f; |
2856 float device_scale = 1.3f; | 2852 float device_scale = 1.3f; |
2857 float page_scale = 1.4f; | 2853 float page_scale = 1.4f; |
2858 float maximum_animation_scale = 1.f; | 2854 float maximum_animation_scale = 1.f; |
2859 float starting_animation_scale = 0.f; | 2855 float starting_animation_scale = 0.f; |
2860 bool animating_transform = false; | 2856 bool animating_transform = false; |
2861 | 2857 |
2862 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, | 2858 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, |
2863 maximum_animation_scale, | 2859 maximum_animation_scale, |
(...skipping 2171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5035 TEST_F(TileSizeTest, TileSizes) { | 5031 TEST_F(TileSizeTest, TileSizes) { |
5036 host_impl_.CreatePendingTree(); | 5032 host_impl_.CreatePendingTree(); |
5037 | 5033 |
5038 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | 5034 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
5039 scoped_ptr<FakePictureLayerImpl> layer = | 5035 scoped_ptr<FakePictureLayerImpl> layer = |
5040 FakePictureLayerImpl::Create(pending_tree, id_); | 5036 FakePictureLayerImpl::Create(pending_tree, id_); |
5041 | 5037 |
5042 host_impl_.SetViewportSize(gfx::Size(1000, 1000)); | 5038 host_impl_.SetViewportSize(gfx::Size(1000, 1000)); |
5043 gfx::Size result; | 5039 gfx::Size result; |
5044 | 5040 |
5045 host_impl_.set_content_is_suitable_for_gpu_rasterization(true); | 5041 host_impl_.SetContentIsSuitableForGpuRasterization(true); |
5046 host_impl_.set_has_gpu_rasterization_trigger(false); | 5042 host_impl_.SetHasGpuRasterizationTrigger(false); |
5047 host_impl_.UpdateGpuRasterizationStatus(); | |
5048 EXPECT_EQ(host_impl_.gpu_rasterization_status(), | 5043 EXPECT_EQ(host_impl_.gpu_rasterization_status(), |
5049 GpuRasterizationStatus::OFF_VIEWPORT); | 5044 GpuRasterizationStatus::OFF_VIEWPORT); |
5050 | 5045 |
5051 // Default tile-size for large layers. | 5046 // Default tile-size for large layers. |
5052 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); | 5047 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); |
5053 EXPECT_EQ(result.width(), 100); | 5048 EXPECT_EQ(result.width(), 100); |
5054 EXPECT_EQ(result.height(), 100); | 5049 EXPECT_EQ(result.height(), 100); |
5055 // Don't tile and round-up, when under max_untiled_layer_size. | 5050 // Don't tile and round-up, when under max_untiled_layer_size. |
5056 result = layer->CalculateTileSize(gfx::Size(42, 42)); | 5051 result = layer->CalculateTileSize(gfx::Size(42, 42)); |
5057 EXPECT_EQ(result.width(), 64); | 5052 EXPECT_EQ(result.width(), 64); |
5058 EXPECT_EQ(result.height(), 64); | 5053 EXPECT_EQ(result.height(), 64); |
5059 result = layer->CalculateTileSize(gfx::Size(191, 191)); | 5054 result = layer->CalculateTileSize(gfx::Size(191, 191)); |
5060 EXPECT_EQ(result.width(), 192); | 5055 EXPECT_EQ(result.width(), 192); |
5061 EXPECT_EQ(result.height(), 192); | 5056 EXPECT_EQ(result.height(), 192); |
5062 result = layer->CalculateTileSize(gfx::Size(199, 199)); | 5057 result = layer->CalculateTileSize(gfx::Size(199, 199)); |
5063 EXPECT_EQ(result.width(), 200); | 5058 EXPECT_EQ(result.width(), 200); |
5064 EXPECT_EQ(result.height(), 200); | 5059 EXPECT_EQ(result.height(), 200); |
5065 | 5060 |
5066 // Gpu-rasterization uses 25% viewport-height tiles. | 5061 // Gpu-rasterization uses 25% viewport-height tiles. |
5067 // The +2's below are for border texels. | 5062 // The +2's below are for border texels. |
5068 host_impl_.set_has_gpu_rasterization_trigger(true); | 5063 host_impl_.SetHasGpuRasterizationTrigger(true); |
5069 host_impl_.UpdateGpuRasterizationStatus(); | |
5070 EXPECT_EQ(host_impl_.gpu_rasterization_status(), GpuRasterizationStatus::ON); | 5064 EXPECT_EQ(host_impl_.gpu_rasterization_status(), GpuRasterizationStatus::ON); |
5071 host_impl_.SetViewportSize(gfx::Size(2000, 2000)); | 5065 host_impl_.SetViewportSize(gfx::Size(2000, 2000)); |
5072 | 5066 |
5073 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size()); | 5067 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size()); |
5074 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); | 5068 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); |
5075 EXPECT_EQ(result.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels); | 5069 EXPECT_EQ(result.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels); |
5076 EXPECT_EQ(result.height(), 500 + 2); | 5070 EXPECT_EQ(result.height(), 500 + 2); |
5077 | 5071 |
5078 // Clamp and round-up, when smaller than viewport. | 5072 // Clamp and round-up, when smaller than viewport. |
5079 // Tile-height doubles to 50% when width shrinks to <= 50%. | 5073 // Tile-height doubles to 50% when width shrinks to <= 50%. |
5080 host_impl_.SetViewportSize(gfx::Size(1000, 1000)); | 5074 host_impl_.SetViewportSize(gfx::Size(1000, 1000)); |
5081 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size()); | 5075 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size()); |
5082 result = layer->CalculateTileSize(gfx::Size(447, 10000)); | 5076 result = layer->CalculateTileSize(gfx::Size(447, 10000)); |
5083 EXPECT_EQ(result.width(), 448); | 5077 EXPECT_EQ(result.width(), 448); |
5084 EXPECT_EQ(result.height(), 500 + 2); | 5078 EXPECT_EQ(result.height(), 500 + 2); |
5085 | 5079 |
5086 // Largest layer is 50% of viewport width (rounded up), and | 5080 // Largest layer is 50% of viewport width (rounded up), and |
5087 // 50% of viewport in height. | 5081 // 50% of viewport in height. |
5088 result = layer->CalculateTileSize(gfx::Size(447, 400)); | 5082 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
5089 EXPECT_EQ(result.width(), 448); | 5083 EXPECT_EQ(result.width(), 448); |
5090 EXPECT_EQ(result.height(), 448); | 5084 EXPECT_EQ(result.height(), 448); |
5091 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 5085 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
5092 EXPECT_EQ(result.width(), 512); | 5086 EXPECT_EQ(result.width(), 512); |
5093 EXPECT_EQ(result.height(), 500 + 2); | 5087 EXPECT_EQ(result.height(), 500 + 2); |
5094 } | 5088 } |
5095 | 5089 |
5096 } // namespace | 5090 } // namespace |
5097 } // namespace cc | 5091 } // namespace cc |
OLD | NEW |