Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: webrtc/modules/desktop_capture/screen_capturer_integration_test.cc

Issue 2468753002: Add CreateWindowCapturer() and CreateScreenCapturer() in DesktopCapturer (Closed)
Patch Set: Build break without X11 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 <string.h> 11 #include <string.h>
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <initializer_list> 14 #include <initializer_list>
15 #include <memory> 15 #include <memory>
16 #include <utility> 16 #include <utility>
17 17
18 #include "webrtc/modules/desktop_capture/screen_capturer.h" 18 #include "webrtc/modules/desktop_capture/screen_capturer.h"
19 19
20 #include "webrtc/test/gmock.h" 20 #include "webrtc/test/gmock.h"
21 #include "webrtc/test/gtest.h" 21 #include "webrtc/test/gtest.h"
22 #include "webrtc/base/checks.h" 22 #include "webrtc/base/checks.h"
23 #include "webrtc/base/constructormagic.h" 23 #include "webrtc/base/constructormagic.h"
24 #include "webrtc/base/logging.h" 24 #include "webrtc/base/logging.h"
25 #include "webrtc/modules/desktop_capture/rgba_color.h" 25 #include "webrtc/modules/desktop_capture/rgba_color.h"
26 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" 26 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
27 #include "webrtc/modules/desktop_capture/desktop_frame.h" 27 #include "webrtc/modules/desktop_capture/desktop_frame.h"
28 #include "webrtc/modules/desktop_capture/desktop_region.h" 28 #include "webrtc/modules/desktop_capture/desktop_region.h"
29 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" 29 #include "webrtc/modules/desktop_capture/mock_desktop_capturer_callback.h"
30 #include "webrtc/modules/desktop_capture/screen_drawer.h" 30 #include "webrtc/modules/desktop_capture/screen_drawer.h"
31 31
32 #if defined(WEBRTC_WIN) 32 #if defined(WEBRTC_WIN)
33 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h" 33 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h"
34 #endif // defined(WEBRTC_WIN) 34 #endif // defined(WEBRTC_WIN)
35 35
36 using ::testing::_; 36 using ::testing::_;
37 37
38 namespace webrtc { 38 namespace webrtc {
39 39
(...skipping 30 matching lines...) Expand all
70 row += frame.stride(); 70 row += frame.stride();
71 } 71 }
72 return true; 72 return true;
73 } 73 }
74 74
75 } // namespace 75 } // namespace
76 76
77 class ScreenCapturerIntegrationTest : public testing::Test { 77 class ScreenCapturerIntegrationTest : public testing::Test {
78 public: 78 public:
79 void SetUp() override { 79 void SetUp() override {
80 capturer_.reset( 80 capturer_ = DesktopCapturer::CreateScreenCapturer(
81 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); 81 DesktopCaptureOptions::CreateDefault());
82 } 82 }
83 83
84 protected: 84 protected:
85 void TestCaptureUpdatedRegion( 85 void TestCaptureUpdatedRegion(
86 std::initializer_list<ScreenCapturer*> capturers) { 86 std::initializer_list<DesktopCapturer*> capturers) {
87 RTC_DCHECK(capturers.size() > 0); 87 RTC_DCHECK(capturers.size() > 0);
88 // A large enough area for the tests, which should be able to fulfill by 88 // A large enough area for the tests, which should be able to be fulfilled
89 // most of systems. 89 // by most systems.
90 const int kTestArea = 512; 90 const int kTestArea = 512;
91 const int kRectSize = 32; 91 const int kRectSize = 32;
92 std::unique_ptr<ScreenDrawer> drawer = ScreenDrawer::Create(); 92 std::unique_ptr<ScreenDrawer> drawer = ScreenDrawer::Create();
93 if (!drawer || drawer->DrawableRegion().is_empty()) { 93 if (!drawer || drawer->DrawableRegion().is_empty()) {
94 LOG(LS_WARNING) << "No ScreenDrawer implementation for current platform."; 94 LOG(LS_WARNING) << "No ScreenDrawer implementation for current platform.";
95 return; 95 return;
96 } 96 }
97 if (drawer->DrawableRegion().width() < kTestArea || 97 if (drawer->DrawableRegion().width() < kTestArea ||
98 drawer->DrawableRegion().height() < kTestArea) { 98 drawer->DrawableRegion().height() < kTestArea) {
99 LOG(LS_WARNING) << "ScreenDrawer::DrawableRegion() is too small for the " 99 LOG(LS_WARNING) << "ScreenDrawer::DrawableRegion() is too small for the "
100 "CaptureUpdatedRegion tests."; 100 "CaptureUpdatedRegion tests.";
101 return; 101 return;
102 } 102 }
103 103
104 for (ScreenCapturer* capturer : capturers) { 104 for (DesktopCapturer* capturer : capturers) {
105 capturer->Start(&callback_); 105 capturer->Start(&callback_);
106 } 106 }
107 107
108 // Draw a set of |kRectSize| by |kRectSize| rectangles at (|i|, |i|), or 108 // Draw a set of |kRectSize| by |kRectSize| rectangles at (|i|, |i|), or
109 // |i| by |i| rectangles at (|kRectSize|, |kRectSize|). One of (controlled 109 // |i| by |i| rectangles at (|kRectSize|, |kRectSize|). One of (controlled
110 // by |c|) its primary colors is |i|, and the other two are 0x7f. So we 110 // by |c|) its primary colors is |i|, and the other two are 0x7f. So we
111 // won't draw a black or white rectangle. 111 // won't draw a black or white rectangle.
112 for (int c = 0; c < 3; c++) { 112 for (int c = 0; c < 3; c++) {
113 // A fixed size rectangle. 113 // A fixed size rectangle.
114 for (int i = 0; i < kTestArea - kRectSize; i += 16) { 114 for (int i = 0; i < kTestArea - kRectSize; i += 16) {
(...skipping 16 matching lines...) Expand all
131 } 131 }
132 } 132 }
133 } 133 }
134 134
135 void TestCaptureUpdatedRegion() { 135 void TestCaptureUpdatedRegion() {
136 TestCaptureUpdatedRegion({capturer_.get()}); 136 TestCaptureUpdatedRegion({capturer_.get()});
137 } 137 }
138 138
139 #if defined(WEBRTC_WIN) 139 #if defined(WEBRTC_WIN)
140 // Enable allow_directx_capturer in DesktopCaptureOptions, but let 140 // Enable allow_directx_capturer in DesktopCaptureOptions, but let
141 // ScreenCapturer::Create to decide whether a DirectX capturer should be used. 141 // DesktopCapturer::CreateScreenCapturer() to decide whether a DirectX
142 // capturer should be used.
142 void MaybeCreateDirectxCapturer() { 143 void MaybeCreateDirectxCapturer() {
143 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); 144 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault());
144 options.set_allow_directx_capturer(true); 145 options.set_allow_directx_capturer(true);
145 capturer_.reset(ScreenCapturer::Create(options)); 146 capturer_ = DesktopCapturer::CreateScreenCapturer(options);
146 } 147 }
147 148
148 bool CreateDirectxCapturer() { 149 bool CreateDirectxCapturer() {
149 if (!ScreenCapturerWinDirectx::IsSupported()) { 150 if (!ScreenCapturerWinDirectx::IsSupported()) {
150 LOG(LS_WARNING) << "Directx capturer is not supported"; 151 LOG(LS_WARNING) << "Directx capturer is not supported";
151 return false; 152 return false;
152 } 153 }
153 154
154 MaybeCreateDirectxCapturer(); 155 MaybeCreateDirectxCapturer();
155 return true; 156 return true;
156 } 157 }
157 158
158 void CreateMagnifierCapturer() { 159 void CreateMagnifierCapturer() {
159 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); 160 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault());
160 options.set_allow_use_magnification_api(true); 161 options.set_allow_use_magnification_api(true);
161 capturer_.reset(ScreenCapturer::Create(options)); 162 capturer_ = DesktopCapturer::CreateScreenCapturer(options);
162 } 163 }
163 #endif // defined(WEBRTC_WIN) 164 #endif // defined(WEBRTC_WIN)
164 165
165 std::unique_ptr<ScreenCapturer> capturer_; 166 std::unique_ptr<DesktopCapturer> capturer_;
166 MockScreenCapturerCallback callback_; 167 MockDesktopCapturerCallback callback_;
167 168
168 private: 169 private:
169 // Repeats capturing the frame by using |capturers| one-by-one for 600 times, 170 // Repeats capturing the frame by using |capturers| one-by-one for 600 times,
170 // typically 30 seconds, until they succeeded captured a |color| rectangle at 171 // typically 30 seconds, until they succeeded captured a |color| rectangle at
171 // |rect|. This function uses |drawer|->WaitForPendingDraws() between two 172 // |rect|. This function uses |drawer|->WaitForPendingDraws() between two
172 // attempts to wait for the screen to update. 173 // attempts to wait for the screen to update.
173 void TestCaptureOneFrame(std::vector<ScreenCapturer*> capturers, 174 void TestCaptureOneFrame(std::vector<DesktopCapturer*> capturers,
174 ScreenDrawer* drawer, 175 ScreenDrawer* drawer,
175 DesktopRect rect, 176 DesktopRect rect,
176 RgbaColor color) { 177 RgbaColor color) {
177 const int wait_capture_round = 600; 178 const int wait_capture_round = 600;
178 drawer->Clear(); 179 drawer->Clear();
179 size_t succeeded_capturers = 0; 180 size_t succeeded_capturers = 0;
180 for (int i = 0; i < wait_capture_round; i++) { 181 for (int i = 0; i < wait_capture_round; i++) {
181 drawer->DrawRectangle(rect, color); 182 drawer->DrawRectangle(rect, color);
182 drawer->WaitForPendingDraws(); 183 drawer->WaitForPendingDraws();
183 for (size_t j = 0; j < capturers.size(); j++) { 184 for (size_t j = 0; j < capturers.size(); j++) {
184 if (capturers[j] == nullptr) { 185 if (capturers[j] == nullptr) {
185 // ScreenCapturer should return an empty updated_region() if no 186 // DesktopCapturer should return an empty updated_region() if no
186 // update detected. So we won't test it again if it has captured 187 // update detected. So we won't test it again if it has captured
187 // the rectangle we drew. 188 // the rectangle we drew.
188 continue; 189 continue;
189 } 190 }
190 std::unique_ptr<DesktopFrame> frame = CaptureFrame(capturers[j]); 191 std::unique_ptr<DesktopFrame> frame = CaptureFrame(capturers[j]);
191 if (!frame) { 192 if (!frame) {
192 // CaptureFrame() has triggered an assertion failure already, we 193 // CaptureFrame() has triggered an assertion failure already, we
193 // only need to return here. 194 // only need to return here.
194 return; 195 return;
195 } 196 }
196 197
197 if (ArePixelsColoredBy( 198 if (ArePixelsColoredBy(
198 *frame, rect, color, drawer->MayDrawIncompleteShapes())) { 199 *frame, rect, color, drawer->MayDrawIncompleteShapes())) {
199 capturers[j] = nullptr; 200 capturers[j] = nullptr;
200 succeeded_capturers++; 201 succeeded_capturers++;
201 } 202 }
202 } 203 }
203 204
204 if (succeeded_capturers == capturers.size()) { 205 if (succeeded_capturers == capturers.size()) {
205 break; 206 break;
206 } 207 }
207 } 208 }
208 209
209 ASSERT_EQ(succeeded_capturers, capturers.size()); 210 ASSERT_EQ(succeeded_capturers, capturers.size());
210 } 211 }
211 212
212 // Expects |capturer| to successfully capture a frame, and returns it. 213 // Expects |capturer| to successfully capture a frame, and returns it.
213 std::unique_ptr<DesktopFrame> CaptureFrame(ScreenCapturer* capturer) { 214 std::unique_ptr<DesktopFrame> CaptureFrame(DesktopCapturer* capturer) {
214 std::unique_ptr<DesktopFrame> frame; 215 std::unique_ptr<DesktopFrame> frame;
215 EXPECT_CALL(callback_, 216 EXPECT_CALL(callback_,
216 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) 217 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _))
217 .WillOnce(SaveUniquePtrArg(&frame)); 218 .WillOnce(SaveUniquePtrArg(&frame));
218 capturer->CaptureFrame(); 219 capturer->CaptureFrame();
219 EXPECT_TRUE(frame); 220 EXPECT_TRUE(frame);
220 return frame; 221 return frame;
221 } 222 }
222 }; 223 };
223 224
224 TEST_F(ScreenCapturerIntegrationTest, CaptureUpdatedRegion) { 225 TEST_F(ScreenCapturerIntegrationTest, CaptureUpdatedRegion) {
225 TestCaptureUpdatedRegion(); 226 TestCaptureUpdatedRegion();
226 } 227 }
227 228
228 TEST_F(ScreenCapturerIntegrationTest, TwoCapturers) { 229 TEST_F(ScreenCapturerIntegrationTest, TwoCapturers) {
229 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); 230 std::unique_ptr<DesktopCapturer> capturer2 = std::move(capturer_);
230 SetUp(); 231 SetUp();
231 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); 232 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()});
232 } 233 }
233 234
234 #if defined(WEBRTC_WIN) 235 #if defined(WEBRTC_WIN)
235 236
236 TEST_F(ScreenCapturerIntegrationTest, CaptureUpdatedRegionWithDirectxCapturer) { 237 TEST_F(ScreenCapturerIntegrationTest, CaptureUpdatedRegionWithDirectxCapturer) {
237 if (!CreateDirectxCapturer()) { 238 if (!CreateDirectxCapturer()) {
238 return; 239 return;
239 } 240 }
240 241
241 TestCaptureUpdatedRegion(); 242 TestCaptureUpdatedRegion();
242 } 243 }
243 244
244 TEST_F(ScreenCapturerIntegrationTest, TwoDirectxCapturers) { 245 TEST_F(ScreenCapturerIntegrationTest, TwoDirectxCapturers) {
245 if (!CreateDirectxCapturer()) { 246 if (!CreateDirectxCapturer()) {
246 return; 247 return;
247 } 248 }
248 249
249 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); 250 std::unique_ptr<DesktopCapturer> capturer2 = std::move(capturer_);
250 RTC_CHECK(CreateDirectxCapturer()); 251 RTC_CHECK(CreateDirectxCapturer());
251 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); 252 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()});
252 } 253 }
253 254
254 TEST_F(ScreenCapturerIntegrationTest, 255 TEST_F(ScreenCapturerIntegrationTest,
255 CaptureUpdatedRegionWithMagnifierCapturer) { 256 CaptureUpdatedRegionWithMagnifierCapturer) {
256 CreateMagnifierCapturer(); 257 CreateMagnifierCapturer();
257 TestCaptureUpdatedRegion(); 258 TestCaptureUpdatedRegion();
258 } 259 }
259 260
260 TEST_F(ScreenCapturerIntegrationTest, TwoMagnifierCapturers) { 261 TEST_F(ScreenCapturerIntegrationTest, TwoMagnifierCapturers) {
261 CreateMagnifierCapturer(); 262 CreateMagnifierCapturer();
262 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); 263 std::unique_ptr<DesktopCapturer> capturer2 = std::move(capturer_);
263 CreateMagnifierCapturer(); 264 CreateMagnifierCapturer();
264 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); 265 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()});
265 } 266 }
266 267
267 TEST_F(ScreenCapturerIntegrationTest, 268 TEST_F(ScreenCapturerIntegrationTest,
268 MaybeCaptureUpdatedRegionWithDirectxCapturer) { 269 MaybeCaptureUpdatedRegionWithDirectxCapturer) {
269 // Even DirectX capturer is not supported in current system, we should be able 270 // Even DirectX capturer is not supported in current system, we should be able
270 // to select a usable capturer. 271 // to select a usable capturer.
271 MaybeCreateDirectxCapturer(); 272 MaybeCreateDirectxCapturer();
272 TestCaptureUpdatedRegion(); 273 TestCaptureUpdatedRegion();
273 } 274 }
274 275
275 #endif // defined(WEBRTC_WIN) 276 #endif // defined(WEBRTC_WIN)
276 277
277 } // namespace webrtc 278 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h ('k') | webrtc/modules/desktop_capture/screen_capturer_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698