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

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

Issue 1988783003: Use std::unique_ptr<> to pass frame ownership in DesktopCapturer impls. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 months 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) 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
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_->OnCaptureCompleted(next_frame_.release()); 81 callback_->OnCaptureResult(
82 next_frame_ ? Result::SUCCESS : Result::ERROR_TEMPORARY,
83 std::move(next_frame_));
82 } 84 }
83 85
84 void SetNextFrame(DesktopFrame* next_frame) { 86 void SetNextFrame(std::unique_ptr<DesktopFrame> next_frame) {
85 next_frame_.reset(next_frame); 87 next_frame_ = std::move(next_frame);
86 } 88 }
87 89
88 private: 90 private:
89 Callback* callback_; 91 Callback* callback_ = nullptr;
90 92
91 std::unique_ptr<DesktopFrame> next_frame_; 93 std::unique_ptr<DesktopFrame> next_frame_;
92 }; 94 };
93 95
94 class FakeMouseMonitor : public MouseCursorMonitor { 96 class FakeMouseMonitor : public MouseCursorMonitor {
95 public: 97 public:
96 FakeMouseMonitor() : changed_(true) {} 98 FakeMouseMonitor() : changed_(true) {}
97 99
98 void SetState(CursorState state, const DesktopVector& pos) { 100 void SetState(CursorState state, const DesktopVector& pos) {
99 state_ = state; 101 state_ = state;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 160 }
159 } 161 }
160 } 162 }
161 163
162 class DesktopAndCursorComposerTest : public testing::Test, 164 class DesktopAndCursorComposerTest : public testing::Test,
163 public DesktopCapturer::Callback { 165 public DesktopCapturer::Callback {
164 public: 166 public:
165 DesktopAndCursorComposerTest() 167 DesktopAndCursorComposerTest()
166 : fake_screen_(new FakeScreenCapturer()), 168 : fake_screen_(new FakeScreenCapturer()),
167 fake_cursor_(new FakeMouseMonitor()), 169 fake_cursor_(new FakeMouseMonitor()),
168 blender_(fake_screen_, fake_cursor_) { 170 blender_(fake_screen_, fake_cursor_) {}
169 }
170 171
171 // DesktopCapturer::Callback interface 172 // DesktopCapturer::Callback interface
172 void OnCaptureCompleted(DesktopFrame* frame) override { frame_.reset(frame); } 173 void OnCaptureResult(DesktopCapturer::Result result,
174 std::unique_ptr<DesktopFrame> frame) override {
175 frame_ = std::move(frame);
176 }
173 177
174 protected: 178 protected:
175 // Owned by |blender_|. 179 // Owned by |blender_|.
176 FakeScreenCapturer* fake_screen_; 180 FakeScreenCapturer* fake_screen_;
177 FakeMouseMonitor* fake_cursor_; 181 FakeMouseMonitor* fake_cursor_;
178 182
179 DesktopAndCursorComposer blender_; 183 DesktopAndCursorComposer blender_;
180 std::unique_ptr<DesktopFrame> frame_; 184 std::unique_ptr<DesktopFrame> frame_;
181 }; 185 };
182 186
183 // Verify DesktopAndCursorComposer can handle the case when the screen capturer 187 // Verify DesktopAndCursorComposer can handle the case when the screen capturer
184 // fails. 188 // fails.
185 TEST_F(DesktopAndCursorComposerTest, Error) { 189 TEST_F(DesktopAndCursorComposerTest, Error) {
186 blender_.Start(this); 190 blender_.Start(this);
187 191
188 fake_cursor_->SetHotspot(DesktopVector()); 192 fake_cursor_->SetHotspot(DesktopVector());
189 fake_cursor_->SetState(MouseCursorMonitor::INSIDE, DesktopVector()); 193 fake_cursor_->SetState(MouseCursorMonitor::INSIDE, DesktopVector());
190 fake_screen_->SetNextFrame(NULL); 194 fake_screen_->SetNextFrame(nullptr);
191 195
192 blender_.Capture(DesktopRegion()); 196 blender_.Capture(DesktopRegion());
193 197
194 EXPECT_FALSE(frame_); 198 EXPECT_FALSE(frame_);
195 } 199 }
196 200
197 TEST_F(DesktopAndCursorComposerTest, Blend) { 201 TEST_F(DesktopAndCursorComposerTest, Blend) {
198 struct { 202 struct {
199 int x, y; 203 int x, y;
200 int hotspot_x, hotspot_y; 204 int hotspot_x, hotspot_y;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // Verify that the cursor is erased before the frame buffer is returned to 244 // Verify that the cursor is erased before the frame buffer is returned to
241 // the screen capturer. 245 // the screen capturer.
242 frame_.reset(); 246 frame_.reset();
243 VerifyFrame(*frame, MouseCursorMonitor::OUTSIDE, DesktopVector()); 247 VerifyFrame(*frame, MouseCursorMonitor::OUTSIDE, DesktopVector());
244 } 248 }
245 } 249 }
246 250
247 } // namespace 251 } // namespace
248 252
249 } // namespace webrtc 253 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/desktop_and_cursor_composer.cc ('k') | webrtc/modules/desktop_capture/desktop_capturer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698