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