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

Side by Side Diff: webrtc/modules/desktop_capture/desktop_frame_win.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 12 matching lines...) Expand all
23 HBITMAP bitmap) 23 HBITMAP bitmap)
24 : DesktopFrame(size, stride, data, shared_memory.get()), 24 : DesktopFrame(size, stride, data, shared_memory.get()),
25 bitmap_(bitmap), 25 bitmap_(bitmap),
26 owned_shared_memory_(std::move(shared_memory)) {} 26 owned_shared_memory_(std::move(shared_memory)) {}
27 27
28 DesktopFrameWin::~DesktopFrameWin() { 28 DesktopFrameWin::~DesktopFrameWin() {
29 DeleteObject(bitmap_); 29 DeleteObject(bitmap_);
30 } 30 }
31 31
32 // static 32 // static
33 DesktopFrameWin* DesktopFrameWin::Create( 33 std::unique_ptr<DesktopFrameWin> DesktopFrameWin::Create(
34 DesktopSize size, 34 DesktopSize size,
35 SharedMemoryFactory* shared_memory_factory, 35 SharedMemoryFactory* shared_memory_factory,
36 HDC hdc) { 36 HDC hdc) {
37 int bytes_per_row = size.width() * kBytesPerPixel; 37 int bytes_per_row = size.width() * kBytesPerPixel;
38 int buffer_size = bytes_per_row * size.height(); 38 int buffer_size = bytes_per_row * size.height();
39 39
40 // Describe a device independent bitmap (DIB) that is the size of the desktop. 40 // Describe a device independent bitmap (DIB) that is the size of the desktop.
41 BITMAPINFO bmi = {}; 41 BITMAPINFO bmi = {};
42 bmi.bmiHeader.biHeight = -size.height(); 42 bmi.bmiHeader.biHeight = -size.height();
43 bmi.bmiHeader.biWidth = size.width(); 43 bmi.bmiHeader.biWidth = size.width();
44 bmi.bmiHeader.biPlanes = 1; 44 bmi.bmiHeader.biPlanes = 1;
45 bmi.bmiHeader.biBitCount = DesktopFrameWin::kBytesPerPixel * 8; 45 bmi.bmiHeader.biBitCount = DesktopFrameWin::kBytesPerPixel * 8;
46 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); 46 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
47 bmi.bmiHeader.biSizeImage = bytes_per_row * size.height(); 47 bmi.bmiHeader.biSizeImage = bytes_per_row * size.height();
48 48
49 std::unique_ptr<SharedMemory> shared_memory; 49 std::unique_ptr<SharedMemory> shared_memory;
50 HANDLE section_handle = nullptr; 50 HANDLE section_handle = nullptr;
51 if (shared_memory_factory) { 51 if (shared_memory_factory) {
52 shared_memory = shared_memory_factory->CreateSharedMemory(buffer_size); 52 shared_memory = shared_memory_factory->CreateSharedMemory(buffer_size);
53 section_handle = shared_memory->handle(); 53 section_handle = shared_memory->handle();
54 } 54 }
55 void* data = nullptr; 55 void* data = nullptr;
56 HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &data, 56 HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &data,
57 section_handle, 0); 57 section_handle, 0);
58 if (!bitmap) { 58 if (!bitmap) {
59 LOG(LS_WARNING) << "Failed to allocate new window frame " << GetLastError(); 59 LOG(LS_WARNING) << "Failed to allocate new window frame " << GetLastError();
60 return nullptr; 60 return nullptr;
61 } 61 }
62 62
63 return new DesktopFrameWin(size, bytes_per_row, 63 return std::unique_ptr<DesktopFrameWin>(
64 reinterpret_cast<uint8_t*>(data), 64 new DesktopFrameWin(size, bytes_per_row, reinterpret_cast<uint8_t*>(data),
65 std::move(shared_memory), bitmap); 65 std::move(shared_memory), bitmap));
66 } 66 }
67 67
68 } // namespace webrtc 68 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/desktop_frame_win.h ('k') | webrtc/modules/desktop_capture/screen_capture_frame_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698