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

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

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

Powered by Google App Engine
This is Rietveld 408576698