blob: 41efa849053e38b13b78a8be3183767b091099bf [file] [log] [blame]
zijiehe2d618de2016-08-08 17:50:21 -07001/*
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_D3D_DEVICE_H_
12#define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_D3D_DEVICE_H_
13
14#include <comdef.h>
15#include <wrl/client.h>
16#include <D3D11.h>
17#include <DXGI.h>
18
19#include <vector>
20
21namespace webrtc {
22
23// A wrapper of ID3D11Device and its corresponding context and IDXGIAdapter.
24// This class represents one video card in the system.
25class D3dDevice {
26 public:
sergeyue1831212016-10-26 13:15:42 -070027 D3dDevice(const D3dDevice& other);
28 D3dDevice(D3dDevice&& other);
zijiehe2d618de2016-08-08 17:50:21 -070029 ~D3dDevice();
30
31 ID3D11Device* d3d_device() const { return d3d_device_.Get(); }
32
33 ID3D11DeviceContext* context() const { return context_.Get(); }
34
35 IDXGIDevice* dxgi_device() const { return dxgi_device_.Get(); }
36
37 IDXGIAdapter* dxgi_adapter() const { return dxgi_adapter_.Get(); }
38
39 // Returns all D3dDevice instances on the system. Returns an empty vector if
40 // anything wrong.
41 static std::vector<D3dDevice> EnumDevices();
42
43 private:
44 // Instances of D3dDevice should only be created by EnumDevices() static
45 // function.
46 D3dDevice();
47
zijiehe66cadfc2016-09-21 17:19:10 -070048 // Initializes the D3dDevice from an IDXGIAdapter.
zijiehe2d618de2016-08-08 17:50:21 -070049 bool Initialize(const Microsoft::WRL::ComPtr<IDXGIAdapter>& adapter);
50
51 Microsoft::WRL::ComPtr<ID3D11Device> d3d_device_;
52 Microsoft::WRL::ComPtr<ID3D11DeviceContext> context_;
53 Microsoft::WRL::ComPtr<IDXGIDevice> dxgi_device_;
54 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter_;
55};
56
57} // namespace webrtc
58
59#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_D3D_DEVICE_H_