| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 // Tests for GLES2Implementation. | 5 // Tests for GLES2Implementation. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
| 10 #include <GLES2/gl2extchromium.h> | 10 #include <GLES2/gl2extchromium.h> |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 kTestSize - MaxTransferBufferSize())) | 575 kTestSize - MaxTransferBufferSize())) |
| 576 .RetiresOnSaturation(); | 576 .RetiresOnSaturation(); |
| 577 | 577 |
| 578 std::vector<int8> data; | 578 std::vector<int8> data; |
| 579 GetBucketContents(kBucketId, &data); | 579 GetBucketContents(kBucketId, &data); |
| 580 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); | 580 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
| 581 ASSERT_EQ(kTestSize, data.size()); | 581 ASSERT_EQ(kTestSize, data.size()); |
| 582 EXPECT_EQ(0, memcmp(expected_data, &data[0], data.size())); | 582 EXPECT_EQ(0, memcmp(expected_data, &data[0], data.size())); |
| 583 } | 583 } |
| 584 | 584 |
| 585 TEST_F(GLES2ImplementationTest, GetShaderPrecisionFormat) { |
| 586 struct Cmds { |
| 587 cmds::GetShaderPrecisionFormat cmd; |
| 588 }; |
| 589 typedef cmds::GetShaderPrecisionFormat::Result Result; |
| 590 |
| 591 // The first call for mediump should trigger a command buffer request. |
| 592 GLint range1[2] = {0, 0}; |
| 593 GLint precision1 = 0; |
| 594 Cmds expected1; |
| 595 ExpectedMemoryInfo client_result1 = GetExpectedResultMemory(4); |
| 596 expected1.cmd.Init(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, |
| 597 client_result1.id, client_result1.offset); |
| 598 Result server_result1 = {true, 14, 14, 10}; |
| 599 EXPECT_CALL(*command_buffer(), OnFlush()) |
| 600 .WillOnce(SetMemory(client_result1.ptr, server_result1)) |
| 601 .RetiresOnSaturation(); |
| 602 gl_->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, |
| 603 range1, &precision1); |
| 604 const void* commands2 = GetPut(); |
| 605 EXPECT_NE(commands_, commands2); |
| 606 EXPECT_EQ(0, memcmp(&expected1, commands_, sizeof(expected1))); |
| 607 EXPECT_EQ(range1[0], 14); |
| 608 EXPECT_EQ(range1[1], 14); |
| 609 EXPECT_EQ(precision1, 10); |
| 610 |
| 611 // The second call for mediump should use the cached value and avoid |
| 612 // triggering a command buffer request, so we do not expect a call to |
| 613 // OnFlush() here. We do expect the results to be correct though. |
| 614 GLint range2[2] = {0, 0}; |
| 615 GLint precision2 = 0; |
| 616 gl_->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, |
| 617 range2, &precision2); |
| 618 const void* commands3 = GetPut(); |
| 619 EXPECT_EQ(commands2, commands3); |
| 620 EXPECT_EQ(range2[0], 14); |
| 621 EXPECT_EQ(range2[1], 14); |
| 622 EXPECT_EQ(precision2, 10); |
| 623 |
| 624 // If we then make a request for highp, we should get another command |
| 625 // buffer request since it hasn't been cached yet. |
| 626 GLint range3[2] = {0, 0}; |
| 627 GLint precision3 = 0; |
| 628 Cmds expected3; |
| 629 ExpectedMemoryInfo result3 = GetExpectedResultMemory(4); |
| 630 expected3.cmd.Init(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, |
| 631 result3.id, result3.offset); |
| 632 Result result3_source = {true, 62, 62, 16}; |
| 633 EXPECT_CALL(*command_buffer(), OnFlush()) |
| 634 .WillOnce(SetMemory(result3.ptr, result3_source)) |
| 635 .RetiresOnSaturation(); |
| 636 gl_->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, |
| 637 range3, &precision3); |
| 638 const void* commands4 = GetPut(); |
| 639 EXPECT_NE(commands3, commands4); |
| 640 EXPECT_EQ(0, memcmp(&expected3, commands3, sizeof(expected3))); |
| 641 EXPECT_EQ(range3[0], 62); |
| 642 EXPECT_EQ(range3[1], 62); |
| 643 EXPECT_EQ(precision3, 16); |
| 644 } |
| 645 |
| 585 TEST_F(GLES2ImplementationTest, ShaderSource) { | 646 TEST_F(GLES2ImplementationTest, ShaderSource) { |
| 586 const uint32 kBucketId = GLES2Implementation::kResultBucketId; | 647 const uint32 kBucketId = GLES2Implementation::kResultBucketId; |
| 587 const GLuint kShaderId = 456; | 648 const GLuint kShaderId = 456; |
| 588 const char* kString1 = "foobar"; | 649 const char* kString1 = "foobar"; |
| 589 const char* kString2 = "barfoo"; | 650 const char* kString2 = "barfoo"; |
| 590 const size_t kString1Size = strlen(kString1); | 651 const size_t kString1Size = strlen(kString1); |
| 591 const size_t kString2Size = strlen(kString2); | 652 const size_t kString2Size = strlen(kString2); |
| 592 const size_t kString3Size = 1; // Want the NULL; | 653 const size_t kString3Size = 1; // Want the NULL; |
| 593 const size_t kSourceSize = kString1Size + kString2Size + kString3Size; | 654 const size_t kSourceSize = kString1Size + kString2Size + kString3Size; |
| 594 const size_t kPaddedString1Size = | 655 const size_t kPaddedString1Size = |
| (...skipping 2208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2803 gl_->Enable(GL_BLEND); | 2864 gl_->Enable(GL_BLEND); |
| 2804 EXPECT_TRUE(NoCommandsWritten()); | 2865 EXPECT_TRUE(NoCommandsWritten()); |
| 2805 } | 2866 } |
| 2806 | 2867 |
| 2807 | 2868 |
| 2808 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 2869 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
| 2809 | 2870 |
| 2810 } // namespace gles2 | 2871 } // namespace gles2 |
| 2811 } // namespace gpu | 2872 } // namespace gpu |
| 2812 | 2873 |
| OLD | NEW |