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