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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "cc/resources/prioritized_resource_manager.h" | 24 #include "cc/resources/prioritized_resource_manager.h" |
25 #include "cc/resources/resource_update_queue.h" | 25 #include "cc/resources/resource_update_queue.h" |
26 #include "cc/scheduler/frame_rate_controller.h" | 26 #include "cc/scheduler/frame_rate_controller.h" |
27 #include "cc/test/fake_content_layer.h" | 27 #include "cc/test/fake_content_layer.h" |
28 #include "cc/test/fake_content_layer_client.h" | 28 #include "cc/test/fake_content_layer_client.h" |
29 #include "cc/test/fake_layer_tree_host_client.h" | 29 #include "cc/test/fake_layer_tree_host_client.h" |
30 #include "cc/test/fake_output_surface.h" | 30 #include "cc/test/fake_output_surface.h" |
31 #include "cc/test/fake_picture_layer.h" | 31 #include "cc/test/fake_picture_layer.h" |
32 #include "cc/test/fake_picture_layer_impl.h" | 32 #include "cc/test/fake_picture_layer_impl.h" |
33 #include "cc/test/fake_proxy.h" | 33 #include "cc/test/fake_proxy.h" |
| 34 #include "cc/test/fake_scoped_ui_resource.h" |
34 #include "cc/test/fake_scrollbar_layer.h" | 35 #include "cc/test/fake_scrollbar_layer.h" |
35 #include "cc/test/geometry_test_utils.h" | 36 #include "cc/test/geometry_test_utils.h" |
36 #include "cc/test/layer_tree_test.h" | 37 #include "cc/test/layer_tree_test.h" |
37 #include "cc/test/occlusion_tracker_test_common.h" | 38 #include "cc/test/occlusion_tracker_test_common.h" |
38 #include "cc/trees/layer_tree_host_impl.h" | 39 #include "cc/trees/layer_tree_host_impl.h" |
39 #include "cc/trees/layer_tree_impl.h" | 40 #include "cc/trees/layer_tree_impl.h" |
40 #include "cc/trees/single_thread_proxy.h" | 41 #include "cc/trees/single_thread_proxy.h" |
41 #include "cc/trees/thread_proxy.h" | 42 #include "cc/trees/thread_proxy.h" |
42 #include "gpu/GLES2/gl2extchromium.h" | 43 #include "gpu/GLES2/gl2extchromium.h" |
43 #include "skia/ext/refptr.h" | 44 #include "skia/ext/refptr.h" |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 | 1101 |
1101 private: | 1102 private: |
1102 FakeContentLayerClient client_; | 1103 FakeContentLayerClient client_; |
1103 scoped_refptr<NoScaleContentLayer> root_layer_; | 1104 scoped_refptr<NoScaleContentLayer> root_layer_; |
1104 scoped_refptr<ContentLayer> child_layer_; | 1105 scoped_refptr<ContentLayer> child_layer_; |
1105 }; | 1106 }; |
1106 | 1107 |
1107 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); | 1108 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); |
1108 | 1109 |
1109 // Verify atomicity of commits and reuse of textures. | 1110 // Verify atomicity of commits and reuse of textures. |
1110 class LayerTreeHostTestAtomicCommit : public LayerTreeHostTest { | 1111 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { |
1111 public: | 1112 public: |
1112 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1113 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
1113 // Make sure partial texture updates are turned off. | 1114 // Make sure partial texture updates are turned off. |
1114 settings->max_partial_texture_updates = 0; | 1115 settings->max_partial_texture_updates = 0; |
1115 // Linear fade animator prevents scrollbars from drawing immediately. | 1116 // Linear fade animator prevents scrollbars from drawing immediately. |
1116 settings->use_linear_fade_scrollbar_animator = false; | 1117 settings->use_linear_fade_scrollbar_animator = false; |
1117 } | 1118 } |
1118 | 1119 |
1119 virtual void SetupTree() OVERRIDE { | 1120 virtual void SetupTree() OVERRIDE { |
1120 layer_ = FakeContentLayer::Create(&client_); | 1121 layer_ = FakeContentLayer::Create(&client_); |
(...skipping 30 matching lines...) Expand all Loading... |
1151 // 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. |
1152 EXPECT_EQ(2u, context->NumUsedTextures()); | 1153 EXPECT_EQ(2u, context->NumUsedTextures()); |
1153 // Verify that used texture is correct. | 1154 // Verify that used texture is correct. |
1154 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); | 1155 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); |
1155 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); | 1156 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
1156 | 1157 |
1157 context->ResetUsedTextures(); | 1158 context->ResetUsedTextures(); |
1158 PostSetNeedsCommitToMainThread(); | 1159 PostSetNeedsCommitToMainThread(); |
1159 break; | 1160 break; |
1160 case 1: | 1161 case 1: |
1161 // Number of textures should be doubled as the first textures | 1162 // Number of textures should be one for scrollbar layer since it was |
1162 // are used by impl thread and cannot by used for update. | 1163 // requested and deleted on the impl-thread, and double for the content |
1163 ASSERT_EQ(4u, context->NumTextures()); | 1164 // layer since its first texture is used by impl thread and cannot by |
1164 // Number of textures used for commit should still be | 1165 // used for update. |
1165 // one for each layer. | 1166 ASSERT_EQ(3u, context->NumTextures()); |
| 1167 // Number of textures used for commit should be one for each layer. |
1166 EXPECT_EQ(2u, context->NumUsedTextures()); | 1168 EXPECT_EQ(2u, context->NumUsedTextures()); |
1167 // First textures should not have been used. | 1169 // First textures should not have been used. |
1168 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); | 1170 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); |
1169 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); | 1171 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
1170 // New textures should have been used. | 1172 // New textures should have been used. |
1171 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); | 1173 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
1172 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | |
1173 | |
1174 context->ResetUsedTextures(); | 1174 context->ResetUsedTextures(); |
1175 PostSetNeedsCommitToMainThread(); | 1175 PostSetNeedsCommitToMainThread(); |
1176 break; | 1176 break; |
1177 case 2: | 1177 case 2: |
1178 EndTest(); | 1178 EndTest(); |
1179 break; | 1179 break; |
1180 default: | 1180 default: |
1181 NOTREACHED(); | 1181 NOTREACHED(); |
1182 break; | 1182 break; |
1183 } | 1183 } |
(...skipping 14 matching lines...) Expand all Loading... |
1198 context->ResetUsedTextures(); | 1198 context->ResetUsedTextures(); |
1199 } | 1199 } |
1200 | 1200 |
1201 virtual void Layout() OVERRIDE { | 1201 virtual void Layout() OVERRIDE { |
1202 layer_->SetNeedsDisplay(); | 1202 layer_->SetNeedsDisplay(); |
1203 scrollbar_->SetNeedsDisplay(); | 1203 scrollbar_->SetNeedsDisplay(); |
1204 } | 1204 } |
1205 | 1205 |
1206 virtual void AfterTest() OVERRIDE {} | 1206 virtual void AfterTest() OVERRIDE {} |
1207 | 1207 |
1208 private: | 1208 protected: |
1209 FakeContentLayerClient client_; | 1209 FakeContentLayerClient client_; |
1210 scoped_refptr<FakeContentLayer> layer_; | 1210 scoped_refptr<FakeContentLayer> layer_; |
1211 scoped_refptr<FakeScrollbarLayer> scrollbar_; | 1211 scoped_refptr<FakeScrollbarLayer> scrollbar_; |
1212 int drew_frame_; | 1212 int drew_frame_; |
1213 }; | 1213 }; |
1214 | 1214 |
1215 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); |
1216 | 1270 |
1217 static void SetLayerPropertiesForTesting(Layer* layer, | 1271 static void SetLayerPropertiesForTesting(Layer* layer, |
1218 Layer* parent, | 1272 Layer* parent, |
1219 const gfx::Transform& transform, | 1273 const gfx::Transform& transform, |
1220 gfx::PointF anchor, | 1274 gfx::PointF anchor, |
1221 gfx::PointF position, | 1275 gfx::PointF position, |
1222 gfx::Size bounds, | 1276 gfx::Size bounds, |
1223 bool opaque) { | 1277 bool opaque) { |
1224 layer->RemoveAllChildren(); | 1278 layer->RemoveAllChildren(); |
1225 if (parent) | 1279 if (parent) |
1226 parent->AddChild(layer); | 1280 parent->AddChild(layer); |
1227 layer->SetTransform(transform); | 1281 layer->SetTransform(transform); |
1228 layer->SetAnchorPoint(anchor); | 1282 layer->SetAnchorPoint(anchor); |
1229 layer->SetPosition(position); | 1283 layer->SetPosition(position); |
1230 layer->SetBounds(bounds); | 1284 layer->SetBounds(bounds); |
1231 layer->SetContentsOpaque(opaque); | 1285 layer->SetContentsOpaque(opaque); |
1232 } | 1286 } |
1233 | 1287 |
1234 class LayerTreeHostTestAtomicCommitWithPartialUpdate | 1288 class LayerTreeHostTestAtomicCommitWithPartialUpdate |
1235 : public LayerTreeHostTest { | 1289 : public LayerTreeHostTest { |
1236 public: | 1290 public: |
1237 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1291 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
1238 // Allow one partial texture update. | 1292 // Allow one partial texture update. |
1239 settings->max_partial_texture_updates = 1; | 1293 settings->max_partial_texture_updates = 1; |
1240 // Linear fade animator prevents scrollbars from drawing immediately. | |
1241 settings->use_linear_fade_scrollbar_animator = false; | |
1242 // No partial updates when impl side painting is enabled. | 1294 // No partial updates when impl side painting is enabled. |
1243 settings->impl_side_painting = false; | 1295 settings->impl_side_painting = false; |
1244 } | 1296 } |
1245 | 1297 |
1246 virtual void SetupTree() OVERRIDE { | 1298 virtual void SetupTree() OVERRIDE { |
1247 parent_ = FakeContentLayer::Create(&client_); | 1299 parent_ = FakeContentLayer::Create(&client_); |
1248 parent_->SetBounds(gfx::Size(10, 20)); | 1300 parent_->SetBounds(gfx::Size(10, 20)); |
1249 | 1301 |
1250 child_ = FakeContentLayer::Create(&client_); | 1302 child_ = FakeContentLayer::Create(&client_); |
1251 child_->SetPosition(gfx::Point(0, 10)); | 1303 child_->SetPosition(gfx::Point(0, 10)); |
1252 child_->SetBounds(gfx::Size(3, 10)); | 1304 child_->SetBounds(gfx::Size(3, 10)); |
1253 | 1305 |
1254 bool paint_scrollbar = true; | |
1255 bool has_thumb = false; | |
1256 scrollbar_with_paints_ = | |
1257 FakeScrollbarLayer::Create(paint_scrollbar, has_thumb, parent_->id()); | |
1258 scrollbar_with_paints_->SetPosition(gfx::Point(3, 10)); | |
1259 scrollbar_with_paints_->SetBounds(gfx::Size(3, 10)); | |
1260 | |
1261 paint_scrollbar = false; | |
1262 scrollbar_without_paints_ = | |
1263 FakeScrollbarLayer::Create(paint_scrollbar, has_thumb, parent_->id()); | |
1264 scrollbar_without_paints_->SetPosition(gfx::Point(6, 10)); | |
1265 scrollbar_without_paints_->SetBounds(gfx::Size(3, 10)); | |
1266 | |
1267 parent_->AddChild(child_); | 1306 parent_->AddChild(child_); |
1268 parent_->AddChild(scrollbar_with_paints_); | |
1269 parent_->AddChild(scrollbar_without_paints_); | |
1270 | 1307 |
1271 layer_tree_host()->SetRootLayer(parent_); | 1308 layer_tree_host()->SetRootLayer(parent_); |
1272 LayerTreeHostTest::SetupTree(); | 1309 LayerTreeHostTest::SetupTree(); |
1273 } | 1310 } |
1274 | 1311 |
1275 virtual void BeginTest() OVERRIDE { | 1312 virtual void BeginTest() OVERRIDE { |
1276 PostSetNeedsCommitToMainThread(); | 1313 PostSetNeedsCommitToMainThread(); |
1277 } | 1314 } |
1278 | 1315 |
1279 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1316 virtual void DidCommitAndDrawFrame() OVERRIDE { |
1280 switch (layer_tree_host()->source_frame_number()) { | 1317 switch (layer_tree_host()->source_frame_number()) { |
1281 case 1: | 1318 case 1: |
1282 parent_->SetNeedsDisplay(); | 1319 parent_->SetNeedsDisplay(); |
1283 child_->SetNeedsDisplay(); | 1320 child_->SetNeedsDisplay(); |
1284 scrollbar_with_paints_->SetNeedsDisplay(); | |
1285 scrollbar_without_paints_->SetNeedsDisplay(); | |
1286 break; | 1321 break; |
1287 case 2: | 1322 case 2: |
1288 // Damage part of layers. | 1323 // Damage part of layers. |
1289 parent_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); | 1324 parent_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); |
1290 child_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); | 1325 child_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); |
1291 scrollbar_with_paints_->SetNeedsDisplayRect( | |
1292 gfx::RectF(0.f, 0.f, 5.f, 5.f)); | |
1293 scrollbar_without_paints_->SetNeedsDisplayRect( | |
1294 gfx::RectF(0.f, 0.f, 5.f, 5.f)); | |
1295 break; | 1326 break; |
1296 case 3: | 1327 case 3: |
1297 child_->SetNeedsDisplay(); | 1328 child_->SetNeedsDisplay(); |
1298 scrollbar_with_paints_->SetNeedsDisplay(); | |
1299 scrollbar_without_paints_->SetNeedsDisplay(); | |
1300 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); | 1329 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); |
1301 break; | 1330 break; |
1302 case 4: | 1331 case 4: |
1303 layer_tree_host()->SetViewportSize(gfx::Size(10, 20)); | 1332 layer_tree_host()->SetViewportSize(gfx::Size(10, 20)); |
1304 break; | 1333 break; |
1305 case 5: | 1334 case 5: |
1306 EndTest(); | 1335 EndTest(); |
1307 break; | 1336 break; |
1308 default: | 1337 default: |
1309 NOTREACHED() << layer_tree_host()->source_frame_number(); | 1338 NOTREACHED() << layer_tree_host()->source_frame_number(); |
1310 break; | 1339 break; |
1311 } | 1340 } |
1312 } | 1341 } |
1313 | 1342 |
1314 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1343 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
1315 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); | 1344 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); |
1316 | 1345 |
1317 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( | 1346 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
1318 impl->output_surface()->context3d()); | 1347 impl->output_surface()->context3d()); |
1319 | 1348 |
1320 switch (impl->active_tree()->source_frame_number()) { | 1349 switch (impl->active_tree()->source_frame_number()) { |
1321 case 0: | 1350 case 0: |
1322 // Number of textures should be one for each layer. | 1351 // Number of textures should be one for each layer. |
1323 ASSERT_EQ(4u, context->NumTextures()); | 1352 ASSERT_EQ(2u, context->NumTextures()); |
1324 // Number of textures used for commit should be one for each layer. | 1353 // Number of textures used for commit should be one for each layer. |
1325 EXPECT_EQ(4u, context->NumUsedTextures()); | 1354 EXPECT_EQ(2u, context->NumUsedTextures()); |
1326 // Verify that used textures are correct. | 1355 // Verify that used textures are correct. |
1327 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); | 1356 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); |
1328 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); | 1357 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
| 1358 context->ResetUsedTextures(); |
| 1359 break; |
| 1360 case 1: |
| 1361 // Number of textures should be two for each content layer. |
| 1362 ASSERT_EQ(4u, context->NumTextures()); |
| 1363 // Number of textures used for commit should be one for each content |
| 1364 // layer. |
| 1365 EXPECT_EQ(2u, context->NumUsedTextures()); |
| 1366 |
| 1367 // First content textures should not have been used. |
| 1368 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); |
| 1369 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); |
| 1370 // New textures should have been used. |
1329 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); | 1371 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
1330 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | 1372 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); |
1331 | 1373 |
1332 context->ResetUsedTextures(); | 1374 context->ResetUsedTextures(); |
1333 break; | 1375 break; |
1334 case 1: | 1376 case 2: |
1335 // Number of textures should be two for each content layer and one | 1377 // Number of textures should be two for each content layer. |
1336 // for each scrollbar, since they always do a partial update. | 1378 ASSERT_EQ(4u, context->NumTextures()); |
1337 ASSERT_EQ(6u, context->NumTextures()); | |
1338 // Number of textures used for commit should be one for each content | 1379 // Number of textures used for commit should be one for each content |
1339 // layer, and one for the scrollbar layer that paints. | 1380 // layer. |
1340 EXPECT_EQ(3u, context->NumUsedTextures()); | 1381 EXPECT_EQ(2u, context->NumUsedTextures()); |
1341 | 1382 |
1342 // First content textures should not have been used. | 1383 // One content layer does a partial update also. |
1343 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); | 1384 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
1344 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); | 1385 EXPECT_FALSE(context->UsedTexture(context->TextureAt(3))); |
1345 // The non-painting scrollbar's texture wasn't updated. | |
1346 EXPECT_FALSE(context->UsedTexture(context->TextureAt(2))); | |
1347 // The painting scrollbar's partial update texture was used. | |
1348 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | |
1349 // New textures should have been used. | |
1350 EXPECT_TRUE(context->UsedTexture(context->TextureAt(4))); | |
1351 EXPECT_TRUE(context->UsedTexture(context->TextureAt(5))); | |
1352 | 1386 |
1353 context->ResetUsedTextures(); | 1387 context->ResetUsedTextures(); |
1354 break; | 1388 break; |
1355 case 2: | |
1356 // Number of textures should be two for each content layer and one | |
1357 // for each scrollbar, since they always do a partial update. | |
1358 ASSERT_EQ(6u, context->NumTextures()); | |
1359 // Number of textures used for commit should be one for each content | |
1360 // layer, and one for the scrollbar layer that paints. | |
1361 EXPECT_EQ(3u, context->NumUsedTextures()); | |
1362 | |
1363 // The non-painting scrollbar's texture wasn't updated. | |
1364 EXPECT_FALSE(context->UsedTexture(context->TextureAt(2))); | |
1365 // The painting scrollbar does a partial update. | |
1366 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | |
1367 // One content layer does a partial update also. | |
1368 EXPECT_TRUE(context->UsedTexture(context->TextureAt(4))); | |
1369 EXPECT_FALSE(context->UsedTexture(context->TextureAt(5))); | |
1370 | |
1371 context->ResetUsedTextures(); | |
1372 break; | |
1373 case 3: | 1389 case 3: |
1374 // No textures should be used for commit. | 1390 // No textures should be used for commit. |
1375 EXPECT_EQ(0u, context->NumUsedTextures()); | 1391 EXPECT_EQ(0u, context->NumUsedTextures()); |
1376 | 1392 |
1377 context->ResetUsedTextures(); | 1393 context->ResetUsedTextures(); |
1378 break; | 1394 break; |
1379 case 4: | 1395 case 4: |
1380 // Number of textures used for commit should be two. One for the | 1396 // Number of textures used for commit should be one, for the |
1381 // content layer, and one for the painting scrollbar. The | 1397 // content layer. |
1382 // non-painting scrollbar doesn't update its texture. | 1398 EXPECT_EQ(1u, context->NumUsedTextures()); |
1383 EXPECT_EQ(2u, context->NumUsedTextures()); | |
1384 | 1399 |
1385 context->ResetUsedTextures(); | 1400 context->ResetUsedTextures(); |
1386 break; | 1401 break; |
1387 default: | 1402 default: |
1388 NOTREACHED(); | 1403 NOTREACHED(); |
1389 break; | 1404 break; |
1390 } | 1405 } |
1391 } | 1406 } |
1392 | 1407 |
1393 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1408 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
1394 EXPECT_LT(impl->active_tree()->source_frame_number(), 5); | 1409 EXPECT_LT(impl->active_tree()->source_frame_number(), 5); |
1395 | 1410 |
1396 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( | 1411 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
1397 impl->output_surface()->context3d()); | 1412 impl->output_surface()->context3d()); |
1398 | 1413 |
1399 // Number of textures used for drawing should one per layer except for | 1414 // Number of textures used for drawing should one per layer except for |
1400 // frame 3 where the viewport only contains one layer. | 1415 // frame 3 where the viewport only contains one layer. |
1401 if (impl->active_tree()->source_frame_number() == 3) { | 1416 if (impl->active_tree()->source_frame_number() == 3) { |
1402 EXPECT_EQ(1u, context->NumUsedTextures()); | 1417 EXPECT_EQ(1u, context->NumUsedTextures()); |
1403 } else { | 1418 } else { |
1404 EXPECT_EQ(4u, context->NumUsedTextures()) << | 1419 EXPECT_EQ(2u, context->NumUsedTextures()) << |
1405 "For frame " << impl->active_tree()->source_frame_number(); | 1420 "For frame " << impl->active_tree()->source_frame_number(); |
1406 } | 1421 } |
1407 | 1422 |
1408 context->ResetUsedTextures(); | 1423 context->ResetUsedTextures(); |
1409 } | 1424 } |
1410 | 1425 |
1411 virtual void AfterTest() OVERRIDE {} | 1426 virtual void AfterTest() OVERRIDE {} |
1412 | 1427 |
1413 private: | 1428 private: |
1414 FakeContentLayerClient client_; | 1429 FakeContentLayerClient client_; |
1415 scoped_refptr<FakeContentLayer> parent_; | 1430 scoped_refptr<FakeContentLayer> parent_; |
1416 scoped_refptr<FakeContentLayer> child_; | 1431 scoped_refptr<FakeContentLayer> child_; |
1417 scoped_refptr<FakeScrollbarLayer> scrollbar_with_paints_; | |
1418 scoped_refptr<FakeScrollbarLayer> scrollbar_without_paints_; | |
1419 }; | 1432 }; |
1420 | 1433 |
1421 // Partial updates are not possible with a delegating renderer. | 1434 // Partial updates are not possible with a delegating renderer. |
1422 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1435 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1423 LayerTreeHostTestAtomicCommitWithPartialUpdate); | 1436 LayerTreeHostTestAtomicCommitWithPartialUpdate); |
1424 | 1437 |
1425 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { | 1438 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { |
1426 public: | 1439 public: |
1427 LayerTreeHostTestFinishAllRendering() : once_(false), draw_count_(0) {} | 1440 LayerTreeHostTestFinishAllRendering() : once_(false), draw_count_(0) {} |
1428 | 1441 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 }; | 1941 }; |
1929 | 1942 |
1930 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); | 1943 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); |
1931 | 1944 |
1932 class LayerTreeHostWithProxy : public LayerTreeHost { | 1945 class LayerTreeHostWithProxy : public LayerTreeHost { |
1933 public: | 1946 public: |
1934 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, | 1947 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, |
1935 const LayerTreeSettings& settings, | 1948 const LayerTreeSettings& settings, |
1936 scoped_ptr<FakeProxy> proxy) | 1949 scoped_ptr<FakeProxy> proxy) |
1937 : LayerTreeHost(client, settings) { | 1950 : LayerTreeHost(client, settings) { |
1938 proxy->SetLayerTreeHost(this); | 1951 proxy->SetLayerTreeHost(this); |
1939 EXPECT_TRUE(InitializeForTesting(proxy.PassAs<Proxy>())); | 1952 EXPECT_TRUE(InitializeForTesting(proxy.PassAs<Proxy>())); |
1940 } | 1953 } |
1941 }; | 1954 }; |
1942 | 1955 |
1943 TEST(LayerTreeHostTest, LimitPartialUpdates) { | 1956 TEST(LayerTreeHostTest, LimitPartialUpdates) { |
1944 // When partial updates are not allowed, max updates should be 0. | 1957 // When partial updates are not allowed, max updates should be 0. |
1945 { | 1958 { |
1946 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 1959 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
1947 | 1960 |
1948 scoped_ptr<FakeProxy> proxy(new FakeProxy); | 1961 scoped_ptr<FakeProxy> proxy(new FakeProxy); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2365 virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE { | 2378 virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE { |
2366 if (name == GL_EXTENSIONS) { | 2379 if (name == GL_EXTENSIONS) { |
2367 return WebKit::WebString( | 2380 return WebKit::WebString( |
2368 "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle"); | 2381 "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle"); |
2369 } | 2382 } |
2370 return WebKit::WebString(); | 2383 return WebKit::WebString(); |
2371 } | 2384 } |
2372 | 2385 |
2373 MOCK_METHOD1(activeTexture, void(WebKit::WGC3Denum texture)); | 2386 MOCK_METHOD1(activeTexture, void(WebKit::WGC3Denum texture)); |
2374 MOCK_METHOD2(bindTexture, void(WebKit::WGC3Denum target, | 2387 MOCK_METHOD2(bindTexture, void(WebKit::WGC3Denum target, |
2375 WebKit::WebGLId texture_id)); | 2388 WebKit::WebGLId texture_id)); |
2376 MOCK_METHOD3(texParameteri, void(WebKit::WGC3Denum target, | 2389 MOCK_METHOD3(texParameteri, void(WebKit::WGC3Denum target, |
2377 WebKit::WGC3Denum pname, | 2390 WebKit::WGC3Denum pname, |
2378 WebKit::WGC3Dint param)); | 2391 WebKit::WGC3Dint param)); |
2379 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(WebKit::WGC3Denum target, | 2392 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(WebKit::WGC3Denum target, |
2380 WebKit::WGC3Dint width, | 2393 WebKit::WGC3Dint width, |
2381 WebKit::WGC3Dint height, | 2394 WebKit::WGC3Dint height, |
2382 WebKit::WGC3Duint ioSurfaceId, | 2395 WebKit::WGC3Duint ioSurfaceId, |
2383 WebKit::WGC3Duint plane)); | 2396 WebKit::WGC3Duint plane)); |
2384 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, | 2397 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, |
2385 WebKit::WGC3Dsizei count, | 2398 WebKit::WGC3Dsizei count, |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3186 private: | 3199 private: |
3187 FakeContentLayerClient client_; | 3200 FakeContentLayerClient client_; |
3188 scoped_refptr<FakePictureLayer> layer_; | 3201 scoped_refptr<FakePictureLayer> layer_; |
3189 bool did_initialize_gl_; | 3202 bool did_initialize_gl_; |
3190 bool did_release_gl_; | 3203 bool did_release_gl_; |
3191 int last_source_frame_number_drawn_; | 3204 int last_source_frame_number_drawn_; |
3192 }; | 3205 }; |
3193 | 3206 |
3194 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); | 3207 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); |
3195 | 3208 |
| 3209 // Test for UI Resource management. |
| 3210 class LayerTreeHostTestUIResource : public LayerTreeHostTest { |
| 3211 public: |
| 3212 LayerTreeHostTestUIResource() : num_ui_resources_(0), num_commits_(0) {} |
| 3213 |
| 3214 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 3215 |
| 3216 virtual void DidCommit() OVERRIDE { |
| 3217 int frame = num_commits_; |
| 3218 switch (frame) { |
| 3219 case 1: |
| 3220 CreateResource(); |
| 3221 CreateResource(); |
| 3222 PostSetNeedsCommitToMainThread(); |
| 3223 break; |
| 3224 case 2: |
| 3225 // Usually ScopedUIResource are deleted from the manager in their |
| 3226 // destructor. Here we just want to test that a direct call to |
| 3227 // DeleteUIResource works. |
| 3228 layer_tree_host()->DeleteUIResource(ui_resources_[0]->id()); |
| 3229 PostSetNeedsCommitToMainThread(); |
| 3230 break; |
| 3231 case 3: |
| 3232 // DeleteUIResource can be called with an invalid id. |
| 3233 layer_tree_host()->DeleteUIResource(ui_resources_[0]->id()); |
| 3234 PostSetNeedsCommitToMainThread(); |
| 3235 break; |
| 3236 case 4: |
| 3237 CreateResource(); |
| 3238 CreateResource(); |
| 3239 PostSetNeedsCommitToMainThread(); |
| 3240 break; |
| 3241 case 5: |
| 3242 ClearResources(); |
| 3243 EndTest(); |
| 3244 break; |
| 3245 } |
| 3246 } |
| 3247 |
| 3248 void PerformTest(LayerTreeHostImpl* impl) { |
| 3249 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 3250 impl->output_surface()->context3d()); |
| 3251 |
| 3252 int frame = num_commits_; |
| 3253 switch (frame) { |
| 3254 case 1: |
| 3255 ASSERT_EQ(0u, context->NumTextures()); |
| 3256 break; |
| 3257 case 2: |
| 3258 // Created two textures. |
| 3259 ASSERT_EQ(2u, context->NumTextures()); |
| 3260 break; |
| 3261 case 3: |
| 3262 // One texture left after one deletion. |
| 3263 ASSERT_EQ(1u, context->NumTextures()); |
| 3264 break; |
| 3265 case 4: |
| 3266 // Resource manager state should not change when delete is called on an |
| 3267 // invalid id. |
| 3268 ASSERT_EQ(1u, context->NumTextures()); |
| 3269 break; |
| 3270 case 5: |
| 3271 // Creation after deletion: two more creates should total up to |
| 3272 // three textures. |
| 3273 ASSERT_EQ(3u, context->NumTextures()); |
| 3274 break; |
| 3275 } |
| 3276 } |
| 3277 |
| 3278 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 3279 ++num_commits_; |
| 3280 if (!layer_tree_host()->settings().impl_side_painting) |
| 3281 PerformTest(impl); |
| 3282 } |
| 3283 |
| 3284 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 3285 if (layer_tree_host()->settings().impl_side_painting) |
| 3286 PerformTest(impl); |
| 3287 } |
| 3288 |
| 3289 virtual void AfterTest() OVERRIDE {} |
| 3290 |
| 3291 private: |
| 3292 // Must clear all resources before exiting. |
| 3293 void ClearResources() { |
| 3294 for (int i = 0; i < num_ui_resources_; i++) |
| 3295 ui_resources_[i].reset(); |
| 3296 } |
| 3297 |
| 3298 void CreateResource() { |
| 3299 ui_resources_[num_ui_resources_++] = |
| 3300 FakeScopedUIResource::Create(layer_tree_host()); |
| 3301 } |
| 3302 |
| 3303 scoped_ptr<FakeScopedUIResource> ui_resources_[5]; |
| 3304 int num_ui_resources_; |
| 3305 int num_commits_; |
| 3306 }; |
| 3307 |
| 3308 MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource); |
| 3309 |
3196 class PushPropertiesCountingLayer : public Layer { | 3310 class PushPropertiesCountingLayer : public Layer { |
3197 public: | 3311 public: |
3198 static scoped_refptr<PushPropertiesCountingLayer> Create() { | 3312 static scoped_refptr<PushPropertiesCountingLayer> Create() { |
3199 return new PushPropertiesCountingLayer(); | 3313 return new PushPropertiesCountingLayer(); |
3200 } | 3314 } |
3201 | 3315 |
3202 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE { | 3316 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE { |
3203 Layer::PushPropertiesTo(layer); | 3317 Layer::PushPropertiesTo(layer); |
3204 push_properties_count_++; | 3318 push_properties_count_++; |
3205 if (persist_needs_push_properties_) | 3319 if (persist_needs_push_properties_) |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3952 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) { | 4066 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) { |
3953 RunTest(true, false, true); | 4067 RunTest(true, false, true); |
3954 } | 4068 } |
3955 | 4069 |
3956 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) { | 4070 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) { |
3957 RunTest(true, true, true); | 4071 RunTest(true, true, true); |
3958 } | 4072 } |
3959 | 4073 |
3960 } // namespace | 4074 } // namespace |
3961 } // namespace cc | 4075 } // namespace cc |
OLD | NEW |