Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: cc/layers/picture_layer_impl_unittest.cc

Issue 343463004: Move occlusion info to TilePriority. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 2791 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 2802
2803 // No occlusion. 2803 // No occlusion.
2804 int unoccluded_tile_count = 0; 2804 int unoccluded_tile_count = 0;
2805 for (PictureLayerImpl::LayerRasterTileIterator it = 2805 for (PictureLayerImpl::LayerRasterTileIterator it =
2806 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); 2806 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
2807 it; 2807 it;
2808 ++it) { 2808 ++it) {
2809 Tile* tile = *it; 2809 Tile* tile = *it;
2810 2810
2811 // Occluded tiles should not be iterated over. 2811 // Occluded tiles should not be iterated over.
2812 EXPECT_FALSE(tile->is_occluded()); 2812 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded);
2813 2813
2814 // Some tiles may not be visible (i.e. outside the viewport). The rest are 2814 // Some tiles may not be visible (i.e. outside the viewport). The rest are
2815 // visible and at least partially unoccluded, verified by the above expect. 2815 // visible and at least partially unoccluded, verified by the above expect.
2816 bool tile_is_visible = 2816 bool tile_is_visible =
2817 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); 2817 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
2818 if (tile_is_visible) 2818 if (tile_is_visible)
2819 unoccluded_tile_count++; 2819 unoccluded_tile_count++;
2820 } 2820 }
2821 EXPECT_EQ(unoccluded_tile_count, 25 + 4); 2821 EXPECT_EQ(unoccluded_tile_count, 25 + 4);
2822 2822
2823 // Partial occlusion. 2823 // Partial occlusion.
2824 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); 2824 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
2825 LayerImpl* layer1 = pending_layer_->children()[0]; 2825 LayerImpl* layer1 = pending_layer_->children()[0];
2826 layer1->SetBounds(layer_bounds); 2826 layer1->SetBounds(layer_bounds);
2827 layer1->SetContentBounds(layer_bounds); 2827 layer1->SetContentBounds(layer_bounds);
2828 layer1->SetDrawsContent(true); 2828 layer1->SetDrawsContent(true);
2829 layer1->SetContentsOpaque(true); 2829 layer1->SetContentsOpaque(true);
2830 layer1->SetPosition(occluding_layer_position); 2830 layer1->SetPosition(occluding_layer_position);
2831 2831
2832 host_impl_.pending_tree()->UpdateDrawProperties(); 2832 host_impl_.pending_tree()->UpdateDrawProperties();
2833 2833
2834 unoccluded_tile_count = 0; 2834 unoccluded_tile_count = 0;
2835 for (PictureLayerImpl::LayerRasterTileIterator it = 2835 for (PictureLayerImpl::LayerRasterTileIterator it =
2836 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); 2836 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
2837 it; 2837 it;
2838 ++it) { 2838 ++it) {
2839 Tile* tile = *it; 2839 Tile* tile = *it;
2840 2840
2841 EXPECT_FALSE(tile->is_occluded()); 2841 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded);
2842 2842
2843 bool tile_is_visible = 2843 bool tile_is_visible =
2844 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); 2844 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
2845 if (tile_is_visible) 2845 if (tile_is_visible)
2846 unoccluded_tile_count++; 2846 unoccluded_tile_count++;
2847 } 2847 }
2848 EXPECT_EQ(unoccluded_tile_count, 20 + 2); 2848 EXPECT_EQ(unoccluded_tile_count, 20 + 2);
2849 2849
2850 // Full occlusion. 2850 // Full occlusion.
2851 layer1->SetPosition(gfx::Point(0, 0)); 2851 layer1->SetPosition(gfx::Point(0, 0));
2852 2852
2853 host_impl_.pending_tree()->UpdateDrawProperties(); 2853 host_impl_.pending_tree()->UpdateDrawProperties();
2854 2854
2855 unoccluded_tile_count = 0; 2855 unoccluded_tile_count = 0;
2856 for (PictureLayerImpl::LayerRasterTileIterator it = 2856 for (PictureLayerImpl::LayerRasterTileIterator it =
2857 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); 2857 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
2858 it; 2858 it;
2859 ++it) { 2859 ++it) {
2860 Tile* tile = *it; 2860 Tile* tile = *it;
2861 2861
2862 EXPECT_FALSE(tile->is_occluded()); 2862 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded);
2863 2863
2864 bool tile_is_visible = 2864 bool tile_is_visible =
2865 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); 2865 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
2866 if (tile_is_visible) 2866 if (tile_is_visible)
2867 unoccluded_tile_count++; 2867 unoccluded_tile_count++;
2868 } 2868 }
2869 EXPECT_EQ(unoccluded_tile_count, 0); 2869 EXPECT_EQ(unoccluded_tile_count, 0);
2870 } 2870 }
2871 2871
2872 TEST_F(OcclusionTrackingPictureLayerImplTest, 2872 TEST_F(OcclusionTrackingPictureLayerImplTest,
(...skipping 21 matching lines...) Expand all
2894 tiling, 2894 tiling,
2895 pending_layer_->contents_scale_x(), 2895 pending_layer_->contents_scale_x(),
2896 gfx::Rect(layer_bounds)); 2896 gfx::Rect(layer_bounds));
2897 iter; 2897 iter;
2898 ++iter) { 2898 ++iter) {
2899 if (!*iter) 2899 if (!*iter)
2900 continue; 2900 continue;
2901 const Tile* tile = *iter; 2901 const Tile* tile = *iter;
2902 2902
2903 // Fully occluded tiles are not required for activation. 2903 // Fully occluded tiles are not required for activation.
2904 if (tile->is_occluded()) { 2904 if (tile->priority(PENDING_TREE).is_occluded) {
2905 EXPECT_FALSE(tile->required_for_activation()); 2905 EXPECT_FALSE(tile->required_for_activation());
2906 occluded_tile_count++; 2906 occluded_tile_count++;
2907 } 2907 }
2908 } 2908 }
2909 EXPECT_EQ(occluded_tile_count, 0); 2909 EXPECT_EQ(occluded_tile_count, 0);
2910 } 2910 }
2911 2911
2912 // Partial occlusion. 2912 // Partial occlusion.
2913 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); 2913 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
2914 LayerImpl* layer1 = pending_layer_->children()[0]; 2914 LayerImpl* layer1 = pending_layer_->children()[0];
(...skipping 12 matching lines...) Expand all
2927 for (PictureLayerTiling::CoverageIterator iter( 2927 for (PictureLayerTiling::CoverageIterator iter(
2928 tiling, 2928 tiling,
2929 pending_layer_->contents_scale_x(), 2929 pending_layer_->contents_scale_x(),
2930 gfx::Rect(layer_bounds)); 2930 gfx::Rect(layer_bounds));
2931 iter; 2931 iter;
2932 ++iter) { 2932 ++iter) {
2933 if (!*iter) 2933 if (!*iter)
2934 continue; 2934 continue;
2935 const Tile* tile = *iter; 2935 const Tile* tile = *iter;
2936 2936
2937 if (tile->is_occluded()) { 2937 if (tile->priority(PENDING_TREE).is_occluded) {
2938 EXPECT_FALSE(tile->required_for_activation()); 2938 EXPECT_FALSE(tile->required_for_activation());
2939 occluded_tile_count++; 2939 occluded_tile_count++;
2940 } 2940 }
2941 } 2941 }
2942 switch (i) { 2942 switch (i) {
2943 case 0: 2943 case 0:
2944 EXPECT_EQ(occluded_tile_count, 5); 2944 EXPECT_EQ(occluded_tile_count, 5);
2945 break; 2945 break;
2946 case 1: 2946 case 1:
2947 EXPECT_EQ(occluded_tile_count, 2); 2947 EXPECT_EQ(occluded_tile_count, 2);
(...skipping 15 matching lines...) Expand all
2963 for (PictureLayerTiling::CoverageIterator iter( 2963 for (PictureLayerTiling::CoverageIterator iter(
2964 tiling, 2964 tiling,
2965 pending_layer_->contents_scale_x(), 2965 pending_layer_->contents_scale_x(),
2966 gfx::Rect(layer_bounds)); 2966 gfx::Rect(layer_bounds));
2967 iter; 2967 iter;
2968 ++iter) { 2968 ++iter) {
2969 if (!*iter) 2969 if (!*iter)
2970 continue; 2970 continue;
2971 const Tile* tile = *iter; 2971 const Tile* tile = *iter;
2972 2972
2973 if (tile->is_occluded()) { 2973 if (tile->priority(PENDING_TREE).is_occluded) {
2974 EXPECT_FALSE(tile->required_for_activation()); 2974 EXPECT_FALSE(tile->required_for_activation());
2975 occluded_tile_count++; 2975 occluded_tile_count++;
2976 } 2976 }
2977 } 2977 }
2978 switch (i) { 2978 switch (i) {
2979 case 0: 2979 case 0:
2980 EXPECT_EQ(occluded_tile_count, 25); 2980 EXPECT_EQ(occluded_tile_count, 25);
2981 break; 2981 break;
2982 case 1: 2982 case 1:
2983 EXPECT_EQ(occluded_tile_count, 4); 2983 EXPECT_EQ(occluded_tile_count, 4);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 int tiling_count = 0; 3024 int tiling_count = 0;
3025 int occluded_tile_count = 0; 3025 int occluded_tile_count = 0;
3026 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = 3026 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator =
3027 tilings.begin(); 3027 tilings.begin();
3028 tiling_iterator != tilings.end(); 3028 tiling_iterator != tilings.end();
3029 ++tiling_iterator) { 3029 ++tiling_iterator) {
3030 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); 3030 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting();
3031 3031
3032 occluded_tile_count = 0; 3032 occluded_tile_count = 0;
3033 for (size_t i = 0; i < tiles.size(); ++i) { 3033 for (size_t i = 0; i < tiles.size(); ++i) {
3034 if (tiles[i]->is_occluded()) { 3034 if (tiles[i]->priority(PENDING_TREE).is_occluded) {
3035 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( 3035 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
3036 tiles[i]->content_rect(), 1.0f / tiles[i]->contents_scale()); 3036 tiles[i]->content_rect(), 1.0f / tiles[i]->contents_scale());
3037 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x()); 3037 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x());
3038 occluded_tile_count++; 3038 occluded_tile_count++;
3039 } 3039 }
3040 } 3040 }
3041 switch (tiling_count) { 3041 switch (tiling_count) {
3042 case 0: 3042 case 0:
3043 case 1: 3043 case 1:
3044 EXPECT_EQ(occluded_tile_count, 2); 3044 EXPECT_EQ(occluded_tile_count, 2);
3045 break; 3045 break;
3046 case 2: 3046 case 2:
3047 EXPECT_EQ(occluded_tile_count, 4); 3047 EXPECT_EQ(occluded_tile_count, 4);
3048 break; 3048 break;
3049 case 3: 3049 case 3:
3050 EXPECT_EQ(occluded_tile_count, 5); 3050 EXPECT_EQ(occluded_tile_count, 5);
3051 break; 3051 break;
3052 case 4: 3052 case 4:
3053 EXPECT_EQ(occluded_tile_count, 30); 3053 EXPECT_EQ(occluded_tile_count, 30);
3054 break; 3054 break;
3055 default: 3055 default:
3056 NOTREACHED(); 3056 NOTREACHED();
3057 } 3057 }
3058 3058
3059 tiling_count++; 3059 tiling_count++;
3060 } 3060 }
3061 3061
3062 EXPECT_EQ(tiling_count, 5); 3062 EXPECT_EQ(tiling_count, 5);
3063 } 3063 }
3064
3065 TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) {
3066 gfx::Size tile_size(102, 102);
3067 gfx::Size layer_bounds(1000, 1000);
3068 gfx::Size viewport_size(1000, 1000);
3069 gfx::Point occluding_layer_position(310, 0);
3070 gfx::Rect invalidation_rect(230, 230, 102, 102);
3071
3072 scoped_refptr<FakePicturePileImpl> pending_pile =
3073 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3074 scoped_refptr<FakePicturePileImpl> active_pile =
3075 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3076 SetupTrees(pending_pile, active_pile);
3077
3078 // Partially occlude the active layer.
3079 active_layer_->AddChild(LayerImpl::Create(host_impl_.active_tree(), 2));
3080 LayerImpl* layer1 = active_layer_->children()[0];
3081 layer1->SetBounds(layer_bounds);
3082 layer1->SetContentBounds(layer_bounds);
3083 layer1->SetDrawsContent(true);
3084 layer1->SetContentsOpaque(true);
3085 layer1->SetPosition(occluding_layer_position);
3086
3087 // Partially invalidate the pending layer.
3088 pending_layer_->set_invalidation(invalidation_rect);
3089
3090 host_impl_.SetViewportSize(viewport_size);
3091
3092 active_layer_->CreateDefaultTilingsAndTiles();
3093 pending_layer_->CreateDefaultTilingsAndTiles();
3094
3095 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3096 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3097
3098 for (PictureLayerTiling::CoverageIterator iter(
3099 tiling,
3100 pending_layer_->contents_scale_x(),
3101 gfx::Rect(layer_bounds));
3102 iter;
3103 ++iter) {
3104 if (!*iter)
3105 continue;
3106 const Tile* tile = *iter;
3107
3108 // All tiles are unoccluded on the pending tree.
3109 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded);
3110
3111 Tile* twin_tile =
3112 pending_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j());
3113 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
3114 tile->content_rect(), 1.0f / tile->contents_scale());
3115
3116 if (scaled_content_rect.Intersects(invalidation_rect)) {
3117 // Tiles inside the invalidation rect are only on the pending tree.
3118 EXPECT_NE(tile, twin_tile);
3119
3120 // Unshared tiles should have the default TilePriority of being
3121 // unoccluded on the active tree.
3122 EXPECT_FALSE(tile->priority(ACTIVE_TREE).is_occluded);
3123 } else {
3124 // Tiles outside the invalidation rect are shared between both trees.
3125 EXPECT_EQ(tile, twin_tile);
3126
3127 // Shared tiles are occluded on the active tree iff they lie beneath the
3128 // occluding layer.
3129 EXPECT_EQ(tile->priority(ACTIVE_TREE).is_occluded,
3130 scaled_content_rect.x() >= occluding_layer_position.x());
3131 }
3132 }
3133 }
3134
3135 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
3136 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
3137
3138 for (PictureLayerTiling::CoverageIterator iter(
3139 tiling,
3140 active_layer_->contents_scale_x(),
3141 gfx::Rect(layer_bounds));
3142 iter;
3143 ++iter) {
3144 if (!*iter)
3145 continue;
3146 const Tile* tile = *iter;
3147
3148 Tile* twin_tile =
3149 active_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j());
3150 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
3151 tile->content_rect(), 1.0f / tile->contents_scale());
3152
3153 // Since we've already checked the shared tiles, only consider tiles in
3154 // the invalidation rect.
3155 if (scaled_content_rect.Intersects(invalidation_rect)) {
3156 // Tiles inside the invalidation rect are only on the active tree.
3157 EXPECT_NE(tile, twin_tile);
3158
3159 // Unshared tiles should have the default TilePriority of being
3160 // unoccluded on the pending tree.
3161 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded);
3162
3163 // Unshared tiles are occluded on the active tree iff they lie beneath
3164 // the occluding layer.
3165 EXPECT_EQ(tile->priority(ACTIVE_TREE).is_occluded,
3166 scaled_content_rect.x() >= occluding_layer_position.x());
3167 }
3168 }
3169 }
3170 }
3064 } // namespace 3171 } // namespace
3065 } // namespace cc 3172 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698