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