OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/host/video_frame_capturer_helper.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace remoting { |
| 11 |
| 12 class VideoFrameCapturerHelperTest : public testing::Test { |
| 13 protected: |
| 14 VideoFrameCapturerHelper capturer_helper_; |
| 15 }; |
| 16 |
| 17 bool Equals(const SkRegion& region1, const SkRegion& region2) { |
| 18 SkRegion::Iterator iter1(region1); |
| 19 SkRegion::Iterator iter2(region2); |
| 20 while (!iter1.done()) { |
| 21 SkIRect rect1 = iter1.rect(); |
| 22 iter1.next(); |
| 23 if (iter2.done()) { |
| 24 return false; |
| 25 } |
| 26 SkIRect rect2 = iter2.rect(); |
| 27 iter2.next(); |
| 28 if (rect1 != rect2) { |
| 29 return false; |
| 30 } |
| 31 } |
| 32 if (!iter2.done()) { |
| 33 return false; |
| 34 } |
| 35 return true; |
| 36 } |
| 37 |
| 38 TEST_F(VideoFrameCapturerHelperTest, ClearInvalidRegion) { |
| 39 SkRegion region; |
| 40 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4))); |
| 41 capturer_helper_.ClearInvalidRegion(); |
| 42 capturer_helper_.SwapInvalidRegion(®ion); |
| 43 ASSERT_TRUE(region.isEmpty()); |
| 44 } |
| 45 |
| 46 TEST_F(VideoFrameCapturerHelperTest, InvalidateRegion) { |
| 47 SkRegion region; |
| 48 capturer_helper_.SwapInvalidRegion(®ion); |
| 49 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeEmpty()), region)); |
| 50 |
| 51 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4))); |
| 52 region.setEmpty(); |
| 53 capturer_helper_.SwapInvalidRegion(®ion); |
| 54 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4)), region)); |
| 55 |
| 56 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(1, 2, 3, 4))); |
| 57 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(4, 2, 3, 4))); |
| 58 region.setEmpty(); |
| 59 capturer_helper_.SwapInvalidRegion(®ion); |
| 60 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(1, 2, 6, 4)), region)); |
| 61 } |
| 62 |
| 63 TEST_F(VideoFrameCapturerHelperTest, InvalidateScreen) { |
| 64 SkRegion region; |
| 65 capturer_helper_.InvalidateScreen(SkISize::Make(12, 34)); |
| 66 capturer_helper_.SwapInvalidRegion(®ion); |
| 67 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeWH(12, 34)), region)); |
| 68 } |
| 69 |
| 70 TEST_F(VideoFrameCapturerHelperTest, InvalidateFullScreen) { |
| 71 SkRegion region; |
| 72 capturer_helper_.set_size_most_recent(SkISize::Make(12, 34)); |
| 73 capturer_helper_.InvalidateFullScreen(); |
| 74 capturer_helper_.SwapInvalidRegion(®ion); |
| 75 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeWH(12, 34)), region)); |
| 76 } |
| 77 |
| 78 TEST_F(VideoFrameCapturerHelperTest, SizeMostRecent) { |
| 79 ASSERT_EQ(SkISize::Make(0, 0), capturer_helper_.size_most_recent()); |
| 80 capturer_helper_.set_size_most_recent(SkISize::Make(12, 34)); |
| 81 ASSERT_EQ(SkISize::Make(12, 34), capturer_helper_.size_most_recent()); |
| 82 } |
| 83 |
| 84 TEST_F(VideoFrameCapturerHelperTest, SetLogGridSize) { |
| 85 capturer_helper_.set_size_most_recent(SkISize::Make(10, 10)); |
| 86 |
| 87 SkRegion region; |
| 88 capturer_helper_.SwapInvalidRegion(®ion); |
| 89 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeEmpty()), region)); |
| 90 |
| 91 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); |
| 92 region.setEmpty(); |
| 93 capturer_helper_.SwapInvalidRegion(®ion); |
| 94 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1)), region)); |
| 95 |
| 96 capturer_helper_.SetLogGridSize(-1); |
| 97 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); |
| 98 region.setEmpty(); |
| 99 capturer_helper_.SwapInvalidRegion(®ion); |
| 100 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1)), region)); |
| 101 |
| 102 capturer_helper_.SetLogGridSize(0); |
| 103 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); |
| 104 region.setEmpty(); |
| 105 capturer_helper_.SwapInvalidRegion(®ion); |
| 106 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1)), region)); |
| 107 |
| 108 capturer_helper_.SetLogGridSize(1); |
| 109 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); |
| 110 region.setEmpty(); |
| 111 capturer_helper_.SwapInvalidRegion(®ion); |
| 112 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(6, 6, 2, 2)), region)); |
| 113 |
| 114 capturer_helper_.SetLogGridSize(2); |
| 115 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); |
| 116 region.setEmpty(); |
| 117 capturer_helper_.SwapInvalidRegion(®ion); |
| 118 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(4, 4, 4, 4)), region)); |
| 119 |
| 120 capturer_helper_.SetLogGridSize(0); |
| 121 capturer_helper_.InvalidateRegion(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1))); |
| 122 region.setEmpty(); |
| 123 capturer_helper_.SwapInvalidRegion(®ion); |
| 124 ASSERT_TRUE(Equals(SkRegion(SkIRect::MakeXYWH(7, 7, 1, 1)), region)); |
| 125 } |
| 126 |
| 127 void TestExpandRegionToGrid(const SkRegion& region, int log_grid_size, |
| 128 const SkRegion& expandedRegionExpected) { |
| 129 scoped_ptr<SkRegion> expandedRegion1( |
| 130 VideoFrameCapturerHelper::ExpandToGrid(region, log_grid_size)); |
| 131 ASSERT_TRUE(Equals(expandedRegionExpected, *expandedRegion1)); |
| 132 scoped_ptr<SkRegion> expandedRegion2( |
| 133 VideoFrameCapturerHelper::ExpandToGrid(*expandedRegion1, log_grid_size)); |
| 134 ASSERT_TRUE(Equals(*expandedRegion1, *expandedRegion2)); |
| 135 } |
| 136 |
| 137 void TestExpandRectToGrid(int l, int t, int r, int b, int log_grid_size, |
| 138 int lExpanded, int tExpanded, |
| 139 int rExpanded, int bExpanded) { |
| 140 TestExpandRegionToGrid(SkRegion(SkIRect::MakeLTRB(l, t, r, b)), log_grid_size, |
| 141 SkRegion(SkIRect::MakeLTRB(lExpanded, tExpanded, |
| 142 rExpanded, bExpanded))); |
| 143 } |
| 144 |
| 145 TEST_F(VideoFrameCapturerHelperTest, ExpandToGrid) { |
| 146 const int LOG_GRID_SIZE = 4; |
| 147 const int GRID_SIZE = 1 << LOG_GRID_SIZE; |
| 148 for (int i = -2; i <= 2; i++) { |
| 149 int x = i * GRID_SIZE; |
| 150 for (int j = -2; j <= 2; j++) { |
| 151 int y = j * 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); |
| 154 TestExpandRectToGrid(x + 0, y + GRID_SIZE - 1, x + 1, y + GRID_SIZE, |
| 155 LOG_GRID_SIZE, |
| 156 x + 0, y + 0, x + GRID_SIZE, y + GRID_SIZE); |
| 157 TestExpandRectToGrid(x + GRID_SIZE - 1, y + GRID_SIZE - 1, |
| 158 x + GRID_SIZE, y + GRID_SIZE, LOG_GRID_SIZE, |
| 159 x + 0, y + 0, x + GRID_SIZE, y + GRID_SIZE); |
| 160 TestExpandRectToGrid(x + GRID_SIZE - 1, y + 0, |
| 161 x + GRID_SIZE, y + 1, LOG_GRID_SIZE, |
| 162 x + 0, y + 0, x + GRID_SIZE, y + GRID_SIZE); |
| 163 TestExpandRectToGrid(x - 1, y + 0, x + 1, y + 1, LOG_GRID_SIZE, |
| 164 x - GRID_SIZE, y + 0, x + GRID_SIZE, y + GRID_SIZE); |
| 165 TestExpandRectToGrid(x - 1, y - 1, x + 1, y + 0, LOG_GRID_SIZE, |
| 166 x - GRID_SIZE, y - GRID_SIZE, x + GRID_SIZE, y); |
| 167 TestExpandRectToGrid(x + 0, y - 1, x + 1, y + 1, LOG_GRID_SIZE, |
| 168 x, y - GRID_SIZE, x + GRID_SIZE, y + GRID_SIZE); |
| 169 TestExpandRectToGrid(x - 1, y - 1, x + 0, y + 1, LOG_GRID_SIZE, |
| 170 x - GRID_SIZE, y - GRID_SIZE, x, y + GRID_SIZE); |
| 171 |
| 172 SkRegion region(SkIRect::MakeLTRB(x - 1, y - 1, x + 1, y + 1)); |
| 173 region.op(SkIRect::MakeLTRB(x - 1, y - 1, x + 0, y + 0), |
| 174 SkRegion::kDifference_Op); |
| 175 SkRegion expandedRegionExpected(SkIRect::MakeLTRB( |
| 176 x - GRID_SIZE, y - GRID_SIZE, x + GRID_SIZE, y + GRID_SIZE)); |
| 177 expandedRegionExpected.op( |
| 178 SkIRect::MakeLTRB(x - GRID_SIZE, y - GRID_SIZE, x + 0, y + 0), |
| 179 SkRegion::kDifference_Op); |
| 180 TestExpandRegionToGrid(region, LOG_GRID_SIZE, expandedRegionExpected); |
| 181 |
| 182 region.setRect(SkIRect::MakeLTRB(x - 1, y - 1, x + 1, y + 1)); |
| 183 region.op(SkIRect::MakeLTRB(x - 1, y + 0, x + 0, y + 1), |
| 184 SkRegion::kDifference_Op); |
| 185 expandedRegionExpected.setRect(SkIRect::MakeLTRB( |
| 186 x - GRID_SIZE, y - GRID_SIZE, x + GRID_SIZE, y + GRID_SIZE)); |
| 187 expandedRegionExpected.op( |
| 188 SkIRect::MakeLTRB(x - GRID_SIZE, y + 0, x + 0, y + GRID_SIZE), |
| 189 SkRegion::kDifference_Op); |
| 190 TestExpandRegionToGrid(region, LOG_GRID_SIZE, expandedRegionExpected); |
| 191 |
| 192 region.setRect(SkIRect::MakeLTRB(x - 1, y - 1, x + 1, y + 1)); |
| 193 region.op(SkIRect::MakeLTRB(x + 0, y + 0, x + 1, y + 1), |
| 194 SkRegion::kDifference_Op); |
| 195 expandedRegionExpected.setRect(SkIRect::MakeLTRB( |
| 196 x - GRID_SIZE, y - GRID_SIZE, x + GRID_SIZE, y + GRID_SIZE)); |
| 197 expandedRegionExpected.op( |
| 198 SkIRect::MakeLTRB(x + 0, y + 0, x + GRID_SIZE, y + GRID_SIZE), |
| 199 SkRegion::kDifference_Op); |
| 200 TestExpandRegionToGrid(region, LOG_GRID_SIZE, expandedRegionExpected); |
| 201 |
| 202 region.setRect(SkIRect::MakeLTRB(x - 1, y - 1, x + 1, y + 1)); |
| 203 region.op(SkIRect::MakeLTRB(x + 0, y - 1, x + 1, y + 0), |
| 204 SkRegion::kDifference_Op); |
| 205 expandedRegionExpected.setRect(SkIRect::MakeLTRB( |
| 206 x - GRID_SIZE, y - GRID_SIZE, x + GRID_SIZE, y + GRID_SIZE)); |
| 207 expandedRegionExpected.op( |
| 208 SkIRect::MakeLTRB(x + 0, y - GRID_SIZE, x + GRID_SIZE, y + 0), |
| 209 SkRegion::kDifference_Op); |
| 210 TestExpandRegionToGrid(region, LOG_GRID_SIZE, expandedRegionExpected); |
| 211 } |
| 212 } |
| 213 } |
| 214 |
| 215 } // namespace remoting |
OLD | NEW |