Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: cc/trees/layer_tree_host_unittest_context.cc

Issue 134623005: Make SingleThreadProxy a SchedulerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: impl_task_runner => task_runner Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 68 // For sanity-checking tests, they should only call this when the
69 GL_INNOCENT_CONTEXT_RESET_ARB); 69 // context is not lost.
70 CHECK(context3d_);
71
72 // Set the context3d_ member to null *before* calling lose context,
73 // as the single-threaded proxy may synchronously recreate the
74 // output surface, setting context3d_ back to not-NULL.
75 TestWebGraphicsContext3D* temp_context3d = context3d_;
70 context3d_ = NULL; 76 context3d_ = NULL;
77 temp_context3d->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
78 GL_INNOCENT_CONTEXT_RESET_ARB);
71 } 79 }
72 80
73 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { 81 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() {
74 return TestWebGraphicsContext3D::Create(); 82 return TestWebGraphicsContext3D::Create();
75 } 83 }
76 84
77 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 85 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback)
78 OVERRIDE { 86 OVERRIDE {
79 if (times_to_fail_create_) { 87 if (times_to_fail_create_) {
80 --times_to_fail_create_; 88 --times_to_fail_create_;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 virtual void InvalidateAndSetNeedsCommit() { 201 virtual void InvalidateAndSetNeedsCommit() {
194 // Cause damage so we try to draw. 202 // Cause damage so we try to draw.
195 layer_tree_host()->root_layer()->SetNeedsDisplay(); 203 layer_tree_host()->root_layer()->SetNeedsDisplay();
196 layer_tree_host()->SetNeedsCommit(); 204 layer_tree_host()->SetNeedsCommit();
197 } 205 }
198 206
199 bool NextTestCase() { 207 bool NextTestCase() {
200 static const TestCase kTests[] = { 208 static const TestCase kTests[] = {
201 // Losing the context and failing to recreate it (or losing it again 209 // Losing the context and failing to recreate it (or losing it again
202 // immediately) a small number of times should succeed. 210 // immediately) a small number of times should succeed.
203 {1, // times_to_lose_during_commit 211 {
212 1, // times_to_lose_during_commit
204 0, // times_to_lose_during_draw 213 0, // times_to_lose_during_draw
205 0, // times_to_fail_recreate 214 0, // times_to_fail_recreate
206 false, // fallback_context_works 215 false, // fallback_context_works
207 }, 216 },
208 {0, // times_to_lose_during_commit 217 {
218 0, // times_to_lose_during_commit
209 1, // times_to_lose_during_draw 219 1, // times_to_lose_during_draw
210 0, // times_to_fail_recreate 220 0, // times_to_fail_recreate
211 false, // fallback_context_works 221 false, // fallback_context_works
212 }, 222 },
213 {1, // times_to_lose_during_commit 223 {
224 1, // times_to_lose_during_commit
214 0, // times_to_lose_during_draw 225 0, // times_to_lose_during_draw
215 3, // times_to_fail_recreate 226 3, // times_to_fail_recreate
216 false, // fallback_context_works 227 false, // fallback_context_works
217 }, 228 },
218 {0, // times_to_lose_during_commit 229 {
230 0, // times_to_lose_during_commit
219 1, // times_to_lose_during_draw 231 1, // times_to_lose_during_draw
220 3, // times_to_fail_recreate 232 3, // times_to_fail_recreate
221 false, // fallback_context_works 233 false, // fallback_context_works
222 }, 234 },
223 // Losing the context and recreating it any number of times should 235 // Losing the context and recreating it any number of times should
224 // succeed. 236 // succeed.
225 {10, // times_to_lose_during_commit 237 {
238 10, // times_to_lose_during_commit
226 0, // times_to_lose_during_draw 239 0, // times_to_lose_during_draw
227 0, // times_to_fail_recreate 240 0, // times_to_fail_recreate
228 false, // fallback_context_works 241 false, // fallback_context_works
229 }, 242 },
230 {0, // times_to_lose_during_commit 243 {
244 0, // times_to_lose_during_commit
231 10, // times_to_lose_during_draw 245 10, // times_to_lose_during_draw
232 0, // times_to_fail_recreate 246 0, // times_to_fail_recreate
233 false, // fallback_context_works 247 false, // fallback_context_works
234 }, 248 },
235 // Losing the context, failing to reinitialize it, and making a fallback 249 // Losing the context, failing to reinitialize it, and making a fallback
236 // context should work. 250 // context should work.
237 {0, // times_to_lose_during_commit 251 {
252 0, // times_to_lose_during_commit
238 1, // times_to_lose_during_draw 253 1, // times_to_lose_during_draw
239 0, // times_to_fail_recreate 254 0, // times_to_fail_recreate
240 true, // fallback_context_works 255 true, // fallback_context_works
241 }, }; 256 },
257 };
242 258
243 if (test_case_ >= arraysize(kTests)) 259 if (test_case_ >= arraysize(kTests))
244 return false; 260 return false;
245 // Make sure that we lost our context at least once in the last test run so 261 // Make sure that we lost our context at least once in the last test run so
246 // the test did something. 262 // the test did something.
247 EXPECT_GT(num_losses_, num_losses_last_test_case_); 263 EXPECT_GT(num_losses_, num_losses_last_test_case_);
248 num_losses_last_test_case_ = num_losses_; 264 num_losses_last_test_case_ = num_losses_;
249 265
250 times_to_lose_during_commit_ = 266 times_to_lose_during_commit_ =
251 kTests[test_case_].times_to_lose_during_commit; 267 kTests[test_case_].times_to_lose_during_commit;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 EXPECT_TRUE(false); 309 EXPECT_TRUE(false);
294 return scoped_ptr<OutputSurface>(); 310 return scoped_ptr<OutputSurface>();
295 } 311 }
296 312
297 virtual void DidInitializeOutputSurface() OVERRIDE { EXPECT_TRUE(false); } 313 virtual void DidInitializeOutputSurface() OVERRIDE { EXPECT_TRUE(false); }
298 314
299 virtual void AfterTest() OVERRIDE { 315 virtual void AfterTest() OVERRIDE {
300 } 316 }
301 }; 317 };
302 318
303 MULTI_THREAD_TEST_F(LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); 319 SINGLE_AND_MULTI_THREAD_TEST_F(
320 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface);
304 321
305 class LayerTreeHostContextTestLostContextSucceedsWithContent 322 class LayerTreeHostContextTestLostContextSucceedsWithContent
306 : public LayerTreeHostContextTestLostContextSucceeds { 323 : public LayerTreeHostContextTestLostContextSucceeds {
307 public: 324 public:
308 virtual void SetupTree() OVERRIDE { 325 virtual void SetupTree() OVERRIDE {
309 root_ = Layer::Create(); 326 root_ = Layer::Create();
310 root_->SetBounds(gfx::Size(10, 10)); 327 root_->SetBounds(gfx::Size(10, 10));
311 root_->SetIsDrawable(true); 328 root_->SetIsDrawable(true);
312 329
313 content_ = FakeContentLayer::Create(&client_); 330 content_ = FakeContentLayer::Create(&client_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 : public LayerTreeHostContextTest { 368 : public LayerTreeHostContextTest {
352 public: 369 public:
353 // Run a test that initially fails OutputSurface creation |times_to_fail| 370 // Run a test that initially fails OutputSurface creation |times_to_fail|
354 // times. If |expect_fallback_attempt| is |true|, an attempt to create a 371 // times. If |expect_fallback_attempt| is |true|, an attempt to create a
355 // fallback/software OutputSurface is expected to occur. 372 // fallback/software OutputSurface is expected to occur.
356 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, 373 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail,
357 bool expect_fallback_attempt) 374 bool expect_fallback_attempt)
358 : times_to_fail_(times_to_fail), 375 : times_to_fail_(times_to_fail),
359 expect_fallback_attempt_(expect_fallback_attempt), 376 expect_fallback_attempt_(expect_fallback_attempt),
360 did_attempt_fallback_(false), 377 did_attempt_fallback_(false),
361 times_initialized_(0) {} 378 times_initialized_(0) {
379 times_to_fail_create_ = times_to_fail_;
380 }
362 381
363 virtual void BeginTest() OVERRIDE { 382 virtual void BeginTest() OVERRIDE {
364 times_to_fail_create_ = times_to_fail_;
365 PostSetNeedsCommitToMainThread(); 383 PostSetNeedsCommitToMainThread();
366 } 384 }
367 385
368 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 386 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback)
369 OVERRIDE { 387 OVERRIDE {
370 scoped_ptr<FakeOutputSurface> surface = 388 scoped_ptr<FakeOutputSurface> surface =
371 LayerTreeHostContextTest::CreateFakeOutputSurface(fallback); 389 LayerTreeHostContextTest::CreateFakeOutputSurface(fallback);
372 390
373 if (surface) 391 if (surface)
374 EXPECT_EQ(times_to_fail_, times_create_failed_); 392 EXPECT_EQ(times_to_fail_, times_create_failed_);
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 // backtrack). 986 // backtrack).
969 EXPECT_EQ(1, scrollbar_layer_->update_count()); 987 EXPECT_EQ(1, scrollbar_layer_->update_count());
970 LoseContext(); 988 LoseContext();
971 break; 989 break;
972 case 2: 990 case 2:
973 // Second update, after the lost context, we should still upload 2 991 // Second update, after the lost context, we should still upload 2
974 // resources even if the contents haven't changed. 992 // resources even if the contents haven't changed.
975 EXPECT_EQ(2, scrollbar_layer_->update_count()); 993 EXPECT_EQ(2, scrollbar_layer_->update_count());
976 EndTest(); 994 EndTest();
977 break; 995 break;
978 case 3:
979 // Single thread proxy issues extra commits after context lost.
980 // http://crbug.com/287250
981 if (HasImplThread())
982 NOTREACHED();
983 break;
984 default: 996 default:
985 NOTREACHED(); 997 NOTREACHED();
986 } 998 }
987 } 999 }
988 1000
989 private: 1001 private:
990 int commits_; 1002 int commits_;
991 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; 1003 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_;
992 }; 1004 };
993 1005
(...skipping 23 matching lines...) Expand all
1017 void PostStepCompleteToMainThread() { 1029 void PostStepCompleteToMainThread() {
1018 proxy()->MainThreadTaskRunner()->PostTask( 1030 proxy()->MainThreadTaskRunner()->PostTask(
1019 FROM_HERE, 1031 FROM_HERE,
1020 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, 1032 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal,
1021 base::Unretained(this), 1033 base::Unretained(this),
1022 time_step_)); 1034 time_step_));
1023 } 1035 }
1024 1036
1025 void PostLoseContextToImplThread() { 1037 void PostLoseContextToImplThread() {
1026 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); 1038 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
1027 base::SingleThreadTaskRunner* task_runner = 1039 ImplThreadTaskRunner()->PostTask(
1028 HasImplThread() ? ImplThreadTaskRunner() 1040 FROM_HERE,
1029 : base::MessageLoopProxy::current(); 1041 base::Bind(&LayerTreeHostContextTest::LoseContext,
1030 task_runner->PostTask(FROM_HERE, 1042 base::Unretained(this)));
1031 base::Bind(&LayerTreeHostContextTest::LoseContext,
1032 base::Unretained(this)));
1033 } 1043 }
1034 1044
1035 protected: 1045 protected:
1036 int time_step_; 1046 int time_step_;
1037 scoped_ptr<FakeScopedUIResource> ui_resource_; 1047 scoped_ptr<FakeScopedUIResource> ui_resource_;
1038 1048
1039 private: 1049 private:
1040 void StepCompleteOnMainThreadInternal(int step) { 1050 void StepCompleteOnMainThreadInternal(int step) {
1041 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); 1051 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
1042 StepCompleteOnMainThread(step); 1052 StepCompleteOnMainThread(step);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 // Expects a valid UIResourceId. 1087 // Expects a valid UIResourceId.
1078 EXPECT_NE(0, ui_resource_->id()); 1088 EXPECT_NE(0, ui_resource_->id());
1079 PostSetNeedsCommitToMainThread(); 1089 PostSetNeedsCommitToMainThread();
1080 break; 1090 break;
1081 case 4: 1091 case 4:
1082 // Release resource before ending the test. 1092 // Release resource before ending the test.
1083 ui_resource_.reset(); 1093 ui_resource_.reset();
1084 EndTest(); 1094 EndTest();
1085 break; 1095 break;
1086 case 5: 1096 case 5:
1087 // Single thread proxy issues extra commits after context lost. 1097 NOTREACHED();
1088 // http://crbug.com/287250
1089 if (HasImplThread())
1090 NOTREACHED();
1091 break; 1098 break;
1092 case 6:
1093 NOTREACHED();
1094 } 1099 }
1095 } 1100 }
1096 1101
1097 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { 1102 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE {
1098 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1103 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1099 switch (time_step_) { 1104 switch (time_step_) {
1100 case 1: 1105 case 1:
1101 // The resource should have been created on LTHI after the commit. 1106 // The resource should have been created on LTHI after the commit.
1102 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); 1107 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1103 PostSetNeedsCommitToMainThread(); 1108 PostSetNeedsCommitToMainThread();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 layer_tree_host()->DeleteUIResource(test_id0_); 1176 layer_tree_host()->DeleteUIResource(test_id0_);
1172 // Delete the resouce and then lose the context. 1177 // Delete the resouce and then lose the context.
1173 PostLoseContextToImplThread(); 1178 PostLoseContextToImplThread();
1174 break; 1179 break;
1175 case 5: 1180 case 5:
1176 // Release resource before ending the test. 1181 // Release resource before ending the test.
1177 ui_resource_.reset(); 1182 ui_resource_.reset();
1178 EndTest(); 1183 EndTest();
1179 break; 1184 break;
1180 case 6: 1185 case 6:
1181 // Single thread proxy issues extra commits after context lost. 1186 NOTREACHED();
1182 // http://crbug.com/287250
1183 if (HasImplThread())
1184 NOTREACHED();
1185 break; 1187 break;
1186 case 8:
1187 NOTREACHED();
1188 } 1188 }
1189 } 1189 }
1190 1190
1191 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { 1191 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE {
1192 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1192 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1193 switch (time_step_) { 1193 switch (time_step_) {
1194 case 1: 1194 case 1:
1195 // Sequence 1 (continued): 1195 // Sequence 1 (continued):
1196 // The first context lost happens before the resources were created, 1196 // The first context lost happens before the resources were created,
1197 // and because it resulted in no resources being destroyed, it does not 1197 // and because it resulted in no resources being destroyed, it does not
1198 // trigger resource re-creation. 1198 // trigger resource re-creation.
1199 EXPECT_EQ(1, ui_resource_->resource_create_count); 1199 EXPECT_EQ(1, ui_resource_->resource_create_count);
1200 EXPECT_EQ(0, ui_resource_->lost_resource_count); 1200 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1201 // Resource Id on the impl-side has been created. 1201 // Resource Id on the impl-side has been created.
1202 PostSetNeedsCommitToMainThread(); 1202 PostSetNeedsCommitToMainThread();
1203 break; 1203 break;
1204 case 3: 1204 case 3:
1205 // Sequence 2 (continued): 1205 // Sequence 2 (continued):
1206 // The previous resource should have been deleted. 1206 // The previous resource should have been deleted.
1207 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); 1207 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_));
1208 if (HasImplThread()) { 1208 // The second resource should have been created.
1209 // The second resource should have been created. 1209 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_));
1210 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_));
1211 } else {
1212 // The extra commit that happens at context lost in the single thread
1213 // proxy changes the timing so that the resource has been destroyed.
1214 // http://crbug.com/287250
1215 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id1_));
1216 }
1217 // The second resource called the resource callback once and since the 1210 // The second resource called the resource callback once and since the
1218 // context is lost, a "resource lost" callback was also issued. 1211 // context is lost, a "resource lost" callback was also issued.
1219 EXPECT_EQ(2, ui_resource_->resource_create_count); 1212 EXPECT_EQ(2, ui_resource_->resource_create_count);
1220 EXPECT_EQ(1, ui_resource_->lost_resource_count); 1213 EXPECT_EQ(1, ui_resource_->lost_resource_count);
1221 break; 1214 break;
1222 case 5: 1215 case 5:
1223 // Sequence 3 (continued): 1216 // Sequence 3 (continued):
1224 // Expect the resource callback to have been called once. 1217 // Expect the resource callback to have been called once.
1225 EXPECT_EQ(1, ui_resource_->resource_create_count); 1218 EXPECT_EQ(1, ui_resource_->resource_create_count);
1226 // No "resource lost" callbacks. 1219 // No "resource lost" callbacks.
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 EXPECT_FALSE(layer_tree_host()->output_surface_lost()); 1515 EXPECT_FALSE(layer_tree_host()->output_surface_lost());
1523 } 1516 }
1524 1517
1525 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); } 1518 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); }
1526 1519
1527 virtual void AfterTest() OVERRIDE {} 1520 virtual void AfterTest() OVERRIDE {}
1528 1521
1529 bool deferred_; 1522 bool deferred_;
1530 }; 1523 };
1531 1524
1532 // TODO(danakj): We don't use scheduler with SingleThreadProxy yet. 1525 SINGLE_AND_MULTI_THREAD_TEST_F(
1533 MULTI_THREAD_TEST_F(LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); 1526 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame);
1534 1527
1535 } // namespace 1528 } // namespace
1536 } // namespace cc 1529 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698