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 17 matching lines...) Expand all Loading... |
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_scrollbar_layer.h" | 34 #include "cc/test/fake_scrollbar_layer.h" |
35 #include "cc/test/geometry_test_utils.h" | 35 #include "cc/test/geometry_test_utils.h" |
36 #include "cc/test/layer_tree_test.h" | 36 #include "cc/test/layer_tree_test.h" |
37 #include "cc/test/occlusion_tracker_test_common.h" | 37 #include "cc/test/occlusion_tracker_test_common.h" |
| 38 #include "cc/test/test_ui_resource_client.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" |
44 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
45 #include "third_party/khronos/GLES2/gl2.h" | 46 #include "third_party/khronos/GLES2/gl2.h" |
46 #include "third_party/khronos/GLES2/gl2ext.h" | 47 #include "third_party/khronos/GLES2/gl2ext.h" |
47 #include "third_party/skia/include/core/SkPicture.h" | 48 #include "third_party/skia/include/core/SkPicture.h" |
(...skipping 1052 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 doubled as the first textures |
1162 // are used by impl thread and cannot by used for update. | 1163 // are used by impl thread and cannot by used for update. |
1163 ASSERT_EQ(4u, context->NumTextures()); | 1164 ASSERT_EQ(3u, context->NumTextures()); |
1164 // Number of textures used for commit should still be | 1165 // Number of textures used for commit should still be |
1165 // one for each layer. | 1166 // one for each layer. |
1166 EXPECT_EQ(2u, context->NumUsedTextures()); | 1167 EXPECT_EQ(2u, context->NumUsedTextures()); |
1167 // First textures should not have been used. | 1168 // First textures should not have been used. |
1168 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); | 1169 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); |
1169 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); | 1170 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
1170 // New textures should have been used. | 1171 // New textures should have been used. |
1171 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); | 1172 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
1172 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | |
1173 | |
1174 context->ResetUsedTextures(); | 1173 context->ResetUsedTextures(); |
1175 PostSetNeedsCommitToMainThread(); | 1174 PostSetNeedsCommitToMainThread(); |
1176 break; | 1175 break; |
1177 case 2: | 1176 case 2: |
1178 EndTest(); | 1177 EndTest(); |
1179 break; | 1178 break; |
1180 default: | 1179 default: |
1181 NOTREACHED(); | 1180 NOTREACHED(); |
1182 break; | 1181 break; |
1183 } | 1182 } |
(...skipping 14 matching lines...) Expand all Loading... |
1198 context->ResetUsedTextures(); | 1197 context->ResetUsedTextures(); |
1199 } | 1198 } |
1200 | 1199 |
1201 virtual void Layout() OVERRIDE { | 1200 virtual void Layout() OVERRIDE { |
1202 layer_->SetNeedsDisplay(); | 1201 layer_->SetNeedsDisplay(); |
1203 scrollbar_->SetNeedsDisplay(); | 1202 scrollbar_->SetNeedsDisplay(); |
1204 } | 1203 } |
1205 | 1204 |
1206 virtual void AfterTest() OVERRIDE {} | 1205 virtual void AfterTest() OVERRIDE {} |
1207 | 1206 |
1208 private: | 1207 protected: |
1209 FakeContentLayerClient client_; | 1208 FakeContentLayerClient client_; |
1210 scoped_refptr<FakeContentLayer> layer_; | 1209 scoped_refptr<FakeContentLayer> layer_; |
1211 scoped_refptr<FakeScrollbarLayer> scrollbar_; | 1210 scoped_refptr<FakeScrollbarLayer> scrollbar_; |
1212 int drew_frame_; | 1211 int drew_frame_; |
1213 }; | 1212 }; |
1214 | 1213 |
1215 MULTI_THREAD_TEST_F(LayerTreeHostTestAtomicCommit); | 1214 MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1215 LayerTreeHostTestDirectRendererAtomicCommit); |
| 1216 |
| 1217 class LayerTreeHostTestDelegatingRendererAtomicCommit |
| 1218 : public LayerTreeHostTestDirectRendererAtomicCommit { |
| 1219 public: |
| 1220 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1221 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); |
| 1222 |
| 1223 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 1224 impl->output_surface()->context3d()); |
| 1225 |
| 1226 switch (impl->active_tree()->source_frame_number()) { |
| 1227 case 0: |
| 1228 // Number of textures should be one for each layer |
| 1229 ASSERT_EQ(2u, context->NumTextures()); |
| 1230 // Number of textures used for commit should be one for each layer. |
| 1231 EXPECT_EQ(2u, context->NumUsedTextures()); |
| 1232 // Verify that used texture is correct. |
| 1233 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); |
| 1234 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
| 1235 context->ResetUsedTextures(); |
| 1236 PostSetNeedsCommitToMainThread(); |
| 1237 break; |
| 1238 case 1: |
| 1239 // Number of textures should be doubled as the first textures |
| 1240 // are used by impl thread and cannot by used for update. |
| 1241 ASSERT_EQ(4u, context->NumTextures()); |
| 1242 // Number of textures used for commit should still be |
| 1243 // one for each layer. |
| 1244 EXPECT_EQ(2u, context->NumUsedTextures()); |
| 1245 // First textures should not have been used. |
| 1246 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); |
| 1247 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); |
| 1248 // New textures should have been used. |
| 1249 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
| 1250 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); |
| 1251 context->ResetUsedTextures(); |
| 1252 PostSetNeedsCommitToMainThread(); |
| 1253 break; |
| 1254 case 2: |
| 1255 EndTest(); |
| 1256 break; |
| 1257 default: |
| 1258 NOTREACHED(); |
| 1259 break; |
| 1260 } |
| 1261 } |
| 1262 }; |
| 1263 |
| 1264 MULTI_THREAD_DELEGATING_RENDERER_TEST_F( |
| 1265 LayerTreeHostTestDelegatingRendererAtomicCommit); |
1216 | 1266 |
1217 static void SetLayerPropertiesForTesting(Layer* layer, | 1267 static void SetLayerPropertiesForTesting(Layer* layer, |
1218 Layer* parent, | 1268 Layer* parent, |
1219 const gfx::Transform& transform, | 1269 const gfx::Transform& transform, |
1220 gfx::PointF anchor, | 1270 gfx::PointF anchor, |
1221 gfx::PointF position, | 1271 gfx::PointF position, |
1222 gfx::Size bounds, | 1272 gfx::Size bounds, |
1223 bool opaque) { | 1273 bool opaque) { |
1224 layer->RemoveAllChildren(); | 1274 layer->RemoveAllChildren(); |
1225 if (parent) | 1275 if (parent) |
1226 parent->AddChild(layer); | 1276 parent->AddChild(layer); |
1227 layer->SetTransform(transform); | 1277 layer->SetTransform(transform); |
1228 layer->SetAnchorPoint(anchor); | 1278 layer->SetAnchorPoint(anchor); |
1229 layer->SetPosition(position); | 1279 layer->SetPosition(position); |
1230 layer->SetBounds(bounds); | 1280 layer->SetBounds(bounds); |
1231 layer->SetContentsOpaque(opaque); | 1281 layer->SetContentsOpaque(opaque); |
1232 } | 1282 } |
1233 | 1283 |
1234 class LayerTreeHostTestAtomicCommitWithPartialUpdate | 1284 class LayerTreeHostTestAtomicCommitWithPartialUpdate |
1235 : public LayerTreeHostTest { | 1285 : public LayerTreeHostTest { |
1236 public: | 1286 public: |
1237 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1287 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
1238 // Allow one partial texture update. | 1288 // Allow one partial texture update. |
1239 settings->max_partial_texture_updates = 1; | 1289 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. | 1290 // No partial updates when impl side painting is enabled. |
1243 settings->impl_side_painting = false; | 1291 settings->impl_side_painting = false; |
1244 } | 1292 } |
1245 | 1293 |
1246 virtual void SetupTree() OVERRIDE { | 1294 virtual void SetupTree() OVERRIDE { |
1247 parent_ = FakeContentLayer::Create(&client_); | 1295 parent_ = FakeContentLayer::Create(&client_); |
1248 parent_->SetBounds(gfx::Size(10, 20)); | 1296 parent_->SetBounds(gfx::Size(10, 20)); |
1249 | 1297 |
1250 child_ = FakeContentLayer::Create(&client_); | 1298 child_ = FakeContentLayer::Create(&client_); |
1251 child_->SetPosition(gfx::Point(0, 10)); | 1299 child_->SetPosition(gfx::Point(0, 10)); |
1252 child_->SetBounds(gfx::Size(3, 10)); | 1300 child_->SetBounds(gfx::Size(3, 10)); |
1253 | 1301 |
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_); | 1302 parent_->AddChild(child_); |
1268 parent_->AddChild(scrollbar_with_paints_); | |
1269 parent_->AddChild(scrollbar_without_paints_); | |
1270 | 1303 |
1271 layer_tree_host()->SetRootLayer(parent_); | 1304 layer_tree_host()->SetRootLayer(parent_); |
1272 LayerTreeHostTest::SetupTree(); | 1305 LayerTreeHostTest::SetupTree(); |
1273 } | 1306 } |
1274 | 1307 |
1275 virtual void BeginTest() OVERRIDE { | 1308 virtual void BeginTest() OVERRIDE { |
1276 PostSetNeedsCommitToMainThread(); | 1309 PostSetNeedsCommitToMainThread(); |
1277 } | 1310 } |
1278 | 1311 |
1279 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1312 virtual void DidCommitAndDrawFrame() OVERRIDE { |
1280 switch (layer_tree_host()->commit_number()) { | 1313 switch (layer_tree_host()->commit_number()) { |
1281 case 1: | 1314 case 1: |
1282 parent_->SetNeedsDisplay(); | 1315 parent_->SetNeedsDisplay(); |
1283 child_->SetNeedsDisplay(); | 1316 child_->SetNeedsDisplay(); |
1284 scrollbar_with_paints_->SetNeedsDisplay(); | |
1285 scrollbar_without_paints_->SetNeedsDisplay(); | |
1286 break; | 1317 break; |
1287 case 2: | 1318 case 2: |
1288 // Damage part of layers. | 1319 // Damage part of layers. |
1289 parent_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); | 1320 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)); | 1321 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; | 1322 break; |
1296 case 3: | 1323 case 3: |
1297 child_->SetNeedsDisplay(); | 1324 child_->SetNeedsDisplay(); |
1298 scrollbar_with_paints_->SetNeedsDisplay(); | |
1299 scrollbar_without_paints_->SetNeedsDisplay(); | |
1300 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); | 1325 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); |
1301 break; | 1326 break; |
1302 case 4: | 1327 case 4: |
1303 layer_tree_host()->SetViewportSize(gfx::Size(10, 20)); | 1328 layer_tree_host()->SetViewportSize(gfx::Size(10, 20)); |
1304 break; | 1329 break; |
1305 case 5: | 1330 case 5: |
1306 EndTest(); | 1331 EndTest(); |
1307 break; | 1332 break; |
1308 default: | 1333 default: |
1309 NOTREACHED() << layer_tree_host()->commit_number(); | 1334 NOTREACHED() << layer_tree_host()->commit_number(); |
1310 break; | 1335 break; |
1311 } | 1336 } |
1312 } | 1337 } |
1313 | 1338 |
1314 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1339 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
1315 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); | 1340 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); |
1316 | 1341 |
1317 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( | 1342 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
1318 impl->output_surface()->context3d()); | 1343 impl->output_surface()->context3d()); |
1319 | 1344 |
1320 switch (impl->active_tree()->source_frame_number()) { | 1345 switch (impl->active_tree()->source_frame_number()) { |
1321 case 0: | 1346 case 0: |
1322 // Number of textures should be one for each layer. | 1347 // Number of textures should be one for each layer. |
1323 ASSERT_EQ(4u, context->NumTextures()); | 1348 ASSERT_EQ(2u, context->NumTextures()); |
1324 // Number of textures used for commit should be one for each layer. | 1349 // Number of textures used for commit should be one for each layer. |
1325 EXPECT_EQ(4u, context->NumUsedTextures()); | 1350 EXPECT_EQ(2u, context->NumUsedTextures()); |
1326 // Verify that used textures are correct. | 1351 // Verify that used textures are correct. |
1327 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); | 1352 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); |
1328 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); | 1353 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
| 1354 context->ResetUsedTextures(); |
| 1355 break; |
| 1356 case 1: |
| 1357 // Number of textures should be two for each content layer. |
| 1358 ASSERT_EQ(4u, context->NumTextures()); |
| 1359 // Number of textures used for commit should be one for each content |
| 1360 // layer. |
| 1361 EXPECT_EQ(2u, context->NumUsedTextures()); |
| 1362 |
| 1363 // First content textures should not have been used. |
| 1364 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); |
| 1365 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); |
| 1366 // New textures should have been used. |
1329 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); | 1367 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
1330 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | 1368 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); |
1331 | 1369 |
1332 context->ResetUsedTextures(); | 1370 context->ResetUsedTextures(); |
1333 break; | 1371 break; |
1334 case 1: | 1372 case 2: |
1335 // Number of textures should be two for each content layer and one | 1373 // Number of textures should be two for each content layer. |
1336 // for each scrollbar, since they always do a partial update. | 1374 ASSERT_EQ(4u, context->NumTextures()); |
1337 ASSERT_EQ(6u, context->NumTextures()); | |
1338 // Number of textures used for commit should be one for each content | 1375 // Number of textures used for commit should be one for each content |
1339 // layer, and one for the scrollbar layer that paints. | 1376 // layer. |
1340 EXPECT_EQ(3u, context->NumUsedTextures()); | 1377 EXPECT_EQ(2u, context->NumUsedTextures()); |
1341 | 1378 |
1342 // First content textures should not have been used. | 1379 // One content layer does a partial update also. |
1343 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); | 1380 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
1344 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); | 1381 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 | 1382 |
1353 context->ResetUsedTextures(); | 1383 context->ResetUsedTextures(); |
1354 break; | 1384 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: | 1385 case 3: |
1374 // No textures should be used for commit. | 1386 // No textures should be used for commit. |
1375 EXPECT_EQ(0u, context->NumUsedTextures()); | 1387 EXPECT_EQ(0u, context->NumUsedTextures()); |
1376 | 1388 |
1377 context->ResetUsedTextures(); | 1389 context->ResetUsedTextures(); |
1378 break; | 1390 break; |
1379 case 4: | 1391 case 4: |
1380 // Number of textures used for commit should be two. One for the | 1392 // Number of textures used for commit should be one, for the |
1381 // content layer, and one for the painting scrollbar. The | 1393 // content layer. |
1382 // non-painting scrollbar doesn't update its texture. | 1394 EXPECT_EQ(1u, context->NumUsedTextures()); |
1383 EXPECT_EQ(2u, context->NumUsedTextures()); | |
1384 | 1395 |
1385 context->ResetUsedTextures(); | 1396 context->ResetUsedTextures(); |
1386 break; | 1397 break; |
1387 default: | 1398 default: |
1388 NOTREACHED(); | 1399 NOTREACHED(); |
1389 break; | 1400 break; |
1390 } | 1401 } |
1391 } | 1402 } |
1392 | 1403 |
1393 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1404 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
1394 EXPECT_LT(impl->active_tree()->source_frame_number(), 5); | 1405 EXPECT_LT(impl->active_tree()->source_frame_number(), 5); |
1395 | 1406 |
1396 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( | 1407 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
1397 impl->output_surface()->context3d()); | 1408 impl->output_surface()->context3d()); |
1398 | 1409 |
1399 // Number of textures used for drawing should one per layer except for | 1410 // Number of textures used for drawing should one per layer except for |
1400 // frame 3 where the viewport only contains one layer. | 1411 // frame 3 where the viewport only contains one layer. |
1401 if (impl->active_tree()->source_frame_number() == 3) { | 1412 if (impl->active_tree()->source_frame_number() == 3) { |
1402 EXPECT_EQ(1u, context->NumUsedTextures()); | 1413 EXPECT_EQ(1u, context->NumUsedTextures()); |
1403 } else { | 1414 } else { |
1404 EXPECT_EQ(4u, context->NumUsedTextures()) << | 1415 EXPECT_EQ(2u, context->NumUsedTextures()) << |
1405 "For frame " << impl->active_tree()->source_frame_number(); | 1416 "For frame " << impl->active_tree()->source_frame_number(); |
1406 } | 1417 } |
1407 | 1418 |
1408 context->ResetUsedTextures(); | 1419 context->ResetUsedTextures(); |
1409 } | 1420 } |
1410 | 1421 |
1411 virtual void AfterTest() OVERRIDE {} | 1422 virtual void AfterTest() OVERRIDE {} |
1412 | 1423 |
1413 private: | 1424 private: |
1414 FakeContentLayerClient client_; | 1425 FakeContentLayerClient client_; |
1415 scoped_refptr<FakeContentLayer> parent_; | 1426 scoped_refptr<FakeContentLayer> parent_; |
1416 scoped_refptr<FakeContentLayer> child_; | 1427 scoped_refptr<FakeContentLayer> child_; |
1417 scoped_refptr<FakeScrollbarLayer> scrollbar_with_paints_; | |
1418 scoped_refptr<FakeScrollbarLayer> scrollbar_without_paints_; | |
1419 }; | 1428 }; |
1420 | 1429 |
1421 // Partial updates are not possible with a delegating renderer. | 1430 // Partial updates are not possible with a delegating renderer. |
1422 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1431 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1423 LayerTreeHostTestAtomicCommitWithPartialUpdate); | 1432 LayerTreeHostTestAtomicCommitWithPartialUpdate); |
1424 | 1433 |
1425 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { | 1434 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { |
1426 public: | 1435 public: |
1427 LayerTreeHostTestFinishAllRendering() : once_(false), draw_count_(0) {} | 1436 LayerTreeHostTestFinishAllRendering() : once_(false), draw_count_(0) {} |
1428 | 1437 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 }; | 1937 }; |
1929 | 1938 |
1930 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); | 1939 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); |
1931 | 1940 |
1932 class LayerTreeHostWithProxy : public LayerTreeHost { | 1941 class LayerTreeHostWithProxy : public LayerTreeHost { |
1933 public: | 1942 public: |
1934 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, | 1943 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, |
1935 const LayerTreeSettings& settings, | 1944 const LayerTreeSettings& settings, |
1936 scoped_ptr<FakeProxy> proxy) | 1945 scoped_ptr<FakeProxy> proxy) |
1937 : LayerTreeHost(client, settings) { | 1946 : LayerTreeHost(client, settings) { |
1938 proxy->SetLayerTreeHost(this); | 1947 proxy->SetLayerTreeHost(this); |
1939 EXPECT_TRUE(InitializeForTesting(proxy.PassAs<Proxy>())); | 1948 EXPECT_TRUE(InitializeForTesting(proxy.PassAs<Proxy>())); |
1940 } | 1949 } |
1941 }; | 1950 }; |
1942 | 1951 |
1943 TEST(LayerTreeHostTest, LimitPartialUpdates) { | 1952 TEST(LayerTreeHostTest, LimitPartialUpdates) { |
1944 // When partial updates are not allowed, max updates should be 0. | 1953 // When partial updates are not allowed, max updates should be 0. |
1945 { | 1954 { |
1946 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 1955 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
1947 | 1956 |
1948 scoped_ptr<FakeProxy> proxy(new FakeProxy); | 1957 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 { | 2374 virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE { |
2366 if (name == GL_EXTENSIONS) { | 2375 if (name == GL_EXTENSIONS) { |
2367 return WebKit::WebString( | 2376 return WebKit::WebString( |
2368 "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle"); | 2377 "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle"); |
2369 } | 2378 } |
2370 return WebKit::WebString(); | 2379 return WebKit::WebString(); |
2371 } | 2380 } |
2372 | 2381 |
2373 MOCK_METHOD1(activeTexture, void(WebKit::WGC3Denum texture)); | 2382 MOCK_METHOD1(activeTexture, void(WebKit::WGC3Denum texture)); |
2374 MOCK_METHOD2(bindTexture, void(WebKit::WGC3Denum target, | 2383 MOCK_METHOD2(bindTexture, void(WebKit::WGC3Denum target, |
2375 WebKit::WebGLId texture_id)); | 2384 WebKit::WebGLId texture_id)); |
2376 MOCK_METHOD3(texParameteri, void(WebKit::WGC3Denum target, | 2385 MOCK_METHOD3(texParameteri, void(WebKit::WGC3Denum target, |
2377 WebKit::WGC3Denum pname, | 2386 WebKit::WGC3Denum pname, |
2378 WebKit::WGC3Dint param)); | 2387 WebKit::WGC3Dint param)); |
2379 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(WebKit::WGC3Denum target, | 2388 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(WebKit::WGC3Denum target, |
2380 WebKit::WGC3Dint width, | 2389 WebKit::WGC3Dint width, |
2381 WebKit::WGC3Dint height, | 2390 WebKit::WGC3Dint height, |
2382 WebKit::WGC3Duint ioSurfaceId, | 2391 WebKit::WGC3Duint ioSurfaceId, |
2383 WebKit::WGC3Duint plane)); | 2392 WebKit::WGC3Duint plane)); |
2384 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, | 2393 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, |
2385 WebKit::WGC3Dsizei count, | 2394 WebKit::WGC3Dsizei count, |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3183 private: | 3192 private: |
3184 FakeContentLayerClient client_; | 3193 FakeContentLayerClient client_; |
3185 scoped_refptr<FakePictureLayer> layer_; | 3194 scoped_refptr<FakePictureLayer> layer_; |
3186 bool did_initialize_gl_; | 3195 bool did_initialize_gl_; |
3187 bool did_release_gl_; | 3196 bool did_release_gl_; |
3188 int last_source_frame_number_drawn_; | 3197 int last_source_frame_number_drawn_; |
3189 }; | 3198 }; |
3190 | 3199 |
3191 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); | 3200 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); |
3192 | 3201 |
| 3202 // Test for UI Resource management. |
| 3203 class LayerTreeHostTestUIResource : public LayerTreeHostTest { |
| 3204 public: |
| 3205 virtual void BeginTest() OVERRIDE { |
| 3206 ui_resource_client_ = new TestUIResourceClient(); |
| 3207 PostSetNeedsCommitToMainThread(); |
| 3208 } |
| 3209 |
| 3210 virtual void DidCommit() OVERRIDE { |
| 3211 int frame = layer_tree_host()->commit_number(); |
| 3212 switch (frame) { |
| 3213 case 1: |
| 3214 ui_resource_id_ = layer_tree_host()->CreateUIResource(base::Bind( |
| 3215 &TestUIResourceClient::GetBitmap, ui_resource_client_.get())); |
| 3216 layer_tree_host()->CreateUIResource(base::Bind( |
| 3217 &TestUIResourceClient::GetBitmap, ui_resource_client_.get())); |
| 3218 PostSetNeedsCommitToMainThread(); |
| 3219 break; |
| 3220 case 2: |
| 3221 layer_tree_host()->DeleteUIResource(ui_resource_id_); |
| 3222 PostSetNeedsCommitToMainThread(); |
| 3223 break; |
| 3224 case 3: |
| 3225 layer_tree_host()->DeleteUIResource(ui_resource_id_); |
| 3226 PostSetNeedsCommitToMainThread(); |
| 3227 break; |
| 3228 case 4: |
| 3229 layer_tree_host()->CreateUIResource(base::Bind( |
| 3230 &TestUIResourceClient::GetBitmap, ui_resource_client_.get())); |
| 3231 layer_tree_host()->CreateUIResource(base::Bind( |
| 3232 &TestUIResourceClient::GetBitmap, ui_resource_client_.get())); |
| 3233 PostSetNeedsCommitToMainThread(); |
| 3234 break; |
| 3235 case 5: |
| 3236 EndTest(); |
| 3237 break; |
| 3238 } |
| 3239 } |
| 3240 |
| 3241 void PerformTest(LayerTreeHostImpl* impl) { |
| 3242 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 3243 impl->output_surface()->context3d()); |
| 3244 |
| 3245 int frame = layer_tree_host()->commit_number(); |
| 3246 switch (frame) { |
| 3247 case 1: |
| 3248 ASSERT_EQ(0u, context->NumTextures()); |
| 3249 break; |
| 3250 case 2: |
| 3251 // Created two textures. |
| 3252 ASSERT_EQ(2u, context->NumTextures()); |
| 3253 break; |
| 3254 case 3: |
| 3255 // One texture left after one deletion. |
| 3256 ASSERT_EQ(1u, context->NumTextures()); |
| 3257 break; |
| 3258 case 4: |
| 3259 // Texture state should not change when delete is called on an |
| 3260 // invalid id. |
| 3261 ASSERT_EQ(1u, context->NumTextures()); |
| 3262 break; |
| 3263 case 5: |
| 3264 // Creation after deletion: two more creates should total up to |
| 3265 // three textures. |
| 3266 ASSERT_EQ(3u, context->NumTextures()); |
| 3267 break; |
| 3268 } |
| 3269 } |
| 3270 |
| 3271 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 3272 if (!layer_tree_host()->settings().impl_side_painting) |
| 3273 PerformTest(impl); |
| 3274 } |
| 3275 |
| 3276 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 3277 if (layer_tree_host()->settings().impl_side_painting) |
| 3278 PerformTest(impl); |
| 3279 } |
| 3280 |
| 3281 virtual void AfterTest() {} |
| 3282 |
| 3283 private: |
| 3284 scoped_refptr<TestUIResourceClient> ui_resource_client_; |
| 3285 UIResourceId ui_resource_id_; |
| 3286 }; |
| 3287 |
| 3288 MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource); |
| 3289 |
3193 class PushPropertiesCountingLayer : public Layer { | 3290 class PushPropertiesCountingLayer : public Layer { |
3194 public: | 3291 public: |
3195 static scoped_refptr<PushPropertiesCountingLayer> Create() { | 3292 static scoped_refptr<PushPropertiesCountingLayer> Create() { |
3196 return new PushPropertiesCountingLayer(); | 3293 return new PushPropertiesCountingLayer(); |
3197 } | 3294 } |
3198 | 3295 |
3199 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE { | 3296 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE { |
3200 Layer::PushPropertiesTo(layer); | 3297 Layer::PushPropertiesTo(layer); |
3201 push_properties_count_++; | 3298 push_properties_count_++; |
3202 if (persist_needs_push_properties_) | 3299 if (persist_needs_push_properties_) |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3965 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) { | 4062 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) { |
3966 RunTest(true, false, true); | 4063 RunTest(true, false, true); |
3967 } | 4064 } |
3968 | 4065 |
3969 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) { | 4066 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) { |
3970 RunTest(true, true, true); | 4067 RunTest(true, true, true); |
3971 } | 4068 } |
3972 | 4069 |
3973 } // namespace | 4070 } // namespace |
3974 } // namespace cc | 4071 } // namespace cc |
OLD | NEW |