Chromium Code Reviews| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 drawer->DrawableRegion().height() < kTestArea) { | 113 drawer->DrawableRegion().height() < kTestArea) { |
| 114 LOG(LS_WARNING) << "ScreenDrawer::DrawableRegion() is too small for the " | 114 LOG(LS_WARNING) << "ScreenDrawer::DrawableRegion() is too small for the " |
| 115 "CaptureUpdatedRegion tests."; | 115 "CaptureUpdatedRegion tests."; |
| 116 return; | 116 return; |
| 117 } | 117 } |
| 118 | 118 |
| 119 for (ScreenCapturer* capturer : capturers) { | 119 for (ScreenCapturer* capturer : capturers) { |
| 120 capturer->Start(&callback_); | 120 capturer->Start(&callback_); |
| 121 } | 121 } |
| 122 | 122 |
| 123 for (int c = 0; c < 3; c++) { | 123 for (int c = 0; c < 3; c++) { |
|
Sergey Ulanov
2016/09/09 17:23:15
Where does 3 come from? Maybe add a comment here w
Hzj_jie
2016/09/12 23:13:40
Done.
| |
| 124 for (int i = 0; i < kTestArea - kRectSize; i += 16) { | 124 for (int i = 0; i < kTestArea - kRectSize; i += 16) { |
| 125 DesktopRect rect = DesktopRect::MakeXYWH(i, i, kRectSize, kRectSize); | 125 DesktopRect rect = DesktopRect::MakeXYWH(i, i, kRectSize, kRectSize); |
| 126 rect.Translate(drawer->DrawableRegion().top_left()); | 126 rect.Translate(drawer->DrawableRegion().top_left()); |
| 127 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), | 127 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), |
| 128 (c == 1 ? (i & 0xff) : 0x7f), | 128 (c == 1 ? (i & 0xff) : 0x7f), |
| 129 (c == 2 ? (i & 0xff) : 0x7f)); | 129 (c == 2 ? (i & 0xff) : 0x7f)); |
| 130 drawer->Clear(); | 130 drawer->Clear(); |
| 131 drawer->DrawRectangle(rect, color); | 131 drawer->DrawRectangle(rect, color); |
| 132 | 132 |
| 133 const int wait_first_capture_round = 20; | 133 std::vector<ScreenCapturer*> test_capturers(capturers); |
| 134 for (int j = 0; j < wait_first_capture_round; j++) { | 134 size_t succeeded_capturers = 0; |
| 135 const int wait_capture_round = 20; | |
| 136 for (int j = 0; j < wait_capture_round; j++) { | |
|
Sergey Ulanov
2016/09/09 17:23:15
Maybe move this code to a separate function to mak
Hzj_jie
2016/09/12 23:13:41
Sure.
| |
| 135 drawer->WaitForPendingDraws(); | 137 drawer->WaitForPendingDraws(); |
| 136 std::unique_ptr<DesktopFrame> frame = | 138 for (size_t k = 0; k < test_capturers.size(); k++) { |
| 137 CaptureFrame(*capturers.begin(), &callback_); | 139 if (test_capturers[k] == nullptr) { |
| 138 if (!frame) { | 140 // TODO(zijiehe): ScreenCapturerX11 and ScreenCapturerWinGdi |
| 139 return; | 141 // cannot capture a correct frame again if screen does not update. |
|
Sergey Ulanov
2016/09/09 17:23:14
I don't understand this comment. All capturers sho
Hzj_jie
2016/09/12 23:13:40
Emmm, updated.
| |
| 142 continue; | |
| 143 } | |
| 144 std::unique_ptr<DesktopFrame> frame = | |
| 145 CaptureFrame(test_capturers[k], &callback_); | |
| 146 if (!frame) { | |
| 147 return; | |
|
Sergey Ulanov
2016/09/09 17:23:15
Is it appropriate to just return if one of the cap
Hzj_jie
2016/09/12 23:13:41
Not really. CaptureFrame triggers an assertion fai
| |
| 148 } | |
| 149 | |
| 150 if (ArePixelsColoredBy(*frame, rect, color)) { | |
| 151 test_capturers[k] = nullptr; | |
| 152 succeeded_capturers++; | |
| 153 } | |
| 140 } | 154 } |
| 141 | 155 |
| 142 if (ArePixelsColoredBy(*frame, rect, color)) { | 156 if (succeeded_capturers == test_capturers.size()) { |
| 143 // The first capturer successfully captured the frame we expected. | |
| 144 // So the others should also be able to capture it. | |
| 145 break; | 157 break; |
| 146 } else { | |
| 147 ASSERT_LT(j, wait_first_capture_round); | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 for (ScreenCapturer* capturer : capturers) { | |
| 152 if (capturer == *capturers.begin()) { | |
| 153 // TODO(zijiehe): ScreenCapturerX11 and ScreenCapturerWinGdi cannot | |
| 154 // capture a correct frame again if screen does not update. | |
| 155 continue; | |
| 156 } | |
| 157 std::unique_ptr<DesktopFrame> frame = | |
| 158 CaptureFrame(capturer, &callback_); | |
| 159 if (!frame) { | |
| 160 return; | |
| 161 } | 158 } |
| 162 | 159 |
| 163 ASSERT_TRUE(ArePixelsColoredBy(*frame, rect, color)); | 160 ASSERT_LT(j, wait_capture_round); |
| 164 } | 161 } |
| 165 } | 162 } |
| 166 } | 163 } |
| 167 } | 164 } |
| 168 | 165 |
| 169 void TestCaptureUpdatedRegion() { | 166 void TestCaptureUpdatedRegion() { |
| 170 TestCaptureUpdatedRegion({capturer_.get()}); | 167 TestCaptureUpdatedRegion({capturer_.get()}); |
| 171 } | 168 } |
| 172 | 169 |
| 173 #if defined(WEBRTC_WIN) | 170 #if defined(WEBRTC_WIN) |
| 174 bool SetDirectxCapturerMode() { | 171 bool SetDirectxCapturerMode() { |
| 175 if (!ScreenCapturerWinDirectx::IsSupported()) { | 172 if (!ScreenCapturerWinDirectx::IsSupported()) { |
| 176 LOG(LS_WARNING) << "Directx capturer is not supported"; | 173 LOG(LS_WARNING) << "Directx capturer is not supported"; |
| 177 return false; | 174 return false; |
| 178 } | 175 } |
| 179 | 176 |
| 180 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 177 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
| 181 options.set_allow_directx_capturer(true); | 178 options.set_allow_directx_capturer(true); |
| 182 capturer_.reset(ScreenCapturer::Create(options)); | 179 capturer_.reset(ScreenCapturer::Create(options)); |
| 183 return true; | 180 return true; |
| 184 } | 181 } |
| 182 | |
| 183 void SetMagnifierMode() { | |
| 184 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | |
| 185 options.set_allow_use_magnification_api(true); | |
| 186 capturer_.reset(ScreenCapturer::Create(options)); | |
|
Sergey Ulanov
2016/09/09 17:23:15
It doesn't look right that a method called Set*()
Hzj_jie
2016/09/12 23:13:40
Done.
| |
| 187 } | |
| 185 #endif // defined(WEBRTC_WIN) | 188 #endif // defined(WEBRTC_WIN) |
| 186 | 189 |
| 187 std::unique_ptr<ScreenCapturer> capturer_; | 190 std::unique_ptr<ScreenCapturer> capturer_; |
| 188 MockScreenCapturerCallback callback_; | 191 MockScreenCapturerCallback callback_; |
| 189 }; | 192 }; |
| 190 | 193 |
| 191 class FakeSharedMemory : public SharedMemory { | 194 class FakeSharedMemory : public SharedMemory { |
| 192 public: | 195 public: |
| 193 FakeSharedMemory(char* buffer, size_t size) | 196 FakeSharedMemory(char* buffer, size_t size) |
| 194 : SharedMemory(buffer, size, 0, kTestSharedMemoryId), | 197 : SharedMemory(buffer, size, 0, kTestSharedMemoryId), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 ASSERT_TRUE(!it.IsAtEnd()); | 255 ASSERT_TRUE(!it.IsAtEnd()); |
| 253 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); | 256 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); |
| 254 it.Advance(); | 257 it.Advance(); |
| 255 EXPECT_TRUE(it.IsAtEnd()); | 258 EXPECT_TRUE(it.IsAtEnd()); |
| 256 } | 259 } |
| 257 | 260 |
| 258 TEST_F(ScreenCapturerTest, CaptureUpdatedRegion) { | 261 TEST_F(ScreenCapturerTest, CaptureUpdatedRegion) { |
| 259 TestCaptureUpdatedRegion(); | 262 TestCaptureUpdatedRegion(); |
| 260 } | 263 } |
| 261 | 264 |
| 265 TEST_F(ScreenCapturerTest, TwoCapturers) { | |
| 266 std::unique_ptr<ScreenCapturer> capturer2(capturer_.release()); | |
| 267 SetUp(); | |
| 268 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); | |
| 269 } | |
| 270 | |
| 262 #if defined(WEBRTC_WIN) | 271 #if defined(WEBRTC_WIN) |
| 263 | 272 |
| 264 TEST_F(ScreenCapturerTest, UseSharedBuffers) { | 273 TEST_F(ScreenCapturerTest, UseSharedBuffers) { |
| 265 std::unique_ptr<DesktopFrame> frame; | 274 std::unique_ptr<DesktopFrame> frame; |
| 266 EXPECT_CALL(callback_, | 275 EXPECT_CALL(callback_, |
| 267 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | 276 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 268 .WillOnce(SaveUniquePtrArg(&frame)); | 277 .WillOnce(SaveUniquePtrArg(&frame)); |
| 269 | 278 |
| 270 capturer_->Start(&callback_); | 279 capturer_->Start(&callback_); |
| 271 capturer_->SetSharedMemoryFactory( | 280 capturer_->SetSharedMemoryFactory( |
| 272 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); | 281 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); |
| 273 capturer_->Capture(DesktopRegion()); | 282 capturer_->Capture(DesktopRegion()); |
| 274 | 283 |
| 275 ASSERT_TRUE(frame); | 284 ASSERT_TRUE(frame); |
| 276 ASSERT_TRUE(frame->shared_memory()); | 285 ASSERT_TRUE(frame->shared_memory()); |
| 277 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); | 286 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
| 278 } | 287 } |
| 279 | 288 |
| 280 TEST_F(ScreenCapturerTest, UseMagnifier) { | 289 TEST_F(ScreenCapturerTest, UseMagnifier) { |
| 281 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 290 SetMagnifierMode(); |
| 282 options.set_allow_use_magnification_api(true); | |
| 283 capturer_.reset(ScreenCapturer::Create(options)); | |
| 284 | 291 |
| 285 std::unique_ptr<DesktopFrame> frame; | 292 std::unique_ptr<DesktopFrame> frame; |
| 286 EXPECT_CALL(callback_, | 293 EXPECT_CALL(callback_, |
| 287 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | 294 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 288 .WillOnce(SaveUniquePtrArg(&frame)); | 295 .WillOnce(SaveUniquePtrArg(&frame)); |
| 289 | 296 |
| 290 capturer_->Start(&callback_); | 297 capturer_->Start(&callback_); |
| 291 capturer_->Capture(DesktopRegion()); | 298 capturer_->Capture(DesktopRegion()); |
| 292 ASSERT_TRUE(frame); | 299 ASSERT_TRUE(frame); |
| 293 } | 300 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 TEST_F(ScreenCapturerTest, TwoDirectxCapturers) { | 344 TEST_F(ScreenCapturerTest, TwoDirectxCapturers) { |
| 338 if (!SetDirectxCapturerMode()) { | 345 if (!SetDirectxCapturerMode()) { |
| 339 return; | 346 return; |
| 340 } | 347 } |
| 341 | 348 |
| 342 std::unique_ptr<ScreenCapturer> capturer2(capturer_.release()); | 349 std::unique_ptr<ScreenCapturer> capturer2(capturer_.release()); |
| 343 RTC_CHECK(SetDirectxCapturerMode()); | 350 RTC_CHECK(SetDirectxCapturerMode()); |
| 344 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); | 351 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); |
| 345 } | 352 } |
| 346 | 353 |
| 354 TEST_F(ScreenCapturerTest, TwoMagnifierCapturers) { | |
| 355 SetMagnifierMode(); | |
| 356 std::unique_ptr<ScreenCapturer> capturer2(capturer_.release()); | |
|
Sergey Ulanov
2016/09/09 17:23:15
capturer2 = std::move(capturer_);
Hzj_jie
2016/09/12 23:13:41
Done.
| |
| 357 SetMagnifierMode(); | |
| 358 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); | |
| 359 } | |
| 360 | |
| 347 #endif // defined(WEBRTC_WIN) | 361 #endif // defined(WEBRTC_WIN) |
| 348 | 362 |
| 349 } // namespace webrtc | 363 } // namespace webrtc |
| OLD | NEW |