Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: webrtc/modules/desktop_capture/desktop_frame_rotation_unittest.cc

Issue 2500883004: Add DesktopFrame rotation functions (Closed)
Patch Set: Resolve review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC 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 "webrtc/modules/desktop_capture/desktop_frame_rotation.h"
12
13 #include "webrtc/modules/desktop_capture/desktop_frame.h"
14 #include "webrtc/modules/desktop_capture/desktop_region.h"
15 #include "webrtc/modules/desktop_capture/rgba_color.h"
Sergey Ulanov 2016/11/19 02:11:40 This doesn't seem to be used anywhere
Hzj_jie 2016/11/19 05:10:59 Done.
16 #include "webrtc/modules/desktop_capture/test_utils.h"
17 #include "webrtc/test/gtest.h"
18
19 namespace webrtc {
20
21 namespace {
22
23 // A DesktopFrame implementation which stores data in external int array.
24 class ArrayDesktopFrame : public DesktopFrame {
25 public:
26 ArrayDesktopFrame(DesktopSize size, uint32_t* data);
27 ~ArrayDesktopFrame() override;
28 };
29
30 ArrayDesktopFrame::ArrayDesktopFrame(DesktopSize size, uint32_t* data)
31 : DesktopFrame(size,
32 size.width() * kBytesPerPixel,
33 reinterpret_cast<uint8_t*>(data),
34 nullptr) {}
35
36 ArrayDesktopFrame::~ArrayDesktopFrame() = default;
37
38 } // namespace
39
40 TEST(DesktopFrameRotationTest, CopyRect3x4) {
41 // A DesktopFrame of 4-pixel width by 3-pixel height.
42 static uint32_t frame_pixels[] = {
43 0, 1, 2, 3, //
44 4, 5, 6, 7, //
45 8, 9, 10, 11, //
46 };
47 ArrayDesktopFrame frame(DesktopSize(4, 3), frame_pixels);
48
49 {
50 BasicDesktopFrame target(DesktopSize(4, 3));
51 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_0,
52 DesktopRect::MakeSize(target.size()), &target);
53 ASSERT_TRUE(DesktopFrameDataEquals(frame, target));
54 }
55
56 // After Rotating clock-wise 90 degree
57 {
58 static uint32_t expected_pixels[] = {
59 8, 4, 0, //
60 9, 5, 1, //
61 10, 6, 2, //
62 11, 7, 3, //
63 };
64 ArrayDesktopFrame expected(DesktopSize(3, 4), expected_pixels);
65
66 BasicDesktopFrame target(DesktopSize(3, 4));
67 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_90,
68 DesktopRect::MakeSize(target.size()), &target);
69 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
70 }
71
72 // After Rotating clock-wise 180 degree
73 {
74 static uint32_t expected_pixels[] = {
75 11, 10, 9, 8, //
76 7, 6, 5, 4, //
77 3, 2, 1, 0, //
78 };
79 ArrayDesktopFrame expected(DesktopSize(4, 3), expected_pixels);
80
81 BasicDesktopFrame target(DesktopSize(4, 3));
82 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_180,
83 DesktopRect::MakeSize(target.size()), &target);
84 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
85 }
86
87 // After Rotating clock-wise 270 degree
88 {
89 static uint32_t expected_pixels[] = {
90 3, 7, 11, //
91 2, 6, 10, //
92 1, 5, 9, //
93 0, 4, 8, //
94 };
95 ArrayDesktopFrame expected(DesktopSize(3, 4), expected_pixels);
96
97 BasicDesktopFrame target(DesktopSize(3, 4));
98 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_270,
99 DesktopRect::MakeSize(target.size()), &target);
100 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
101 }
102 }
103
104 TEST(DesktopFrameRotationTest, CopyRect3x5) {
105 // A DesktopFrame of 5-pixel width by 3-pixel height.
106 static uint32_t frame_pixels[] = {
107 0, 1, 2, 3, 4, //
108 5, 6, 7, 8, 9, //
109 10, 11, 12, 13, 14, //
110 };
111 ArrayDesktopFrame frame(DesktopSize(5, 3), frame_pixels);
112
113 {
114 BasicDesktopFrame target(DesktopSize(5, 3));
115 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_0,
116 DesktopRect::MakeSize(target.size()), &target);
117 ASSERT_TRUE(DesktopFrameDataEquals(target, frame));
118 }
119
120 // After Rotating clock-wise 90 degree
121 {
122 static uint32_t expected_pixels[] = {
123 10, 5, 0, //
124 11, 6, 1, //
125 12, 7, 2, //
126 13, 8, 3, //
127 14, 9, 4, //
128 };
129 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
130
131 BasicDesktopFrame target(DesktopSize(3, 5));
132 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_90,
133 DesktopRect::MakeSize(target.size()), &target);
134 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
135 }
136
137 // After Rotating clock-wise 180 degree
138 {
139 static uint32_t expected_pixels[] {
140 14, 13, 12, 11, 10, //
141 9, 8, 7, 6, 5, //
142 4, 3, 2, 1, 0, //
143 };
144 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
145
146 BasicDesktopFrame target(DesktopSize(5, 3));
147 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_180,
148 DesktopRect::MakeSize(target.size()), &target);
149 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
150 }
151
152 // After Rotating clock-wise 270 degree
153 {
154 static uint32_t expected_pixels[] = {
155 4, 9, 14, //
156 3, 8, 13, //
157 2, 7, 12, //
158 1, 6, 11, //
159 0, 5, 10, //
160 };
161 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
162
163 BasicDesktopFrame target(DesktopSize(3, 5));
164 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_270,
165 DesktopRect::MakeSize(target.size()), &target);
166 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
167 }
168 }
169
170 TEST(DesktopFrameRotationTest, PartialCopyRect3x5) {
171 // A DesktopFrame of 5-pixel width by 3-pixel height.
172 static uint32_t frame_pixels[] = {
173 0, 1, 2, 3, 4, //
174 5, 6, 7, 8, 9, //
175 10, 11, 12, 13, 14, //
176 };
177 ArrayDesktopFrame frame(DesktopSize(5, 3), frame_pixels);
178
179 {
180 static uint32_t expected_pixels[] = {
181 0, 0, 0, 0, 0, //
182 0, 6, 7, 8, 0, //
183 0, 0, 0, 0, 0, //
184 };
185 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
186
187 BasicDesktopFrame target(DesktopSize(5, 3));
188 ClearDesktopFrame(&target);
189 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_0,
190 DesktopRect::MakeXYWH(1, 1, 3, 1), &target);
191 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
192 }
193
194 {
195 static uint32_t expected_pixels[] = {
196 0, 1, 2, 3, 0, //
197 0, 6, 7, 8, 0, //
198 0, 0, 0, 0, 0, //
199 };
200 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
201
202 BasicDesktopFrame target(DesktopSize(5, 3));
203 ClearDesktopFrame(&target);
204 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_0,
205 DesktopRect::MakeXYWH(1, 0, 3, 2), &target);
206 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
207 }
208
209 // After Rotating clock-wise 90 degree
210 {
211 static uint32_t expected_pixels[] = {
212 0, 0, 0, //
213 0, 6, 0, //
214 0, 7, 0, //
215 0, 8, 0, //
216 0, 0, 0, //
217 };
218 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
219
220 BasicDesktopFrame target(DesktopSize(3, 5));
221 ClearDesktopFrame(&target);
222 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_90,
223 DesktopRect::MakeXYWH(1, 1, 1, 3), &target);
224 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
225 }
226
227 {
228 static uint32_t expected_pixels[] = {
229 0, 0, 0, //
230 11, 6, 0, //
231 12, 7, 0, //
232 13, 8, 0, //
233 0, 0, 0, //
234 };
235 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
236
237 BasicDesktopFrame target(DesktopSize(3, 5));
238 ClearDesktopFrame(&target);
239 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_90,
240 DesktopRect::MakeXYWH(0, 1, 2, 3), &target);
241 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
242 }
243
244 // After Rotating clock-wise 180 degree
245 {
246 static uint32_t expected_pixels[] = {
247 0, 0, 0, 0, 0, //
248 0, 8, 7, 6, 0, //
249 0, 0, 0, 0, 0, //
250 };
251 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
252
253 BasicDesktopFrame target(DesktopSize(5, 3));
254 ClearDesktopFrame(&target);
255 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_180,
256 DesktopRect::MakeXYWH(1, 1, 3, 1), &target);
257 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
258 }
259
260 {
261 static uint32_t expected_pixels[] = {
262 0, 13, 12, 11, 0, //
263 0, 8, 7, 6, 0, //
264 0, 0, 0, 0, 0, //
265 };
266 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
267
268 BasicDesktopFrame target(DesktopSize(5, 3));
269 ClearDesktopFrame(&target);
270 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_180,
271 DesktopRect::MakeXYWH(1, 0, 3, 2), &target);
272 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
273 }
274
275 // After Rotating clock-wise 270 degree
276 {
277 static uint32_t expected_pixels[] = {
278 0, 0, 0, //
279 0, 8, 0, //
280 0, 7, 0, //
281 0, 6, 0, //
282 0, 0, 0, //
283 };
284 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
285
286 BasicDesktopFrame target(DesktopSize(3, 5));
287 ClearDesktopFrame(&target);
288 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_270,
289 DesktopRect::MakeXYWH(1, 1, 1, 3), &target);
290 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
291 }
292
293 {
294 static uint32_t expected_pixels[] = {
295 0, 0, 0, //
296 3, 8, 0, //
297 2, 7, 0, //
298 1, 6, 0, //
299 0, 0, 0, //
300 };
301 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
302
303 BasicDesktopFrame target(DesktopSize(3, 5));
304 ClearDesktopFrame(&target);
305 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_270,
306 DesktopRect::MakeXYWH(0, 1, 2, 3), &target);
307 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
308 }
309 }
310
311 // On a typical machine (Intel(R) Xeon(R) E5-1650 v3 @ 3.50GHz, with O2
312 // optimization, the following case uses ~1.4s to finish. It means entirely
313 // rotating one 2048 x 1536 frame, which is a large enough number to cover most
314 // of desktop computer users, uses around 14ms.
315 TEST(DesktopFrameRotationTest, DISABLED_PerformanceTest) {
316 BasicDesktopFrame frame(DesktopSize(2048, 1536));
317 BasicDesktopFrame target(DesktopSize(1536, 2048));
318 BasicDesktopFrame target2(DesktopSize(2048, 1536));
319 for (int i = 0; i < 100; i++) {
320 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_90,
321 DesktopRect::MakeSize(target.size()), &target);
322 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_270,
323 DesktopRect::MakeSize(target.size()), &target);
324 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_0,
325 DesktopRect::MakeSize(target2.size()), &target2);
326 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_180,
327 DesktopRect::MakeSize(target2.size()), &target2);
328 }
329 }
330
331 // On a typical machine (Intel(R) Xeon(R) E5-1650 v3 @ 3.50GHz, with O2
332 // optimization, the following case uses ~6.7s to finish. It means entirely
333 // rotating one 4096 x 3072 frame uses around 67ms.
334 TEST(DesktopFrameRotationTest, DISABLED_PerformanceTestOnLargeScreen) {
335 BasicDesktopFrame frame(DesktopSize(4096, 3072));
336 BasicDesktopFrame target(DesktopSize(3072, 4096));
337 BasicDesktopFrame target2(DesktopSize(4096, 3072));
338 for (int i = 0; i < 100; i++) {
339 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_90,
340 DesktopRect::MakeSize(target.size()), &target);
341 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_270,
342 DesktopRect::MakeSize(target.size()), &target);
343 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_0,
344 DesktopRect::MakeSize(target2.size()), &target2);
345 RotateDesktopFrame(frame, Rotation::CLOCK_WISE_180,
346 DesktopRect::MakeSize(target2.size()), &target2);
347 }
348 }
349
350 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698