OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "cc/layers/content_layer.h" | 8 #include "cc/layers/content_layer.h" |
9 #include "cc/layers/delegated_frame_provider.h" | 9 #include "cc/layers/delegated_frame_provider.h" |
10 #include "cc/layers/delegated_frame_resource_collection.h" | 10 #include "cc/layers/delegated_frame_resource_collection.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 times_to_fail_recreate_(0), | 58 times_to_fail_recreate_(0), |
59 times_to_expect_create_failed_(0), | 59 times_to_expect_create_failed_(0), |
60 times_create_failed_(0), | 60 times_create_failed_(0), |
61 committed_at_least_once_(false), | 61 committed_at_least_once_(false), |
62 context_should_support_io_surface_(false), | 62 context_should_support_io_surface_(false), |
63 fallback_context_works_(false) { | 63 fallback_context_works_(false) { |
64 media::InitializeMediaLibraryForTesting(); | 64 media::InitializeMediaLibraryForTesting(); |
65 } | 65 } |
66 | 66 |
67 void LoseContext() { | 67 void LoseContext() { |
| 68 // For sanity-checking tests, they should only call this when the |
| 69 // context is not lost. |
| 70 CHECK(context3d_); |
68 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 71 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
69 GL_INNOCENT_CONTEXT_RESET_ARB); | 72 GL_INNOCENT_CONTEXT_RESET_ARB); |
70 context3d_ = NULL; | 73 context3d_ = NULL; |
71 } | 74 } |
72 | 75 |
73 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { | 76 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { |
74 return TestWebGraphicsContext3D::Create(); | 77 return TestWebGraphicsContext3D::Create(); |
75 } | 78 } |
76 | 79 |
77 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) | 80 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 EXPECT_TRUE(false); | 304 EXPECT_TRUE(false); |
302 return scoped_ptr<OutputSurface>(); | 305 return scoped_ptr<OutputSurface>(); |
303 } | 306 } |
304 | 307 |
305 virtual void DidInitializeOutputSurface() OVERRIDE { EXPECT_TRUE(false); } | 308 virtual void DidInitializeOutputSurface() OVERRIDE { EXPECT_TRUE(false); } |
306 | 309 |
307 virtual void AfterTest() OVERRIDE { | 310 virtual void AfterTest() OVERRIDE { |
308 } | 311 } |
309 }; | 312 }; |
310 | 313 |
311 MULTI_THREAD_TEST_F(LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); | 314 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 315 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); |
312 | 316 |
313 class LayerTreeHostContextTestLostContextSucceedsWithContent | 317 class LayerTreeHostContextTestLostContextSucceedsWithContent |
314 : public LayerTreeHostContextTestLostContextSucceeds { | 318 : public LayerTreeHostContextTestLostContextSucceeds { |
315 public: | 319 public: |
316 virtual void SetupTree() OVERRIDE { | 320 virtual void SetupTree() OVERRIDE { |
317 root_ = Layer::Create(); | 321 root_ = Layer::Create(); |
318 root_->SetBounds(gfx::Size(10, 10)); | 322 root_->SetBounds(gfx::Size(10, 10)); |
319 root_->SetIsDrawable(true); | 323 root_->SetIsDrawable(true); |
320 | 324 |
321 content_ = FakeContentLayer::Create(&client_); | 325 content_ = FakeContentLayer::Create(&client_); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 : public LayerTreeHostContextTest { | 363 : public LayerTreeHostContextTest { |
360 public: | 364 public: |
361 // Run a test that initially fails OutputSurface creation |times_to_fail| | 365 // Run a test that initially fails OutputSurface creation |times_to_fail| |
362 // times. If |expect_fallback_attempt| is |true|, an attempt to create a | 366 // times. If |expect_fallback_attempt| is |true|, an attempt to create a |
363 // fallback/software OutputSurface is expected to occur. | 367 // fallback/software OutputSurface is expected to occur. |
364 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, | 368 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, |
365 bool expect_fallback_attempt) | 369 bool expect_fallback_attempt) |
366 : times_to_fail_(times_to_fail), | 370 : times_to_fail_(times_to_fail), |
367 expect_fallback_attempt_(expect_fallback_attempt), | 371 expect_fallback_attempt_(expect_fallback_attempt), |
368 did_attempt_fallback_(false), | 372 did_attempt_fallback_(false), |
369 times_initialized_(0) {} | 373 times_initialized_(0) { |
| 374 times_to_fail_create_ = times_to_fail_; |
| 375 } |
370 | 376 |
371 virtual void BeginTest() OVERRIDE { | 377 virtual void BeginTest() OVERRIDE { |
372 times_to_fail_create_ = times_to_fail_; | |
373 PostSetNeedsCommitToMainThread(); | 378 PostSetNeedsCommitToMainThread(); |
374 } | 379 } |
375 | 380 |
376 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) | 381 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
377 OVERRIDE { | 382 OVERRIDE { |
378 scoped_ptr<FakeOutputSurface> surface = | 383 scoped_ptr<FakeOutputSurface> surface = |
379 LayerTreeHostContextTest::CreateFakeOutputSurface(fallback); | 384 LayerTreeHostContextTest::CreateFakeOutputSurface(fallback); |
380 | 385 |
381 if (surface) | 386 if (surface) |
382 EXPECT_EQ(times_to_fail_, times_create_failed_); | 387 EXPECT_EQ(times_to_fail_, times_create_failed_); |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 // backtrack). | 981 // backtrack). |
977 EXPECT_EQ(1, scrollbar_layer_->update_count()); | 982 EXPECT_EQ(1, scrollbar_layer_->update_count()); |
978 LoseContext(); | 983 LoseContext(); |
979 break; | 984 break; |
980 case 2: | 985 case 2: |
981 // Second update, after the lost context, we should still upload 2 | 986 // Second update, after the lost context, we should still upload 2 |
982 // resources even if the contents haven't changed. | 987 // resources even if the contents haven't changed. |
983 EXPECT_EQ(2, scrollbar_layer_->update_count()); | 988 EXPECT_EQ(2, scrollbar_layer_->update_count()); |
984 EndTest(); | 989 EndTest(); |
985 break; | 990 break; |
986 case 3: | |
987 // Single thread proxy issues extra commits after context lost. | |
988 // http://crbug.com/287250 | |
989 if (HasImplThread()) | |
990 NOTREACHED(); | |
991 break; | |
992 default: | 991 default: |
993 NOTREACHED(); | 992 NOTREACHED(); |
994 } | 993 } |
995 } | 994 } |
996 | 995 |
997 private: | 996 private: |
998 int commits_; | 997 int commits_; |
999 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; | 998 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; |
1000 }; | 999 }; |
1001 | 1000 |
(...skipping 23 matching lines...) Expand all Loading... |
1025 void PostStepCompleteToMainThread() { | 1024 void PostStepCompleteToMainThread() { |
1026 proxy()->MainThreadTaskRunner()->PostTask( | 1025 proxy()->MainThreadTaskRunner()->PostTask( |
1027 FROM_HERE, | 1026 FROM_HERE, |
1028 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, | 1027 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, |
1029 base::Unretained(this), | 1028 base::Unretained(this), |
1030 time_step_)); | 1029 time_step_)); |
1031 } | 1030 } |
1032 | 1031 |
1033 void PostLoseContextToImplThread() { | 1032 void PostLoseContextToImplThread() { |
1034 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 1033 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
1035 base::SingleThreadTaskRunner* task_runner = | 1034 ImplThreadTaskRunner()->PostTask( |
1036 HasImplThread() ? ImplThreadTaskRunner() | 1035 FROM_HERE, |
1037 : base::MessageLoopProxy::current(); | 1036 base::Bind(&LayerTreeHostContextTest::LoseContext, |
1038 task_runner->PostTask(FROM_HERE, | 1037 base::Unretained(this))); |
1039 base::Bind(&LayerTreeHostContextTest::LoseContext, | |
1040 base::Unretained(this))); | |
1041 } | 1038 } |
1042 | 1039 |
1043 protected: | 1040 protected: |
1044 int time_step_; | 1041 int time_step_; |
1045 scoped_ptr<FakeScopedUIResource> ui_resource_; | 1042 scoped_ptr<FakeScopedUIResource> ui_resource_; |
1046 | 1043 |
1047 private: | 1044 private: |
1048 void StepCompleteOnMainThreadInternal(int step) { | 1045 void StepCompleteOnMainThreadInternal(int step) { |
1049 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 1046 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
1050 StepCompleteOnMainThread(step); | 1047 StepCompleteOnMainThread(step); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 // Expects a valid UIResourceId. | 1082 // Expects a valid UIResourceId. |
1086 EXPECT_NE(0, ui_resource_->id()); | 1083 EXPECT_NE(0, ui_resource_->id()); |
1087 PostSetNeedsCommitToMainThread(); | 1084 PostSetNeedsCommitToMainThread(); |
1088 break; | 1085 break; |
1089 case 4: | 1086 case 4: |
1090 // Release resource before ending the test. | 1087 // Release resource before ending the test. |
1091 ui_resource_.reset(); | 1088 ui_resource_.reset(); |
1092 EndTest(); | 1089 EndTest(); |
1093 break; | 1090 break; |
1094 case 5: | 1091 case 5: |
1095 // Single thread proxy issues extra commits after context lost. | 1092 NOTREACHED(); |
1096 // http://crbug.com/287250 | |
1097 if (HasImplThread()) | |
1098 NOTREACHED(); | |
1099 break; | 1093 break; |
1100 case 6: | |
1101 NOTREACHED(); | |
1102 } | 1094 } |
1103 } | 1095 } |
1104 | 1096 |
1105 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { | 1097 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { |
1106 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1098 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1107 switch (time_step_) { | 1099 switch (time_step_) { |
1108 case 1: | 1100 case 1: |
1109 // The resource should have been created on LTHI after the commit. | 1101 // The resource should have been created on LTHI after the commit. |
1110 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1102 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
1111 PostSetNeedsCommitToMainThread(); | 1103 PostSetNeedsCommitToMainThread(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 layer_tree_host()->DeleteUIResource(test_id0_); | 1171 layer_tree_host()->DeleteUIResource(test_id0_); |
1180 // Delete the resouce and then lose the context. | 1172 // Delete the resouce and then lose the context. |
1181 PostLoseContextToImplThread(); | 1173 PostLoseContextToImplThread(); |
1182 break; | 1174 break; |
1183 case 5: | 1175 case 5: |
1184 // Release resource before ending the test. | 1176 // Release resource before ending the test. |
1185 ui_resource_.reset(); | 1177 ui_resource_.reset(); |
1186 EndTest(); | 1178 EndTest(); |
1187 break; | 1179 break; |
1188 case 6: | 1180 case 6: |
1189 // Single thread proxy issues extra commits after context lost. | 1181 NOTREACHED(); |
1190 // http://crbug.com/287250 | |
1191 if (HasImplThread()) | |
1192 NOTREACHED(); | |
1193 break; | 1182 break; |
1194 case 8: | |
1195 NOTREACHED(); | |
1196 } | 1183 } |
1197 } | 1184 } |
1198 | 1185 |
1199 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { | 1186 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { |
1200 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1187 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1201 switch (time_step_) { | 1188 switch (time_step_) { |
1202 case 1: | 1189 case 1: |
1203 // Sequence 1 (continued): | 1190 // Sequence 1 (continued): |
1204 // The first context lost happens before the resources were created, | 1191 // The first context lost happens before the resources were created, |
1205 // and because it resulted in no resources being destroyed, it does not | 1192 // and because it resulted in no resources being destroyed, it does not |
1206 // trigger resource re-creation. | 1193 // trigger resource re-creation. |
1207 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1194 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1208 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1195 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1209 // Resource Id on the impl-side has been created. | 1196 // Resource Id on the impl-side has been created. |
1210 PostSetNeedsCommitToMainThread(); | 1197 PostSetNeedsCommitToMainThread(); |
1211 break; | 1198 break; |
1212 case 3: | 1199 case 3: |
1213 // Sequence 2 (continued): | 1200 // Sequence 2 (continued): |
1214 // The previous resource should have been deleted. | 1201 // The previous resource should have been deleted. |
1215 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1202 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
1216 if (HasImplThread()) { | 1203 // The second resource should have been created. |
1217 // The second resource should have been created. | 1204 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); |
1218 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); | |
1219 } else { | |
1220 // The extra commit that happens at context lost in the single thread | |
1221 // proxy changes the timing so that the resource has been destroyed. | |
1222 // http://crbug.com/287250 | |
1223 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id1_)); | |
1224 } | |
1225 // The second resource called the resource callback once and since the | 1205 // The second resource called the resource callback once and since the |
1226 // context is lost, a "resource lost" callback was also issued. | 1206 // context is lost, a "resource lost" callback was also issued. |
1227 EXPECT_EQ(2, ui_resource_->resource_create_count); | 1207 EXPECT_EQ(2, ui_resource_->resource_create_count); |
1228 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1208 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
1229 break; | 1209 break; |
1230 case 5: | 1210 case 5: |
1231 // Sequence 3 (continued): | 1211 // Sequence 3 (continued): |
1232 // Expect the resource callback to have been called once. | 1212 // Expect the resource callback to have been called once. |
1233 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1213 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1234 // No "resource lost" callbacks. | 1214 // No "resource lost" callbacks. |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 EXPECT_FALSE(layer_tree_host()->output_surface_lost()); | 1510 EXPECT_FALSE(layer_tree_host()->output_surface_lost()); |
1531 } | 1511 } |
1532 | 1512 |
1533 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); } | 1513 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); } |
1534 | 1514 |
1535 virtual void AfterTest() OVERRIDE {} | 1515 virtual void AfterTest() OVERRIDE {} |
1536 | 1516 |
1537 bool deferred_; | 1517 bool deferred_; |
1538 }; | 1518 }; |
1539 | 1519 |
1540 // TODO(danakj): We don't use scheduler with SingleThreadProxy yet. | 1520 SINGLE_AND_MULTI_THREAD_TEST_F( |
1541 MULTI_THREAD_TEST_F(LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1521 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1542 | 1522 |
1543 } // namespace | 1523 } // namespace |
1544 } // namespace cc | 1524 } // namespace cc |
OLD | NEW |