d3d_device.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #ifndef MODULES_DESKTOP_CAPTURE_WIN_D3D_DEVICE_H_
  11. #define MODULES_DESKTOP_CAPTURE_WIN_D3D_DEVICE_H_
  12. #include <comdef.h>
  13. #include <d3d11.h>
  14. #include <dxgi.h>
  15. #include <wrl/client.h>
  16. #include <vector>
  17. namespace webrtc {
  18. // A wrapper of ID3D11Device and its corresponding context and IDXGIAdapter.
  19. // This class represents one video card in the system.
  20. class D3dDevice {
  21. public:
  22. D3dDevice(const D3dDevice& other);
  23. D3dDevice(D3dDevice&& other);
  24. ~D3dDevice();
  25. ID3D11Device* d3d_device() const { return d3d_device_.Get(); }
  26. ID3D11DeviceContext* context() const { return context_.Get(); }
  27. IDXGIDevice* dxgi_device() const { return dxgi_device_.Get(); }
  28. IDXGIAdapter* dxgi_adapter() const { return dxgi_adapter_.Get(); }
  29. // Returns all D3dDevice instances on the system. Returns an empty vector if
  30. // anything wrong.
  31. static std::vector<D3dDevice> EnumDevices();
  32. private:
  33. // Instances of D3dDevice should only be created by EnumDevices() static
  34. // function.
  35. D3dDevice();
  36. // Initializes the D3dDevice from an IDXGIAdapter.
  37. bool Initialize(const Microsoft::WRL::ComPtr<IDXGIAdapter>& adapter);
  38. Microsoft::WRL::ComPtr<ID3D11Device> d3d_device_;
  39. Microsoft::WRL::ComPtr<ID3D11DeviceContext> context_;
  40. Microsoft::WRL::ComPtr<IDXGIDevice> dxgi_device_;
  41. Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter_;
  42. };
  43. } // namespace webrtc
  44. #endif // MODULES_DESKTOP_CAPTURE_WIN_D3D_DEVICE_H_