| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/capturer/video_frame_capturer_helper.h" | 5 #include "media/video/capture/screen/screen_capturer_helper.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace remoting { | 10 namespace media { |
| 11 | 11 |
| 12 class VideoFrameCapturerHelperTest : public testing::Test { | 12 class ScreenCapturerHelperTest : public testing::Test { |
| 13 protected: | 13 protected: |
| 14 VideoFrameCapturerHelper capturer_helper_; | 14 ScreenCapturerHelper capturer_helper_; |
| 15 }; | 15 }; |
| 16 | 16 |
| 17 bool Equals(const SkRegion& region1, const SkRegion& region2) { | 17 bool Equals(const SkRegion& region1, const SkRegion& region2) { |
| 18 SkRegion::Iterator iter1(region1); | 18 SkRegion::Iterator iter1(region1); |
| 19 SkRegion::Iterator iter2(region2); | 19 SkRegion::Iterator iter2(region2); |
| 20 while (!iter1.done()) { | 20 while (!iter1.done()) { |
| 21 SkIRect rect1 = iter1.rect(); | 21 SkIRect rect1 = iter1.rect(); |
| 22 iter1.next(); | 22 iter1.next(); |
| 23 if (iter2.done()) { | 23 if (iter2.done()) { |
| 24 return false; | 24 return false; |
| 25 } | 25 } |
| 26 SkIRect rect2 = iter2.rect(); | 26 SkIRect rect2 = iter2.rect(); |
| 27 iter2.next(); | 27 iter2.next(); |
| 28 if (rect1 != rect2) { | 28 if (rect1 != rect2) { |
| 29 return false; | 29 return false; |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 if (!iter2.done()) { | 32 if (!iter2.done()) { |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 return true; | 35 return true; |
| 36 } | 36 } |
| 37 | 37 |
| 38 TEST_F(VideoFrameCapturerHelperTest, ClearInvalidRegion) { | 38 TEST_F(ScreenCapturerHelperTest, ClearInvalidRegion) { |
| 39 SkRegion region; | 39 SkRegion region; |
| 40 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4))); | 40 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4))); |
| 41 capturer_helper_.ClearInvalidRegion(); | 41 capturer_helper_.ClearInvalidRegion(); |
| 42 capturer_helper_.SwapInvalidRegion(®ion); | 42 capturer_helper_.SwapInvalidRegion(®ion); |
| 43 ASSERT_TRUE(region.isEmpty()); | 43 ASSERT_TRUE(region.isEmpty()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 TEST_F(VideoFrameCapturerHelperTest, InvalidateRegion) { | 46 TEST_F(ScreenCapturerHelperTest, InvalidateRegion) { |
| 47 SkRegion region; | 47 SkRegion region; |
| 48 capturer_helper_.SwapInvalidRegion(®ion); | 48 capturer_helper_.SwapInvalidRegion(®ion); |
| 49 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeEmpty()), region)); | 49 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeEmpty()), region)); |
| 50 | 50 |
| 51 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4))); | 51 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4))); |
| 52 region.setEmpty(); | 52 region.setEmpty(); |
| 53 capturer_helper_.SwapInvalidRegion(®ion); | 53 capturer_helper_.SwapInvalidRegion(®ion); |
| 54 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4)), region)); | 54 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4)), region)); |
| 55 | 55 |
| 56 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4))); | 56 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4))); |
| 57 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(4, 2, 3, 4))); | 57 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(4, 2, 3, 4))); |
| 58 region.setEmpty(); | 58 region.setEmpty(); |
| 59 capturer_helper_.SwapInvalidRegion(®ion); | 59 capturer_helper_.SwapInvalidRegion(®ion); |
| 60 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(1, 2, 6, 4)), region)); | 60 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(1, 2, 6, 4)), region)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST_F(VideoFrameCapturerHelperTest, InvalidateScreen) { | 63 TEST_F(ScreenCapturerHelperTest, InvalidateScreen) { |
| 64 SkRegion region; | 64 SkRegion region; |
| 65 capturer_helper_.InvalidateScreen(SkISize::Make(12, 34)); | 65 capturer_helper_.InvalidateScreen(SkISize::Make(12, 34)); |
| 66 capturer_helper_.SwapInvalidRegion(®ion); | 66 capturer_helper_.SwapInvalidRegion(®ion); |
| 67 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeWH(12, 34)), region)); | 67 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeWH(12, 34)), region)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST_F(VideoFrameCapturerHelperTest, InvalidateFullScreen) { | 70 TEST_F(ScreenCapturerHelperTest, InvalidateFullScreen) { |
| 71 SkRegion region; | 71 SkRegion region; |
| 72 capturer_helper_.set_size_most_recent(SkISize::Make(12, 34)); | 72 capturer_helper_.set_size_most_recent(SkISize::Make(12, 34)); |
| 73 capturer_helper_.InvalidateFullScreen(); | 73 capturer_helper_.InvalidateFullScreen(); |
| 74 capturer_helper_.SwapInvalidRegion(®ion); | 74 capturer_helper_.SwapInvalidRegion(®ion); |
| 75 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeWH(12, 34)), region)); | 75 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeWH(12, 34)), region)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TEST_F(VideoFrameCapturerHelperTest, SizeMostRecent) { | 78 TEST_F(ScreenCapturerHelperTest, SizeMostRecent) { |
| 79 ASSERT_EQ(SkISize::Make(0, 0), capturer_helper_.size_most_recent()); | 79 ASSERT_EQ(SkISize::Make(0, 0), capturer_helper_.size_most_recent()); |
| 80 capturer_helper_.set_size_most_recent(SkISize::Make(12, 34)); | 80 capturer_helper_.set_size_most_recent(SkISize::Make(12, 34)); |
| 81 ASSERT_EQ(SkISize::Make(12, 34), capturer_helper_.size_most_recent()); | 81 ASSERT_EQ(SkISize::Make(12, 34), capturer_helper_.size_most_recent()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 TEST_F(VideoFrameCapturerHelperTest, SetLogGridSize) { | 84 TEST_F(ScreenCapturerHelperTest, SetLogGridSize) { |
| 85 capturer_helper_.set_size_most_recent(SkISize::Make(10, 10)); | 85 capturer_helper_.set_size_most_recent(SkISize::Make(10, 10)); |
| 86 | 86 |
| 87 SkRegion region; | 87 SkRegion region; |
| 88 capturer_helper_.SwapInvalidRegion(®ion); | 88 capturer_helper_.SwapInvalidRegion(®ion); |
| 89 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeEmpty()), region)); | 89 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeEmpty()), region)); |
| 90 | 90 |
| 91 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); | 91 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); |
| 92 region.setEmpty(); | 92 region.setEmpty(); |
| 93 capturer_helper_.SwapInvalidRegion(®ion); | 93 capturer_helper_.SwapInvalidRegion(®ion); |
| 94 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1)), region)); | 94 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1)), region)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 120 capturer_helper_.SetLogGridSize(0); | 120 capturer_helper_.SetLogGridSize(0); |
| 121 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); | 121 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); |
| 122 region.setEmpty(); | 122 region.setEmpty(); |
| 123 capturer_helper_.SwapInvalidRegion(®ion); | 123 capturer_helper_.SwapInvalidRegion(®ion); |
| 124 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1)), region)); | 124 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1)), region)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void TestExpandRegionToGrid(const SkRegion& region, int log_grid_size, | 127 void TestExpandRegionToGrid(const SkRegion& region, int log_grid_size, |
| 128 const SkRegion& expandedRegionExpected) { | 128 const SkRegion& expandedRegionExpected) { |
| 129 scoped_ptr<SkRegion> expandedRegion1( | 129 scoped_ptr<SkRegion> expandedRegion1( |
| 130 VideoFrameCapturerHelper::ExpandToGrid(region, log_grid_size)); | 130 ScreenCapturerHelper::ExpandToGrid(region, log_grid_size)); |
| 131 ASSERT_TRUE(Equals(expandedRegionExpected, *expandedRegion1)); | 131 ASSERT_TRUE(Equals(expandedRegionExpected, *expandedRegion1)); |
| 132 scoped_ptr<SkRegion> expandedRegion2( | 132 scoped_ptr<SkRegion> expandedRegion2( |
| 133 VideoFrameCapturerHelper::ExpandToGrid(*expandedRegion1, log_grid_size)); | 133 ScreenCapturerHelper::ExpandToGrid(*expandedRegion1, log_grid_size)); |
| 134 ASSERT_TRUE(Equals(*expandedRegion1, *expandedRegion2)); | 134 ASSERT_TRUE(Equals(*expandedRegion1, *expandedRegion2)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void TestExpandRectToGrid(int l, int t, int r, int b, int log_grid_size, | 137 void TestExpandRectToGrid(int l, int t, int r, int b, int log_grid_size, |
| 138 int lExpanded, int tExpanded, | 138 int lExpanded, int tExpanded, |
| 139 int rExpanded, int bExpanded) { | 139 int rExpanded, int bExpanded) { |
| 140 TestExpandRegionToGrid(SkRegion(SkIRect::MakeLTRB(l, t, r, b)), log_grid_size, | 140 TestExpandRegionToGrid(SkRegion(SkIRect::MakeLTRB(l, t, r, b)), log_grid_size, |
| 141 SkRegion(SkIRect::MakeLTRB(lExpanded, tExpanded, | 141 SkRegion(SkIRect::MakeLTRB(lExpanded, tExpanded, |
| 142 rExpanded, bExpanded))); | 142 rExpanded, bExpanded))); |
| 143 } | 143 } |
| 144 | 144 |
| 145 TEST_F(VideoFrameCapturerHelperTest, ExpandToGrid) { | 145 TEST_F(ScreenCapturerHelperTest, ExpandToGrid) { |
| 146 const int LOG_GRID_SIZE = 4; | 146 const int LOG_GRID_SIZE = 4; |
| 147 const int GRID_SIZE = 1 << LOG_GRID_SIZE; | 147 const int GRID_SIZE = 1 << LOG_GRID_SIZE; |
| 148 for (int i = -2; i <= 2; i++) { | 148 for (int i = -2; i <= 2; i++) { |
| 149 int x = i * GRID_SIZE; | 149 int x = i * GRID_SIZE; |
| 150 for (int j = -2; j <= 2; j++) { | 150 for (int j = -2; j <= 2; j++) { |
| 151 int y = j * GRID_SIZE; | 151 int y = j * GRID_SIZE; |
| 152 TestExpandRectToGrid(x + 0, y + 0, x + 1, y + 1, LOG_GRID_SIZE, | 152 TestExpandRectToGrid(x + 0, y + 0, x + 1, y + 1, LOG_GRID_SIZE, |
| 153 x + 0, y + 0, x + GRID_SIZE, y + GRID_SIZE); | 153 x + 0, y + 0, x + GRID_SIZE, y + GRID_SIZE); |
| 154 TestExpandRectToGrid(x + 0, y + GRID_SIZE - 1, x + 1, y + GRID_SIZE, | 154 TestExpandRectToGrid(x + 0, y + GRID_SIZE - 1, x + 1, y + GRID_SIZE, |
| 155 LOG_GRID_SIZE, | 155 LOG_GRID_SIZE, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 expandedRegionExpected.setRect(SkIRect::MakeLTRB( | 205 expandedRegionExpected.setRect(SkIRect::MakeLTRB( |
| 206 x - GRID_SIZE, y - GRID_SIZE, x + GRID_SIZE, y + GRID_SIZE)); | 206 x - GRID_SIZE, y - GRID_SIZE, x + GRID_SIZE, y + GRID_SIZE)); |
| 207 expandedRegionExpected.op( | 207 expandedRegionExpected.op( |
| 208 SkIRect::MakeLTRB(x + 0, y - GRID_SIZE, x + GRID_SIZE, y + 0), | 208 SkIRect::MakeLTRB(x + 0, y - GRID_SIZE, x + GRID_SIZE, y + 0), |
| 209 SkRegion::kDifference_Op); | 209 SkRegion::kDifference_Op); |
| 210 TestExpandRegionToGrid(region, LOG_GRID_SIZE, expandedRegionExpected); | 210 TestExpandRegionToGrid(region, LOG_GRID_SIZE, expandedRegionExpected); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace remoting | 215 } // namespace media |
| OLD | NEW |