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

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

Issue 1845113002: DirectX based screen capturer logic (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 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> 13 #include <utility>
14 14
15 #include "webrtc/system_wrappers/include/logging.h" 15 #include "webrtc/system_wrappers/include/logging.h"
16 16
17 namespace webrtc { 17 namespace webrtc {
18 18
19 using Microsoft::WRL::ComPtr;
20
21 namespace {
22
23 int CalculateStrideFromDesktopSize(DesktopSize size) {
24 return size.width() * DesktopFrame::kBytesPerPixel;
25 }
26
27 } // namespace
28
19 DesktopFrameWin::DesktopFrameWin(DesktopSize size, 29 DesktopFrameWin::DesktopFrameWin(DesktopSize size,
20 int stride, 30 int stride,
21 uint8_t* data, 31 uint8_t* data,
22 std::unique_ptr<SharedMemory> shared_memory, 32 std::unique_ptr<SharedMemory> shared_memory,
23 HBITMAP bitmap) 33 HBITMAP bitmap)
24 : DesktopFrame(size, stride, data, shared_memory.get()), 34 : DesktopFrame(size, stride, data, shared_memory.get()),
25 bitmap_(bitmap), 35 bitmap_(bitmap),
26 owned_shared_memory_(std::move(shared_memory)) {} 36 owned_shared_memory_(std::move(shared_memory)) {}
27 37
28 DesktopFrameWin::~DesktopFrameWin() { 38 DesktopFrameWin::~DesktopFrameWin() {
29 DeleteObject(bitmap_); 39 DeleteObject(bitmap_);
30 } 40 }
31 41
32 // static 42 // static
33 DesktopFrameWin* DesktopFrameWin::Create( 43 DesktopFrameWin* DesktopFrameWin::Create(
34 DesktopSize size, 44 DesktopSize size,
35 SharedMemoryFactory* shared_memory_factory, 45 SharedMemoryFactory* shared_memory_factory,
36 HDC hdc) { 46 HDC hdc) {
37 int bytes_per_row = size.width() * kBytesPerPixel; 47 int bytes_per_row = CalculateStrideFromDesktopSize(size);
38 int buffer_size = bytes_per_row * size.height(); 48 int buffer_size = bytes_per_row * size.height();
39 49
40 // Describe a device independent bitmap (DIB) that is the size of the desktop. 50 // Describe a device independent bitmap (DIB) that is the size of the desktop.
41 BITMAPINFO bmi = {}; 51 BITMAPINFO bmi = {};
42 bmi.bmiHeader.biHeight = -size.height(); 52 bmi.bmiHeader.biHeight = -size.height();
43 bmi.bmiHeader.biWidth = size.width(); 53 bmi.bmiHeader.biWidth = size.width();
44 bmi.bmiHeader.biPlanes = 1; 54 bmi.bmiHeader.biPlanes = 1;
45 bmi.bmiHeader.biBitCount = DesktopFrameWin::kBytesPerPixel * 8; 55 bmi.bmiHeader.biBitCount = DesktopFrame::kBytesPerPixel * 8;
46 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); 56 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
47 bmi.bmiHeader.biSizeImage = bytes_per_row * size.height(); 57 bmi.bmiHeader.biSizeImage = buffer_size;
48 58
49 std::unique_ptr<SharedMemory> shared_memory; 59 std::unique_ptr<SharedMemory> shared_memory;
50 HANDLE section_handle = nullptr; 60 HANDLE section_handle = nullptr;
51 if (shared_memory_factory) { 61 if (shared_memory_factory) {
52 shared_memory = rtc::ScopedToUnique( 62 shared_memory = rtc::ScopedToUnique(
53 shared_memory_factory->CreateSharedMemory(buffer_size)); 63 shared_memory_factory->CreateSharedMemory(buffer_size));
54 if (shared_memory) 64 if (shared_memory)
55 section_handle = shared_memory->handle(); 65 section_handle = shared_memory->handle();
56 } 66 }
57 void* data = nullptr; 67 void* data = nullptr;
58 HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &data, 68 HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &data,
59 section_handle, 0); 69 section_handle, 0);
60 if (!bitmap) { 70 if (!bitmap) {
61 LOG(LS_WARNING) << "Failed to allocate new window frame " << GetLastError(); 71 LOG(LS_WARNING) << "Failed to allocate new window frame " << GetLastError();
62 return nullptr; 72 return nullptr;
63 } 73 }
64 74
65 return new DesktopFrameWin(size, bytes_per_row, 75 return new DesktopFrameWin(size, bytes_per_row,
66 reinterpret_cast<uint8_t*>(data), 76 reinterpret_cast<uint8_t*>(data),
67 std::move(shared_memory), bitmap); 77 std::move(shared_memory), bitmap);
68 } 78 }
69 79
80 DesktopFrameWinDXGI::~DesktopFrameWinDXGI() {}
81
82 DesktopFrameWinDXGI::DesktopFrameWinDXGI(DesktopSize size,
83 ComPtr<IDXGISurface> surface,
84 DXGI_MAPPED_RECT rect) :
Sergey Ulanov 2016/03/31 18:41:15 Do you really need to pass this parameter? It can
Hzj_jie 2016/04/05 23:15:17 Yes, I can move the logic in ScreenCapturerWinDire
85 DesktopFrame(size,
86 CalculateStrideFromDesktopSize(size),
Sergey Ulanov 2016/03/31 18:41:15 DXGI_MAPPED_RECT contains pitch field. Use it her
Hzj_jie 2016/04/05 23:15:17 Done.
87 rect.pBits,
88 nullptr),
89 surface_(surface) {}
90
91 DesktopFrameWinDXGI::DesktopFrameWinDXGI(DesktopSize size) :
92 DesktopFrame(size,
93 0,
94 nullptr,
95 nullptr) {}
96
70 } // namespace webrtc 97 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698