Chromium Code Reviews| Index: webrtc/modules/desktop_capture/desktop_frame_rotator_unittest.cc |
| diff --git a/webrtc/modules/desktop_capture/desktop_frame_rotator_unittest.cc b/webrtc/modules/desktop_capture/desktop_frame_rotator_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..02db839d890c66d03c397babb18af626f1330e1e |
| --- /dev/null |
| +++ b/webrtc/modules/desktop_capture/desktop_frame_rotator_unittest.cc |
| @@ -0,0 +1,531 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/desktop_capture/desktop_frame_rotator.h" |
| + |
| +#include "webrtc/modules/desktop_capture/desktop_frame.h" |
| +#include "webrtc/modules/desktop_capture/desktop_region.h" |
| +#include "webrtc/modules/desktop_capture/rgba_color.h" |
| +#include "webrtc/modules/desktop_capture/test_utils.h" |
| +#include "webrtc/test/gtest.h" |
| + |
| +namespace webrtc { |
| + |
| +TEST(DesktopFrameRotatorTest, CopyRect3x4) { |
| + // A DesktopFrame of 4-pixel width by 3-pixel height. |
| + BasicDesktopFrame frame(DesktopSize(4, 3)); |
| + for (int i = 0; i < 4; i++) { |
| + for (int j = 0; j < 3; j++) { |
| + PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(4 * j + i)); |
| + } |
| + } |
| + // The frame is |
| + // +---+---+---+---+ |
| + // | 0 | 1 | 2 | 3 | |
| + // +---+---+---+---+ |
| + // | 4 | 5 | 6 | 7 | |
| + // +---+---+---+---+ |
| + // | 8 | 9 |10 |11 | |
| + // +---+---+---+---+ |
| + |
| + { |
| + BasicDesktopFrame target(DesktopSize(4, 3)); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_0, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(frame, target)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(4, 3)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_0, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(frame, target2)); |
| + } |
| + |
| + // After Rotating clock-wise 90 degree |
| + // +---+---+---+ |
| + // | 8 | 4 | 0 | |
| + // +---+---+---+ |
| + // | 9 | 5 | 1 | |
| + // +---+---+---+ |
| + // |10 | 6 | 2 | |
| + // +---+---+---+ |
| + // |11 | 7 | 3 | |
| + // +---+---+---+ |
| + { |
| + BasicDesktopFrame expected(DesktopSize(3, 4)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(8)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(9)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(10)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(11)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(4)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(5)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(6)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(0)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(1)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(2)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 3), RgbaColor(3)); |
| + |
| + BasicDesktopFrame target(DesktopSize(3, 4)); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_90, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(3, 4)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_90, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| + |
| + // After Rotating clock-wise 180 degree |
| + // +---+---+---+---+ |
| + // |11 |10 | 9 | 8 | |
| + // +---+---+---+---+ |
| + // | 7 | 6 | 5 | 4 | |
| + // +---+---+---+---+ |
| + // | 3 | 2 | 1 | 0 | |
| + // +---+---+---+---+ |
| + { |
| + BasicDesktopFrame expected(DesktopSize(4, 3)); |
| + 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.
|
| + PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(10)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(9)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 0), RgbaColor(8)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(5)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 1), RgbaColor(4)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(3)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(2)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(1)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 2), RgbaColor(0)); |
| + |
| + BasicDesktopFrame target(DesktopSize(4, 3)); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_180, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(4, 3)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_180, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| + |
| + // After Rotating clock-wise 270 degree |
| + // +---+---+---+ |
| + // | 3 | 7 |11 | |
| + // +---+---+---+ |
| + // | 2 | 6 |10 | |
| + // +---+---+---+ |
| + // | 1 | 5 | 9 | |
| + // +---+---+---+ |
| + // | 0 | 4 | 8 | |
| + // +---+---+---+ |
| + { |
| + BasicDesktopFrame expected(DesktopSize(3, 4)); |
| + 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.
|
| + PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(2)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(1)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(0)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(5)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(4)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(11)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(10)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(9)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 3), RgbaColor(8)); |
| + |
| + BasicDesktopFrame target(DesktopSize(3, 4)); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_270, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(3, 4)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_270, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| +} |
| + |
| +TEST(DesktopFrameRotatorTest, CopyRect3x5) { |
| + // A DesktopFrame of 5-pixel width by 3-pixel height. |
| + BasicDesktopFrame frame(DesktopSize(5, 3)); |
| + for (int i = 0; i < 5; i++) { |
| + for (int j = 0; j < 3; j++) { |
| + PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(5 * j + i)); |
| + } |
| + } |
| + // The frame is |
| + // +---+---+---+---+---+ |
| + // | 0 | 1 | 2 | 3 | 4 | |
| + // +---+---+---+---+---+ |
| + // | 5 | 6 | 7 | 8 | 9 | |
| + // +---+---+---+---+---+ |
| + // |10 |11 |12 |13 |14 | |
| + // +---+---+---+---+---+ |
| + |
| + { |
| + BasicDesktopFrame target(DesktopSize(5, 3)); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_0, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, frame)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(5, 3)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_0, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, frame)); |
| + } |
| + |
| + // After Rotating clock-wise 90 degree |
| + // +---+---+---+ |
| + // |10 | 5 | 0 | |
| + // +---+---+---+ |
| + // |11 | 6 | 1 | |
| + // +---+---+---+ |
| + // |12 | 7 | 2 | |
| + // +---+---+---+ |
| + // |13 | 8 | 3 | |
| + // +---+---+---+ |
| + // |14 | 9 | 4 | |
| + // +---+---+---+ |
| + { |
| + BasicDesktopFrame expected(DesktopSize(3, 5)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(10)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(11)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(12)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(13)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 4), RgbaColor(14)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(5)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(8)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 4), RgbaColor(9)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(0)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(1)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(2)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 3), RgbaColor(3)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 4), RgbaColor(4)); |
| + |
| + BasicDesktopFrame target(DesktopSize(3, 5)); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_90, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(3, 5)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_90, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| + |
| + // After Rotating clock-wise 180 degree |
| + // +---+---+---+---+---+ |
| + // |14 |13 |12 |11 |10 | |
| + // +---+---+---+---+---+ |
| + // | 9 | 8 | 7 | 6 | 5 | |
| + // +---+---+---+---+---+ |
| + // | 4 | 3 | 2 | 1 | 0 | |
| + // +---+---+---+---+---+ |
| + { |
| + BasicDesktopFrame expected(DesktopSize(5, 3)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(14)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(13)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(12)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 0), RgbaColor(11)); |
| + PaintDesktopFrame(&expected, DesktopVector(4, 0), RgbaColor(10)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(9)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(8)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 1), RgbaColor(6)); |
| + PaintDesktopFrame(&expected, DesktopVector(4, 1), RgbaColor(5)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(4)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(3)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(2)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 2), RgbaColor(1)); |
| + PaintDesktopFrame(&expected, DesktopVector(4, 2), RgbaColor(0)); |
| + |
| + BasicDesktopFrame target(DesktopSize(5, 3)); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_180, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(5, 3)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_180, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| + |
| + // After Rotating clock-wise 270 degree |
| + // +---+---+---+ |
| + // | 4 | 9 |14 | |
| + // +---+---+---+ |
| + // | 3 | 8 |13 | |
| + // +---+---+---+ |
| + // | 2 | 7 |12 | |
| + // +---+---+---+ |
| + // | 1 | 6 |11 | |
| + // +---+---+---+ |
| + // | 0 | 5 |10 | |
| + // +---+---+---+ |
| + { |
| + BasicDesktopFrame expected(DesktopSize(3, 5)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 0), RgbaColor(4)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(3)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(2)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(1)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 4), RgbaColor(0)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(9)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(8)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(6)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 4), RgbaColor(5)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(14)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(13)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 2), RgbaColor(12)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 3), RgbaColor(11)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 4), RgbaColor(10)); |
| + |
| + BasicDesktopFrame target(DesktopSize(3, 5)); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeSize(frame.size()), |
| + Rotation::CLOCK_WISE_270, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(3, 5)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_270, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| +} |
| + |
| +TEST(DesktopFrameRotatorTest, PartialCopyRect3x5) { |
| + // A DesktopFrame of 5-pixel width by 3-pixel height. |
| + BasicDesktopFrame frame(DesktopSize(5, 3)); |
| + for (int i = 0; i < 5; i++) { |
| + for (int j = 0; j < 3; j++) { |
| + PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(5 * j + i)); |
| + } |
| + } |
| + // The frame is |
| + // +---+---+---+---+---+ |
| + // | 0 | 1 | 2 | 3 | 4 | |
| + // +---+---+---+---+---+ |
| + // | 5 | 6 | 7 | 8 | 9 | |
| + // +---+---+---+---+---+ |
| + // |10 |11 |12 |13 |14 | |
| + // +---+---+---+---+---+ |
| + |
| + { |
| + BasicDesktopFrame expected(DesktopSize(5, 3)); |
| + ClearDesktopFrame(&expected); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 1), RgbaColor(8)); |
| + |
| + BasicDesktopFrame target(DesktopSize(5, 3)); |
| + ClearDesktopFrame(&target); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1), |
| + Rotation::CLOCK_WISE_0, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(5, 3)); |
| + ClearDesktopFrame(&target2); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1), |
| + Rotation::CLOCK_WISE_0, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + |
| + PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(1)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(2)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 0), RgbaColor(3)); |
| + |
| + ClearDesktopFrame(&target); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2), |
| + Rotation::CLOCK_WISE_0, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + ClearDesktopFrame(&target2); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2), |
| + Rotation::CLOCK_WISE_0, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| + |
| + // After Rotating clock-wise 90 degree |
| + // +---+---+---+ |
| + // |10 | 5 | 0 | |
| + // +---+---+---+ |
| + // |11 | 6 | 1 | |
| + // +---+---+---+ |
| + // |12 | 7 | 2 | |
| + // +---+---+---+ |
| + // |13 | 8 | 3 | |
| + // +---+---+---+ |
| + // |14 | 9 | 4 | |
| + // +---+---+---+ |
| + { |
| + BasicDesktopFrame expected(DesktopSize(3, 5)); |
| + ClearDesktopFrame(&expected); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(6)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(8)); |
| + |
| + BasicDesktopFrame target(DesktopSize(3, 5)); |
| + ClearDesktopFrame(&target); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1), |
| + Rotation::CLOCK_WISE_90, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(3, 5)); |
| + ClearDesktopFrame(&target2); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 1, 3), |
| + Rotation::CLOCK_WISE_90, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + |
| + PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(11)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(12)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(13)); |
| + |
| + ClearDesktopFrame(&target); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 2), |
| + Rotation::CLOCK_WISE_90, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + ClearDesktopFrame(&target2); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(0, 1, 2, 3), |
| + Rotation::CLOCK_WISE_90, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| + |
| + // After Rotating clock-wise 180 degree |
| + // +---+---+---+---+---+ |
| + // |14 |13 |12 |11 |10 | |
| + // +---+---+---+---+---+ |
| + // | 9 | 8 | 7 | 6 | 5 | |
| + // +---+---+---+---+---+ |
| + // | 4 | 3 | 2 | 1 | 0 | |
| + // +---+---+---+---+---+ |
| + { |
| + BasicDesktopFrame expected(DesktopSize(5, 3)); |
| + ClearDesktopFrame(&expected); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(8)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 1), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 1), RgbaColor(6)); |
| + |
| + BasicDesktopFrame target(DesktopSize(5, 3)); |
| + ClearDesktopFrame(&target); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1), |
| + Rotation::CLOCK_WISE_180, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(5, 3)); |
| + ClearDesktopFrame(&target2); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1), |
| + Rotation::CLOCK_WISE_180, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + |
| + PaintDesktopFrame(&expected, DesktopVector(1, 0), RgbaColor(13)); |
| + PaintDesktopFrame(&expected, DesktopVector(2, 0), RgbaColor(12)); |
| + PaintDesktopFrame(&expected, DesktopVector(3, 0), RgbaColor(11)); |
| + |
| + ClearDesktopFrame(&target); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 2), |
| + Rotation::CLOCK_WISE_180, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + ClearDesktopFrame(&target2); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2), |
| + Rotation::CLOCK_WISE_180, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| + |
| + // After Rotating clock-wise 270 degree |
| + // +---+---+---+ |
| + // | 4 | 9 |14 | |
| + // +---+---+---+ |
| + // | 3 | 8 |13 | |
| + // +---+---+---+ |
| + // | 2 | 7 |12 | |
| + // +---+---+---+ |
| + // | 1 | 6 |11 | |
| + // +---+---+---+ |
| + // | 0 | 5 |10 | |
| + // +---+---+---+ |
| + { |
| + BasicDesktopFrame expected(DesktopSize(3, 5)); |
| + ClearDesktopFrame(&expected); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 1), RgbaColor(8)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 2), RgbaColor(7)); |
| + PaintDesktopFrame(&expected, DesktopVector(1, 3), RgbaColor(6)); |
| + |
| + BasicDesktopFrame target(DesktopSize(3, 5)); |
| + ClearDesktopFrame(&target); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 3, 1), |
| + Rotation::CLOCK_WISE_270, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + BasicDesktopFrame target2(DesktopSize(3, 5)); |
| + ClearDesktopFrame(&target2); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(1, 1, 1, 3), |
| + Rotation::CLOCK_WISE_270, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + |
| + PaintDesktopFrame(&expected, DesktopVector(0, 1), RgbaColor(3)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 2), RgbaColor(2)); |
| + PaintDesktopFrame(&expected, DesktopVector(0, 3), RgbaColor(1)); |
| + |
| + ClearDesktopFrame(&target); |
| + ASSERT_TRUE(CopyUnrotatedRectTo(frame, DesktopRect::MakeXYWH(1, 0, 3, 2), |
| + Rotation::CLOCK_WISE_270, &target)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target, expected)); |
| + |
| + ClearDesktopFrame(&target2); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeXYWH(0, 1, 2, 3), |
| + Rotation::CLOCK_WISE_270, &target2)); |
| + ASSERT_TRUE(DesktopFrameDataEquals(target2, expected)); |
| + } |
| +} |
| + |
| +// On a typical machine (Intel(R) Xeon(R) E5-1650 v3 @ 3.50GHz, with O2 |
| +// optimization, the following case uses ~1.4s to finish. It means entirely |
| +// rotating one 2048 x 1536 frame, which is a large enough number to cover most |
| +// of desktop computer users, uses around 14ms. |
| +TEST(DesktopFrameRotatorTest, DISABLED_PerformanceTest) { |
| + BasicDesktopFrame frame(DesktopSize(2048, 1536)); |
| + BasicDesktopFrame target(DesktopSize(1536, 2048)); |
| + BasicDesktopFrame target2(DesktopSize(2048, 1536)); |
| + for (int i = 0; i < 100; i++) { |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()), |
| + Rotation::CLOCK_WISE_90, &target)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()), |
| + Rotation::CLOCK_WISE_270, &target)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_0, &target2)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_180, &target2)); |
| + } |
| +} |
| + |
| +// On a typical machine (Intel(R) Xeon(R) E5-1650 v3 @ 3.50GHz, with O2 |
| +// optimization, the following case uses ~6.7s to finish. It means entirely |
| +// 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.
|
| +TEST(DesktopFrameRotatorTest, DISABLED_PerformanceTestOnLargeScreen) { |
| + BasicDesktopFrame frame(DesktopSize(4096, 3072)); |
| + BasicDesktopFrame target(DesktopSize(3072, 4096)); |
| + BasicDesktopFrame target2(DesktopSize(4096, 3072)); |
| + for (int i = 0; i < 100; i++) { |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()), |
| + Rotation::CLOCK_WISE_90, &target)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target.size()), |
| + Rotation::CLOCK_WISE_270, &target)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_0, &target2)); |
| + ASSERT_TRUE(CopyRotatedRectTo(frame, DesktopRect::MakeSize(target2.size()), |
| + Rotation::CLOCK_WISE_180, &target2)); |
| + } |
| +} |
| + |
| +} // namespace webrtc |