Chromium Code Reviews

Side by Side Diff: webrtc/modules/desktop_capture/win/desktop_frame_win_dxgi.h

Issue 1845113002: DirectX based screen capturer logic (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Lint errors Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DESKTOP_FRAME_WIN_DXGI_H_
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DESKTOP_FRAME_WIN_DXGI_H_
13
14 #include <windows.h>
15
16 #include <windef.h>
17 #include <wrl/client.h>
18
19 #include <memory>
20 #include <vector>
21
22 #include <D3D11.h>
23 #include <DXGI.h>
24 #include <DXGI1_2.h>
25
26 #include "webrtc/modules/desktop_capture/desktop_frame.h"
27 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
28
29 namespace webrtc {
30
31 // DesktopFrame implementation used by screen captures on Windows.
32 // Frame data is stored in the IDXGISurface instance and also the SharedMemory.
33 // Since Windows does not allow to share memory between a file mapping and
34 // IDXGIResource.
35 // To avoid memory recreation in ID3D11Texture2D, we reuse DesktopFrameWinDxgi
36 // instance. So a Capture function is added.
37 // Capture function is thread unsafe.
38 class DesktopFrameWinDxgi : public DesktopFrame {
39 public:
40 virtual ~DesktopFrameWinDxgi();
41
42 // Initialize device and context for further use. Thread unsafe.
43 static void Initialize(ID3D11Device* device, ID3D11DeviceContext* context);
44
45 // Creates a DesktopFrameWinDxgi instance, returns nullptr when memory
46 // allocation failed.
47 static std::unique_ptr<DesktopFrameWinDxgi> Create(
48 DesktopSize size,
49 SharedMemoryFactory* shared_memory_factory);
50
51 uint8_t* data() const override { return rect_.pBits; }
Sergey Ulanov 2016/04/08 21:22:26 virtual methods should not be inlined, but I don't
Hzj_jie 2016/04/11 22:19:16 Done.
52
53 // Captures a frame represented by frame_info and resource. Returns false if
54 // anything wrong.
55 // Before the first Capture is called, this instance is still workable, but
56 // the data in underlying buffer (SharedMemory) is undefined.
57 bool Capture(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
Sergey Ulanov 2016/04/08 21:22:26 DesktopFrame is supposed to be a dumb holder of th
Hzj_jie 2016/04/11 22:19:16 The reason to leave capture logic here is because
58 IDXGIResource* resource);
59
60 private:
61 DesktopFrameWinDxgi(DesktopSize size,
62 int stride,
63 SharedMemory* shared_memory);
64
65 // Initializes stage_ from a CPU inaccessible IDXGIResource.
66 // Returns false if it fails to execute windows api.
67 bool CreateTexture(ID3D11Texture2D* texture);
68
69 // Update during Capture (CreateTexture).
70 Microsoft::WRL::ComPtr<ID3D11Texture2D> stage_;
71 Microsoft::WRL::ComPtr<IDXGISurface> surface_;
72 // Always be the mapped rectangle or empty.
73 DXGI_MAPPED_RECT rect_;
74
75 RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrameWinDxgi);
76 };
77
78 } // namespace webrtc
79
80 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DESKTOP_FRAME_WIN_DXGI_H_
OLDNEW

Powered by Google App Engine