| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "webrtc/modules/desktop_capture/screen_capturer.h" | 14 #include "webrtc/modules/desktop_capture/screen_capturer.h" |
| 15 | 15 |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/base/logging.h" |
| 19 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 20 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
| 20 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 21 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 21 #include "webrtc/modules/desktop_capture/desktop_region.h" | 22 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 22 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" | 23 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" |
| 23 | 24 |
| 25 #if defined(WEBRTC_WIN) |
| 26 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h" |
| 27 #endif // defined(WEBRTC_WIN) |
| 28 |
| 24 using ::testing::_; | 29 using ::testing::_; |
| 25 using ::testing::AnyNumber; | 30 using ::testing::AnyNumber; |
| 26 using ::testing::Return; | 31 using ::testing::Return; |
| 27 | 32 |
| 28 const int kTestSharedMemoryId = 123; | 33 const int kTestSharedMemoryId = 123; |
| 29 | 34 |
| 30 namespace webrtc { | 35 namespace webrtc { |
| 31 | 36 |
| 32 class ScreenCapturerTest : public testing::Test { | 37 class ScreenCapturerTest : public testing::Test { |
| 33 public: | 38 public: |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 EXPECT_CALL(callback_, | 144 EXPECT_CALL(callback_, |
| 140 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | 145 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 141 .WillOnce(SaveUniquePtrArg(&frame)); | 146 .WillOnce(SaveUniquePtrArg(&frame)); |
| 142 | 147 |
| 143 capturer_->Start(&callback_); | 148 capturer_->Start(&callback_); |
| 144 capturer_->Capture(DesktopRegion()); | 149 capturer_->Capture(DesktopRegion()); |
| 145 ASSERT_TRUE(frame); | 150 ASSERT_TRUE(frame); |
| 146 } | 151 } |
| 147 | 152 |
| 148 TEST_F(ScreenCapturerTest, UseDirectxCapturer) { | 153 TEST_F(ScreenCapturerTest, UseDirectxCapturer) { |
| 154 if (!ScreenCapturerWinDirectx::IsSupported()) { |
| 155 LOG(LS_WARNING) << "Directx capturer is not supported"; |
| 156 return; |
| 157 } |
| 158 |
| 149 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 159 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
| 150 options.set_allow_directx_capturer(true); | 160 options.set_allow_directx_capturer(true); |
| 151 capturer_.reset(ScreenCapturer::Create(options)); | 161 capturer_.reset(ScreenCapturer::Create(options)); |
| 152 | 162 |
| 153 std::unique_ptr<DesktopFrame> frame; | 163 std::unique_ptr<DesktopFrame> frame; |
| 154 EXPECT_CALL(callback_, | 164 EXPECT_CALL(callback_, |
| 155 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | 165 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 156 .WillOnce(SaveUniquePtrArg(&frame)); | 166 .WillOnce(SaveUniquePtrArg(&frame)); |
| 157 | 167 |
| 158 capturer_->Start(&callback_); | 168 capturer_->Start(&callback_); |
| 159 capturer_->Capture(DesktopRegion()); | 169 capturer_->Capture(DesktopRegion()); |
| 160 ASSERT_TRUE(frame); | 170 ASSERT_TRUE(frame); |
| 161 } | 171 } |
| 162 | 172 |
| 163 TEST_F(ScreenCapturerTest, UseDirectxCapturerWithSharedBuffers) { | 173 TEST_F(ScreenCapturerTest, UseDirectxCapturerWithSharedBuffers) { |
| 174 if (!ScreenCapturerWinDirectx::IsSupported()) { |
| 175 LOG(LS_WARNING) << "Directx capturer is not supported"; |
| 176 return; |
| 177 } |
| 178 |
| 164 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 179 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
| 165 options.set_allow_directx_capturer(true); | 180 options.set_allow_directx_capturer(true); |
| 166 capturer_.reset(ScreenCapturer::Create(options)); | 181 capturer_.reset(ScreenCapturer::Create(options)); |
| 167 | 182 |
| 168 std::unique_ptr<DesktopFrame> frame; | 183 std::unique_ptr<DesktopFrame> frame; |
| 169 EXPECT_CALL(callback_, | 184 EXPECT_CALL(callback_, |
| 170 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | 185 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 171 .WillOnce(SaveUniquePtrArg(&frame)); | 186 .WillOnce(SaveUniquePtrArg(&frame)); |
| 172 | 187 |
| 173 capturer_->Start(&callback_); | 188 capturer_->Start(&callback_); |
| 174 capturer_->SetSharedMemoryFactory( | 189 capturer_->SetSharedMemoryFactory( |
| 175 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); | 190 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); |
| 176 capturer_->Capture(DesktopRegion()); | 191 capturer_->Capture(DesktopRegion()); |
| 177 ASSERT_TRUE(frame); | 192 ASSERT_TRUE(frame); |
| 178 ASSERT_TRUE(frame->shared_memory()); | 193 ASSERT_TRUE(frame->shared_memory()); |
| 179 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); | 194 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
| 180 } | 195 } |
| 181 | 196 |
| 182 #endif // defined(WEBRTC_WIN) | 197 #endif // defined(WEBRTC_WIN) |
| 183 | 198 |
| 184 } // namespace webrtc | 199 } // namespace webrtc |
| OLD | NEW |