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

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

Powered by Google App Engine
This is Rietveld 408576698