OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "cc/animation/timing_function.h" | 11 #include "cc/animation/timing_function.h" |
12 #include "cc/debug/frame_rate_counter.h" | 12 #include "cc/debug/frame_rate_counter.h" |
13 #include "cc/layers/content_layer.h" | 13 #include "cc/layers/content_layer.h" |
14 #include "cc/layers/content_layer_client.h" | 14 #include "cc/layers/content_layer_client.h" |
15 #include "cc/layers/io_surface_layer.h" | 15 #include "cc/layers/io_surface_layer.h" |
16 #include "cc/layers/layer_impl.h" | 16 #include "cc/layers/layer_impl.h" |
17 #include "cc/layers/picture_layer.h" | 17 #include "cc/layers/picture_layer.h" |
18 #include "cc/layers/scrollbar_layer.h" | 18 #include "cc/layers/scrollbar_layer.h" |
19 #include "cc/layers/video_layer.h" | |
20 #include "cc/output/begin_frame_args.h" | 19 #include "cc/output/begin_frame_args.h" |
21 #include "cc/output/copy_output_request.h" | 20 #include "cc/output/copy_output_request.h" |
22 #include "cc/output/copy_output_result.h" | 21 #include "cc/output/copy_output_result.h" |
23 #include "cc/output/output_surface.h" | 22 #include "cc/output/output_surface.h" |
24 #include "cc/resources/prioritized_resource.h" | 23 #include "cc/resources/prioritized_resource.h" |
25 #include "cc/resources/prioritized_resource_manager.h" | 24 #include "cc/resources/prioritized_resource_manager.h" |
26 #include "cc/resources/resource_update_queue.h" | 25 #include "cc/resources/resource_update_queue.h" |
27 #include "cc/scheduler/frame_rate_controller.h" | 26 #include "cc/scheduler/frame_rate_controller.h" |
28 #include "cc/test/fake_content_layer.h" | 27 #include "cc/test/fake_content_layer.h" |
29 #include "cc/test/fake_content_layer_client.h" | 28 #include "cc/test/fake_content_layer_client.h" |
30 #include "cc/test/fake_layer_tree_host_client.h" | 29 #include "cc/test/fake_layer_tree_host_client.h" |
31 #include "cc/test/fake_output_surface.h" | 30 #include "cc/test/fake_output_surface.h" |
32 #include "cc/test/fake_picture_layer.h" | 31 #include "cc/test/fake_picture_layer.h" |
33 #include "cc/test/fake_picture_layer_impl.h" | 32 #include "cc/test/fake_picture_layer_impl.h" |
34 #include "cc/test/fake_proxy.h" | 33 #include "cc/test/fake_proxy.h" |
35 #include "cc/test/fake_scoped_ui_resource.h" | 34 #include "cc/test/fake_scoped_ui_resource.h" |
36 #include "cc/test/fake_scrollbar_layer.h" | 35 #include "cc/test/fake_scrollbar_layer.h" |
37 #include "cc/test/fake_video_frame_provider.h" | |
38 #include "cc/test/geometry_test_utils.h" | 36 #include "cc/test/geometry_test_utils.h" |
39 #include "cc/test/layer_tree_test.h" | 37 #include "cc/test/layer_tree_test.h" |
40 #include "cc/test/occlusion_tracker_test_common.h" | 38 #include "cc/test/occlusion_tracker_test_common.h" |
41 #include "cc/trees/layer_tree_host_impl.h" | 39 #include "cc/trees/layer_tree_host_impl.h" |
42 #include "cc/trees/layer_tree_impl.h" | 40 #include "cc/trees/layer_tree_impl.h" |
43 #include "cc/trees/single_thread_proxy.h" | 41 #include "cc/trees/single_thread_proxy.h" |
44 #include "cc/trees/thread_proxy.h" | 42 #include "cc/trees/thread_proxy.h" |
45 #include "gpu/GLES2/gl2extchromium.h" | 43 #include "gpu/GLES2/gl2extchromium.h" |
46 #include "skia/ext/refptr.h" | 44 #include "skia/ext/refptr.h" |
47 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 | 1101 |
1104 private: | 1102 private: |
1105 FakeContentLayerClient client_; | 1103 FakeContentLayerClient client_; |
1106 scoped_refptr<NoScaleContentLayer> root_layer_; | 1104 scoped_refptr<NoScaleContentLayer> root_layer_; |
1107 scoped_refptr<ContentLayer> child_layer_; | 1105 scoped_refptr<ContentLayer> child_layer_; |
1108 }; | 1106 }; |
1109 | 1107 |
1110 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); | 1108 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); |
1111 | 1109 |
1112 // Verify atomicity of commits and reuse of textures. | 1110 // Verify atomicity of commits and reuse of textures. |
1113 class LayerTreeHostTestAtomicCommit : public LayerTreeHostTest { | 1111 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { |
1114 public: | 1112 public: |
1115 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1113 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
1116 // Make sure partial texture updates are turned off. | 1114 // Make sure partial texture updates are turned off. |
1117 settings->max_partial_texture_updates = 0; | 1115 settings->max_partial_texture_updates = 0; |
1118 // Linear fade animator prevents scrollbars from drawing immediately. | 1116 // Linear fade animator prevents scrollbars from drawing immediately. |
1119 settings->use_linear_fade_scrollbar_animator = false; | 1117 settings->use_linear_fade_scrollbar_animator = false; |
1120 } | 1118 } |
1121 | 1119 |
1122 virtual void SetupTree() OVERRIDE { | 1120 virtual void SetupTree() OVERRIDE { |
1123 layer_ = FakeContentLayer::Create(&client_); | 1121 layer_ = FakeContentLayer::Create(&client_); |
(...skipping 30 matching lines...) Expand all Loading... |
1154 // Number of textures used for commit should be one for each layer. | 1152 // Number of textures used for commit should be one for each layer. |
1155 EXPECT_EQ(2u, context->NumUsedTextures()); | 1153 EXPECT_EQ(2u, context->NumUsedTextures()); |
1156 // Verify that used texture is correct. | 1154 // Verify that used texture is correct. |
1157 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); | 1155 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); |
1158 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); | 1156 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
1159 | 1157 |
1160 context->ResetUsedTextures(); | 1158 context->ResetUsedTextures(); |
1161 PostSetNeedsCommitToMainThread(); | 1159 PostSetNeedsCommitToMainThread(); |
1162 break; | 1160 break; |
1163 case 1: | 1161 case 1: |
1164 // Number of textures should be doubled as the first textures | 1162 // Number of textures should be one for scrollbar layer since it was |
1165 // are used by impl thread and cannot by used for update. | 1163 // requested and deleted on the impl-thread, and double for the content |
1166 ASSERT_EQ(4u, context->NumTextures()); | 1164 // layer since its first texture is used by impl thread and cannot by |
1167 // Number of textures used for commit should still be | 1165 // used for update. |
1168 // one for each layer. | 1166 ASSERT_EQ(3u, context->NumTextures()); |
| 1167 // Number of textures used for commit should be one for each layer. |
1169 EXPECT_EQ(2u, context->NumUsedTextures()); | 1168 EXPECT_EQ(2u, context->NumUsedTextures()); |
1170 // First textures should not have been used. | 1169 // First textures should not have been used. |
1171 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); | 1170 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); |
1172 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); | 1171 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
1173 // New textures should have been used. | 1172 // New textures should have been used. |
1174 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); | 1173 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
1175 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | |
1176 | |
1177 context->ResetUsedTextures(); | 1174 context->ResetUsedTextures(); |
1178 PostSetNeedsCommitToMainThread(); | 1175 PostSetNeedsCommitToMainThread(); |
1179 break; | 1176 break; |
1180 case 2: | 1177 case 2: |
1181 EndTest(); | 1178 EndTest(); |
1182 break; | 1179 break; |
1183 default: | 1180 default: |
1184 NOTREACHED(); | 1181 NOTREACHED(); |
1185 break; | 1182 break; |
1186 } | 1183 } |
(...skipping 14 matching lines...) Expand all Loading... |
1201 context->ResetUsedTextures(); | 1198 context->ResetUsedTextures(); |
1202 } | 1199 } |
1203 | 1200 |
1204 virtual void Layout() OVERRIDE { | 1201 virtual void Layout() OVERRIDE { |
1205 layer_->SetNeedsDisplay(); | 1202 layer_->SetNeedsDisplay(); |
1206 scrollbar_->SetNeedsDisplay(); | 1203 scrollbar_->SetNeedsDisplay(); |
1207 } | 1204 } |
1208 | 1205 |
1209 virtual void AfterTest() OVERRIDE {} | 1206 virtual void AfterTest() OVERRIDE {} |
1210 | 1207 |
1211 private: | 1208 protected: |
1212 FakeContentLayerClient client_; | 1209 FakeContentLayerClient client_; |
1213 scoped_refptr<FakeContentLayer> layer_; | 1210 scoped_refptr<FakeContentLayer> layer_; |
1214 scoped_refptr<FakeScrollbarLayer> scrollbar_; | 1211 scoped_refptr<FakeScrollbarLayer> scrollbar_; |
1215 int drew_frame_; | 1212 int drew_frame_; |
1216 }; | 1213 }; |
1217 | 1214 |
1218 MULTI_THREAD_TEST_F(LayerTreeHostTestAtomicCommit); | 1215 MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1216 LayerTreeHostTestDirectRendererAtomicCommit); |
| 1217 |
| 1218 class LayerTreeHostTestDelegatingRendererAtomicCommit |
| 1219 : public LayerTreeHostTestDirectRendererAtomicCommit { |
| 1220 public: |
| 1221 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1222 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); |
| 1223 |
| 1224 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 1225 impl->output_surface()->context3d()); |
| 1226 |
| 1227 switch (impl->active_tree()->source_frame_number()) { |
| 1228 case 0: |
| 1229 // Number of textures should be one for each layer |
| 1230 ASSERT_EQ(2u, context->NumTextures()); |
| 1231 // Number of textures used for commit should be one for each layer. |
| 1232 EXPECT_EQ(2u, context->NumUsedTextures()); |
| 1233 // Verify that used texture is correct. |
| 1234 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); |
| 1235 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
| 1236 context->ResetUsedTextures(); |
| 1237 PostSetNeedsCommitToMainThread(); |
| 1238 break; |
| 1239 case 1: |
| 1240 // Number of textures should be doubled as the first context layer |
| 1241 // texture is being used by the impl-thread and cannot be used for |
| 1242 // update. The scrollbar behavior is different direct renderer because |
| 1243 // UI resource deletion with delegating renderer occurs after tree |
| 1244 // activation. |
| 1245 ASSERT_EQ(4u, context->NumTextures()); |
| 1246 // Number of textures used for commit should still be |
| 1247 // one for each layer. |
| 1248 EXPECT_EQ(2u, context->NumUsedTextures()); |
| 1249 // First textures should not have been used. |
| 1250 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); |
| 1251 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); |
| 1252 // New textures should have been used. |
| 1253 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
| 1254 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); |
| 1255 context->ResetUsedTextures(); |
| 1256 PostSetNeedsCommitToMainThread(); |
| 1257 break; |
| 1258 case 2: |
| 1259 EndTest(); |
| 1260 break; |
| 1261 default: |
| 1262 NOTREACHED(); |
| 1263 break; |
| 1264 } |
| 1265 } |
| 1266 }; |
| 1267 |
| 1268 MULTI_THREAD_DELEGATING_RENDERER_TEST_F( |
| 1269 LayerTreeHostTestDelegatingRendererAtomicCommit); |
1219 | 1270 |
1220 static void SetLayerPropertiesForTesting(Layer* layer, | 1271 static void SetLayerPropertiesForTesting(Layer* layer, |
1221 Layer* parent, | 1272 Layer* parent, |
1222 const gfx::Transform& transform, | 1273 const gfx::Transform& transform, |
1223 gfx::PointF anchor, | 1274 gfx::PointF anchor, |
1224 gfx::PointF position, | 1275 gfx::PointF position, |
1225 gfx::Size bounds, | 1276 gfx::Size bounds, |
1226 bool opaque) { | 1277 bool opaque) { |
1227 layer->RemoveAllChildren(); | 1278 layer->RemoveAllChildren(); |
1228 if (parent) | 1279 if (parent) |
(...skipping 2787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4016 }; | 4067 }; |
4017 | 4068 |
4018 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) { | 4069 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) { |
4019 RunTest(true, false, true); | 4070 RunTest(true, false, true); |
4020 } | 4071 } |
4021 | 4072 |
4022 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) { | 4073 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) { |
4023 RunTest(true, true, true); | 4074 RunTest(true, true, true); |
4024 } | 4075 } |
4025 | 4076 |
4026 // VideoLayer must support being invalidated and then passing that along | |
4027 // to the compositor thread, even though no resources are updated in | |
4028 // response to that invalidation. | |
4029 class LayerTreeHostTestVideoLayerInvalidate : public LayerTreeHostTest { | |
4030 public: | |
4031 LayerTreeHostTestVideoLayerInvalidate() : num_commits_(0), num_draws_(0) {} | |
4032 | |
4033 virtual void SetupTree() OVERRIDE { | |
4034 LayerTreeHostTest::SetupTree(); | |
4035 video_layer_ = VideoLayer::Create(&provider_); | |
4036 video_layer_->SetBounds(gfx::Size(10, 10)); | |
4037 video_layer_->SetIsDrawable(true); | |
4038 layer_tree_host()->root_layer()->AddChild(video_layer_); | |
4039 } | |
4040 | |
4041 virtual void BeginTest() OVERRIDE { | |
4042 // One initial commit. | |
4043 PostSetNeedsCommitToMainThread(); | |
4044 } | |
4045 | |
4046 virtual void DidCommitAndDrawFrame() OVERRIDE { | |
4047 // After commit, invalidate the video layer. This should cause a commit. | |
4048 if (layer_tree_host()->source_frame_number() == 1) | |
4049 video_layer_->SetNeedsDisplay(); | |
4050 } | |
4051 | |
4052 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
4053 num_draws_++; | |
4054 if (impl->active_tree()->source_frame_number() == 1) | |
4055 EndTest(); | |
4056 } | |
4057 | |
4058 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
4059 num_commits_++; | |
4060 } | |
4061 | |
4062 virtual void AfterTest() OVERRIDE { | |
4063 EXPECT_GE(2, num_commits_); | |
4064 EXPECT_GE(2, num_draws_); | |
4065 } | |
4066 | |
4067 private: | |
4068 FakeVideoFrameProvider provider_; | |
4069 scoped_refptr<VideoLayer> video_layer_; | |
4070 int num_commits_; | |
4071 int num_draws_; | |
4072 }; | |
4073 | |
4074 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestVideoLayerInvalidate); | |
4075 | |
4076 } // namespace | 4077 } // namespace |
4077 } // namespace cc | 4078 } // namespace cc |
OLD | NEW |