OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/output/output_surface.h" | 5 #include "cc/output/output_surface.h" |
6 | 6 |
7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
8 #include "cc/output/managed_memory_policy.h" | 8 #include "cc/output/managed_memory_policy.h" |
9 #include "cc/output/output_surface_client.h" | 9 #include "cc/output/output_surface_client.h" |
10 #include "cc/output/software_output_device.h" | 10 #include "cc/output/software_output_device.h" |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 423 |
424 TestOutputSurface output_surface(context_provider); | 424 TestOutputSurface output_surface(context_provider); |
425 | 425 |
426 FakeOutputSurfaceClient client; | 426 FakeOutputSurfaceClient client; |
427 EXPECT_TRUE(output_surface.BindToClient(&client)); | 427 EXPECT_TRUE(output_surface.BindToClient(&client)); |
428 | 428 |
429 ManagedMemoryPolicy policy(0); | 429 ManagedMemoryPolicy policy(0); |
430 policy.bytes_limit_when_visible = 1234; | 430 policy.bytes_limit_when_visible = 1234; |
431 policy.priority_cutoff_when_visible = | 431 policy.priority_cutoff_when_visible = |
432 gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY; | 432 gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY; |
433 policy.bytes_limit_when_not_visible = 4567; | |
434 policy.priority_cutoff_when_not_visible = | |
435 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING; | |
436 | 433 |
437 bool discard_backbuffer_when_not_visible = false; | 434 context_provider->SetMemoryAllocation(policy); |
438 | |
439 context_provider->SetMemoryAllocation(policy, | |
440 discard_backbuffer_when_not_visible); | |
441 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); | 435 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); |
442 EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY, | 436 EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY, |
443 client.memory_policy().priority_cutoff_when_visible); | 437 client.memory_policy().priority_cutoff_when_visible); |
444 EXPECT_EQ(4567u, client.memory_policy().bytes_limit_when_not_visible); | |
445 EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING, | |
446 client.memory_policy().priority_cutoff_when_not_visible); | |
447 EXPECT_FALSE(client.discard_backbuffer_when_not_visible()); | |
448 | |
449 discard_backbuffer_when_not_visible = true; | |
450 context_provider->SetMemoryAllocation(policy, | |
451 discard_backbuffer_when_not_visible); | |
452 EXPECT_TRUE(client.discard_backbuffer_when_not_visible()); | |
453 | 438 |
454 policy.priority_cutoff_when_visible = | 439 policy.priority_cutoff_when_visible = |
455 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; | 440 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; |
456 policy.priority_cutoff_when_not_visible = | 441 context_provider->SetMemoryAllocation(policy); |
457 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | |
458 context_provider->SetMemoryAllocation(policy, | |
459 discard_backbuffer_when_not_visible); | |
460 EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, | 442 EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, |
461 client.memory_policy().priority_cutoff_when_visible); | 443 client.memory_policy().priority_cutoff_when_visible); |
462 EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, | |
463 client.memory_policy().priority_cutoff_when_not_visible); | |
464 | 444 |
465 // 0 bytes limit should be ignored. | 445 // 0 bytes limit should be ignored. |
466 policy.bytes_limit_when_visible = 0; | 446 policy.bytes_limit_when_visible = 0; |
467 context_provider->SetMemoryAllocation(policy, | 447 context_provider->SetMemoryAllocation(policy); |
468 discard_backbuffer_when_not_visible); | |
469 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); | 448 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); |
470 } | 449 } |
471 | 450 |
472 TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) { | 451 TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) { |
473 TestSoftwareOutputDevice* software_output_device = | 452 TestSoftwareOutputDevice* software_output_device = |
474 new TestSoftwareOutputDevice(); | 453 new TestSoftwareOutputDevice(); |
475 | 454 |
476 // TestOutputSurface now owns software_output_device and has responsibility to | 455 // TestOutputSurface now owns software_output_device and has responsibility to |
477 // free it. | 456 // free it. |
478 scoped_ptr<TestSoftwareOutputDevice> p(software_output_device); | 457 scoped_ptr<TestSoftwareOutputDevice> p(software_output_device); |
479 TestOutputSurface output_surface(p.PassAs<SoftwareOutputDevice>()); | 458 TestOutputSurface output_surface(p.PassAs<SoftwareOutputDevice>()); |
480 | 459 |
481 EXPECT_EQ(0, software_output_device->ensure_backbuffer_count()); | 460 EXPECT_EQ(0, software_output_device->ensure_backbuffer_count()); |
482 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); | 461 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); |
483 | 462 |
484 output_surface.EnsureBackbuffer(); | 463 output_surface.EnsureBackbuffer(); |
485 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 464 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
486 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); | 465 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); |
487 output_surface.DiscardBackbuffer(); | 466 output_surface.DiscardBackbuffer(); |
488 | 467 |
489 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 468 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
490 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); | 469 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); |
491 } | 470 } |
492 | 471 |
493 } // namespace | 472 } // namespace |
494 } // namespace cc | 473 } // namespace cc |
OLD | NEW |