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::kInvalidArguments, ExecuteCmd(cmd)); |
| 681 EXPECT_EQ(GL_NO_ERROR, 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 uint32 result_shm_id = kSharedMemoryId; |
| 691 uint32 result_shm_offset = kSharedMemoryOffset; |
| 692 uint32 pixels_shm_id = kSharedMemoryId; |
| 693 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(ReadPixels::Result); |
| 694 |
| 695 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); |
| 696 DoBufferData(GL_PIXEL_PACK_BUFFER, size); |
| 697 |
| 698 ReadPixels cmd; |
| 699 cmd.Init(0, |
| 700 0, |
| 701 kWidth, |
| 702 kHeight, |
| 703 GL_RGBA, |
| 704 GL_UNSIGNED_BYTE, |
| 705 pixels_shm_id, |
| 706 pixels_shm_offset, |
| 707 result_shm_id, |
| 708 result_shm_offset, |
| 709 false); |
| 710 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd)); |
| 711 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 712 } |
| 713 |
| 714 TEST_P(GLES3DecoderTest, ReadPixels2PixelPackBuffer) { |
| 715 const GLsizei kWidth = 5; |
| 716 const GLsizei kHeight = 3; |
| 717 const GLint kBytesPerPixel = 4; |
| 718 GLint size = kWidth * kHeight * kBytesPerPixel; |
| 719 |
| 720 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); |
| 721 DoBufferData(GL_PIXEL_PACK_BUFFER, size); |
| 722 |
| 723 EXPECT_CALL(*gl_, GetError()) |
| 724 .WillOnce(Return(GL_NO_ERROR)) |
| 725 .RetiresOnSaturation(); |
| 726 EXPECT_CALL(*gl_, |
| 727 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _)); |
| 728 ReadPixels cmd; |
| 729 cmd.Init(0, |
| 730 0, |
| 731 kWidth, |
| 732 kHeight, |
| 733 GL_RGBA, |
| 734 GL_UNSIGNED_BYTE, |
| 735 0, |
| 736 0, |
| 737 0, |
| 738 0, |
| 739 false); |
| 740 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 741 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 742 } |
| 743 |
| 744 TEST_P(GLES3DecoderTest, ReadPixelsPixelPackBufferMapped) { |
| 745 const GLsizei kWidth = 5; |
| 746 const GLsizei kHeight = 3; |
| 747 const GLint kBytesPerPixel = 4; |
| 748 GLint size = kWidth * kHeight * kBytesPerPixel; |
| 749 |
| 750 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); |
| 751 |
| 752 uint32_t result_shm_id = kSharedMemoryId; |
| 753 uint32_t result_shm_offset = kSharedMemoryOffset; |
| 754 uint32_t data_shm_id = kSharedMemoryId; |
| 755 // uint32_t is Result for both MapBufferRange and UnmapBuffer commands. |
| 756 uint32_t data_shm_offset = kSharedMemoryOffset + sizeof(uint32_t); |
| 757 EXPECT_CALL(*gl_, |
| 758 MapBufferRange(GL_PIXEL_PACK_BUFFER, 0, size, GL_MAP_READ_BIT)) |
| 759 .RetiresOnSaturation(); |
| 760 MapBufferRange map_buffer_range; |
| 761 map_buffer_range.Init(GL_PIXEL_PACK_BUFFER, 0, size, GL_MAP_READ_BIT, |
| 762 data_shm_id, data_shm_offset, |
| 763 result_shm_id, result_shm_offset); |
| 764 EXPECT_EQ(error::kNoError, ExecuteCmd(map_buffer_range)); |
| 765 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 766 |
| 767 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); |
| 768 ReadPixels cmd; |
| 769 cmd.Init(0, |
| 770 0, |
| 771 kWidth, |
| 772 kHeight, |
| 773 GL_RGBA, |
| 774 GL_UNSIGNED_BYTE, |
| 775 0, |
| 776 0, |
| 777 0, |
| 778 0, |
| 779 false); |
| 780 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 781 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 782 } |
| 783 |
| 784 TEST_P(GLES3DecoderTest, ReadPixelsPixelPackBufferIsNotLargeEnough) { |
| 785 const GLsizei kWidth = 5; |
| 786 const GLsizei kHeight = 3; |
| 787 const GLint kBytesPerPixel = 4; |
| 788 GLint size = kWidth * kHeight * kBytesPerPixel; |
| 789 |
| 790 DoBindBuffer(GL_PIXEL_PACK_BUFFER, client_buffer_id_, kServiceBufferId); |
| 791 |
| 792 DoBufferData(GL_PIXEL_PACK_BUFFER, size - 4); |
| 793 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0); |
| 794 |
| 795 ReadPixels cmd; |
| 796 cmd.Init(0, |
| 797 0, |
| 798 kWidth, |
| 799 kHeight, |
| 800 GL_RGBA, |
| 801 GL_UNSIGNED_BYTE, |
| 802 0, |
| 803 0, |
| 804 0, |
| 805 0, |
| 806 false); |
| 807 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 808 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 809 } |
| 810 |
663 TEST_P(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) { | 811 TEST_P(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) { |
664 const GLsizei kWidth = 3; | 812 const GLsizei kWidth = 3; |
665 const GLsizei kHeight = 3; | 813 const GLsizei kHeight = 3; |
666 const GLint kBytesPerPixel = 4; | 814 const GLint kBytesPerPixel = 4; |
667 const GLint kPackAlignment = 4; | 815 const GLint kPackAlignment = 4; |
668 static const uint8 kExpectedPixels[kWidth * kHeight * kBytesPerPixel] = { | 816 static const uint8 kExpectedPixels[kWidth * kHeight * kBytesPerPixel] = { |
669 12, 13, 14, 255, 19, 18, 19, 255, 13, 14, 18, 255, | 817 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, | 818 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, | 819 31, 34, 39, 255, 32, 37, 32, 255, 34, 39, 37, 255, |
672 }; | 820 }; |
(...skipping 2244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2917 EXPECT_EQ(1, result->GetNumResults()); | 3065 EXPECT_EQ(1, result->GetNumResults()); |
2918 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 3066 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
2919 } | 3067 } |
2920 | 3068 |
2921 // TODO(gman): PixelStorei | 3069 // TODO(gman): PixelStorei |
2922 | 3070 |
2923 // TODO(gman): SwapBuffers | 3071 // TODO(gman): SwapBuffers |
2924 | 3072 |
2925 } // namespace gles2 | 3073 } // namespace gles2 |
2926 } // namespace gpu | 3074 } // namespace gpu |
OLD | NEW |