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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/desktop_frame_win.cc
diff --git a/webrtc/modules/desktop_capture/desktop_frame_win.cc b/webrtc/modules/desktop_capture/desktop_frame_win.cc
index 6b97b132d8da6ef90119f45b0f9a2e0c60bf0194..22f97420c4de8dd4815855adb50ff3ca5e1c2ab7 100644
--- a/webrtc/modules/desktop_capture/desktop_frame_win.cc
+++ b/webrtc/modules/desktop_capture/desktop_frame_win.cc
@@ -10,6 +10,8 @@
#include "webrtc/modules/desktop_capture/desktop_frame_win.h"
+#include <utility>
+
#include "webrtc/system_wrappers/include/logging.h"
namespace webrtc {
@@ -17,22 +19,23 @@ namespace webrtc {
DesktopFrameWin::DesktopFrameWin(DesktopSize size,
int stride,
uint8_t* data,
- SharedMemory* shared_memory,
+ rtc::scoped_ptr<SharedMemory> shared_memory,
HBITMAP bitmap)
- : DesktopFrame(size, stride, data, shared_memory),
+ : DesktopFrame(size, stride, data, shared_memory.get()),
bitmap_(bitmap),
- owned_shared_memory_(shared_memory_) {
-}
+ owned_shared_memory_(std::move(shared_memory)) {}
DesktopFrameWin::~DesktopFrameWin() {
DeleteObject(bitmap_);
}
// static
-DesktopFrameWin* DesktopFrameWin::Create(DesktopSize size,
- SharedMemory* shared_memory,
- HDC hdc) {
+DesktopFrameWin* DesktopFrameWin::Create(
+ DesktopSize size,
+ SharedMemoryFactory* shared_memory_factory,
+ HDC hdc) {
int bytes_per_row = size.width() * kBytesPerPixel;
+ int buffer_size = bytes_per_row * size.height();
// Describe a device independent bitmap (DIB) that is the size of the desktop.
BITMAPINFO bmi = {};
@@ -43,21 +46,24 @@ DesktopFrameWin* DesktopFrameWin::Create(DesktopSize size,
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
bmi.bmiHeader.biSizeImage = bytes_per_row * size.height();
- HANDLE section_handle = NULL;
- if (shared_memory)
- section_handle = shared_memory->handle();
- void* data = NULL;
+ rtc::scoped_ptr<SharedMemory> shared_memory;
+ HANDLE section_handle = nullptr;
+ if (shared_memory_factory) {
+ shared_memory = shared_memory_factory->CreateSharedMemory(buffer_size);
+ if (shared_memory)
+ section_handle = shared_memory->handle();
+ }
+ void* data = nullptr;
HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &data,
section_handle, 0);
if (!bitmap) {
LOG(LS_WARNING) << "Failed to allocate new window frame " << GetLastError();
- delete shared_memory;
- return NULL;
+ return nullptr;
}
return new DesktopFrameWin(size, bytes_per_row,
reinterpret_cast<uint8_t*>(data),
- shared_memory, bitmap);
+ std::move(shared_memory), bitmap);
}
} // namespace webrtc
« 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