OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 9 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 result_shm_id, | 653 result_shm_id, |
654 result_shm_offset, | 654 result_shm_offset, |
655 false); | 655 false); |
656 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 656 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
657 for (GLint yy = 0; yy < kHeight; ++yy) { | 657 for (GLint yy = 0; yy < kHeight; ++yy) { |
658 EXPECT_TRUE(emu.CompareRowSegment( | 658 EXPECT_TRUE(emu.CompareRowSegment( |
659 0, yy, kWidth, emu.ComputePackAlignmentAddress(0, yy, kWidth, dest))); | 659 0, yy, kWidth, emu.ComputePackAlignmentAddress(0, yy, kWidth, dest))); |
660 } | 660 } |
661 } | 661 } |
662 | 662 |
| 663 TEST_P(GLES3DecoderTest, ReadPixels2PixelPackBufferNoBufferBound) { |
| 664 const GLsizei kWidth = 5; |
| 665 const GLsizei kHeight = 3; |
| 666 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); |
| 667 |
| 668 ReadPixels cmd; |
| 669 cmd.Init(0, |
| 670 0, |
| 671 kWidth, |
| 672 kHeight, |
| 673 GL_RGBA, |
| 674 GL_UNSIGNED_BYTE, |
| 675 0, |
| 676 0, |
| 677 0, |
| 678 0, |
| 679 false); |
| 680 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 681 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 682 } |
| 683 |
| 684 TEST_P(GLES3DecoderTest, ReadPixelsBufferBound) { |
| 685 const GLsizei kWidth = 5; |
| 686 const GLsizei kHeight = 3; |
| 687 const GLint kBytesPerPixel = 4; |
| 688 GLint size = kWidth * kHeight * kBytesPerPixel; |
| 689 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); |
| 690 typedef ReadPixels::Result Result; |
| 691 Result* result = GetSharedMemoryAs<Result*>(); |
| 692 uint32 result_shm_id = kSharedMemoryId; |
| 693 uint32 result_shm_offset = kSharedMemoryOffset; |
| 694 uint32 pixels_shm_id = kSharedMemoryId; |
| 695 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result); |
| 696 |
| 697 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); |
| 698 DoBufferData(GL_PIXEL_PACK_BUFFER, size); |
| 699 |
| 700 ReadPixels cmd; |
| 701 cmd.Init(0, |
| 702 0, |
| 703 kWidth, |
| 704 kHeight, |
| 705 GL_RGBA, |
| 706 GL_UNSIGNED_BYTE, |
| 707 pixels_shm_id, |
| 708 pixels_shm_offset, |
| 709 result_shm_id, |
| 710 result_shm_offset, |
| 711 false); |
| 712 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 713 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 714 } |
| 715 |
| 716 TEST_P(GLES3DecoderTest, ReadPixels2PixelPackBuffer) { |
| 717 const GLsizei kWidth = 5; |
| 718 const GLsizei kHeight = 3; |
| 719 const GLint kBytesPerPixel = 4; |
| 720 GLint size = kWidth * kHeight * kBytesPerPixel; |
| 721 |
| 722 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); |
| 723 DoBufferData(GL_PIXEL_PACK_BUFFER, size); |
| 724 |
| 725 EXPECT_CALL(*gl_, GetError()) |
| 726 .WillOnce(Return(GL_NO_ERROR)) |
| 727 .RetiresOnSaturation(); |
| 728 EXPECT_CALL(*gl_, |
| 729 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _)); |
| 730 ReadPixels cmd; |
| 731 cmd.Init(0, |
| 732 0, |
| 733 kWidth, |
| 734 kHeight, |
| 735 GL_RGBA, |
| 736 GL_UNSIGNED_BYTE, |
| 737 0, |
| 738 0, |
| 739 0, |
| 740 0, |
| 741 false); |
| 742 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 743 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 744 } |
| 745 |
| 746 TEST_P(GLES3DecoderTest, ReadPixelsPixelPackBufferMapped) { |
| 747 const GLsizei kWidth = 5; |
| 748 const GLsizei kHeight = 3; |
| 749 const GLint kBytesPerPixel = 4; |
| 750 GLint size = kWidth * kHeight * kBytesPerPixel; |
| 751 |
| 752 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); |
| 753 |
| 754 uint32_t result_shm_id = kSharedMemoryId; |
| 755 uint32_t result_shm_offset = kSharedMemoryOffset; |
| 756 uint32_t data_shm_id = kSharedMemoryId; |
| 757 // uint32_t is Result for both MapBufferRange and UnmapBuffer commands. |
| 758 uint32_t data_shm_offset = kSharedMemoryOffset + sizeof(uint32_t); |
| 759 EXPECT_CALL(*gl_, |
| 760 MapBufferRange(GL_PIXEL_PACK_BUFFER, 0, size, GL_MAP_READ_BIT)) |
| 761 .RetiresOnSaturation(); |
| 762 MapBufferRange map_buffer_range; |
| 763 map_buffer_range.Init(GL_PIXEL_PACK_BUFFER, 0, size, GL_MAP_READ_BIT, |
| 764 data_shm_id, data_shm_offset, |
| 765 result_shm_id, result_shm_offset); |
| 766 EXPECT_EQ(error::kNoError, ExecuteCmd(map_buffer_range)); |
| 767 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 768 |
| 769 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); |
| 770 ReadPixels cmd; |
| 771 cmd.Init(0, |
| 772 0, |
| 773 kWidth, |
| 774 kHeight, |
| 775 GL_RGBA, |
| 776 GL_UNSIGNED_BYTE, |
| 777 0, |
| 778 0, |
| 779 0, |
| 780 0, |
| 781 false); |
| 782 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 783 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 784 } |
| 785 |
| 786 TEST_P(GLES3DecoderTest, ReadPixelsPixelPackBufferIsNotLargeEnough) { |
| 787 const GLsizei kWidth = 5; |
| 788 const GLsizei kHeight = 3; |
| 789 const GLint kBytesPerPixel = 4; |
| 790 GLint size = kWidth * kHeight * kBytesPerPixel; |
| 791 |
| 792 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); |
| 793 |
| 794 DoBufferData(GL_PIXEL_PACK_BUFFER, size - 4); |
| 795 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); |
| 796 |
| 797 ReadPixels cmd; |
| 798 cmd.Init(0, |
| 799 0, |
| 800 kWidth, |
| 801 kHeight, |
| 802 GL_RGBA, |
| 803 GL_UNSIGNED_BYTE, |
| 804 0, |
| 805 0, |
| 806 0, |
| 807 0, |
| 808 false); |
| 809 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 810 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 811 } |
| 812 |
663 TEST_P(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) { | 813 TEST_P(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) { |
664 const GLsizei kWidth = 3; | 814 const GLsizei kWidth = 3; |
665 const GLsizei kHeight = 3; | 815 const GLsizei kHeight = 3; |
666 const GLint kBytesPerPixel = 4; | 816 const GLint kBytesPerPixel = 4; |
667 const GLint kPackAlignment = 4; | 817 const GLint kPackAlignment = 4; |
668 static const uint8 kExpectedPixels[kWidth * kHeight * kBytesPerPixel] = { | 818 static const uint8 kExpectedPixels[kWidth * kHeight * kBytesPerPixel] = { |
669 12, 13, 14, 255, 19, 18, 19, 255, 13, 14, 18, 255, | 819 12, 13, 14, 255, 19, 18, 19, 255, 13, 14, 18, 255, |
670 29, 28, 23, 255, 21, 22, 21, 255, 28, 23, 22, 255, | 820 29, 28, 23, 255, 21, 22, 21, 255, 28, 23, 22, 255, |
671 31, 34, 39, 255, 32, 37, 32, 255, 34, 39, 37, 255, | 821 31, 34, 39, 255, 32, 37, 32, 255, 34, 39, 37, 255, |
672 }; | 822 }; |
(...skipping 2244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2917 EXPECT_EQ(1, result->GetNumResults()); | 3067 EXPECT_EQ(1, result->GetNumResults()); |
2918 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 3068 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
2919 } | 3069 } |
2920 | 3070 |
2921 // TODO(gman): PixelStorei | 3071 // TODO(gman): PixelStorei |
2922 | 3072 |
2923 // TODO(gman): SwapBuffers | 3073 // TODO(gman): SwapBuffers |
2924 | 3074 |
2925 } // namespace gles2 | 3075 } // namespace gles2 |
2926 } // namespace gpu | 3076 } // namespace gpu |
OLD | NEW |