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

Side by Side Diff: webrtc/modules/desktop_capture/desktop_frame_rotator_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_rotator.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"
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(DesktopFrameRotatorTest, 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 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
52 Rotation::CLOCK_WISE_0, &target));
53 ASSERT_TRUE(DesktopFrameDataEquals(frame, target));
54
55 BasicDesktopFrame target2(DesktopSize(4, 3));
56 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
57 Rotation::CLOCK_WISE_0, &target2));
58 ASSERT_TRUE(DesktopFrameDataEquals(frame, target2));
59 }
60
61 // After Rotating clock-wise 90 degree
62 {
63 static uint32_t expected_pixels[] = {
64 8, 4, 0, //
65 9, 5, 1, //
66 10, 6, 2, //
67 11, 7, 3, //
68 };
69 ArrayDesktopFrame expected(DesktopSize(3, 4), expected_pixels);
70
71 BasicDesktopFrame target(DesktopSize(3, 4));
72 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
73 Rotation::CLOCK_WISE_90, &target));
74 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
75
76 BasicDesktopFrame target2(DesktopSize(3, 4));
77 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
78 Rotation::CLOCK_WISE_90, &target2));
79 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
80 }
81
82 // After Rotating clock-wise 180 degree
83 {
84 static uint32_t expected_pixels[] = {
85 11, 10, 9, 8, //
86 7, 6, 5, 4, //
87 3, 2, 1, 0, //
88 };
89 ArrayDesktopFrame expected(DesktopSize(4, 3), expected_pixels);
90
91 BasicDesktopFrame target(DesktopSize(4, 3));
92 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
93 Rotation::CLOCK_WISE_180, &target));
94 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
95
96 BasicDesktopFrame target2(DesktopSize(4, 3));
97 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
98 Rotation::CLOCK_WISE_180, &target2));
99 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
100 }
101
102 // After Rotating clock-wise 270 degree
103 {
104 static uint32_t expected_pixels[] = {
105 3, 7, 11, //
106 2, 6, 10, //
107 1, 5, 9, //
108 0, 4, 8, //
109 };
110 ArrayDesktopFrame expected(DesktopSize(3, 4), expected_pixels);
111
112 BasicDesktopFrame target(DesktopSize(3, 4));
113 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
114 Rotation::CLOCK_WISE_270, &target));
115 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
116
117 BasicDesktopFrame target2(DesktopSize(3, 4));
118 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
119 Rotation::CLOCK_WISE_270, &target2));
120 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
121 }
122 }
123
124 TEST(DesktopFrameRotatorTest, CopyRect3x5) {
125 // A DesktopFrame of 5-pixel width by 3-pixel height.
126 static uint32_t frame_pixels[] = {
127 0, 1, 2, 3, 4, //
128 5, 6, 7, 8, 9, //
129 10, 11, 12, 13, 14, //
130 };
131 ArrayDesktopFrame frame(DesktopSize(5, 3), frame_pixels);
132
133 {
134 BasicDesktopFrame target(DesktopSize(5, 3));
135 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
136 Rotation::CLOCK_WISE_0, &target));
137 ASSERT_TRUE(DesktopFrameDataEquals(target, frame));
138
139 BasicDesktopFrame target2(DesktopSize(5, 3));
140 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
141 Rotation::CLOCK_WISE_0, &target2));
142 ASSERT_TRUE(DesktopFrameDataEquals(target2, frame));
143 }
144
145 // After Rotating clock-wise 90 degree
146 {
147 static uint32_t expected_pixels[] = {
148 10, 5, 0, //
149 11, 6, 1, //
150 12, 7, 2, //
151 13, 8, 3, //
152 14, 9, 4, //
153 };
154 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
155
156 BasicDesktopFrame target(DesktopSize(3, 5));
157 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
158 Rotation::CLOCK_WISE_90, &target));
159 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
160
161 BasicDesktopFrame target2(DesktopSize(3, 5));
162 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
163 Rotation::CLOCK_WISE_90, &target2));
164 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
165 }
166
167 // After Rotating clock-wise 180 degree
168 {
169 static uint32_t expected_pixels[] {
170 14, 13, 12, 11, 10, //
171 9, 8, 7, 6, 5, //
172 4, 3, 2, 1, 0, //
173 };
174 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
175
176 BasicDesktopFrame target(DesktopSize(5, 3));
177 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
178 Rotation::CLOCK_WISE_180, &target));
179 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
180
181 BasicDesktopFrame target2(DesktopSize(5, 3));
182 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
183 Rotation::CLOCK_WISE_180, &target2));
184 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
185 }
186
187 // After Rotating clock-wise 270 degree
188 {
189 static uint32_t expected_pixels[] = {
190 4, 9, 14, //
191 3, 8, 13, //
192 2, 7, 12, //
193 1, 6, 11, //
194 0, 5, 10, //
195 };
196 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
197
198 BasicDesktopFrame target(DesktopSize(3, 5));
199 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
200 Rotation::CLOCK_WISE_270, &target));
201 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
202
203 BasicDesktopFrame target2(DesktopSize(3, 5));
204 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
205 Rotation::CLOCK_WISE_270, &target2));
206 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
207 }
208 }
209
210 TEST(DesktopFrameRotatorTest, PartialCopyRect3x5) {
211 // A DesktopFrame of 5-pixel width by 3-pixel height.
212 static uint32_t frame_pixels[] = {
213 0, 1, 2, 3, 4, //
214 5, 6, 7, 8, 9, //
215 10, 11, 12, 13, 14, //
216 };
217 ArrayDesktopFrame frame(DesktopSize(5, 3), frame_pixels);
218
219 {
220 static uint32_t expected_pixels[] = {
221 0, 0, 0, 0, 0, //
222 0, 6, 7, 8, 0, //
223 0, 0, 0, 0, 0, //
224 };
225 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
226
227 BasicDesktopFrame target(DesktopSize(5, 3));
228 ClearDesktopFrame(&target);
229 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
230 Rotation::CLOCK_WISE_0, &target));
231 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
232
233 BasicDesktopFrame target2(DesktopSize(5, 3));
234 ClearDesktopFrame(&target2);
235 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
236 Rotation::CLOCK_WISE_0, &target2));
237 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
238 }
239
240 {
241 static uint32_t expected_pixels[] = {
242 0, 1, 2, 3, 0, //
243 0, 6, 7, 8, 0, //
244 0, 0, 0, 0, 0, //
245 };
246 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
247
248 BasicDesktopFrame target(DesktopSize(5, 3));
249 ClearDesktopFrame(&target);
250 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2),
251 Rotation::CLOCK_WISE_0, &target));
252 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
253
254 BasicDesktopFrame target2(DesktopSize(5, 3));
255 ClearDesktopFrame(&target2);
256 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2),
257 Rotation::CLOCK_WISE_0, &target2));
258 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
259 }
260
261 // After Rotating clock-wise 90 degree
262 {
263 static uint32_t expected_pixels[] = {
264 0, 0, 0, //
265 0, 6, 0, //
266 0, 7, 0, //
267 0, 8, 0, //
268 0, 0, 0, //
269 };
270 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
271
272 BasicDesktopFrame target(DesktopSize(3, 5));
273 ClearDesktopFrame(&target);
274 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
275 Rotation::CLOCK_WISE_90, &target));
276 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
277
278 BasicDesktopFrame target2(DesktopSize(3, 5));
279 ClearDesktopFrame(&target2);
280 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 1, 3),
281 Rotation::CLOCK_WISE_90, &target2));
282 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
283 }
284
285 {
286 static uint32_t expected_pixels[] = {
287 0, 0, 0, //
288 11, 6, 0, //
289 12, 7, 0, //
290 13, 8, 0, //
291 0, 0, 0, //
292 };
293 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
294
295 BasicDesktopFrame target(DesktopSize(3, 5));
296 ClearDesktopFrame(&target);
297 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 2),
298 Rotation::CLOCK_WISE_90, &target));
299 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
300
301 BasicDesktopFrame target2(DesktopSize(3, 5));
302 ClearDesktopFrame(&target2);
303 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(0, 1, 2, 3),
304 Rotation::CLOCK_WISE_90, &target2));
305 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
306 }
307
308 // After Rotating clock-wise 180 degree
309 {
310 static uint32_t expected_pixels[] = {
311 0, 0, 0, 0, 0, //
312 0, 8, 7, 6, 0, //
313 0, 0, 0, 0, 0, //
314 };
315 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
316
317 BasicDesktopFrame target(DesktopSize(5, 3));
318 ClearDesktopFrame(&target);
319 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
320 Rotation::CLOCK_WISE_180, &target));
321 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
322
323 BasicDesktopFrame target2(DesktopSize(5, 3));
324 ClearDesktopFrame(&target2);
325 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
326 Rotation::CLOCK_WISE_180, &target2));
327 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
328 }
329
330 {
331 static uint32_t expected_pixels[] = {
332 0, 13, 12, 11, 0, //
333 0, 8, 7, 6, 0, //
334 0, 0, 0, 0, 0, //
335 };
336 ArrayDesktopFrame expected(DesktopSize(5, 3), expected_pixels);
337
338 BasicDesktopFrame target(DesktopSize(5, 3));
339 ClearDesktopFrame(&target);
340 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 2),
341 Rotation::CLOCK_WISE_180, &target));
342 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
343
344 BasicDesktopFrame target2(DesktopSize(5, 3));
345 ClearDesktopFrame(&target2);
346 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2),
347 Rotation::CLOCK_WISE_180, &target2));
348 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
349 }
350
351 // After Rotating clock-wise 270 degree
352 {
353 static uint32_t expected_pixels[] = {
354 0, 0, 0, //
355 0, 8, 0, //
356 0, 7, 0, //
357 0, 6, 0, //
358 0, 0, 0, //
359 };
360 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
361
362 BasicDesktopFrame target(DesktopSize(3, 5));
363 ClearDesktopFrame(&target);
364 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
365 Rotation::CLOCK_WISE_270, &target));
366 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
367
368 BasicDesktopFrame target2(DesktopSize(3, 5));
369 ClearDesktopFrame(&target2);
370 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 1, 3),
371 Rotation::CLOCK_WISE_270, &target2));
372 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
373 }
374
375 {
376 static uint32_t expected_pixels[] = {
377 0, 0, 0, //
378 3, 8, 0, //
379 2, 7, 0, //
380 1, 6, 0, //
381 0, 0, 0, //
382 };
383 ArrayDesktopFrame expected(DesktopSize(3, 5), expected_pixels);
384
385 BasicDesktopFrame target(DesktopSize(3, 5));
386 ClearDesktopFrame(&target);
387 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2),
388 Rotation::CLOCK_WISE_270, &target));
389 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
390
391 BasicDesktopFrame target2(DesktopSize(3, 5));
392 ClearDesktopFrame(&target2);
393 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(0, 1, 2, 3),
394 Rotation::CLOCK_WISE_270, &target2));
395 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
396 }
397 }
398
399 // On a typical machine (Intel(R) Xeon(R) E5-1650 v3 @ 3.50GHz, with O2
400 // optimization, the following case uses ~1.4s to finish. It means entirely
401 // rotating one 2048 x 1536 frame, which is a large enough number to cover most
402 // of desktop computer users, uses around 14ms.
403 TEST(DesktopFrameRotatorTest, DISABLED_PerformanceTest) {
404 BasicDesktopFrame frame(DesktopSize(2048, 1536));
405 BasicDesktopFrame target(DesktopSize(1536, 2048));
406 BasicDesktopFrame target2(DesktopSize(2048, 1536));
407 for (int i = 0; i < 100; i++) {
408 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()),
409 Rotation::CLOCK_WISE_90, &target));
410 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()),
411 Rotation::CLOCK_WISE_270, &target));
412 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
413 Rotation::CLOCK_WISE_0, &target2));
414 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
415 Rotation::CLOCK_WISE_180, &target2));
416 }
417 }
418
419 // On a typical machine (Intel(R) Xeon(R) E5-1650 v3 @ 3.50GHz, with O2
420 // optimization, the following case uses ~6.7s to finish. It means entirely
421 // rotating one 4096 x 3072 frame uses around 67ms.
422 TEST(DesktopFrameRotatorTest, DISABLED_PerformanceTestOnLargeScreen) {
423 BasicDesktopFrame frame(DesktopSize(4096, 3072));
424 BasicDesktopFrame target(DesktopSize(3072, 4096));
425 BasicDesktopFrame target2(DesktopSize(4096, 3072));
426 for (int i = 0; i < 100; i++) {
427 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()),
428 Rotation::CLOCK_WISE_90, &target));
429 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()),
430 Rotation::CLOCK_WISE_270, &target));
431 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
432 Rotation::CLOCK_WISE_0, &target2));
433 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
434 Rotation::CLOCK_WISE_180, &target2));
435 }
436 }
437
438 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698