| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 ACTION_P(SaveUniquePtrArg, dest) { | 47 ACTION_P(SaveUniquePtrArg, dest) { |
| 48 *dest = std::move(*arg1); | 48 *dest = std::move(*arg1); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Returns true if color in |rect| of |frame| is |color|. | 51 // Returns true if color in |rect| of |frame| is |color|. |
| 52 bool ArePixelsColoredBy(const DesktopFrame& frame, | 52 bool ArePixelsColoredBy(const DesktopFrame& frame, |
| 53 DesktopRect rect, | 53 DesktopRect rect, |
| 54 RgbaColor color) { | 54 RgbaColor color, |
| 55 // updated_region() should cover the painted area. | 55 bool may_partially_draw) { |
| 56 DesktopRegion updated_region(frame.updated_region()); | 56 if (!may_partially_draw) { |
| 57 updated_region.IntersectWith(rect); | 57 // updated_region() should cover the painted area. |
| 58 if (!updated_region.Equals(DesktopRegion(rect))) { | 58 DesktopRegion updated_region(frame.updated_region()); |
| 59 return false; | 59 updated_region.IntersectWith(rect); |
| 60 if (!updated_region.Equals(DesktopRegion(rect))) { |
| 61 return false; |
| 62 } |
| 60 } | 63 } |
| 61 | 64 |
| 62 // Color in the |rect| should be |color|. | 65 // Color in the |rect| should be |color|. |
| 63 uint8_t* row = frame.GetFrameDataAtPos(rect.top_left()); | 66 uint8_t* row = frame.GetFrameDataAtPos(rect.top_left()); |
| 64 for (int i = 0; i < rect.height(); i++) { | 67 for (int i = 0; i < rect.height(); i++) { |
| 65 uint8_t* column = row; | 68 uint8_t* column = row; |
| 66 for (int j = 0; j < rect.width(); j++) { | 69 for (int j = 0; j < rect.width(); j++) { |
| 67 if (color != RgbaColor(column)) { | 70 if (color != RgbaColor(column)) { |
| 68 return false; | 71 return false; |
| 69 } | 72 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 100 drawer->DrawableRegion().height() < kTestArea) { | 103 drawer->DrawableRegion().height() < kTestArea) { |
| 101 LOG(LS_WARNING) << "ScreenDrawer::DrawableRegion() is too small for the " | 104 LOG(LS_WARNING) << "ScreenDrawer::DrawableRegion() is too small for the " |
| 102 "CaptureUpdatedRegion tests."; | 105 "CaptureUpdatedRegion tests."; |
| 103 return; | 106 return; |
| 104 } | 107 } |
| 105 | 108 |
| 106 for (ScreenCapturer* capturer : capturers) { | 109 for (ScreenCapturer* capturer : capturers) { |
| 107 capturer->Start(&callback_); | 110 capturer->Start(&callback_); |
| 108 } | 111 } |
| 109 | 112 |
| 110 // Draw a set of |kRectSize| by |kRectSize| rectangles at (|i|, |i|). One of | 113 // Draw a set of |kRectSize| by |kRectSize| rectangles at (|i|, |i|), or |
| 111 // (controlled by |c|) its primary colors is |i|, and the other two are | 114 // |i| by |i| rectangles at (|kRectSize|, |kRectSize|). One of (controlled |
| 112 // 0xff. So we won't draw a white rectangle. | 115 // by |c|) its primary colors is |i|, and the other two are 0x7f. So we |
| 116 // won't draw a black or white rectangle. |
| 113 for (int c = 0; c < 3; c++) { | 117 for (int c = 0; c < 3; c++) { |
| 118 // A fixed size rectangle. |
| 114 for (int i = 0; i < kTestArea - kRectSize; i += 16) { | 119 for (int i = 0; i < kTestArea - kRectSize; i += 16) { |
| 115 DesktopRect rect = DesktopRect::MakeXYWH(i, i, kRectSize, kRectSize); | 120 DesktopRect rect = DesktopRect::MakeXYWH(i, i, kRectSize, kRectSize); |
| 116 rect.Translate(drawer->DrawableRegion().top_left()); | 121 rect.Translate(drawer->DrawableRegion().top_left()); |
| 117 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), | 122 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), |
| 118 (c == 1 ? (i & 0xff) : 0x7f), | 123 (c == 1 ? (i & 0xff) : 0x7f), |
| 119 (c == 2 ? (i & 0xff) : 0x7f)); | 124 (c == 2 ? (i & 0xff) : 0x7f)); |
| 120 drawer->Clear(); | 125 TestCaptureOneFrame(capturers, drawer.get(), rect, color); |
| 121 drawer->DrawRectangle(rect, color); | 126 } |
| 127 |
| 128 // A variable-size rectangle. |
| 129 for (int i = 0; i < kTestArea - kRectSize; i += 16) { |
| 130 DesktopRect rect = DesktopRect::MakeXYWH(kRectSize, kRectSize, i, i); |
| 131 rect.Translate(drawer->DrawableRegion().top_left()); |
| 132 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), |
| 133 (c == 1 ? (i & 0xff) : 0x7f), |
| 134 (c == 2 ? (i & 0xff) : 0x7f)); |
| 122 TestCaptureOneFrame(capturers, drawer.get(), rect, color); | 135 TestCaptureOneFrame(capturers, drawer.get(), rect, color); |
| 123 } | 136 } |
| 124 } | 137 } |
| 125 } | 138 } |
| 126 | 139 |
| 127 void TestCaptureUpdatedRegion() { | 140 void TestCaptureUpdatedRegion() { |
| 128 TestCaptureUpdatedRegion({capturer_.get()}); | 141 TestCaptureUpdatedRegion({capturer_.get()}); |
| 129 } | 142 } |
| 130 | 143 |
| 131 #if defined(WEBRTC_WIN) | 144 #if defined(WEBRTC_WIN) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 159 | 172 |
| 160 private: | 173 private: |
| 161 // Repeats capturing the frame by using |capturers| one-by-one for 600 times, | 174 // Repeats capturing the frame by using |capturers| one-by-one for 600 times, |
| 162 // typically 30 seconds, until they succeeded captured a |color| rectangle at | 175 // typically 30 seconds, until they succeeded captured a |color| rectangle at |
| 163 // |rect|. This function uses |drawer|->WaitForPendingDraws() between two | 176 // |rect|. This function uses |drawer|->WaitForPendingDraws() between two |
| 164 // attempts to wait for the screen to update. | 177 // attempts to wait for the screen to update. |
| 165 void TestCaptureOneFrame(std::vector<ScreenCapturer*> capturers, | 178 void TestCaptureOneFrame(std::vector<ScreenCapturer*> capturers, |
| 166 ScreenDrawer* drawer, | 179 ScreenDrawer* drawer, |
| 167 DesktopRect rect, | 180 DesktopRect rect, |
| 168 RgbaColor color) { | 181 RgbaColor color) { |
| 182 const int wait_capture_round = 600; |
| 183 drawer->Clear(); |
| 169 size_t succeeded_capturers = 0; | 184 size_t succeeded_capturers = 0; |
| 170 const int wait_capture_round = 600; | |
| 171 for (int i = 0; i < wait_capture_round; i++) { | 185 for (int i = 0; i < wait_capture_round; i++) { |
| 186 drawer->DrawRectangle(rect, color); |
| 172 drawer->WaitForPendingDraws(); | 187 drawer->WaitForPendingDraws(); |
| 173 for (size_t j = 0; j < capturers.size(); j++) { | 188 for (size_t j = 0; j < capturers.size(); j++) { |
| 174 if (capturers[j] == nullptr) { | 189 if (capturers[j] == nullptr) { |
| 175 // ScreenCapturer should return an empty updated_region() if no | 190 // ScreenCapturer should return an empty updated_region() if no |
| 176 // update detected. So we won't test it again if it has captured | 191 // update detected. So we won't test it again if it has captured |
| 177 // the rectangle we drew. | 192 // the rectangle we drew. |
| 178 continue; | 193 continue; |
| 179 } | 194 } |
| 180 std::unique_ptr<DesktopFrame> frame = CaptureFrame(capturers[j]); | 195 std::unique_ptr<DesktopFrame> frame = CaptureFrame(capturers[j]); |
| 181 if (!frame) { | 196 if (!frame) { |
| 182 // CaptureFrame() has triggered an assertion failure already, we | 197 // CaptureFrame() has triggered an assertion failure already, we |
| 183 // only need to return here. | 198 // only need to return here. |
| 184 return; | 199 return; |
| 185 } | 200 } |
| 186 | 201 |
| 187 if (ArePixelsColoredBy(*frame, rect, color)) { | 202 if (ArePixelsColoredBy( |
| 203 *frame, rect, color, drawer->MayDrawIncompleteShapes())) { |
| 188 capturers[j] = nullptr; | 204 capturers[j] = nullptr; |
| 189 succeeded_capturers++; | 205 succeeded_capturers++; |
| 190 } | 206 } |
| 191 } | 207 } |
| 192 | 208 |
| 193 if (succeeded_capturers == capturers.size()) { | 209 if (succeeded_capturers == capturers.size()) { |
| 194 break; | 210 break; |
| 195 } | 211 } |
| 196 } | 212 } |
| 197 | 213 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 EXPECT_FALSE(frame->updated_region().is_empty()); | 288 EXPECT_FALSE(frame->updated_region().is_empty()); |
| 273 DesktopRegion::Iterator it(frame->updated_region()); | 289 DesktopRegion::Iterator it(frame->updated_region()); |
| 274 ASSERT_TRUE(!it.IsAtEnd()); | 290 ASSERT_TRUE(!it.IsAtEnd()); |
| 275 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); | 291 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); |
| 276 it.Advance(); | 292 it.Advance(); |
| 277 EXPECT_TRUE(it.IsAtEnd()); | 293 EXPECT_TRUE(it.IsAtEnd()); |
| 278 } | 294 } |
| 279 | 295 |
| 280 // Disabled due to being flaky due to the fact that it uses rendering / UI, see | 296 // Disabled due to being flaky due to the fact that it uses rendering / UI, see |
| 281 // webrtc/6366. | 297 // webrtc/6366. |
| 282 TEST_F(ScreenCapturerTest, DISABLED_CaptureUpdatedRegion) { | 298 TEST_F(ScreenCapturerTest, CaptureUpdatedRegion) { |
| 283 TestCaptureUpdatedRegion(); | 299 TestCaptureUpdatedRegion(); |
| 284 } | 300 } |
| 285 | 301 |
| 286 // Disabled due to being flaky due to the fact that it uses rendering / UI, see | 302 // Disabled due to being flaky due to the fact that it uses rendering / UI, see |
| 287 // webrtc/6366. | 303 // webrtc/6366. |
| 288 TEST_F(ScreenCapturerTest, DISABLED_TwoCapturers) { | 304 TEST_F(ScreenCapturerTest, TwoCapturers) { |
| 289 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); | 305 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); |
| 290 SetUp(); | 306 SetUp(); |
| 291 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); | 307 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); |
| 292 } | 308 } |
| 293 | 309 |
| 294 #if defined(WEBRTC_WIN) | 310 #if defined(WEBRTC_WIN) |
| 295 | 311 |
| 296 TEST_F(ScreenCapturerTest, UseSharedBuffers) { | 312 TEST_F(ScreenCapturerTest, UseSharedBuffers) { |
| 297 std::unique_ptr<DesktopFrame> frame; | 313 std::unique_ptr<DesktopFrame> frame; |
| 298 EXPECT_CALL(callback_, | 314 EXPECT_CALL(callback_, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 capturer_->SetSharedMemoryFactory( | 367 capturer_->SetSharedMemoryFactory( |
| 352 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); | 368 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); |
| 353 capturer_->Capture(DesktopRegion()); | 369 capturer_->Capture(DesktopRegion()); |
| 354 ASSERT_TRUE(frame); | 370 ASSERT_TRUE(frame); |
| 355 ASSERT_TRUE(frame->shared_memory()); | 371 ASSERT_TRUE(frame->shared_memory()); |
| 356 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); | 372 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
| 357 } | 373 } |
| 358 | 374 |
| 359 // Disabled due to being flaky due to the fact that it uses rendering / UI, see | 375 // Disabled due to being flaky due to the fact that it uses rendering / UI, see |
| 360 // webrtc/6366. | 376 // webrtc/6366. |
| 361 TEST_F(ScreenCapturerTest, DISABLED_CaptureUpdatedRegionWithDirectxCapturer) { | 377 TEST_F(ScreenCapturerTest, CaptureUpdatedRegionWithDirectxCapturer) { |
| 362 if (!CreateDirectxCapturer()) { | 378 if (!CreateDirectxCapturer()) { |
| 363 return; | 379 return; |
| 364 } | 380 } |
| 365 | 381 |
| 366 TestCaptureUpdatedRegion(); | 382 TestCaptureUpdatedRegion(); |
| 367 } | 383 } |
| 368 | 384 |
| 369 // Disabled due to being flaky due to the fact that it uses rendering / UI, see | 385 // Disabled due to being flaky due to the fact that it uses rendering / UI, see |
| 370 // webrtc/6366. | 386 // webrtc/6366. |
| 371 TEST_F(ScreenCapturerTest, DISABLED_TwoDirectxCapturers) { | 387 TEST_F(ScreenCapturerTest, TwoDirectxCapturers) { |
| 372 if (!CreateDirectxCapturer()) { | 388 if (!CreateDirectxCapturer()) { |
| 373 return; | 389 return; |
| 374 } | 390 } |
| 375 | 391 |
| 376 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); | 392 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); |
| 377 RTC_CHECK(CreateDirectxCapturer()); | 393 RTC_CHECK(CreateDirectxCapturer()); |
| 378 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); | 394 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); |
| 379 } | 395 } |
| 380 | 396 |
| 381 // Disabled due to being flaky due to the fact that it uses rendering / UI, see | 397 // Disabled due to being flaky due to the fact that it uses rendering / UI, see |
| 382 // webrtc/6366. | 398 // webrtc/6366. |
| 383 TEST_F(ScreenCapturerTest, DISABLED_CaptureUpdatedRegionWithMagnifierCapturer) { | 399 TEST_F(ScreenCapturerTest, CaptureUpdatedRegionWithMagnifierCapturer) { |
| 384 CreateMagnifierCapturer(); | 400 CreateMagnifierCapturer(); |
| 385 TestCaptureUpdatedRegion(); | 401 TestCaptureUpdatedRegion(); |
| 386 } | 402 } |
| 387 | 403 |
| 388 // Disabled due to being flaky due to the fact that it uses rendering / UI, see | 404 // Disabled due to being flaky due to the fact that it uses rendering / UI, see |
| 389 // webrtc/6366. | 405 // webrtc/6366. |
| 390 TEST_F(ScreenCapturerTest, DISABLED_TwoMagnifierCapturers) { | 406 TEST_F(ScreenCapturerTest, TwoMagnifierCapturers) { |
| 391 CreateMagnifierCapturer(); | 407 CreateMagnifierCapturer(); |
| 392 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); | 408 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); |
| 393 CreateMagnifierCapturer(); | 409 CreateMagnifierCapturer(); |
| 394 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); | 410 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); |
| 395 } | 411 } |
| 396 | 412 |
| 397 // Disabled due to being flaky due to the fact that it uses rendering / UI, see | 413 // Disabled due to being flaky due to the fact that it uses rendering / UI, see |
| 398 // webrtc/6366. | 414 // webrtc/6366. |
| 399 TEST_F(ScreenCapturerTest, | 415 TEST_F(ScreenCapturerTest, |
| 400 DISABLED_MaybeCaptureUpdatedRegionWithDirectxCapturer) { | 416 DISABLED_MaybeCaptureUpdatedRegionWithDirectxCapturer) { |
| 401 // Even DirectX capturer is not supported in current system, we should be able | 417 // Even DirectX capturer is not supported in current system, we should be able |
| 402 // to select a usable capturer. | 418 // to select a usable capturer. |
| 403 MaybeCreateDirectxCapturer(); | 419 MaybeCreateDirectxCapturer(); |
| 404 TestCaptureUpdatedRegion(); | 420 TestCaptureUpdatedRegion(); |
| 405 } | 421 } |
| 406 | 422 |
| 407 #endif // defined(WEBRTC_WIN) | 423 #endif // defined(WEBRTC_WIN) |
| 408 | 424 |
| 409 } // namespace webrtc | 425 } // namespace webrtc |
| OLD | NEW |