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

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

Issue 1678073003: Cleanup shared memory handling in DesktopCapturer interface. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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 "webrtc/modules/desktop_capture/desktop_frame_win.h" 11 #include "webrtc/modules/desktop_capture/desktop_frame_win.h"
12 12
13 #include <utility>
14
13 #include "webrtc/system_wrappers/include/logging.h" 15 #include "webrtc/system_wrappers/include/logging.h"
14 16
15 namespace webrtc { 17 namespace webrtc {
16 18
17 DesktopFrameWin::DesktopFrameWin(DesktopSize size, 19 DesktopFrameWin::DesktopFrameWin(DesktopSize size,
18 int stride, 20 int stride,
19 uint8_t* data, 21 uint8_t* data,
20 SharedMemory* shared_memory, 22 rtc::scoped_ptr<SharedMemory> shared_memory,
21 HBITMAP bitmap) 23 HBITMAP bitmap)
22 : DesktopFrame(size, stride, data, shared_memory), 24 : DesktopFrame(size, stride, data, shared_memory.get()),
23 bitmap_(bitmap), 25 bitmap_(bitmap),
24 owned_shared_memory_(shared_memory_) { 26 owned_shared_memory_(std::move(shared_memory)) {}
25 }
26 27
27 DesktopFrameWin::~DesktopFrameWin() { 28 DesktopFrameWin::~DesktopFrameWin() {
28 DeleteObject(bitmap_); 29 DeleteObject(bitmap_);
29 } 30 }
30 31
31 // static 32 // static
32 DesktopFrameWin* DesktopFrameWin::Create(DesktopSize size, 33 DesktopFrameWin* DesktopFrameWin::Create(
33 SharedMemory* shared_memory, 34 DesktopSize size,
34 HDC hdc) { 35 SharedMemoryFactory* shared_memory_factory,
36 HDC hdc) {
35 int bytes_per_row = size.width() * kBytesPerPixel; 37 int bytes_per_row = size.width() * kBytesPerPixel;
38 int buffer_size = bytes_per_row * size.height();
36 39
37 // 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.
38 BITMAPINFO bmi = {}; 41 BITMAPINFO bmi = {};
39 bmi.bmiHeader.biHeight = -size.height(); 42 bmi.bmiHeader.biHeight = -size.height();
40 bmi.bmiHeader.biWidth = size.width(); 43 bmi.bmiHeader.biWidth = size.width();
41 bmi.bmiHeader.biPlanes = 1; 44 bmi.bmiHeader.biPlanes = 1;
42 bmi.bmiHeader.biBitCount = DesktopFrameWin::kBytesPerPixel * 8; 45 bmi.bmiHeader.biBitCount = DesktopFrameWin::kBytesPerPixel * 8;
43 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); 46 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
44 bmi.bmiHeader.biSizeImage = bytes_per_row * size.height(); 47 bmi.bmiHeader.biSizeImage = bytes_per_row * size.height();
45 48
46 HANDLE section_handle = NULL; 49 rtc::scoped_ptr<SharedMemory> shared_memory;
47 if (shared_memory) 50 HANDLE section_handle = nullptr;
48 section_handle = shared_memory->handle(); 51 if (shared_memory_factory) {
49 void* data = NULL; 52 shared_memory = shared_memory_factory->CreateSharedMemory(buffer_size);
53 if (shared_memory)
54 section_handle = shared_memory->handle();
55 }
56 void* data = nullptr;
50 HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &data, 57 HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &data,
51 section_handle, 0); 58 section_handle, 0);
52 if (!bitmap) { 59 if (!bitmap) {
53 LOG(LS_WARNING) << "Failed to allocate new window frame " << GetLastError(); 60 LOG(LS_WARNING) << "Failed to allocate new window frame " << GetLastError();
54 delete shared_memory; 61 return nullptr;
55 return NULL;
56 } 62 }
57 63
58 return new DesktopFrameWin(size, bytes_per_row, 64 return new DesktopFrameWin(size, bytes_per_row,
59 reinterpret_cast<uint8_t*>(data), 65 reinterpret_cast<uint8_t*>(data),
60 shared_memory, bitmap); 66 std::move(shared_memory), bitmap);
61 } 67 }
62 68
63 } // namespace webrtc 69 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/desktop_frame_win.h ('k') | webrtc/modules/desktop_capture/screen_capturer_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698