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

Side by Side Diff: webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 27 matching lines...) Expand all
38 38
39 // SharedMemoryFactory that creates SharedMemory using the deprecated 39 // SharedMemoryFactory that creates SharedMemory using the deprecated
40 // DesktopCapturer::Callback::CreateSharedMemory(). 40 // DesktopCapturer::Callback::CreateSharedMemory().
41 class CallbackSharedMemoryFactory : public SharedMemoryFactory { 41 class CallbackSharedMemoryFactory : public SharedMemoryFactory {
42 public: 42 public:
43 CallbackSharedMemoryFactory(DesktopCapturer::Callback* callback) 43 CallbackSharedMemoryFactory(DesktopCapturer::Callback* callback)
44 : callback_(callback) {} 44 : callback_(callback) {}
45 ~CallbackSharedMemoryFactory() override {} 45 ~CallbackSharedMemoryFactory() override {}
46 46
47 rtc::scoped_ptr<SharedMemory> CreateSharedMemory(size_t size) override { 47 rtc::scoped_ptr<SharedMemory> CreateSharedMemory(size_t size) override {
48 return rtc_make_scoped_ptr(callback_->CreateSharedMemory(size)); 48 return rtc::scoped_ptr<SharedMemory>(callback_->CreateSharedMemory(size));
49 } 49 }
50 50
51 private: 51 private:
52 DesktopCapturer::Callback* callback_; 52 DesktopCapturer::Callback* callback_;
53 }; 53 };
54 54
55 } // namespace 55 } // namespace
56 56
57 ScreenCapturerWinGdi::ScreenCapturerWinGdi(const DesktopCaptureOptions& options) 57 ScreenCapturerWinGdi::ScreenCapturerWinGdi(const DesktopCaptureOptions& options)
58 : callback_(NULL), 58 : callback_(NULL),
(...skipping 24 matching lines...) Expand all
83 // Restore Aero. 83 // Restore Aero.
84 if (composition_func_) 84 if (composition_func_)
85 (*composition_func_)(DWM_EC_ENABLECOMPOSITION); 85 (*composition_func_)(DWM_EC_ENABLECOMPOSITION);
86 86
87 if (dwmapi_library_) 87 if (dwmapi_library_)
88 FreeLibrary(dwmapi_library_); 88 FreeLibrary(dwmapi_library_);
89 } 89 }
90 90
91 void ScreenCapturerWinGdi::SetSharedMemoryFactory( 91 void ScreenCapturerWinGdi::SetSharedMemoryFactory(
92 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) { 92 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) {
93 shared_memory_factory_ = std::move(shared_memory_factory); 93 shared_memory_factory_ =
94 rtc::ScopedToUnique(std::move(shared_memory_factory));
94 } 95 }
95 96
96 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { 97 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) {
97 TickTime capture_start_time = TickTime::Now(); 98 TickTime capture_start_time = TickTime::Now();
98 99
99 queue_.MoveToNextFrame(); 100 queue_.MoveToNextFrame();
100 101
101 // Request that the system not power-down the system, or the display hardware. 102 // Request that the system not power-down the system, or the display hardware.
102 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { 103 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) {
103 if (!set_thread_execution_state_failed_) { 104 if (!set_thread_execution_state_failed_) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // Vote to disable Aero composited desktop effects while capturing. Windows 178 // Vote to disable Aero composited desktop effects while capturing. Windows
178 // will restore Aero automatically if the process exits. This has no effect 179 // will restore Aero automatically if the process exits. This has no effect
179 // under Windows 8 or higher. See crbug.com/124018. 180 // under Windows 8 or higher. See crbug.com/124018.
180 if (composition_func_) 181 if (composition_func_)
181 (*composition_func_)(DWM_EC_DISABLECOMPOSITION); 182 (*composition_func_)(DWM_EC_DISABLECOMPOSITION);
182 } 183 }
183 184
184 void ScreenCapturerWinGdi::PrepareCaptureResources() { 185 void ScreenCapturerWinGdi::PrepareCaptureResources() {
185 // Switch to the desktop receiving user input if different from the current 186 // Switch to the desktop receiving user input if different from the current
186 // one. 187 // one.
187 rtc::scoped_ptr<Desktop> input_desktop(Desktop::GetInputDesktop()); 188 std::unique_ptr<Desktop> input_desktop(Desktop::GetInputDesktop());
188 if (input_desktop.get() != NULL && !desktop_.IsSame(*input_desktop)) { 189 if (input_desktop.get() != NULL && !desktop_.IsSame(*input_desktop)) {
189 // Release GDI resources otherwise SetThreadDesktop will fail. 190 // Release GDI resources otherwise SetThreadDesktop will fail.
190 if (desktop_dc_) { 191 if (desktop_dc_) {
191 ReleaseDC(NULL, desktop_dc_); 192 ReleaseDC(NULL, desktop_dc_);
192 desktop_dc_ = NULL; 193 desktop_dc_ = NULL;
193 } 194 }
194 195
195 if (memory_dc_) { 196 if (memory_dc_) {
196 DeleteDC(memory_dc_); 197 DeleteDC(memory_dc_);
197 memory_dc_ = NULL; 198 memory_dc_ = NULL;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 256
256 DesktopSize size = screen_rect.size(); 257 DesktopSize size = screen_rect.size();
257 // If the current buffer is from an older generation then allocate a new one. 258 // If the current buffer is from an older generation then allocate a new one.
258 // Note that we can't reallocate other buffers at this point, since the caller 259 // Note that we can't reallocate other buffers at this point, since the caller
259 // may still be reading from them. 260 // may still be reading from them.
260 if (!queue_.current_frame() || 261 if (!queue_.current_frame() ||
261 !queue_.current_frame()->size().equals(screen_rect.size())) { 262 !queue_.current_frame()->size().equals(screen_rect.size())) {
262 assert(desktop_dc_ != NULL); 263 assert(desktop_dc_ != NULL);
263 assert(memory_dc_ != NULL); 264 assert(memory_dc_ != NULL);
264 265
265 rtc::scoped_ptr<DesktopFrame> buffer(DesktopFrameWin::Create( 266 std::unique_ptr<DesktopFrame> buffer(DesktopFrameWin::Create(
266 size, shared_memory_factory_.get(), desktop_dc_)); 267 size, shared_memory_factory_.get(), desktop_dc_));
267 if (!buffer.get()) 268 if (!buffer.get())
268 return false; 269 return false;
269 queue_.ReplaceCurrentFrame(buffer.release()); 270 queue_.ReplaceCurrentFrame(buffer.release());
270 } 271 }
271 272
272 // Select the target bitmap into the memory dc and copy the rect from desktop 273 // Select the target bitmap into the memory dc and copy the rect from desktop
273 // to memory. 274 // to memory.
274 DesktopFrameWin* current = static_cast<DesktopFrameWin*>( 275 DesktopFrameWin* current = static_cast<DesktopFrameWin*>(
275 queue_.current_frame()->GetUnderlyingFrame()); 276 queue_.current_frame()->GetUnderlyingFrame());
276 HGDIOBJ previous_object = SelectObject(memory_dc_, current->bitmap()); 277 HGDIOBJ previous_object = SelectObject(memory_dc_, current->bitmap());
277 if (previous_object != NULL) { 278 if (previous_object != NULL) {
278 BitBlt(memory_dc_, 279 BitBlt(memory_dc_,
279 0, 0, screen_rect.width(), screen_rect.height(), 280 0, 0, screen_rect.width(), screen_rect.height(),
280 desktop_dc_, 281 desktop_dc_,
281 screen_rect.left(), screen_rect.top(), 282 screen_rect.left(), screen_rect.top(),
282 SRCCOPY | CAPTUREBLT); 283 SRCCOPY | CAPTUREBLT);
283 284
284 // Select back the previously selected object to that the device contect 285 // Select back the previously selected object to that the device contect
285 // could be destroyed independently of the bitmap if needed. 286 // could be destroyed independently of the bitmap if needed.
286 SelectObject(memory_dc_, previous_object); 287 SelectObject(memory_dc_, previous_object);
287 } 288 }
288 return true; 289 return true;
289 } 290 }
290 291
291 } // namespace webrtc 292 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698