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 "../unit_test/unit_test.h"
14 #include "libyuv/cpu_id.h"
15 #include "libyuv/rotate_argb.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,
20 int src_height,
21 int dst_width,
22 int dst_height,
23 libyuv::RotationMode mode,
24 int benchmark_iterations,
25 int disable_cpu_flags,
26 int benchmark_cpu_info,
27 const int kBpp) {
28 if (src_width < 1) {
29 src_width = 1;
30 }
31 if (src_height < 1) {
32 src_height = 1;
33 }
34 if (dst_width < 1) {
35 dst_width = 1;
36 }
37 if (dst_height < 1) {
38 dst_height = 1;
39 }
40 int src_stride_argb = src_width * kBpp;
41 int src_argb_plane_size = src_stride_argb * abs(src_height);
42 align_buffer_page_end(src_argb, src_argb_plane_size);
43 for (int i = 0; i < src_argb_plane_size; ++i) {
44 src_argb[i] = fastrand() & 0xff;
45 }
46
47 int dst_stride_argb = dst_width * kBpp;
48 int dst_argb_plane_size = dst_stride_argb * dst_height;
49 align_buffer_page_end(dst_argb_c, dst_argb_plane_size);
50 align_buffer_page_end(dst_argb_opt, dst_argb_plane_size);
51 memset(dst_argb_c, 2, dst_argb_plane_size);
52 memset(dst_argb_opt, 3, dst_argb_plane_size);
53
54 if (kBpp == 1) {
55 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
56 RotatePlane(src_argb, src_stride_argb, dst_argb_c, dst_stride_argb,
57 src_width, src_height, mode);
58
59 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
60 for (int i = 0; i < benchmark_iterations; ++i) {
61 RotatePlane(src_argb, src_stride_argb, 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, dst_argb_c, dst_stride_argb,
67 src_width, src_height, mode);
68
69 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
70 for (int i = 0; i < benchmark_iterations; ++i) {
71 ARGBRotate(src_argb, src_stride_argb, dst_argb_opt, dst_stride_argb,
72 src_width, src_height, mode);
73 }
74 }
75
76 // Rotation should be exact.
77 for (int i = 0; i < dst_argb_plane_size; ++i) {
78 EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]);
79 }
80
81 free_aligned_buffer_page_end(dst_argb_c);
82 free_aligned_buffer_page_end(dst_argb_opt);
83 free_aligned_buffer_page_end(src_argb);
84 }
85
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)86 static void ARGBTestRotate(int src_width,
87 int src_height,
88 int dst_width,
89 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, dst_width, dst_height, mode,
95 benchmark_iterations, disable_cpu_flags, benchmark_cpu_info, 4);
96 }
97
TEST_F(LibYUVRotateTest,ARGBRotate0_Opt)98 TEST_F(LibYUVRotateTest, ARGBRotate0_Opt) {
99 ARGBTestRotate(benchmark_width_, benchmark_height_, benchmark_width_,
100 benchmark_height_, kRotate0, benchmark_iterations_,
101 disable_cpu_flags_, benchmark_cpu_info_);
102 }
103
TEST_F(LibYUVRotateTest,ARGBRotate90_Opt)104 TEST_F(LibYUVRotateTest, ARGBRotate90_Opt) {
105 ARGBTestRotate(benchmark_width_, benchmark_height_, benchmark_height_,
106 benchmark_width_, kRotate90, benchmark_iterations_,
107 disable_cpu_flags_, benchmark_cpu_info_);
108 }
109
TEST_F(LibYUVRotateTest,ARGBRotate180_Opt)110 TEST_F(LibYUVRotateTest, ARGBRotate180_Opt) {
111 ARGBTestRotate(benchmark_width_, benchmark_height_, benchmark_width_,
112 benchmark_height_, kRotate180, benchmark_iterations_,
113 disable_cpu_flags_, benchmark_cpu_info_);
114 }
115
TEST_F(LibYUVRotateTest,ARGBRotate270_Opt)116 TEST_F(LibYUVRotateTest, ARGBRotate270_Opt) {
117 ARGBTestRotate(benchmark_width_, benchmark_height_, benchmark_height_,
118 benchmark_width_, kRotate270, benchmark_iterations_,
119 disable_cpu_flags_, benchmark_cpu_info_);
120 }
121
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)122 static void TestRotatePlane(int src_width,
123 int src_height,
124 int dst_width,
125 int dst_height,
126 libyuv::RotationMode mode,
127 int benchmark_iterations,
128 int disable_cpu_flags,
129 int benchmark_cpu_info) {
130 TestRotateBpp(src_width, src_height, dst_width, dst_height, mode,
131 benchmark_iterations, disable_cpu_flags, benchmark_cpu_info, 1);
132 }
133
TEST_F(LibYUVRotateTest,RotatePlane0_Opt)134 TEST_F(LibYUVRotateTest, RotatePlane0_Opt) {
135 TestRotatePlane(benchmark_width_, benchmark_height_, benchmark_width_,
136 benchmark_height_, kRotate0, benchmark_iterations_,
137 disable_cpu_flags_, benchmark_cpu_info_);
138 }
139
TEST_F(LibYUVRotateTest,RotatePlane90_Opt)140 TEST_F(LibYUVRotateTest, RotatePlane90_Opt) {
141 TestRotatePlane(benchmark_width_, benchmark_height_, benchmark_height_,
142 benchmark_width_, kRotate90, benchmark_iterations_,
143 disable_cpu_flags_, benchmark_cpu_info_);
144 }
145
TEST_F(LibYUVRotateTest,RotatePlane180_Opt)146 TEST_F(LibYUVRotateTest, RotatePlane180_Opt) {
147 TestRotatePlane(benchmark_width_, benchmark_height_, benchmark_width_,
148 benchmark_height_, kRotate180, benchmark_iterations_,
149 disable_cpu_flags_, benchmark_cpu_info_);
150 }
151
TEST_F(LibYUVRotateTest,RotatePlane270_Opt)152 TEST_F(LibYUVRotateTest, RotatePlane270_Opt) {
153 TestRotatePlane(benchmark_width_, benchmark_height_, benchmark_height_,
154 benchmark_width_, kRotate270, benchmark_iterations_,
155 disable_cpu_flags_, benchmark_cpu_info_);
156 }
157
TEST_F(LibYUVRotateTest,DISABLED_RotatePlane0_Odd)158 TEST_F(LibYUVRotateTest, DISABLED_RotatePlane0_Odd) {
159 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
160 benchmark_width_ - 3, benchmark_height_ - 1, kRotate0,
161 benchmark_iterations_, disable_cpu_flags_,
162 benchmark_cpu_info_);
163 }
164
TEST_F(LibYUVRotateTest,DISABLED_RotatePlane90_Odd)165 TEST_F(LibYUVRotateTest, DISABLED_RotatePlane90_Odd) {
166 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
167 benchmark_height_ - 1, benchmark_width_ - 3, kRotate90,
168 benchmark_iterations_, disable_cpu_flags_,
169 benchmark_cpu_info_);
170 }
171
TEST_F(LibYUVRotateTest,DISABLED_RotatePlane180_Odd)172 TEST_F(LibYUVRotateTest, DISABLED_RotatePlane180_Odd) {
173 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
174 benchmark_width_ - 3, benchmark_height_ - 1, kRotate180,
175 benchmark_iterations_, disable_cpu_flags_,
176 benchmark_cpu_info_);
177 }
178
TEST_F(LibYUVRotateTest,DISABLED_RotatePlane270_Odd)179 TEST_F(LibYUVRotateTest, DISABLED_RotatePlane270_Odd) {
180 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
181 benchmark_height_ - 1, benchmark_width_ - 3, kRotate270,
182 benchmark_iterations_, disable_cpu_flags_,
183 benchmark_cpu_info_);
184 }
185
186 } // namespace libyuv
187