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 2824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2835 | 2835 |
2836 // No occlusion. | 2836 // No occlusion. |
2837 int unoccluded_tile_count = 0; | 2837 int unoccluded_tile_count = 0; |
2838 for (PictureLayerImpl::LayerRasterTileIterator it = | 2838 for (PictureLayerImpl::LayerRasterTileIterator it = |
2839 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); | 2839 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); |
2840 it; | 2840 it; |
2841 ++it) { | 2841 ++it) { |
2842 Tile* tile = *it; | 2842 Tile* tile = *it; |
2843 | 2843 |
2844 // Occluded tiles should not be iterated over. | 2844 // Occluded tiles should not be iterated over. |
2845 EXPECT_FALSE(tile->is_occluded()); | 2845 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded); |
2846 | 2846 |
2847 // Some tiles may not be visible (i.e. outside the viewport). The rest are | 2847 // Some tiles may not be visible (i.e. outside the viewport). The rest are |
2848 // visible and at least partially unoccluded, verified by the above expect. | 2848 // visible and at least partially unoccluded, verified by the above expect. |
2849 bool tile_is_visible = | 2849 bool tile_is_visible = |
2850 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); | 2850 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); |
2851 if (tile_is_visible) | 2851 if (tile_is_visible) |
2852 unoccluded_tile_count++; | 2852 unoccluded_tile_count++; |
2853 } | 2853 } |
2854 EXPECT_EQ(unoccluded_tile_count, 25 + 4); | 2854 EXPECT_EQ(unoccluded_tile_count, 25 + 4); |
2855 | 2855 |
2856 // Partial occlusion. | 2856 // Partial occlusion. |
2857 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); | 2857 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); |
2858 LayerImpl* layer1 = pending_layer_->children()[0]; | 2858 LayerImpl* layer1 = pending_layer_->children()[0]; |
2859 layer1->SetBounds(layer_bounds); | 2859 layer1->SetBounds(layer_bounds); |
2860 layer1->SetContentBounds(layer_bounds); | 2860 layer1->SetContentBounds(layer_bounds); |
2861 layer1->SetDrawsContent(true); | 2861 layer1->SetDrawsContent(true); |
2862 layer1->SetContentsOpaque(true); | 2862 layer1->SetContentsOpaque(true); |
2863 layer1->SetPosition(occluding_layer_position); | 2863 layer1->SetPosition(occluding_layer_position); |
2864 | 2864 |
2865 host_impl_.pending_tree()->UpdateDrawProperties(); | 2865 host_impl_.pending_tree()->UpdateDrawProperties(); |
2866 | 2866 |
2867 unoccluded_tile_count = 0; | 2867 unoccluded_tile_count = 0; |
2868 for (PictureLayerImpl::LayerRasterTileIterator it = | 2868 for (PictureLayerImpl::LayerRasterTileIterator it = |
2869 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); | 2869 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); |
2870 it; | 2870 it; |
2871 ++it) { | 2871 ++it) { |
2872 Tile* tile = *it; | 2872 Tile* tile = *it; |
2873 | 2873 |
2874 EXPECT_FALSE(tile->is_occluded()); | 2874 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded); |
2875 | 2875 |
2876 bool tile_is_visible = | 2876 bool tile_is_visible = |
2877 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); | 2877 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); |
2878 if (tile_is_visible) | 2878 if (tile_is_visible) |
2879 unoccluded_tile_count++; | 2879 unoccluded_tile_count++; |
2880 } | 2880 } |
2881 EXPECT_EQ(unoccluded_tile_count, 20 + 2); | 2881 EXPECT_EQ(unoccluded_tile_count, 20 + 2); |
2882 | 2882 |
2883 // Full occlusion. | 2883 // Full occlusion. |
2884 layer1->SetPosition(gfx::Point(0, 0)); | 2884 layer1->SetPosition(gfx::Point(0, 0)); |
2885 | 2885 |
2886 host_impl_.pending_tree()->UpdateDrawProperties(); | 2886 host_impl_.pending_tree()->UpdateDrawProperties(); |
2887 | 2887 |
2888 unoccluded_tile_count = 0; | 2888 unoccluded_tile_count = 0; |
2889 for (PictureLayerImpl::LayerRasterTileIterator it = | 2889 for (PictureLayerImpl::LayerRasterTileIterator it = |
2890 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); | 2890 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); |
2891 it; | 2891 it; |
2892 ++it) { | 2892 ++it) { |
2893 Tile* tile = *it; | 2893 Tile* tile = *it; |
2894 | 2894 |
2895 EXPECT_FALSE(tile->is_occluded()); | 2895 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded); |
2896 | 2896 |
2897 bool tile_is_visible = | 2897 bool tile_is_visible = |
2898 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); | 2898 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); |
2899 if (tile_is_visible) | 2899 if (tile_is_visible) |
2900 unoccluded_tile_count++; | 2900 unoccluded_tile_count++; |
2901 } | 2901 } |
2902 EXPECT_EQ(unoccluded_tile_count, 0); | 2902 EXPECT_EQ(unoccluded_tile_count, 0); |
2903 } | 2903 } |
2904 | 2904 |
2905 TEST_F(OcclusionTrackingPictureLayerImplTest, | 2905 TEST_F(OcclusionTrackingPictureLayerImplTest, |
(...skipping 21 matching lines...) Expand all Loading... |
2927 tiling, | 2927 tiling, |
2928 pending_layer_->contents_scale_x(), | 2928 pending_layer_->contents_scale_x(), |
2929 gfx::Rect(layer_bounds)); | 2929 gfx::Rect(layer_bounds)); |
2930 iter; | 2930 iter; |
2931 ++iter) { | 2931 ++iter) { |
2932 if (!*iter) | 2932 if (!*iter) |
2933 continue; | 2933 continue; |
2934 const Tile* tile = *iter; | 2934 const Tile* tile = *iter; |
2935 | 2935 |
2936 // Fully occluded tiles are not required for activation. | 2936 // Fully occluded tiles are not required for activation. |
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 EXPECT_EQ(occluded_tile_count, 0); | 2942 EXPECT_EQ(occluded_tile_count, 0); |
2943 } | 2943 } |
2944 | 2944 |
2945 // Partial occlusion. | 2945 // Partial occlusion. |
2946 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); | 2946 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); |
2947 LayerImpl* layer1 = pending_layer_->children()[0]; | 2947 LayerImpl* layer1 = pending_layer_->children()[0]; |
(...skipping 12 matching lines...) Expand all Loading... |
2960 for (PictureLayerTiling::CoverageIterator iter( | 2960 for (PictureLayerTiling::CoverageIterator iter( |
2961 tiling, | 2961 tiling, |
2962 pending_layer_->contents_scale_x(), | 2962 pending_layer_->contents_scale_x(), |
2963 gfx::Rect(layer_bounds)); | 2963 gfx::Rect(layer_bounds)); |
2964 iter; | 2964 iter; |
2965 ++iter) { | 2965 ++iter) { |
2966 if (!*iter) | 2966 if (!*iter) |
2967 continue; | 2967 continue; |
2968 const Tile* tile = *iter; | 2968 const Tile* tile = *iter; |
2969 | 2969 |
2970 if (tile->is_occluded()) { | 2970 if (tile->priority(PENDING_TREE).is_occluded) { |
2971 EXPECT_FALSE(tile->required_for_activation()); | 2971 EXPECT_FALSE(tile->required_for_activation()); |
2972 occluded_tile_count++; | 2972 occluded_tile_count++; |
2973 } | 2973 } |
2974 } | 2974 } |
2975 switch (i) { | 2975 switch (i) { |
2976 case 0: | 2976 case 0: |
2977 EXPECT_EQ(occluded_tile_count, 5); | 2977 EXPECT_EQ(occluded_tile_count, 5); |
2978 break; | 2978 break; |
2979 case 1: | 2979 case 1: |
2980 EXPECT_EQ(occluded_tile_count, 2); | 2980 EXPECT_EQ(occluded_tile_count, 2); |
(...skipping 15 matching lines...) Expand all Loading... |
2996 for (PictureLayerTiling::CoverageIterator iter( | 2996 for (PictureLayerTiling::CoverageIterator iter( |
2997 tiling, | 2997 tiling, |
2998 pending_layer_->contents_scale_x(), | 2998 pending_layer_->contents_scale_x(), |
2999 gfx::Rect(layer_bounds)); | 2999 gfx::Rect(layer_bounds)); |
3000 iter; | 3000 iter; |
3001 ++iter) { | 3001 ++iter) { |
3002 if (!*iter) | 3002 if (!*iter) |
3003 continue; | 3003 continue; |
3004 const Tile* tile = *iter; | 3004 const Tile* tile = *iter; |
3005 | 3005 |
3006 if (tile->is_occluded()) { | 3006 if (tile->priority(PENDING_TREE).is_occluded) { |
3007 EXPECT_FALSE(tile->required_for_activation()); | 3007 EXPECT_FALSE(tile->required_for_activation()); |
3008 occluded_tile_count++; | 3008 occluded_tile_count++; |
3009 } | 3009 } |
3010 } | 3010 } |
3011 switch (i) { | 3011 switch (i) { |
3012 case 0: | 3012 case 0: |
3013 EXPECT_EQ(occluded_tile_count, 25); | 3013 EXPECT_EQ(occluded_tile_count, 25); |
3014 break; | 3014 break; |
3015 case 1: | 3015 case 1: |
3016 EXPECT_EQ(occluded_tile_count, 4); | 3016 EXPECT_EQ(occluded_tile_count, 4); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3057 int tiling_count = 0; | 3057 int tiling_count = 0; |
3058 int occluded_tile_count = 0; | 3058 int occluded_tile_count = 0; |
3059 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = | 3059 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = |
3060 tilings.begin(); | 3060 tilings.begin(); |
3061 tiling_iterator != tilings.end(); | 3061 tiling_iterator != tilings.end(); |
3062 ++tiling_iterator) { | 3062 ++tiling_iterator) { |
3063 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | 3063 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); |
3064 | 3064 |
3065 occluded_tile_count = 0; | 3065 occluded_tile_count = 0; |
3066 for (size_t i = 0; i < tiles.size(); ++i) { | 3066 for (size_t i = 0; i < tiles.size(); ++i) { |
3067 if (tiles[i]->is_occluded()) { | 3067 if (tiles[i]->priority(PENDING_TREE).is_occluded) { |
3068 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( | 3068 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( |
3069 tiles[i]->content_rect(), 1.0f / tiles[i]->contents_scale()); | 3069 tiles[i]->content_rect(), 1.0f / tiles[i]->contents_scale()); |
3070 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x()); | 3070 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x()); |
3071 occluded_tile_count++; | 3071 occluded_tile_count++; |
3072 } | 3072 } |
3073 } | 3073 } |
3074 switch (tiling_count) { | 3074 switch (tiling_count) { |
3075 case 0: | 3075 case 0: |
3076 case 1: | 3076 case 1: |
3077 EXPECT_EQ(occluded_tile_count, 2); | 3077 EXPECT_EQ(occluded_tile_count, 2); |
3078 break; | 3078 break; |
3079 case 2: | 3079 case 2: |
3080 EXPECT_EQ(occluded_tile_count, 4); | 3080 EXPECT_EQ(occluded_tile_count, 4); |
3081 break; | 3081 break; |
3082 case 3: | 3082 case 3: |
3083 EXPECT_EQ(occluded_tile_count, 5); | 3083 EXPECT_EQ(occluded_tile_count, 5); |
3084 break; | 3084 break; |
3085 case 4: | 3085 case 4: |
3086 EXPECT_EQ(occluded_tile_count, 30); | 3086 EXPECT_EQ(occluded_tile_count, 30); |
3087 break; | 3087 break; |
3088 default: | 3088 default: |
3089 NOTREACHED(); | 3089 NOTREACHED(); |
3090 } | 3090 } |
3091 | 3091 |
3092 tiling_count++; | 3092 tiling_count++; |
3093 } | 3093 } |
3094 | 3094 |
3095 EXPECT_EQ(tiling_count, 5); | 3095 EXPECT_EQ(tiling_count, 5); |
3096 } | 3096 } |
| 3097 |
| 3098 TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) { |
| 3099 gfx::Size tile_size(102, 102); |
| 3100 gfx::Size layer_bounds(1000, 1000); |
| 3101 gfx::Size viewport_size(1000, 1000); |
| 3102 gfx::Point occluding_layer_position(310, 0); |
| 3103 gfx::Rect invalidation_rect(230, 230, 102, 102); |
| 3104 |
| 3105 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 3106 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 3107 scoped_refptr<FakePicturePileImpl> active_pile = |
| 3108 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 3109 SetupTrees(pending_pile, active_pile); |
| 3110 |
| 3111 // Partially occlude the active layer. |
| 3112 active_layer_->AddChild(LayerImpl::Create(host_impl_.active_tree(), 2)); |
| 3113 LayerImpl* layer1 = active_layer_->children()[0]; |
| 3114 layer1->SetBounds(layer_bounds); |
| 3115 layer1->SetContentBounds(layer_bounds); |
| 3116 layer1->SetDrawsContent(true); |
| 3117 layer1->SetContentsOpaque(true); |
| 3118 layer1->SetPosition(occluding_layer_position); |
| 3119 |
| 3120 // Partially invalidate the pending layer. |
| 3121 pending_layer_->set_invalidation(invalidation_rect); |
| 3122 |
| 3123 host_impl_.SetViewportSize(viewport_size); |
| 3124 |
| 3125 active_layer_->CreateDefaultTilingsAndTiles(); |
| 3126 pending_layer_->CreateDefaultTilingsAndTiles(); |
| 3127 |
| 3128 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { |
| 3129 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); |
| 3130 |
| 3131 for (PictureLayerTiling::CoverageIterator iter( |
| 3132 tiling, |
| 3133 pending_layer_->contents_scale_x(), |
| 3134 gfx::Rect(layer_bounds)); |
| 3135 iter; |
| 3136 ++iter) { |
| 3137 if (!*iter) |
| 3138 continue; |
| 3139 const Tile* tile = *iter; |
| 3140 |
| 3141 // All tiles are unoccluded on the pending tree. |
| 3142 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded); |
| 3143 |
| 3144 Tile* twin_tile = |
| 3145 pending_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j()); |
| 3146 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( |
| 3147 tile->content_rect(), 1.0f / tile->contents_scale()); |
| 3148 |
| 3149 if (scaled_content_rect.Intersects(invalidation_rect)) { |
| 3150 // Tiles inside the invalidation rect are only on the pending tree. |
| 3151 EXPECT_NE(tile, twin_tile); |
| 3152 |
| 3153 // Unshared tiles should have the default TilePriority of being |
| 3154 // unoccluded on the active tree. |
| 3155 EXPECT_FALSE(tile->priority(ACTIVE_TREE).is_occluded); |
| 3156 } else { |
| 3157 // Tiles outside the invalidation rect are shared between both trees. |
| 3158 EXPECT_EQ(tile, twin_tile); |
| 3159 |
| 3160 // Shared tiles are occluded on the active tree iff they lie beneath the |
| 3161 // occluding layer. |
| 3162 EXPECT_EQ(tile->priority(ACTIVE_TREE).is_occluded, |
| 3163 scaled_content_rect.x() >= occluding_layer_position.x()); |
| 3164 } |
| 3165 } |
| 3166 } |
| 3167 |
| 3168 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { |
| 3169 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i); |
| 3170 |
| 3171 for (PictureLayerTiling::CoverageIterator iter( |
| 3172 tiling, |
| 3173 active_layer_->contents_scale_x(), |
| 3174 gfx::Rect(layer_bounds)); |
| 3175 iter; |
| 3176 ++iter) { |
| 3177 if (!*iter) |
| 3178 continue; |
| 3179 const Tile* tile = *iter; |
| 3180 |
| 3181 Tile* twin_tile = |
| 3182 active_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j()); |
| 3183 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( |
| 3184 tile->content_rect(), 1.0f / tile->contents_scale()); |
| 3185 |
| 3186 // Since we've already checked the shared tiles, only consider tiles in |
| 3187 // the invalidation rect. |
| 3188 if (scaled_content_rect.Intersects(invalidation_rect)) { |
| 3189 // Tiles inside the invalidation rect are only on the active tree. |
| 3190 EXPECT_NE(tile, twin_tile); |
| 3191 |
| 3192 // Unshared tiles should have the default TilePriority of being |
| 3193 // unoccluded on the pending tree. |
| 3194 EXPECT_FALSE(tile->priority(PENDING_TREE).is_occluded); |
| 3195 |
| 3196 // Unshared tiles are occluded on the active tree iff they lie beneath |
| 3197 // the occluding layer. |
| 3198 EXPECT_EQ(tile->priority(ACTIVE_TREE).is_occluded, |
| 3199 scaled_content_rect.x() >= occluding_layer_position.x()); |
| 3200 } |
| 3201 } |
| 3202 } |
| 3203 } |
3097 } // namespace | 3204 } // namespace |
3098 } // namespace cc | 3205 } // namespace cc |
OLD | NEW |