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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 return frame; | 71 return frame; |
72 } | 72 } |
73 | 73 |
74 class FakeScreenCapturer : public DesktopCapturer { | 74 class FakeScreenCapturer : public DesktopCapturer { |
75 public: | 75 public: |
76 FakeScreenCapturer() {} | 76 FakeScreenCapturer() {} |
77 | 77 |
78 void Start(Callback* callback) override { callback_ = callback; } | 78 void Start(Callback* callback) override { callback_ = callback; } |
79 | 79 |
80 void Capture(const DesktopRegion& region) override { | 80 void Capture(const DesktopRegion& region) override { |
81 callback_->OnCaptureResult( | 81 callback_->OnCaptureCompleted(next_frame_.release()); |
82 next_frame_ ? Result::SUCCESS : Result::ERROR_TEMPORARY, | |
83 std::move(next_frame_)); | |
84 } | 82 } |
85 | 83 |
86 void SetNextFrame(std::unique_ptr<DesktopFrame> next_frame) { | 84 void SetNextFrame(DesktopFrame* next_frame) { |
87 next_frame_ = std::move(next_frame); | 85 next_frame_.reset(next_frame); |
88 } | 86 } |
89 | 87 |
90 private: | 88 private: |
91 Callback* callback_ = nullptr; | 89 Callback* callback_; |
92 | 90 |
93 std::unique_ptr<DesktopFrame> next_frame_; | 91 std::unique_ptr<DesktopFrame> next_frame_; |
94 }; | 92 }; |
95 | 93 |
96 class FakeMouseMonitor : public MouseCursorMonitor { | 94 class FakeMouseMonitor : public MouseCursorMonitor { |
97 public: | 95 public: |
98 FakeMouseMonitor() : changed_(true) {} | 96 FakeMouseMonitor() : changed_(true) {} |
99 | 97 |
100 void SetState(CursorState state, const DesktopVector& pos) { | 98 void SetState(CursorState state, const DesktopVector& pos) { |
101 state_ = state; | 99 state_ = state; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 158 } |
161 } | 159 } |
162 } | 160 } |
163 | 161 |
164 class DesktopAndCursorComposerTest : public testing::Test, | 162 class DesktopAndCursorComposerTest : public testing::Test, |
165 public DesktopCapturer::Callback { | 163 public DesktopCapturer::Callback { |
166 public: | 164 public: |
167 DesktopAndCursorComposerTest() | 165 DesktopAndCursorComposerTest() |
168 : fake_screen_(new FakeScreenCapturer()), | 166 : fake_screen_(new FakeScreenCapturer()), |
169 fake_cursor_(new FakeMouseMonitor()), | 167 fake_cursor_(new FakeMouseMonitor()), |
170 blender_(fake_screen_, fake_cursor_) {} | 168 blender_(fake_screen_, fake_cursor_) { |
| 169 } |
171 | 170 |
172 // DesktopCapturer::Callback interface | 171 // DesktopCapturer::Callback interface |
173 void OnCaptureResult(DesktopCapturer::Result result, | 172 void OnCaptureCompleted(DesktopFrame* frame) override { frame_.reset(frame); } |
174 std::unique_ptr<DesktopFrame> frame) override { | |
175 frame_ = std::move(frame); | |
176 } | |
177 | 173 |
178 protected: | 174 protected: |
179 // Owned by |blender_|. | 175 // Owned by |blender_|. |
180 FakeScreenCapturer* fake_screen_; | 176 FakeScreenCapturer* fake_screen_; |
181 FakeMouseMonitor* fake_cursor_; | 177 FakeMouseMonitor* fake_cursor_; |
182 | 178 |
183 DesktopAndCursorComposer blender_; | 179 DesktopAndCursorComposer blender_; |
184 std::unique_ptr<DesktopFrame> frame_; | 180 std::unique_ptr<DesktopFrame> frame_; |
185 }; | 181 }; |
186 | 182 |
187 // Verify DesktopAndCursorComposer can handle the case when the screen capturer | 183 // Verify DesktopAndCursorComposer can handle the case when the screen capturer |
188 // fails. | 184 // fails. |
189 TEST_F(DesktopAndCursorComposerTest, Error) { | 185 TEST_F(DesktopAndCursorComposerTest, Error) { |
190 blender_.Start(this); | 186 blender_.Start(this); |
191 | 187 |
192 fake_cursor_->SetHotspot(DesktopVector()); | 188 fake_cursor_->SetHotspot(DesktopVector()); |
193 fake_cursor_->SetState(MouseCursorMonitor::INSIDE, DesktopVector()); | 189 fake_cursor_->SetState(MouseCursorMonitor::INSIDE, DesktopVector()); |
194 fake_screen_->SetNextFrame(nullptr); | 190 fake_screen_->SetNextFrame(NULL); |
195 | 191 |
196 blender_.Capture(DesktopRegion()); | 192 blender_.Capture(DesktopRegion()); |
197 | 193 |
198 EXPECT_FALSE(frame_); | 194 EXPECT_FALSE(frame_); |
199 } | 195 } |
200 | 196 |
201 TEST_F(DesktopAndCursorComposerTest, Blend) { | 197 TEST_F(DesktopAndCursorComposerTest, Blend) { |
202 struct { | 198 struct { |
203 int x, y; | 199 int x, y; |
204 int hotspot_x, hotspot_y; | 200 int hotspot_x, hotspot_y; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // Verify that the cursor is erased before the frame buffer is returned to | 240 // Verify that the cursor is erased before the frame buffer is returned to |
245 // the screen capturer. | 241 // the screen capturer. |
246 frame_.reset(); | 242 frame_.reset(); |
247 VerifyFrame(*frame, MouseCursorMonitor::OUTSIDE, DesktopVector()); | 243 VerifyFrame(*frame, MouseCursorMonitor::OUTSIDE, DesktopVector()); |
248 } | 244 } |
249 } | 245 } |
250 | 246 |
251 } // namespace | 247 } // namespace |
252 | 248 |
253 } // namespace webrtc | 249 } // namespace webrtc |
OLD | NEW |