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 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
6 #include "base/cpu.h" | 6 #include "base/cpu.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "media/base/djb2.h" | 10 #include "media/base/djb2.h" |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 int diff = yuv_reference_bytes[i] - yuv_converted_bytes[i]; | 650 int diff = yuv_reference_bytes[i] - yuv_converted_bytes[i]; |
651 if (diff < 0) | 651 if (diff < 0) |
652 diff = -diff; | 652 diff = -diff; |
653 error += diff; | 653 error += diff; |
654 } | 654 } |
655 | 655 |
656 // Make sure there's no difference from the reference. | 656 // Make sure there's no difference from the reference. |
657 EXPECT_EQ(0, error); | 657 EXPECT_EQ(0, error); |
658 } | 658 } |
659 | 659 |
660 TEST(YUVConvertTest, ConvertYUVToRGB32Row_MMX) { | |
661 base::CPU cpu; | |
662 if (!cpu.has_mmx()) { | |
663 LOG(WARNING) << "System not supported. Test skipped."; | |
664 return; | |
665 } | |
666 | |
667 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | |
668 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | |
669 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | |
670 ReadYV12Data(&yuv_bytes); | |
671 | |
672 const int kWidth = 167; | |
673 ConvertYUVToRGB32Row_C(yuv_bytes.get(), | |
674 yuv_bytes.get() + kSourceUOffset, | |
675 yuv_bytes.get() + kSourceVOffset, | |
676 rgb_bytes_reference.get(), | |
677 kWidth, | |
678 GetLookupTable(YV12)); | |
679 ConvertYUVToRGB32Row_MMX(yuv_bytes.get(), | |
680 yuv_bytes.get() + kSourceUOffset, | |
681 yuv_bytes.get() + kSourceVOffset, | |
682 rgb_bytes_converted.get(), | |
683 kWidth, | |
684 GetLookupTable(YV12)); | |
685 media::EmptyRegisterState(); | |
686 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | |
687 rgb_bytes_converted.get(), | |
688 kWidth * kBpp)); | |
689 } | |
690 | |
691 TEST(YUVConvertTest, ConvertYUVToRGB32Row_SSE) { | 660 TEST(YUVConvertTest, ConvertYUVToRGB32Row_SSE) { |
692 base::CPU cpu; | 661 base::CPU cpu; |
693 if (!cpu.has_sse()) { | 662 if (!cpu.has_sse()) { |
694 LOG(WARNING) << "System not supported. Test skipped."; | 663 LOG(WARNING) << "System not supported. Test skipped."; |
695 return; | 664 return; |
696 } | 665 } |
697 | 666 |
698 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 667 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); |
699 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | 668 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); |
700 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | 669 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); |
(...skipping 11 matching lines...) Expand all Loading... |
712 yuv_bytes.get() + kSourceVOffset, | 681 yuv_bytes.get() + kSourceVOffset, |
713 rgb_bytes_converted.get(), | 682 rgb_bytes_converted.get(), |
714 kWidth, | 683 kWidth, |
715 GetLookupTable(YV12)); | 684 GetLookupTable(YV12)); |
716 media::EmptyRegisterState(); | 685 media::EmptyRegisterState(); |
717 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 686 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
718 rgb_bytes_converted.get(), | 687 rgb_bytes_converted.get(), |
719 kWidth * kBpp)); | 688 kWidth * kBpp)); |
720 } | 689 } |
721 | 690 |
722 TEST(YUVConvertTest, ScaleYUVToRGB32Row_MMX) { | 691 // 64-bit release + component builds on Windows are too smart and optimizes |
723 base::CPU cpu; | 692 // away the function being tested. |
724 if (!cpu.has_mmx()) { | 693 #if defined(OS_WIN) && (defined(ARCH_CPU_X86) || !defined(COMPONENT_BUILD)) |
725 LOG(WARNING) << "System not supported. Test skipped."; | |
726 return; | |
727 } | |
728 | |
729 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | |
730 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | |
731 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | |
732 ReadYV12Data(&yuv_bytes); | |
733 | |
734 const int kWidth = 167; | |
735 const int kSourceDx = 80000; // This value means a scale down. | |
736 ScaleYUVToRGB32Row_C(yuv_bytes.get(), | |
737 yuv_bytes.get() + kSourceUOffset, | |
738 yuv_bytes.get() + kSourceVOffset, | |
739 rgb_bytes_reference.get(), | |
740 kWidth, | |
741 kSourceDx, | |
742 GetLookupTable(YV12)); | |
743 ScaleYUVToRGB32Row_MMX(yuv_bytes.get(), | |
744 yuv_bytes.get() + kSourceUOffset, | |
745 yuv_bytes.get() + kSourceVOffset, | |
746 rgb_bytes_converted.get(), | |
747 kWidth, | |
748 kSourceDx, | |
749 GetLookupTable(YV12)); | |
750 media::EmptyRegisterState(); | |
751 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | |
752 rgb_bytes_converted.get(), | |
753 kWidth * kBpp)); | |
754 } | |
755 | |
756 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE) { | 694 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE) { |
757 base::CPU cpu; | 695 base::CPU cpu; |
758 if (!cpu.has_sse()) { | 696 if (!cpu.has_sse()) { |
759 LOG(WARNING) << "System not supported. Test skipped."; | 697 LOG(WARNING) << "System not supported. Test skipped."; |
760 return; | 698 return; |
761 } | 699 } |
762 | 700 |
763 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 701 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); |
764 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | 702 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); |
765 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | 703 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); |
(...skipping 14 matching lines...) Expand all Loading... |
780 rgb_bytes_converted.get(), | 718 rgb_bytes_converted.get(), |
781 kWidth, | 719 kWidth, |
782 kSourceDx, | 720 kSourceDx, |
783 GetLookupTable(YV12)); | 721 GetLookupTable(YV12)); |
784 media::EmptyRegisterState(); | 722 media::EmptyRegisterState(); |
785 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 723 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
786 rgb_bytes_converted.get(), | 724 rgb_bytes_converted.get(), |
787 kWidth * kBpp)); | 725 kWidth * kBpp)); |
788 } | 726 } |
789 | 727 |
790 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_MMX) { | |
791 base::CPU cpu; | |
792 if (!cpu.has_mmx()) { | |
793 LOG(WARNING) << "System not supported. Test skipped."; | |
794 return; | |
795 } | |
796 | |
797 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | |
798 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | |
799 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | |
800 ReadYV12Data(&yuv_bytes); | |
801 | |
802 const int kWidth = 167; | |
803 const int kSourceDx = 80000; // This value means a scale down. | |
804 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), | |
805 yuv_bytes.get() + kSourceUOffset, | |
806 yuv_bytes.get() + kSourceVOffset, | |
807 rgb_bytes_reference.get(), | |
808 kWidth, | |
809 kSourceDx, | |
810 GetLookupTable(YV12)); | |
811 LinearScaleYUVToRGB32Row_MMX(yuv_bytes.get(), | |
812 yuv_bytes.get() + kSourceUOffset, | |
813 yuv_bytes.get() + kSourceVOffset, | |
814 rgb_bytes_converted.get(), | |
815 kWidth, | |
816 kSourceDx, | |
817 GetLookupTable(YV12)); | |
818 media::EmptyRegisterState(); | |
819 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | |
820 rgb_bytes_converted.get(), | |
821 kWidth * kBpp)); | |
822 } | |
823 | |
824 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_SSE) { | 728 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_SSE) { |
825 base::CPU cpu; | 729 base::CPU cpu; |
826 if (!cpu.has_sse()) { | 730 if (!cpu.has_sse()) { |
827 LOG(WARNING) << "System not supported. Test skipped."; | 731 LOG(WARNING) << "System not supported. Test skipped."; |
828 return; | 732 return; |
829 } | 733 } |
830 | 734 |
831 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 735 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); |
832 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | 736 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); |
833 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | 737 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); |
(...skipping 13 matching lines...) Expand all Loading... |
847 yuv_bytes.get() + kSourceVOffset, | 751 yuv_bytes.get() + kSourceVOffset, |
848 rgb_bytes_converted.get(), | 752 rgb_bytes_converted.get(), |
849 kWidth, | 753 kWidth, |
850 kSourceDx, | 754 kSourceDx, |
851 GetLookupTable(YV12)); | 755 GetLookupTable(YV12)); |
852 media::EmptyRegisterState(); | 756 media::EmptyRegisterState(); |
853 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 757 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
854 rgb_bytes_converted.get(), | 758 rgb_bytes_converted.get(), |
855 kWidth * kBpp)); | 759 kWidth * kBpp)); |
856 } | 760 } |
| 761 #endif // defined(OS_WIN) && (ARCH_CPU_X86 || COMPONENT_BUILD) |
857 | 762 |
858 TEST(YUVConvertTest, FilterYUVRows_C_OutOfBounds) { | 763 TEST(YUVConvertTest, FilterYUVRows_C_OutOfBounds) { |
859 scoped_ptr<uint8[]> src(new uint8[16]); | 764 scoped_ptr<uint8[]> src(new uint8[16]); |
860 scoped_ptr<uint8[]> dst(new uint8[16]); | 765 scoped_ptr<uint8[]> dst(new uint8[16]); |
861 | 766 |
862 memset(src.get(), 0xff, 16); | 767 memset(src.get(), 0xff, 16); |
863 memset(dst.get(), 0, 16); | 768 memset(dst.get(), 0, 16); |
864 | 769 |
865 media::FilterYUVRows_C(dst.get(), src.get(), src.get(), 1, 255); | 770 media::FilterYUVRows_C(dst.get(), src.get(), src.get(), 1, 255); |
866 | 771 |
867 EXPECT_EQ(255u, dst[0]); | 772 EXPECT_EQ(255u, dst[0]); |
868 for (int i = 1; i < 16; ++i) { | 773 for (int i = 1; i < 16; ++i) { |
869 EXPECT_EQ(0u, dst[i]) << " not equal at " << i; | 774 EXPECT_EQ(0u, dst[i]) << " not equal at " << i; |
870 } | 775 } |
871 } | 776 } |
872 | 777 |
873 #if defined(MEDIA_MMX_INTRINSICS_AVAILABLE) | |
874 TEST(YUVConvertTest, FilterYUVRows_MMX_OutOfBounds) { | |
875 base::CPU cpu; | |
876 if (!cpu.has_mmx()) { | |
877 LOG(WARNING) << "System not supported. Test skipped."; | |
878 return; | |
879 } | |
880 | |
881 scoped_ptr<uint8[]> src(new uint8[16]); | |
882 scoped_ptr<uint8[]> dst(new uint8[16]); | |
883 | |
884 memset(src.get(), 0xff, 16); | |
885 memset(dst.get(), 0, 16); | |
886 | |
887 media::FilterYUVRows_MMX(dst.get(), src.get(), src.get(), 1, 255); | |
888 media::EmptyRegisterState(); | |
889 | |
890 EXPECT_EQ(255u, dst[0]); | |
891 for (int i = 1; i < 16; ++i) { | |
892 EXPECT_EQ(0u, dst[i]); | |
893 } | |
894 } | |
895 #endif // defined(MEDIA_MMX_INTRINSICS_AVAILABLE) | |
896 | |
897 TEST(YUVConvertTest, FilterYUVRows_SSE2_OutOfBounds) { | 778 TEST(YUVConvertTest, FilterYUVRows_SSE2_OutOfBounds) { |
898 base::CPU cpu; | 779 base::CPU cpu; |
899 if (!cpu.has_sse2()) { | 780 if (!cpu.has_sse2()) { |
900 LOG(WARNING) << "System not supported. Test skipped."; | 781 LOG(WARNING) << "System not supported. Test skipped."; |
901 return; | 782 return; |
902 } | 783 } |
903 | 784 |
904 scoped_ptr<uint8[]> src(new uint8[16]); | 785 scoped_ptr<uint8[]> src(new uint8[16]); |
905 scoped_ptr<uint8[]> dst(new uint8[16]); | 786 scoped_ptr<uint8[]> dst(new uint8[16]); |
906 | 787 |
907 memset(src.get(), 0xff, 16); | 788 memset(src.get(), 0xff, 16); |
908 memset(dst.get(), 0, 16); | 789 memset(dst.get(), 0, 16); |
909 | 790 |
910 media::FilterYUVRows_SSE2(dst.get(), src.get(), src.get(), 1, 255); | 791 media::FilterYUVRows_SSE2(dst.get(), src.get(), src.get(), 1, 255); |
911 | 792 |
912 EXPECT_EQ(255u, dst[0]); | 793 EXPECT_EQ(255u, dst[0]); |
913 for (int i = 1; i < 16; ++i) { | 794 for (int i = 1; i < 16; ++i) { |
914 EXPECT_EQ(0u, dst[i]); | 795 EXPECT_EQ(0u, dst[i]); |
915 } | 796 } |
916 } | 797 } |
917 | 798 |
918 #if defined(MEDIA_MMX_INTRINSICS_AVAILABLE) | |
919 TEST(YUVConvertTest, FilterYUVRows_MMX_UnalignedDestination) { | |
920 base::CPU cpu; | |
921 if (!cpu.has_mmx()) { | |
922 LOG(WARNING) << "System not supported. Test skipped."; | |
923 return; | |
924 } | |
925 | |
926 const int kSize = 32; | |
927 scoped_ptr<uint8[]> src(new uint8[kSize]); | |
928 scoped_ptr<uint8[]> dst_sample(new uint8[kSize]); | |
929 scoped_ptr<uint8[]> dst(new uint8[kSize]); | |
930 | |
931 memset(dst_sample.get(), 0, kSize); | |
932 memset(dst.get(), 0, kSize); | |
933 for (int i = 0; i < kSize; ++i) | |
934 src[i] = 100 + i; | |
935 | |
936 media::FilterYUVRows_C(dst_sample.get(), | |
937 src.get(), src.get(), 17, 128); | |
938 | |
939 // Generate an unaligned output address. | |
940 uint8* dst_ptr = | |
941 reinterpret_cast<uint8*>( | |
942 (reinterpret_cast<uintptr_t>(dst.get() + 8) & ~7) + 1); | |
943 media::FilterYUVRows_MMX(dst_ptr, src.get(), src.get(), 17, 128); | |
944 media::EmptyRegisterState(); | |
945 | |
946 EXPECT_EQ(0, memcmp(dst_sample.get(), dst_ptr, 17)); | |
947 } | |
948 #endif // defined(MEDIA_MMX_INTRINSICS_AVAILABLE) | |
949 | |
950 TEST(YUVConvertTest, FilterYUVRows_SSE2_UnalignedDestination) { | 799 TEST(YUVConvertTest, FilterYUVRows_SSE2_UnalignedDestination) { |
951 base::CPU cpu; | 800 base::CPU cpu; |
952 if (!cpu.has_sse2()) { | 801 if (!cpu.has_sse2()) { |
953 LOG(WARNING) << "System not supported. Test skipped."; | 802 LOG(WARNING) << "System not supported. Test skipped."; |
954 return; | 803 return; |
955 } | 804 } |
956 | 805 |
957 const int kSize = 64; | 806 const int kSize = 64; |
958 scoped_ptr<uint8[]> src(new uint8[kSize]); | 807 scoped_ptr<uint8[]> src(new uint8[kSize]); |
959 scoped_ptr<uint8[]> dst_sample(new uint8[kSize]); | 808 scoped_ptr<uint8[]> dst_sample(new uint8[kSize]); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 882 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
1034 rgb_bytes_converted.get(), | 883 rgb_bytes_converted.get(), |
1035 kWidth * kBpp)); | 884 kWidth * kBpp)); |
1036 } | 885 } |
1037 | 886 |
1038 #endif // defined(ARCH_CPU_X86_64) | 887 #endif // defined(ARCH_CPU_X86_64) |
1039 | 888 |
1040 #endif // defined(ARCH_CPU_X86_FAMILY) | 889 #endif // defined(ARCH_CPU_X86_FAMILY) |
1041 | 890 |
1042 } // namespace media | 891 } // namespace media |
OLD | NEW |