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

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 TEST(DesktopFrameRotatorTest, CopyRect3x4) {
22 // A DesktopFrame of 4-pixel width by 3-pixel height.
23 BasicDesktopFrame frame(DesktopSize(4, 3));
24 for (int i = 0; i < 4; i++) {
25 for (int j = 0; j < 3; j++) {
26 PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(4 * j + i));
27 }
28 }
29 // The frame is
30 // +---+---+---+---+
31 // | 0 | 1 | 2 | 3 |
32 // +---+---+---+---+
33 // | 4 | 5 | 6 | 7 |
34 // +---+---+---+---+
35 // | 8 | 9 |10 |11 |
36 // +---+---+---+---+
37
38 {
39 BasicDesktopFrame target(DesktopSize(4, 3));
40 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
41 Rotation::CLOCK_WISE_0, &target));
42 ASSERT_TRUE(DesktopFrameDataEquals(frame, target));
43
44 BasicDesktopFrame target2(DesktopSize(4, 3));
45 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
46 Rotation::CLOCK_WISE_0, &target2));
47 ASSERT_TRUE(DesktopFrameDataEquals(frame, target2));
48 }
49
50 // After Rotating clock-wise 90 degree
51 // +---+---+---+
52 // | 8 | 4 | 0 |
53 // +---+---+---+
54 // | 9 | 5 | 1 |
55 // +---+---+---+
56 // |10 | 6 | 2 |
57 // +---+---+---+
58 // |11 | 7 | 3 |
59 // +---+---+---+
60 {
61 BasicDesktopFrame expected(DesktopSize(3, 4));
62 PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(8));
63 PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(9));
64 PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(10));
65 PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(11));
66 PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(4));
67 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(5));
68 PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(6));
69 PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(7));
70 PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(0));
71 PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(1));
72 PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(2));
73 PaintDesktopFrame(&expected, DesktopVector(2, 3), RgbaColor(3));
74
75 BasicDesktopFrame target(DesktopSize(3, 4));
76 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
77 Rotation::CLOCK_WISE_90, &target));
78 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
79
80 BasicDesktopFrame target2(DesktopSize(3, 4));
81 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
82 Rotation::CLOCK_WISE_90, &target2));
83 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
84 }
85
86 // After Rotating clock-wise 180 degree
87 // +---+---+---+---+
88 // |11 |10 | 9 | 8 |
89 // +---+---+---+---+
90 // | 7 | 6 | 5 | 4 |
91 // +---+---+---+---+
92 // | 3 | 2 | 1 | 0 |
93 // +---+---+---+---+
94 {
95 BasicDesktopFrame expected(DesktopSize(4, 3));
96 PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(11));
Sergey Ulanov 2016/11/15 20:50:22 This code would be much simpler with a simple memc
Hzj_jie 2016/11/16 01:18:33 Done.
97 PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(10));
98 PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(9));
99 PaintDesktopFrame(&expected, DesktopVector(3, 0), RgbaColor(8));
100 PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(7));
101 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6));
102 PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(5));
103 PaintDesktopFrame(&expected, DesktopVector(3, 1), RgbaColor(4));
104 PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(3));
105 PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(2));
106 PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(1));
107 PaintDesktopFrame(&expected, DesktopVector(3, 2), RgbaColor(0));
108
109 BasicDesktopFrame target(DesktopSize(4, 3));
110 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
111 Rotation::CLOCK_WISE_180, &target));
112 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
113
114 BasicDesktopFrame target2(DesktopSize(4, 3));
115 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
116 Rotation::CLOCK_WISE_180, &target2));
117 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
118 }
119
120 // After Rotating clock-wise 270 degree
121 // +---+---+---+
122 // | 3 | 7 |11 |
123 // +---+---+---+
124 // | 2 | 6 |10 |
125 // +---+---+---+
126 // | 1 | 5 | 9 |
127 // +---+---+---+
128 // | 0 | 4 | 8 |
129 // +---+---+---+
130 {
131 BasicDesktopFrame expected(DesktopSize(3, 4));
132 PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(3));
Sergey Ulanov 2016/11/15 20:50:22 Instead of initializing expected frame, maybe just
Hzj_jie 2016/11/16 01:18:33 Good point. Updated.
133 PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(2));
134 PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(1));
135 PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(0));
136 PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(7));
137 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6));
138 PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(5));
139 PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(4));
140 PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(11));
141 PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(10));
142 PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(9));
143 PaintDesktopFrame(&expected, DesktopVector(2, 3), RgbaColor(8));
144
145 BasicDesktopFrame target(DesktopSize(3, 4));
146 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
147 Rotation::CLOCK_WISE_270, &target));
148 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
149
150 BasicDesktopFrame target2(DesktopSize(3, 4));
151 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
152 Rotation::CLOCK_WISE_270, &target2));
153 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
154 }
155 }
156
157 TEST(DesktopFrameRotatorTest, CopyRect3x5) {
158 // A DesktopFrame of 5-pixel width by 3-pixel height.
159 BasicDesktopFrame frame(DesktopSize(5, 3));
160 for (int i = 0; i < 5; i++) {
161 for (int j = 0; j < 3; j++) {
162 PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(5 * j + i));
163 }
164 }
165 // The frame is
166 // +---+---+---+---+---+
167 // | 0 | 1 | 2 | 3 | 4 |
168 // +---+---+---+---+---+
169 // | 5 | 6 | 7 | 8 | 9 |
170 // +---+---+---+---+---+
171 // |10 |11 |12 |13 |14 |
172 // +---+---+---+---+---+
173
174 {
175 BasicDesktopFrame target(DesktopSize(5, 3));
176 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
177 Rotation::CLOCK_WISE_0, &target));
178 ASSERT_TRUE(DesktopFrameDataEquals(target, frame));
179
180 BasicDesktopFrame target2(DesktopSize(5, 3));
181 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
182 Rotation::CLOCK_WISE_0, &target2));
183 ASSERT_TRUE(DesktopFrameDataEquals(target2, frame));
184 }
185
186 // After Rotating clock-wise 90 degree
187 // +---+---+---+
188 // |10 | 5 | 0 |
189 // +---+---+---+
190 // |11 | 6 | 1 |
191 // +---+---+---+
192 // |12 | 7 | 2 |
193 // +---+---+---+
194 // |13 | 8 | 3 |
195 // +---+---+---+
196 // |14 | 9 | 4 |
197 // +---+---+---+
198 {
199 BasicDesktopFrame expected(DesktopSize(3, 5));
200 PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(10));
201 PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(11));
202 PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(12));
203 PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(13));
204 PaintDesktopFrame(&expected, DesktopVector(0, 4), RgbaColor(14));
205 PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(5));
206 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6));
207 PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(7));
208 PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(8));
209 PaintDesktopFrame(&expected, DesktopVector(1, 4), RgbaColor(9));
210 PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(0));
211 PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(1));
212 PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(2));
213 PaintDesktopFrame(&expected, DesktopVector(2, 3), RgbaColor(3));
214 PaintDesktopFrame(&expected, DesktopVector(2, 4), RgbaColor(4));
215
216 BasicDesktopFrame target(DesktopSize(3, 5));
217 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
218 Rotation::CLOCK_WISE_90, &target));
219 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
220
221 BasicDesktopFrame target2(DesktopSize(3, 5));
222 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
223 Rotation::CLOCK_WISE_90, &target2));
224 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
225 }
226
227 // After Rotating clock-wise 180 degree
228 // +---+---+---+---+---+
229 // |14 |13 |12 |11 |10 |
230 // +---+---+---+---+---+
231 // | 9 | 8 | 7 | 6 | 5 |
232 // +---+---+---+---+---+
233 // | 4 | 3 | 2 | 1 | 0 |
234 // +---+---+---+---+---+
235 {
236 BasicDesktopFrame expected(DesktopSize(5, 3));
237 PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(14));
238 PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(13));
239 PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(12));
240 PaintDesktopFrame(&expected, DesktopVector(3, 0), RgbaColor(11));
241 PaintDesktopFrame(&expected, DesktopVector(4, 0), RgbaColor(10));
242 PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(9));
243 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(8));
244 PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(7));
245 PaintDesktopFrame(&expected, DesktopVector(3, 1), RgbaColor(6));
246 PaintDesktopFrame(&expected, DesktopVector(4, 1), RgbaColor(5));
247 PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(4));
248 PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(3));
249 PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(2));
250 PaintDesktopFrame(&expected, DesktopVector(3, 2), RgbaColor(1));
251 PaintDesktopFrame(&expected, DesktopVector(4, 2), RgbaColor(0));
252
253 BasicDesktopFrame target(DesktopSize(5, 3));
254 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
255 Rotation::CLOCK_WISE_180, &target));
256 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
257
258 BasicDesktopFrame target2(DesktopSize(5, 3));
259 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
260 Rotation::CLOCK_WISE_180, &target2));
261 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
262 }
263
264 // After Rotating clock-wise 270 degree
265 // +---+---+---+
266 // | 4 | 9 |14 |
267 // +---+---+---+
268 // | 3 | 8 |13 |
269 // +---+---+---+
270 // | 2 | 7 |12 |
271 // +---+---+---+
272 // | 1 | 6 |11 |
273 // +---+---+---+
274 // | 0 | 5 |10 |
275 // +---+---+---+
276 {
277 BasicDesktopFrame expected(DesktopSize(3, 5));
278 PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(4));
279 PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(3));
280 PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(2));
281 PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(1));
282 PaintDesktopFrame(&expected, DesktopVector(0, 4), RgbaColor(0));
283 PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(9));
284 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(8));
285 PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(7));
286 PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(6));
287 PaintDesktopFrame(&expected, DesktopVector(1, 4), RgbaColor(5));
288 PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(14));
289 PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(13));
290 PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(12));
291 PaintDesktopFrame(&expected, DesktopVector(2, 3), RgbaColor(11));
292 PaintDesktopFrame(&expected, DesktopVector(2, 4), RgbaColor(10));
293
294 BasicDesktopFrame target(DesktopSize(3, 5));
295 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()),
296 Rotation::CLOCK_WISE_270, &target));
297 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
298
299 BasicDesktopFrame target2(DesktopSize(3, 5));
300 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
301 Rotation::CLOCK_WISE_270, &target2));
302 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
303 }
304 }
305
306 TEST(DesktopFrameRotatorTest, PartialCopyRect3x5) {
307 // A DesktopFrame of 5-pixel width by 3-pixel height.
308 BasicDesktopFrame frame(DesktopSize(5, 3));
309 for (int i = 0; i < 5; i++) {
310 for (int j = 0; j < 3; j++) {
311 PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(5 * j + i));
312 }
313 }
314 // The frame is
315 // +---+---+---+---+---+
316 // | 0 | 1 | 2 | 3 | 4 |
317 // +---+---+---+---+---+
318 // | 5 | 6 | 7 | 8 | 9 |
319 // +---+---+---+---+---+
320 // |10 |11 |12 |13 |14 |
321 // +---+---+---+---+---+
322
323 {
324 BasicDesktopFrame expected(DesktopSize(5, 3));
325 ClearDesktopFrame(&expected);
326 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6));
327 PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(7));
328 PaintDesktopFrame(&expected, DesktopVector(3, 1), RgbaColor(8));
329
330 BasicDesktopFrame target(DesktopSize(5, 3));
331 ClearDesktopFrame(&target);
332 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
333 Rotation::CLOCK_WISE_0, &target));
334 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
335
336 BasicDesktopFrame target2(DesktopSize(5, 3));
337 ClearDesktopFrame(&target2);
338 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
339 Rotation::CLOCK_WISE_0, &target2));
340 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
341
342 PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(1));
343 PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(2));
344 PaintDesktopFrame(&expected, DesktopVector(3, 0), RgbaColor(3));
345
346 ClearDesktopFrame(&target);
347 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2),
348 Rotation::CLOCK_WISE_0, &target));
349 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
350
351 ClearDesktopFrame(&target2);
352 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2),
353 Rotation::CLOCK_WISE_0, &target2));
354 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
355 }
356
357 // After Rotating clock-wise 90 degree
358 // +---+---+---+
359 // |10 | 5 | 0 |
360 // +---+---+---+
361 // |11 | 6 | 1 |
362 // +---+---+---+
363 // |12 | 7 | 2 |
364 // +---+---+---+
365 // |13 | 8 | 3 |
366 // +---+---+---+
367 // |14 | 9 | 4 |
368 // +---+---+---+
369 {
370 BasicDesktopFrame expected(DesktopSize(3, 5));
371 ClearDesktopFrame(&expected);
372 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6));
373 PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(7));
374 PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(8));
375
376 BasicDesktopFrame target(DesktopSize(3, 5));
377 ClearDesktopFrame(&target);
378 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
379 Rotation::CLOCK_WISE_90, &target));
380 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
381
382 BasicDesktopFrame target2(DesktopSize(3, 5));
383 ClearDesktopFrame(&target2);
384 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 1, 3),
385 Rotation::CLOCK_WISE_90, &target2));
386 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
387
388 PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(11));
389 PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(12));
390 PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(13));
391
392 ClearDesktopFrame(&target);
393 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 2),
394 Rotation::CLOCK_WISE_90, &target));
395 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
396
397 ClearDesktopFrame(&target2);
398 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(0, 1, 2, 3),
399 Rotation::CLOCK_WISE_90, &target2));
400 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
401 }
402
403 // After Rotating clock-wise 180 degree
404 // +---+---+---+---+---+
405 // |14 |13 |12 |11 |10 |
406 // +---+---+---+---+---+
407 // | 9 | 8 | 7 | 6 | 5 |
408 // +---+---+---+---+---+
409 // | 4 | 3 | 2 | 1 | 0 |
410 // +---+---+---+---+---+
411 {
412 BasicDesktopFrame expected(DesktopSize(5, 3));
413 ClearDesktopFrame(&expected);
414 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(8));
415 PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(7));
416 PaintDesktopFrame(&expected, DesktopVector(3, 1), RgbaColor(6));
417
418 BasicDesktopFrame target(DesktopSize(5, 3));
419 ClearDesktopFrame(&target);
420 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
421 Rotation::CLOCK_WISE_180, &target));
422 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
423
424 BasicDesktopFrame target2(DesktopSize(5, 3));
425 ClearDesktopFrame(&target2);
426 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
427 Rotation::CLOCK_WISE_180, &target2));
428 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
429
430 PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(13));
431 PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(12));
432 PaintDesktopFrame(&expected, DesktopVector(3, 0), RgbaColor(11));
433
434 ClearDesktopFrame(&target);
435 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 2),
436 Rotation::CLOCK_WISE_180, &target));
437 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
438
439 ClearDesktopFrame(&target2);
440 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2),
441 Rotation::CLOCK_WISE_180, &target2));
442 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
443 }
444
445 // After Rotating clock-wise 270 degree
446 // +---+---+---+
447 // | 4 | 9 |14 |
448 // +---+---+---+
449 // | 3 | 8 |13 |
450 // +---+---+---+
451 // | 2 | 7 |12 |
452 // +---+---+---+
453 // | 1 | 6 |11 |
454 // +---+---+---+
455 // | 0 | 5 |10 |
456 // +---+---+---+
457 {
458 BasicDesktopFrame expected(DesktopSize(3, 5));
459 ClearDesktopFrame(&expected);
460 PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(8));
461 PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(7));
462 PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(6));
463
464 BasicDesktopFrame target(DesktopSize(3, 5));
465 ClearDesktopFrame(&target);
466 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1),
467 Rotation::CLOCK_WISE_270, &target));
468 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
469
470 BasicDesktopFrame target2(DesktopSize(3, 5));
471 ClearDesktopFrame(&target2);
472 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 1, 3),
473 Rotation::CLOCK_WISE_270, &target2));
474 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
475
476 PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(3));
477 PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(2));
478 PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(1));
479
480 ClearDesktopFrame(&target);
481 ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2),
482 Rotation::CLOCK_WISE_270, &target));
483 ASSERT_TRUE(DesktopFrameDataEquals(target, expected));
484
485 ClearDesktopFrame(&target2);
486 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(0, 1, 2, 3),
487 Rotation::CLOCK_WISE_270, &target2));
488 ASSERT_TRUE(DesktopFrameDataEquals(target2, expected));
489 }
490 }
491
492 // On a typical machine (Intel(R) Xeon(R) E5-1650 v3 @ 3.50GHz, with O2
493 // optimization, the following case uses ~1.4s to finish. It means entirely
494 // rotating one 2048 x 1536 frame, which is a large enough number to cover most
495 // of desktop computer users, uses around 14ms.
496 TEST(DesktopFrameRotatorTest, DISABLED_PerformanceTest) {
497 BasicDesktopFrame frame(DesktopSize(2048, 1536));
498 BasicDesktopFrame target(DesktopSize(1536, 2048));
499 BasicDesktopFrame target2(DesktopSize(2048, 1536));
500 for (int i = 0; i < 100; i++) {
501 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()),
502 Rotation::CLOCK_WISE_90, &target));
503 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()),
504 Rotation::CLOCK_WISE_270, &target));
505 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
506 Rotation::CLOCK_WISE_0, &target2));
507 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
508 Rotation::CLOCK_WISE_180, &target2));
509 }
510 }
511
512 // On a typical machine (Intel(R) Xeon(R) E5-1650 v3 @ 3.50GHz, with O2
513 // optimization, the following case uses ~6.7s to finish. It means entirely
514 // rotating one 4096 x 3072 frame uses around 67ms.
Sergey Ulanov 2016/11/15 20:50:23 Is that the number you get with libyuv?
Hzj_jie 2016/11/16 01:18:33 Yes.
515 TEST(DesktopFrameRotatorTest, DISABLED_PerformanceTestOnLargeScreen) {
516 BasicDesktopFrame frame(DesktopSize(4096, 3072));
517 BasicDesktopFrame target(DesktopSize(3072, 4096));
518 BasicDesktopFrame target2(DesktopSize(4096, 3072));
519 for (int i = 0; i < 100; i++) {
520 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()),
521 Rotation::CLOCK_WISE_90, &target));
522 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()),
523 Rotation::CLOCK_WISE_270, &target));
524 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
525 Rotation::CLOCK_WISE_0, &target2));
526 ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()),
527 Rotation::CLOCK_WISE_180, &target2));
528 }
529 }
530
531 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698