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

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

Issue 1743203002: Replace scoped_ptr with unique_ptr in webrtc/modules/desktop_capture/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: More Windows reverts Created 4 years, 9 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
11 #include <memory>
12
11 #include "webrtc/modules/desktop_capture/desktop_and_cursor_composer.h" 13 #include "webrtc/modules/desktop_capture/desktop_and_cursor_composer.h"
12 14
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" 16 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
16 #include "webrtc/modules/desktop_capture/desktop_frame.h" 17 #include "webrtc/modules/desktop_capture/desktop_frame.h"
17 #include "webrtc/modules/desktop_capture/mouse_cursor.h" 18 #include "webrtc/modules/desktop_capture/mouse_cursor.h"
18 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" 19 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
19 #include "webrtc/modules/desktop_capture/window_capturer.h" 20 #include "webrtc/modules/desktop_capture/window_capturer.h"
20 #include "webrtc/system_wrappers/include/logging.h" 21 #include "webrtc/system_wrappers/include/logging.h"
21 22
22 namespace webrtc { 23 namespace webrtc {
23 24
24 namespace { 25 namespace {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 callback_->OnCaptureCompleted(next_frame_.release()); 81 callback_->OnCaptureCompleted(next_frame_.release());
81 } 82 }
82 83
83 void SetNextFrame(DesktopFrame* next_frame) { 84 void SetNextFrame(DesktopFrame* next_frame) {
84 next_frame_.reset(next_frame); 85 next_frame_.reset(next_frame);
85 } 86 }
86 87
87 private: 88 private:
88 Callback* callback_; 89 Callback* callback_;
89 90
90 rtc::scoped_ptr<DesktopFrame> next_frame_; 91 std::unique_ptr<DesktopFrame> next_frame_;
91 }; 92 };
92 93
93 class FakeMouseMonitor : public MouseCursorMonitor { 94 class FakeMouseMonitor : public MouseCursorMonitor {
94 public: 95 public:
95 FakeMouseMonitor() : changed_(true) {} 96 FakeMouseMonitor() : changed_(true) {}
96 97
97 void SetState(CursorState state, const DesktopVector& pos) { 98 void SetState(CursorState state, const DesktopVector& pos) {
98 state_ = state; 99 state_ = state;
99 position_ = pos; 100 position_ = pos;
100 } 101 }
101 102
102 void SetHotspot(const DesktopVector& hotspot) { 103 void SetHotspot(const DesktopVector& hotspot) {
103 if (!hotspot_.equals(hotspot)) 104 if (!hotspot_.equals(hotspot))
104 changed_ = true; 105 changed_ = true;
105 hotspot_ = hotspot; 106 hotspot_ = hotspot;
106 } 107 }
107 108
108 void Init(Callback* callback, Mode mode) override { callback_ = callback; } 109 void Init(Callback* callback, Mode mode) override { callback_ = callback; }
109 110
110 void Capture() override { 111 void Capture() override {
111 if (changed_) { 112 if (changed_) {
112 rtc::scoped_ptr<DesktopFrame> image( 113 std::unique_ptr<DesktopFrame> image(
113 new BasicDesktopFrame(DesktopSize(kCursorWidth, kCursorHeight))); 114 new BasicDesktopFrame(DesktopSize(kCursorWidth, kCursorHeight)));
114 uint32_t* data = reinterpret_cast<uint32_t*>(image->data()); 115 uint32_t* data = reinterpret_cast<uint32_t*>(image->data());
115 memset(data, 0, image->stride() * kCursorHeight); 116 memset(data, 0, image->stride() * kCursorHeight);
116 117
117 // Set four pixels near the hotspot and leave all other blank. 118 // Set four pixels near the hotspot and leave all other blank.
118 for (int y = 0; y < kTestCursorSize; ++y) { 119 for (int y = 0; y < kTestCursorSize; ++y) {
119 for (int x = 0; x < kTestCursorSize; ++x) { 120 for (int x = 0; x < kTestCursorSize; ++x) {
120 data[(hotspot_.y() + y) * kCursorWidth + (hotspot_.x() + x)] = 121 data[(hotspot_.y() + y) * kCursorWidth + (hotspot_.x() + x)] =
121 kTestCursorData[y][x]; 122 kTestCursorData[y][x];
122 } 123 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 170
170 // DesktopCapturer::Callback interface 171 // DesktopCapturer::Callback interface
171 void OnCaptureCompleted(DesktopFrame* frame) override { frame_.reset(frame); } 172 void OnCaptureCompleted(DesktopFrame* frame) override { frame_.reset(frame); }
172 173
173 protected: 174 protected:
174 // Owned by |blender_|. 175 // Owned by |blender_|.
175 FakeScreenCapturer* fake_screen_; 176 FakeScreenCapturer* fake_screen_;
176 FakeMouseMonitor* fake_cursor_; 177 FakeMouseMonitor* fake_cursor_;
177 178
178 DesktopAndCursorComposer blender_; 179 DesktopAndCursorComposer blender_;
179 rtc::scoped_ptr<DesktopFrame> frame_; 180 std::unique_ptr<DesktopFrame> frame_;
180 }; 181 };
181 182
182 // Verify DesktopAndCursorComposer can handle the case when the screen capturer 183 // Verify DesktopAndCursorComposer can handle the case when the screen capturer
183 // fails. 184 // fails.
184 TEST_F(DesktopAndCursorComposerTest, Error) { 185 TEST_F(DesktopAndCursorComposerTest, Error) {
185 blender_.Start(this); 186 blender_.Start(this);
186 187
187 fake_cursor_->SetHotspot(DesktopVector()); 188 fake_cursor_->SetHotspot(DesktopVector());
188 fake_cursor_->SetState(MouseCursorMonitor::INSIDE, DesktopVector()); 189 fake_cursor_->SetState(MouseCursorMonitor::INSIDE, DesktopVector());
189 fake_screen_->SetNextFrame(NULL); 190 fake_screen_->SetNextFrame(NULL);
190 191
191 blender_.Capture(DesktopRegion()); 192 blender_.Capture(DesktopRegion());
192 193
193 EXPECT_EQ(frame_, static_cast<DesktopFrame*>(NULL)); 194 EXPECT_FALSE(frame_);
194 } 195 }
195 196
196 TEST_F(DesktopAndCursorComposerTest, Blend) { 197 TEST_F(DesktopAndCursorComposerTest, Blend) {
197 struct { 198 struct {
198 int x, y; 199 int x, y;
199 int hotspot_x, hotspot_y; 200 int hotspot_x, hotspot_y;
200 bool inside; 201 bool inside;
201 } tests[] = { 202 } tests[] = {
202 {0, 0, 0, 0, true}, 203 {0, 0, 0, 0, true},
203 {50, 50, 0, 0, true}, 204 {50, 50, 0, 0, true},
(...skipping 17 matching lines...) Expand all
221 222
222 DesktopVector hotspot(tests[i].hotspot_x, tests[i].hotspot_y); 223 DesktopVector hotspot(tests[i].hotspot_x, tests[i].hotspot_y);
223 fake_cursor_->SetHotspot(hotspot); 224 fake_cursor_->SetHotspot(hotspot);
224 225
225 MouseCursorMonitor::CursorState state = tests[i].inside 226 MouseCursorMonitor::CursorState state = tests[i].inside
226 ? MouseCursorMonitor::INSIDE 227 ? MouseCursorMonitor::INSIDE
227 : MouseCursorMonitor::OUTSIDE; 228 : MouseCursorMonitor::OUTSIDE;
228 DesktopVector pos(tests[i].x, tests[i].y); 229 DesktopVector pos(tests[i].x, tests[i].y);
229 fake_cursor_->SetState(state, pos); 230 fake_cursor_->SetState(state, pos);
230 231
231 rtc::scoped_ptr<SharedDesktopFrame> frame( 232 std::unique_ptr<SharedDesktopFrame> frame(
232 SharedDesktopFrame::Wrap(CreateTestFrame())); 233 SharedDesktopFrame::Wrap(CreateTestFrame()));
233 fake_screen_->SetNextFrame(frame->Share()); 234 fake_screen_->SetNextFrame(frame->Share());
234 235
235 blender_.Capture(DesktopRegion()); 236 blender_.Capture(DesktopRegion());
236 237
237 VerifyFrame(*frame_, state, pos); 238 VerifyFrame(*frame_, state, pos);
238 239
239 // 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
240 // the screen capturer. 241 // the screen capturer.
241 frame_.reset(); 242 frame_.reset();
242 VerifyFrame(*frame, MouseCursorMonitor::OUTSIDE, DesktopVector()); 243 VerifyFrame(*frame, MouseCursorMonitor::OUTSIDE, DesktopVector());
243 } 244 }
244 } 245 }
245 246
246 } // namespace 247 } // namespace
247 248
248 } // namespace webrtc 249 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698