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

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

Issue 19267016: Add a flag to allow renderer to use software compositor when GL compositor doesn't work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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/heads_up_display_layer.h" 9 #include "cc/layers/heads_up_display_layer.h"
10 #include "cc/layers/io_surface_layer.h" 10 #include "cc/layers/io_surface_layer.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 times_to_lose_during_draw_(0), 55 times_to_lose_during_draw_(0),
56 times_to_fail_recreate_(0), 56 times_to_fail_recreate_(0),
57 times_to_fail_reinitialize_(0), 57 times_to_fail_reinitialize_(0),
58 times_to_lose_on_recreate_(0), 58 times_to_lose_on_recreate_(0),
59 times_to_fail_create_offscreen_(0), 59 times_to_fail_create_offscreen_(0),
60 times_to_fail_recreate_offscreen_(0), 60 times_to_fail_recreate_offscreen_(0),
61 times_to_expect_create_failed_(0), 61 times_to_expect_create_failed_(0),
62 times_create_failed_(0), 62 times_create_failed_(0),
63 times_offscreen_created_(0), 63 times_offscreen_created_(0),
64 committed_at_least_once_(false), 64 committed_at_least_once_(false),
65 context_should_support_io_surface_(false) { 65 context_should_support_io_surface_(false),
66 fallback_context_works_(false) {
66 media::InitializeMediaLibraryForTesting(); 67 media::InitializeMediaLibraryForTesting();
67 } 68 }
68 69
69 void LoseContext() { 70 void LoseContext() {
70 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 71 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
71 GL_INNOCENT_CONTEXT_RESET_ARB); 72 GL_INNOCENT_CONTEXT_RESET_ARB);
72 context3d_ = NULL; 73 context3d_ = NULL;
73 } 74 }
74 75
75 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { 76 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() {
76 return TestWebGraphicsContext3D::Create(); 77 return TestWebGraphicsContext3D::Create();
77 } 78 }
78 79
79 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { 80 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
81 OVERRIDE {
80 if (times_to_fail_create_) { 82 if (times_to_fail_create_) {
81 --times_to_fail_create_; 83 --times_to_fail_create_;
82 ExpectCreateToFail(); 84 ExpectCreateToFail();
83 return scoped_ptr<OutputSurface>(); 85 return scoped_ptr<OutputSurface>();
84 } 86 }
85 87
86 scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d(); 88 scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d();
87 context3d_ = context3d.get(); 89 context3d_ = context3d.get();
88 90
89 if (context_should_support_io_surface_) { 91 if (context_should_support_io_surface_) {
90 context3d_->set_have_extension_io_surface(true); 92 context3d_->set_have_extension_io_surface(true);
91 context3d_->set_have_extension_egl_image(true); 93 context3d_->set_have_extension_egl_image(true);
92 } 94 }
93 95
94 if (times_to_fail_initialize_) { 96 if (times_to_fail_initialize_ && !(fallback && fallback_context_works_)) {
95 --times_to_fail_initialize_; 97 --times_to_fail_initialize_;
96 // Make the context get lost during reinitialization. 98 // Make the context get lost during reinitialization.
97 // The number of times MakeCurrent succeeds is not important, and 99 // The number of times MakeCurrent succeeds is not important, and
98 // can be changed if needed to make this pass with future changes. 100 // can be changed if needed to make this pass with future changes.
99 context3d_->set_times_make_current_succeeds(2); 101 context3d_->set_times_make_current_succeeds(2);
100 ExpectCreateToFail(); 102 ExpectCreateToFail();
101 } else if (times_to_lose_on_create_) { 103 } else if (times_to_lose_on_create_) {
102 --times_to_lose_on_create_; 104 --times_to_lose_on_create_;
103 LoseContext(); 105 LoseContext();
104 ExpectCreateToFail(); 106 ExpectCreateToFail();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 int times_to_fail_recreate_; 226 int times_to_fail_recreate_;
225 int times_to_fail_reinitialize_; 227 int times_to_fail_reinitialize_;
226 int times_to_lose_on_recreate_; 228 int times_to_lose_on_recreate_;
227 int times_to_fail_create_offscreen_; 229 int times_to_fail_create_offscreen_;
228 int times_to_fail_recreate_offscreen_; 230 int times_to_fail_recreate_offscreen_;
229 int times_to_expect_create_failed_; 231 int times_to_expect_create_failed_;
230 int times_create_failed_; 232 int times_create_failed_;
231 int times_offscreen_created_; 233 int times_offscreen_created_;
232 bool committed_at_least_once_; 234 bool committed_at_least_once_;
233 bool context_should_support_io_surface_; 235 bool context_should_support_io_surface_;
236 bool fallback_context_works_;
234 237
235 scoped_refptr<FakeContextProvider> offscreen_contexts_main_thread_; 238 scoped_refptr<FakeContextProvider> offscreen_contexts_main_thread_;
236 scoped_refptr<FakeContextProvider> offscreen_contexts_compositor_thread_; 239 scoped_refptr<FakeContextProvider> offscreen_contexts_compositor_thread_;
237 }; 240 };
238 241
239 class LayerTreeHostContextTestLostContextSucceeds 242 class LayerTreeHostContextTestLostContextSucceeds
240 : public LayerTreeHostContextTest { 243 : public LayerTreeHostContextTest {
241 public: 244 public:
242 LayerTreeHostContextTestLostContextSucceeds() 245 LayerTreeHostContextTestLostContextSucceeds()
243 : LayerTreeHostContextTest(), 246 : LayerTreeHostContextTest(),
(...skipping 11 matching lines...) Expand all
255 258
256 if (first_initialized_) 259 if (first_initialized_)
257 ++num_losses_; 260 ++num_losses_;
258 else 261 else
259 first_initialized_ = true; 262 first_initialized_ = true;
260 263
261 recovered_context_ = true; 264 recovered_context_ = true;
262 } 265 }
263 266
264 virtual void AfterTest() OVERRIDE { 267 virtual void AfterTest() OVERRIDE {
265 EXPECT_EQ(10u, test_case_); 268 EXPECT_EQ(11u, test_case_);
266 EXPECT_EQ(8 + 10 + 10, num_losses_); 269 EXPECT_EQ(8 + 10 + 10 + 1, num_losses_);
267 } 270 }
268 271
269 virtual void DidCommitAndDrawFrame() OVERRIDE { 272 virtual void DidCommitAndDrawFrame() OVERRIDE {
270 // If the last frame had a context loss, then we'll commit again to 273 // If the last frame had a context loss, then we'll commit again to
271 // recover. 274 // recover.
272 if (!recovered_context_) 275 if (!recovered_context_)
273 return; 276 return;
274 if (times_to_lose_during_commit_) 277 if (times_to_lose_during_commit_)
275 return; 278 return;
276 if (times_to_lose_during_draw_) 279 if (times_to_lose_during_draw_)
277 return; 280 return;
278 281
279 recovered_context_ = false; 282 recovered_context_ = false;
280 if (NextTestCase()) 283 if (NextTestCase())
281 InvalidateAndSetNeedsCommit(); 284 InvalidateAndSetNeedsCommit();
282 else 285 else
283 EndTest(); 286 EndTest();
284 } 287 }
285 288
286 virtual void InvalidateAndSetNeedsCommit() { 289 virtual void InvalidateAndSetNeedsCommit() {
287 // Cause damage so we try to draw. 290 // Cause damage so we try to draw.
288 layer_tree_host()->root_layer()->SetNeedsDisplay(); 291 layer_tree_host()->root_layer()->SetNeedsDisplay();
289 layer_tree_host()->SetNeedsCommit(); 292 layer_tree_host()->SetNeedsCommit();
290 } 293 }
291 294
292 bool NextTestCase() { 295 bool NextTestCase() {
293 static const TestCase kTests[] = { 296 static const TestCase kTests[] = {
294 // Losing the context and failing to recreate it (or losing it again 297 // Losing the context and failing to recreate it (or losing it again
295 // immediately) a small number of times should succeed. 298 // immediately) a small number of times should succeed.
296 { 1, // times_to_lose_during_commit 299 { 1, // times_to_lose_during_commit
297 0, // times_to_lose_during_draw 300 0, // times_to_lose_during_draw
298 3, // times_to_fail_reinitialize 301 3, // times_to_fail_reinitialize
299 0, // times_to_fail_recreate 302 0, // times_to_fail_recreate
300 0, // times_to_lose_on_recreate 303 0, // times_to_lose_on_recreate
301 0, // times_to_fail_recreate_offscreen 304 0, // times_to_fail_recreate_offscreen
302 }, 305 false, // fallback_context_works
303 { 0, // times_to_lose_during_commit 306 },
304 1, // times_to_lose_during_draw 307 { 0, // times_to_lose_during_commit
305 3, // times_to_fail_reinitialize 308 1, // times_to_lose_during_draw
306 0, // times_to_fail_recreate 309 3, // times_to_fail_reinitialize
307 0, // times_to_lose_on_recreate 310 0, // times_to_fail_recreate
308 0, // times_to_fail_recreate_offscreen 311 0, // times_to_lose_on_recreate
309 }, 312 0, // times_to_fail_recreate_offscreen
310 { 1, // times_to_lose_during_commit 313 false, // fallback_context_works
311 0, // times_to_lose_during_draw 314 },
312 0, // times_to_fail_reinitialize 315 { 1, // times_to_lose_during_commit
313 3, // times_to_fail_recreate 316 0, // times_to_lose_during_draw
314 0, // times_to_lose_on_recreate 317 0, // times_to_fail_reinitialize
315 0, // times_to_fail_recreate_offscreen 318 3, // times_to_fail_recreate
316 }, 319 0, // times_to_lose_on_recreate
317 { 0, // times_to_lose_during_commit 320 0, // times_to_fail_recreate_offscreen
318 1, // times_to_lose_during_draw 321 false, // fallback_context_works
319 0, // times_to_fail_reinitialize 322 },
320 3, // times_to_fail_recreate 323 { 0, // times_to_lose_during_commit
321 0, // times_to_lose_on_recreate 324 1, // times_to_lose_during_draw
322 0, // times_to_fail_recreate_offscreen 325 0, // times_to_fail_reinitialize
323 }, 326 3, // times_to_fail_recreate
324 { 1, // times_to_lose_during_commit 327 0, // times_to_lose_on_recreate
325 0, // times_to_lose_during_draw 328 0, // times_to_fail_recreate_offscreen
326 0, // times_to_fail_reinitialize 329 false, // fallback_context_works
327 0, // times_to_fail_recreate 330 },
328 3, // times_to_lose_on_recreate 331 { 1, // times_to_lose_during_commit
329 0, // times_to_fail_recreate_offscreen 332 0, // times_to_lose_during_draw
330 }, 333 0, // times_to_fail_reinitialize
331 { 0, // times_to_lose_during_commit 334 0, // times_to_fail_recreate
332 1, // times_to_lose_during_draw 335 3, // times_to_lose_on_recreate
333 0, // times_to_fail_reinitialize 336 0, // times_to_fail_recreate_offscreen
334 0, // times_to_fail_recreate 337 false, // fallback_context_works
335 3, // times_to_lose_on_recreate 338 },
336 0, // times_to_fail_recreate_offscreen 339 { 0, // times_to_lose_during_commit
337 }, 340 1, // times_to_lose_during_draw
338 { 1, // times_to_lose_during_commit 341 0, // times_to_fail_reinitialize
339 0, // times_to_lose_during_draw 342 0, // times_to_fail_recreate
340 0, // times_to_fail_reinitialize 343 3, // times_to_lose_on_recreate
341 0, // times_to_fail_recreate 344 0, // times_to_fail_recreate_offscreen
342 0, // times_to_lose_on_recreate 345 false, // fallback_context_works
343 3, // times_to_fail_recreate_offscreen 346 },
344 }, 347 { 1, // times_to_lose_during_commit
345 { 0, // times_to_lose_during_commit 348 0, // times_to_lose_during_draw
346 1, // times_to_lose_during_draw 349 0, // times_to_fail_reinitialize
347 0, // times_to_fail_reinitialize 350 0, // times_to_fail_recreate
348 0, // times_to_fail_recreate 351 0, // times_to_lose_on_recreate
349 0, // times_to_lose_on_recreate 352 3, // times_to_fail_recreate_offscreen
350 3, // times_to_fail_recreate_offscreen 353 false, // fallback_context_works
351 }, 354 },
352 // Losing the context and recreating it any number of times should 355 { 0, // times_to_lose_during_commit
356 1, // times_to_lose_during_draw
357 0, // times_to_fail_reinitialize
358 0, // times_to_fail_recreate
359 0, // times_to_lose_on_recreate
360 3, // times_to_fail_recreate_offscreen
361 false, // fallback_context_works
362 },
363 // Losing the context and recreating it any number of times should
353 // succeed. 364 // succeed.
354 { 10, // times_to_lose_during_commit 365 { 10, // times_to_lose_during_commit
355 0, // times_to_lose_during_draw 366 0, // times_to_lose_during_draw
356 0, // times_to_fail_reinitialize 367 0, // times_to_fail_reinitialize
357 0, // times_to_fail_recreate 368 0, // times_to_fail_recreate
358 0, // times_to_lose_on_recreate 369 0, // times_to_lose_on_recreate
359 0, // times_to_fail_recreate_offscreen 370 0, // times_to_fail_recreate_offscreen
360 }, 371 false, // fallback_context_works
361 { 0, // times_to_lose_during_commit 372 },
362 10, // times_to_lose_during_draw 373 { 0, // times_to_lose_during_commit
363 0, // times_to_fail_reinitialize 374 10, // times_to_lose_during_draw
364 0, // times_to_fail_recreate 375 0, // times_to_fail_reinitialize
365 0, // times_to_lose_on_recreate 376 0, // times_to_fail_recreate
366 0, // times_to_fail_recreate_offscreen 377 0, // times_to_lose_on_recreate
367 }, 378 0, // times_to_fail_recreate_offscreen
379 false, // fallback_context_works
380 },
381 // Losing the context, failing to reinitialize it, and making a fallback
382 // context should work.
383 { 0, // times_to_lose_during_commit
384 1, // times_to_lose_during_draw
385 10, // times_to_fail_reinitialize
386 0, // times_to_fail_recreate
387 0, // times_to_lose_on_recreate
388 0, // times_to_fail_recreate_offscreen
389 true, // fallback_context_works
390 },
368 }; 391 };
369 392
370 if (test_case_ >= arraysize(kTests)) 393 if (test_case_ >= arraysize(kTests))
371 return false; 394 return false;
372 395
373 times_to_lose_during_commit_ = 396 times_to_lose_during_commit_ =
374 kTests[test_case_].times_to_lose_during_commit; 397 kTests[test_case_].times_to_lose_during_commit;
375 times_to_lose_during_draw_ = 398 times_to_lose_during_draw_ =
376 kTests[test_case_].times_to_lose_during_draw; 399 kTests[test_case_].times_to_lose_during_draw;
377 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize; 400 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize;
378 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; 401 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate;
379 times_to_lose_on_recreate_ = kTests[test_case_].times_to_lose_on_recreate; 402 times_to_lose_on_recreate_ = kTests[test_case_].times_to_lose_on_recreate;
380 times_to_fail_recreate_offscreen_ = 403 times_to_fail_recreate_offscreen_ =
381 kTests[test_case_].times_to_fail_recreate_offscreen; 404 kTests[test_case_].times_to_fail_recreate_offscreen;
405 fallback_context_works_ = kTests[test_case_].fallback_context_works;
382 ++test_case_; 406 ++test_case_;
383 return true; 407 return true;
384 } 408 }
385 409
386 struct TestCase { 410 struct TestCase {
387 int times_to_lose_during_commit; 411 int times_to_lose_during_commit;
388 int times_to_lose_during_draw; 412 int times_to_lose_during_draw;
389 int times_to_fail_reinitialize; 413 int times_to_fail_reinitialize;
390 int times_to_fail_recreate; 414 int times_to_fail_recreate;
391 int times_to_lose_on_recreate; 415 int times_to_lose_on_recreate;
392 int times_to_fail_recreate_offscreen; 416 int times_to_fail_recreate_offscreen;
417 bool fallback_context_works;
393 }; 418 };
394 419
395 protected: 420 protected:
396 size_t test_case_; 421 size_t test_case_;
397 int num_losses_; 422 int num_losses_;
398 bool recovered_context_; 423 bool recovered_context_;
399 bool first_initialized_; 424 bool first_initialized_;
400 }; 425 };
401 426
402 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds); 427 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 } 484 }
460 } 485 }
461 486
462 virtual void AfterTest() OVERRIDE { 487 virtual void AfterTest() OVERRIDE {
463 LayerTreeHostContextTestLostContextSucceeds::AfterTest(); 488 LayerTreeHostContextTestLostContextSucceeds::AfterTest();
464 if (use_surface_) { 489 if (use_surface_) {
465 // 1 create to start with + 490 // 1 create to start with +
466 // 6 from test cases that fail on initializing the renderer (after the 491 // 6 from test cases that fail on initializing the renderer (after the
467 // offscreen context is created) + 492 // offscreen context is created) +
468 // 6 from test cases that lose the offscreen context directly + 493 // 6 from test cases that lose the offscreen context directly +
494 // 4 from test cases that create a fallback +
469 // All the test cases that recreate both contexts only once 495 // All the test cases that recreate both contexts only once
470 // per time it is lost. 496 // per time it is lost.
471 EXPECT_EQ(6 + 6 + 1 + num_losses_, times_offscreen_created_); 497 EXPECT_EQ(6 + 6 + 1 + 4 + num_losses_, times_offscreen_created_);
472 } else { 498 } else {
473 EXPECT_EQ(0, times_offscreen_created_); 499 EXPECT_EQ(0, times_offscreen_created_);
474 } 500 }
475 } 501 }
476 502
477 protected: 503 protected:
478 bool use_surface_; 504 bool use_surface_;
479 FakeContentLayerClient client_; 505 FakeContentLayerClient client_;
480 scoped_refptr<Layer> root_; 506 scoped_refptr<Layer> root_;
481 scoped_refptr<ContentLayer> content_; 507 scoped_refptr<ContentLayer> content_;
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 1595
1570 // Not reusing LayerTreeTest because it expects creating LTH to always succeed. 1596 // Not reusing LayerTreeTest because it expects creating LTH to always succeed.
1571 class LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface 1597 class LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface
1572 : public testing::Test, 1598 : public testing::Test,
1573 public FakeLayerTreeHostClient { 1599 public FakeLayerTreeHostClient {
1574 public: 1600 public:
1575 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface() 1601 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface()
1576 : FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D) {} 1602 : FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D) {}
1577 1603
1578 // FakeLayerTreeHostClient implementation. 1604 // FakeLayerTreeHostClient implementation.
1579 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { 1605 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
1606 OVERRIDE {
1580 return scoped_ptr<OutputSurface>(); 1607 return scoped_ptr<OutputSurface>();
1581 } 1608 }
1582 1609
1583 void RunTest(bool threaded, 1610 void RunTest(bool threaded,
1584 bool delegating_renderer, 1611 bool delegating_renderer,
1585 bool impl_side_painting) { 1612 bool impl_side_painting) {
1586 scoped_ptr<base::Thread> impl_thread; 1613 scoped_ptr<base::Thread> impl_thread;
1587 if (threaded) { 1614 if (threaded) {
1588 impl_thread.reset(new base::Thread("LayerTreeTest")); 1615 impl_thread.reset(new base::Thread("LayerTreeTest"));
1589 ASSERT_TRUE(impl_thread->Start()); 1616 ASSERT_TRUE(impl_thread->Start());
1590 ASSERT_TRUE(impl_thread->message_loop_proxy().get()); 1617 ASSERT_TRUE(impl_thread->message_loop_proxy().get());
1591 } 1618 }
1592 1619
1593 LayerTreeSettings settings; 1620 LayerTreeSettings settings;
1594 settings.impl_side_painting = impl_side_painting; 1621 settings.impl_side_painting = impl_side_painting;
1595 scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::Create( 1622 scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::Create(
1596 this, 1623 this,
1597 settings, 1624 settings,
1598 impl_thread ? impl_thread->message_loop_proxy() : NULL); 1625 impl_thread ? impl_thread->message_loop_proxy() : NULL);
1599 EXPECT_FALSE(layer_tree_host); 1626 EXPECT_FALSE(layer_tree_host);
1600 } 1627 }
1601 }; 1628 };
1602 1629
1603 SINGLE_AND_MULTI_THREAD_TEST_F( 1630 SINGLE_AND_MULTI_THREAD_TEST_F(
1604 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface); 1631 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface);
1605 1632
1606 } // namespace 1633 } // namespace
1607 } // namespace cc 1634 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | chrome/browser/chromeos/login/chrome_restart_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698