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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // These tests deal with losing the 3d graphics context. | 49 // These tests deal with losing the 3d graphics context. |
50 class LayerTreeHostContextTest : public LayerTreeTest { | 50 class LayerTreeHostContextTest : public LayerTreeTest { |
51 public: | 51 public: |
52 LayerTreeHostContextTest() | 52 LayerTreeHostContextTest() |
53 : LayerTreeTest(), | 53 : LayerTreeTest(), |
54 context3d_(NULL), | 54 context3d_(NULL), |
55 times_to_fail_create_(0), | 55 times_to_fail_create_(0), |
56 times_to_lose_during_commit_(0), | 56 times_to_lose_during_commit_(0), |
57 times_to_lose_during_draw_(0), | 57 times_to_lose_during_draw_(0), |
58 times_to_fail_recreate_(0), | 58 times_to_fail_recreate_(0), |
59 times_to_fail_create_offscreen_(0), | |
60 times_to_fail_recreate_offscreen_(0), | |
61 times_to_expect_create_failed_(0), | 59 times_to_expect_create_failed_(0), |
62 times_create_failed_(0), | 60 times_create_failed_(0), |
63 times_offscreen_created_(0), | |
64 committed_at_least_once_(false), | 61 committed_at_least_once_(false), |
65 context_should_support_io_surface_(false), | 62 context_should_support_io_surface_(false), |
66 fallback_context_works_(false) { | 63 fallback_context_works_(false) { |
67 media::InitializeMediaLibraryForTesting(); | 64 media::InitializeMediaLibraryForTesting(); |
68 } | 65 } |
69 | 66 |
70 void LoseContext() { | 67 void LoseContext() { |
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; |
(...skipping 18 matching lines...) Expand all Loading... |
92 context3d_->set_have_extension_io_surface(true); | 89 context3d_->set_have_extension_io_surface(true); |
93 context3d_->set_have_extension_egl_image(true); | 90 context3d_->set_have_extension_egl_image(true); |
94 } | 91 } |
95 | 92 |
96 if (delegating_renderer()) | 93 if (delegating_renderer()) |
97 return FakeOutputSurface::CreateDelegating3d(context3d.Pass()); | 94 return FakeOutputSurface::CreateDelegating3d(context3d.Pass()); |
98 else | 95 else |
99 return FakeOutputSurface::Create3d(context3d.Pass()); | 96 return FakeOutputSurface::Create3d(context3d.Pass()); |
100 } | 97 } |
101 | 98 |
102 scoped_ptr<TestWebGraphicsContext3D> CreateOffscreenContext3d() { | |
103 if (!context3d_) | |
104 return scoped_ptr<TestWebGraphicsContext3D>(); | |
105 | |
106 ++times_offscreen_created_; | |
107 | |
108 if (times_to_fail_create_offscreen_) { | |
109 --times_to_fail_create_offscreen_; | |
110 ExpectCreateToFail(); | |
111 return scoped_ptr<TestWebGraphicsContext3D>(); | |
112 } | |
113 | |
114 scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d = | |
115 TestWebGraphicsContext3D::Create().Pass(); | |
116 DCHECK(offscreen_context3d); | |
117 context3d_->add_share_group_context(offscreen_context3d.get()); | |
118 | |
119 return offscreen_context3d.Pass(); | |
120 } | |
121 | |
122 virtual scoped_refptr<ContextProvider> OffscreenContextProvider() OVERRIDE { | |
123 if (!offscreen_contexts_.get() || | |
124 offscreen_contexts_->DestroyedOnMainThread()) { | |
125 offscreen_contexts_ = | |
126 TestContextProvider::Create(CreateOffscreenContext3d()); | |
127 } | |
128 return offscreen_contexts_; | |
129 } | |
130 | |
131 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 99 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( |
132 LayerTreeHostImpl* host_impl, | 100 LayerTreeHostImpl* host_impl, |
133 LayerTreeHostImpl::FrameData* frame, | 101 LayerTreeHostImpl::FrameData* frame, |
134 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 102 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { |
135 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 103 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); |
136 if (!times_to_lose_during_draw_) | 104 if (!times_to_lose_during_draw_) |
137 return draw_result; | 105 return draw_result; |
138 | 106 |
139 --times_to_lose_during_draw_; | 107 --times_to_lose_during_draw_; |
140 LoseContext(); | 108 LoseContext(); |
141 | 109 |
142 times_to_fail_create_ = times_to_fail_recreate_; | 110 times_to_fail_create_ = times_to_fail_recreate_; |
143 times_to_fail_recreate_ = 0; | 111 times_to_fail_recreate_ = 0; |
144 times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_; | |
145 times_to_fail_recreate_offscreen_ = 0; | |
146 | 112 |
147 return draw_result; | 113 return draw_result; |
148 } | 114 } |
149 | 115 |
150 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 116 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
151 committed_at_least_once_ = true; | 117 committed_at_least_once_ = true; |
152 | 118 |
153 if (!times_to_lose_during_commit_) | 119 if (!times_to_lose_during_commit_) |
154 return; | 120 return; |
155 --times_to_lose_during_commit_; | 121 --times_to_lose_during_commit_; |
156 LoseContext(); | 122 LoseContext(); |
157 | 123 |
158 times_to_fail_create_ = times_to_fail_recreate_; | 124 times_to_fail_create_ = times_to_fail_recreate_; |
159 times_to_fail_recreate_ = 0; | 125 times_to_fail_recreate_ = 0; |
160 times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_; | |
161 times_to_fail_recreate_offscreen_ = 0; | |
162 } | 126 } |
163 | 127 |
164 virtual void DidFailToInitializeOutputSurface() OVERRIDE { | 128 virtual void DidFailToInitializeOutputSurface() OVERRIDE { |
165 ++times_create_failed_; | 129 ++times_create_failed_; |
166 } | 130 } |
167 | 131 |
168 virtual void TearDown() OVERRIDE { | 132 virtual void TearDown() OVERRIDE { |
169 LayerTreeTest::TearDown(); | 133 LayerTreeTest::TearDown(); |
170 EXPECT_EQ(times_to_expect_create_failed_, times_create_failed_); | 134 EXPECT_EQ(times_to_expect_create_failed_, times_create_failed_); |
171 } | 135 } |
172 | 136 |
173 void ExpectCreateToFail() { ++times_to_expect_create_failed_; } | 137 void ExpectCreateToFail() { ++times_to_expect_create_failed_; } |
174 | 138 |
175 protected: | 139 protected: |
176 TestWebGraphicsContext3D* context3d_; | 140 TestWebGraphicsContext3D* context3d_; |
177 int times_to_fail_create_; | 141 int times_to_fail_create_; |
178 int times_to_lose_during_commit_; | 142 int times_to_lose_during_commit_; |
179 int times_to_lose_during_draw_; | 143 int times_to_lose_during_draw_; |
180 int times_to_fail_recreate_; | 144 int times_to_fail_recreate_; |
181 int times_to_fail_create_offscreen_; | |
182 int times_to_fail_recreate_offscreen_; | |
183 int times_to_expect_create_failed_; | 145 int times_to_expect_create_failed_; |
184 int times_create_failed_; | 146 int times_create_failed_; |
185 int times_offscreen_created_; | |
186 bool committed_at_least_once_; | 147 bool committed_at_least_once_; |
187 bool context_should_support_io_surface_; | 148 bool context_should_support_io_surface_; |
188 bool fallback_context_works_; | 149 bool fallback_context_works_; |
189 | |
190 scoped_refptr<TestContextProvider> offscreen_contexts_; | |
191 }; | 150 }; |
192 | 151 |
193 class LayerTreeHostContextTestLostContextSucceeds | 152 class LayerTreeHostContextTestLostContextSucceeds |
194 : public LayerTreeHostContextTest { | 153 : public LayerTreeHostContextTest { |
195 public: | 154 public: |
196 LayerTreeHostContextTestLostContextSucceeds() | 155 LayerTreeHostContextTestLostContextSucceeds() |
197 : LayerTreeHostContextTest(), | 156 : LayerTreeHostContextTest(), |
198 test_case_(0), | 157 test_case_(0), |
199 num_losses_(0), | 158 num_losses_(0), |
200 num_losses_last_test_case_(-1), | 159 num_losses_last_test_case_(-1), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 layer_tree_host()->SetNeedsCommit(); | 198 layer_tree_host()->SetNeedsCommit(); |
240 } | 199 } |
241 | 200 |
242 bool NextTestCase() { | 201 bool NextTestCase() { |
243 static const TestCase kTests[] = { | 202 static const TestCase kTests[] = { |
244 // Losing the context and failing to recreate it (or losing it again | 203 // Losing the context and failing to recreate it (or losing it again |
245 // immediately) a small number of times should succeed. | 204 // immediately) a small number of times should succeed. |
246 {1, // times_to_lose_during_commit | 205 {1, // times_to_lose_during_commit |
247 0, // times_to_lose_during_draw | 206 0, // times_to_lose_during_draw |
248 0, // times_to_fail_recreate | 207 0, // times_to_fail_recreate |
249 0, // times_to_fail_recreate_offscreen | |
250 false, // fallback_context_works | 208 false, // fallback_context_works |
251 }, | 209 }, |
252 {0, // times_to_lose_during_commit | 210 {0, // times_to_lose_during_commit |
253 1, // times_to_lose_during_draw | 211 1, // times_to_lose_during_draw |
254 0, // times_to_fail_recreate | 212 0, // times_to_fail_recreate |
255 0, // times_to_fail_recreate_offscreen | |
256 false, // fallback_context_works | 213 false, // fallback_context_works |
257 }, | 214 }, |
258 {1, // times_to_lose_during_commit | 215 {1, // times_to_lose_during_commit |
259 0, // times_to_lose_during_draw | 216 0, // times_to_lose_during_draw |
260 3, // times_to_fail_recreate | 217 3, // times_to_fail_recreate |
261 0, // times_to_fail_recreate_offscreen | |
262 false, // fallback_context_works | 218 false, // fallback_context_works |
263 }, | 219 }, |
264 {0, // times_to_lose_during_commit | 220 {0, // times_to_lose_during_commit |
265 1, // times_to_lose_during_draw | 221 1, // times_to_lose_during_draw |
266 3, // times_to_fail_recreate | 222 3, // times_to_fail_recreate |
267 0, // times_to_fail_recreate_offscreen | |
268 false, // fallback_context_works | 223 false, // fallback_context_works |
269 }, | 224 }, |
270 // Losing the context and recreating it any number of times should | 225 // Losing the context and recreating it any number of times should |
271 // succeed. | 226 // succeed. |
272 {10, // times_to_lose_during_commit | 227 {10, // times_to_lose_during_commit |
273 0, // times_to_lose_during_draw | 228 0, // times_to_lose_during_draw |
274 0, // times_to_fail_recreate | 229 0, // times_to_fail_recreate |
275 0, // times_to_fail_recreate_offscreen | |
276 false, // fallback_context_works | 230 false, // fallback_context_works |
277 }, | 231 }, |
278 {0, // times_to_lose_during_commit | 232 {0, // times_to_lose_during_commit |
279 10, // times_to_lose_during_draw | 233 10, // times_to_lose_during_draw |
280 0, // times_to_fail_recreate | 234 0, // times_to_fail_recreate |
281 0, // times_to_fail_recreate_offscreen | |
282 false, // fallback_context_works | 235 false, // fallback_context_works |
283 }, | 236 }, |
284 // Losing the context, failing to reinitialize it, and making a fallback | 237 // Losing the context, failing to reinitialize it, and making a fallback |
285 // context should work. | 238 // context should work. |
286 {0, // times_to_lose_during_commit | 239 {0, // times_to_lose_during_commit |
287 1, // times_to_lose_during_draw | 240 1, // times_to_lose_during_draw |
288 0, // times_to_fail_recreate | 241 0, // times_to_fail_recreate |
289 0, // times_to_fail_recreate_offscreen | |
290 true, // fallback_context_works | 242 true, // fallback_context_works |
291 }, }; | 243 }, }; |
292 | 244 |
293 if (test_case_ >= arraysize(kTests)) | 245 if (test_case_ >= arraysize(kTests)) |
294 return false; | 246 return false; |
295 // Make sure that we lost our context at least once in the last test run so | 247 // Make sure that we lost our context at least once in the last test run so |
296 // the test did something. | 248 // the test did something. |
297 EXPECT_GT(num_losses_, num_losses_last_test_case_); | 249 EXPECT_GT(num_losses_, num_losses_last_test_case_); |
298 num_losses_last_test_case_ = num_losses_; | 250 num_losses_last_test_case_ = num_losses_; |
299 | 251 |
300 times_to_lose_during_commit_ = | 252 times_to_lose_during_commit_ = |
301 kTests[test_case_].times_to_lose_during_commit; | 253 kTests[test_case_].times_to_lose_during_commit; |
302 times_to_lose_during_draw_ = kTests[test_case_].times_to_lose_during_draw; | 254 times_to_lose_during_draw_ = kTests[test_case_].times_to_lose_during_draw; |
303 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; | 255 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; |
304 times_to_fail_recreate_offscreen_ = | |
305 kTests[test_case_].times_to_fail_recreate_offscreen; | |
306 fallback_context_works_ = kTests[test_case_].fallback_context_works; | 256 fallback_context_works_ = kTests[test_case_].fallback_context_works; |
307 ++test_case_; | 257 ++test_case_; |
308 return true; | 258 return true; |
309 } | 259 } |
310 | 260 |
311 struct TestCase { | 261 struct TestCase { |
312 int times_to_lose_during_commit; | 262 int times_to_lose_during_commit; |
313 int times_to_lose_during_draw; | 263 int times_to_lose_during_draw; |
314 int times_to_fail_recreate; | 264 int times_to_fail_recreate; |
315 int times_to_fail_recreate_offscreen; | |
316 bool fallback_context_works; | 265 bool fallback_context_works; |
317 }; | 266 }; |
318 | 267 |
319 protected: | 268 protected: |
320 size_t test_case_; | 269 size_t test_case_; |
321 int num_losses_; | 270 int num_losses_; |
322 int num_losses_last_test_case_; | 271 int num_losses_last_test_case_; |
323 bool recovered_context_; | 272 bool recovered_context_; |
324 bool first_initialized_; | 273 bool first_initialized_; |
325 }; | 274 }; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 class LayerTreeHostContextTestCreateOutputSurfaceIsHopeless | 436 class LayerTreeHostContextTestCreateOutputSurfaceIsHopeless |
488 : public LayerTreeHostContextTestCreateOutputSurfaceFails { | 437 : public LayerTreeHostContextTestCreateOutputSurfaceFails { |
489 public: | 438 public: |
490 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless() | 439 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless() |
491 : LayerTreeHostContextTestCreateOutputSurfaceFails(5, true, true) {} | 440 : LayerTreeHostContextTestCreateOutputSurfaceFails(5, true, true) {} |
492 }; | 441 }; |
493 | 442 |
494 SINGLE_AND_MULTI_THREAD_TEST_F( | 443 SINGLE_AND_MULTI_THREAD_TEST_F( |
495 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless); | 444 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless); |
496 | 445 |
497 | |
498 class LayerTreeHostContextTestOffscreenContextFails | |
499 : public LayerTreeHostContextTest { | |
500 public: | |
501 virtual void SetupTree() OVERRIDE { | |
502 root_ = Layer::Create(); | |
503 root_->SetBounds(gfx::Size(10, 10)); | |
504 root_->SetAnchorPoint(gfx::PointF()); | |
505 root_->SetIsDrawable(true); | |
506 | |
507 content_ = FakeContentLayer::Create(&client_); | |
508 content_->SetBounds(gfx::Size(10, 10)); | |
509 content_->SetAnchorPoint(gfx::PointF()); | |
510 content_->SetIsDrawable(true); | |
511 content_->SetForceRenderSurface(true); | |
512 // Filters require us to create an offscreen context. | |
513 FilterOperations filters; | |
514 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); | |
515 content_->SetFilters(filters); | |
516 content_->SetBackgroundFilters(filters); | |
517 | |
518 root_->AddChild(content_); | |
519 | |
520 layer_tree_host()->SetRootLayer(root_); | |
521 LayerTreeHostContextTest::SetupTree(); | |
522 } | |
523 | |
524 virtual void BeginTest() OVERRIDE { | |
525 times_to_fail_create_offscreen_ = 1; | |
526 PostSetNeedsCommitToMainThread(); | |
527 } | |
528 | |
529 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | |
530 ContextProvider* contexts = host_impl->offscreen_context_provider(); | |
531 EXPECT_FALSE(contexts); | |
532 | |
533 // This did not lead to create failure. | |
534 times_to_expect_create_failed_ = 0; | |
535 EndTest(); | |
536 } | |
537 | |
538 virtual void AfterTest() OVERRIDE {} | |
539 | |
540 protected: | |
541 FakeContentLayerClient client_; | |
542 scoped_refptr<Layer> root_; | |
543 scoped_refptr<ContentLayer> content_; | |
544 }; | |
545 | |
546 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestOffscreenContextFails); | |
547 | |
548 class LayerTreeHostContextTestLostContextFails | 446 class LayerTreeHostContextTestLostContextFails |
549 : public LayerTreeHostContextTest { | 447 : public LayerTreeHostContextTest { |
550 public: | 448 public: |
551 LayerTreeHostContextTestLostContextFails() | 449 LayerTreeHostContextTestLostContextFails() |
552 : LayerTreeHostContextTest(), num_commits_(0), first_initialized_(false) { | 450 : LayerTreeHostContextTest(), num_commits_(0), first_initialized_(false) { |
553 times_to_lose_during_commit_ = 1; | 451 times_to_lose_during_commit_ = 1; |
554 } | 452 } |
555 | 453 |
556 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 454 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
557 | 455 |
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1898 | 1796 |
1899 protected: | 1797 protected: |
1900 FakeContentLayerClient client_; | 1798 FakeContentLayerClient client_; |
1901 scoped_refptr<FakeContentLayer> layer_; | 1799 scoped_refptr<FakeContentLayer> layer_; |
1902 }; | 1800 }; |
1903 | 1801 |
1904 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); | 1802 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); |
1905 | 1803 |
1906 } // namespace | 1804 } // namespace |
1907 } // namespace cc | 1805 } // namespace cc |
OLD | NEW |