1 /*
2 * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <stdlib.h>
12
13 #include "libyuv/cpu_id.h"
14 #include "libyuv/rotate_argb.h"
15 #include "../unit_test/unit_test.h"
16
17 namespace libyuv {
18
TestRotateBpp(int src_width,int src_height,int dst_width,int dst_height,libyuv::RotationMode mode,int benchmark_iterations,int disable_cpu_flags,int benchmark_cpu_info,const int kBpp)19 void TestRotateBpp(int src_width, int src_height,
20 int dst_width, int dst_height,
21 libyuv::RotationMode mode,
22 int benchmark_iterations,
23 int disable_cpu_flags,
24 int benchmark_cpu_info,
25 const int kBpp) {
26 if (src_width < 1) {
27 src_width = 1;
28 }
29 if (src_height < 1) {
30 src_height = 1;
31 }
32 if (dst_width < 1) {
33 dst_width = 1;
34 }
35 if (dst_height < 1) {
36 dst_height = 1;
37 }
38 int src_stride_argb = src_width * kBpp;
39 int src_argb_plane_size = src_stride_argb * abs(src_height);
40 align_buffer_page_end(src_argb, src_argb_plane_size);
41 for (int i = 0; i < src_argb_plane_size; ++i) {
42 src_argb[i] = fastrand() & 0xff;
43 }
44
45 int dst_stride_argb = dst_width * kBpp;
46 int dst_argb_plane_size = dst_stride_argb * dst_height;
47 align_buffer_page_end(dst_argb_c, dst_argb_plane_size);
48 align_buffer_page_end(dst_argb_opt, dst_argb_plane_size);
49 memset(dst_argb_c, 2, dst_argb_plane_size);
50 memset(dst_argb_opt, 3, dst_argb_plane_size);
51
52 if (kBpp == 1) {
53 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
54 RotatePlane(src_argb, src_stride_argb,
55 dst_argb_c, dst_stride_argb,
56 src_width, src_height, mode);
57
58 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
59 for (int i = 0; i < benchmark_iterations; ++i) {
60 RotatePlane(src_argb, src_stride_argb,
61 dst_argb_opt, dst_stride_argb,
62 src_width, src_height, mode);
63 }
64 } else if (kBpp == 4) {
65 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
66 ARGBRotate(src_argb, src_stride_argb,
67 dst_argb_c, dst_stride_argb,
68 src_width, src_height, mode);
69
70 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
71 for (int i = 0; i < benchmark_iterations; ++i) {
72 ARGBRotate(src_argb, src_stride_argb,
73 dst_argb_opt, dst_stride_argb,
74 src_width, src_height, mode);
75 }
76 }
77
78 // Rotation should be exact.
79 for (int i = 0; i < dst_argb_plane_size; ++i) {
80 EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]);
81 }
82
83 free_aligned_buffer_page_end(dst_argb_c);
84 free_aligned_buffer_page_end(dst_argb_opt);
85 free_aligned_buffer_page_end(src_argb);
86 }
87
ARGBTestRotate(int src_width,int src_height,int dst_width,int dst_height,libyuv::RotationMode mode,int benchmark_iterations,int disable_cpu_flags,int benchmark_cpu_info)88 static void ARGBTestRotate(int src_width, int src_height,
89 int dst_width, int dst_height,
90 libyuv::RotationMode mode,
91 int benchmark_iterations,
92 int disable_cpu_flags,
93 int benchmark_cpu_info) {
94 TestRotateBpp(src_width, src_height,
95 dst_width, dst_height,
96 mode, benchmark_iterations,
97 disable_cpu_flags, benchmark_cpu_info, 4);
98 }
99
TEST_F(LibYUVRotateTest,ARGBRotate0_Opt)100 TEST_F(LibYUVRotateTest, ARGBRotate0_Opt) {
101 ARGBTestRotate(benchmark_width_, benchmark_height_,
102 benchmark_width_, benchmark_height_,
103 kRotate0, benchmark_iterations_,
104 disable_cpu_flags_, benchmark_cpu_info_);
105 }
106
TEST_F(LibYUVRotateTest,ARGBRotate90_Opt)107 TEST_F(LibYUVRotateTest, ARGBRotate90_Opt) {
108 ARGBTestRotate(benchmark_width_, benchmark_height_,
109 benchmark_height_, benchmark_width_,
110 kRotate90, benchmark_iterations_,
111 disable_cpu_flags_, benchmark_cpu_info_);
112 }
113
TEST_F(LibYUVRotateTest,ARGBRotate180_Opt)114 TEST_F(LibYUVRotateTest, ARGBRotate180_Opt) {
115 ARGBTestRotate(benchmark_width_, benchmark_height_,
116 benchmark_width_, benchmark_height_,
117 kRotate180, benchmark_iterations_,
118 disable_cpu_flags_, benchmark_cpu_info_);
119 }
120
TEST_F(LibYUVRotateTest,ARGBRotate270_Opt)121 TEST_F(LibYUVRotateTest, ARGBRotate270_Opt) {
122 ARGBTestRotate(benchmark_width_, benchmark_height_,
123 benchmark_height_, benchmark_width_,
124 kRotate270, benchmark_iterations_,
125 disable_cpu_flags_, benchmark_cpu_info_);
126 }
127
TestRotatePlane(int src_width,int src_height,int dst_width,int dst_height,libyuv::RotationMode mode,int benchmark_iterations,int disable_cpu_flags,int benchmark_cpu_info)128 static void TestRotatePlane(int src_width, int src_height,
129 int dst_width, int dst_height,
130 libyuv::RotationMode mode,
131 int benchmark_iterations,
132 int disable_cpu_flags,
133 int benchmark_cpu_info) {
134 TestRotateBpp(src_width, src_height,
135 dst_width, dst_height,
136 mode, benchmark_iterations,
137 disable_cpu_flags, benchmark_cpu_info, 1);
138 }
139
TEST_F(LibYUVRotateTest,RotatePlane0_Opt)140 TEST_F(LibYUVRotateTest, RotatePlane0_Opt) {
141 TestRotatePlane(benchmark_width_, benchmark_height_,
142 benchmark_width_, benchmark_height_,
143 kRotate0, benchmark_iterations_,
144 disable_cpu_flags_, benchmark_cpu_info_);
145 }
146
TEST_F(LibYUVRotateTest,RotatePlane90_Opt)147 TEST_F(LibYUVRotateTest, RotatePlane90_Opt) {
148 TestRotatePlane(benchmark_width_, benchmark_height_,
149 benchmark_height_, benchmark_width_,
150 kRotate90, benchmark_iterations_,
151 disable_cpu_flags_, benchmark_cpu_info_);
152 }
153
TEST_F(LibYUVRotateTest,RotatePlane180_Opt)154 TEST_F(LibYUVRotateTest, RotatePlane180_Opt) {
155 TestRotatePlane(benchmark_width_, benchmark_height_,
156 benchmark_width_, benchmark_height_,
157 kRotate180, benchmark_iterations_,
158 disable_cpu_flags_, benchmark_cpu_info_);
159 }
160
TEST_F(LibYUVRotateTest,RotatePlane270_Opt)161 TEST_F(LibYUVRotateTest, RotatePlane270_Opt) {
162 TestRotatePlane(benchmark_width_, benchmark_height_,
163 benchmark_height_, benchmark_width_,
164 kRotate270, benchmark_iterations_,
165 disable_cpu_flags_, benchmark_cpu_info_);
166 }
167
TEST_F(LibYUVRotateTest,DISABLED_RotatePlane0_Odd)168 TEST_F(LibYUVRotateTest, DISABLED_RotatePlane0_Odd) {
169 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
170 benchmark_width_ - 3, benchmark_height_ - 1,
171 kRotate0, benchmark_iterations_,
172 disable_cpu_flags_, benchmark_cpu_info_);
173 }
174
TEST_F(LibYUVRotateTest,DISABLED_RotatePlane90_Odd)175 TEST_F(LibYUVRotateTest, DISABLED_RotatePlane90_Odd) {
176 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
177 benchmark_height_ - 1, benchmark_width_ - 3,
178 kRotate90, benchmark_iterations_,
179 disable_cpu_flags_, benchmark_cpu_info_);
180 }
181
TEST_F(LibYUVRotateTest,DISABLED_RotatePlane180_Odd)182 TEST_F(LibYUVRotateTest, DISABLED_RotatePlane180_Odd) {
183 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
184 benchmark_width_ - 3, benchmark_height_ - 1,
185 kRotate180, benchmark_iterations_,
186 disable_cpu_flags_, benchmark_cpu_info_);
187 }
188
TEST_F(LibYUVRotateTest,DISABLED_RotatePlane270_Odd)189 TEST_F(LibYUVRotateTest, DISABLED_RotatePlane270_Odd) {
190 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
191 benchmark_height_ - 1, benchmark_width_ - 3,
192 kRotate270, benchmark_iterations_,
193 disable_cpu_flags_, benchmark_cpu_info_);
194 }
195
196 } // namespace libyuv
197