SwapChain.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2019 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <dxgi1_5.h>
  5. #include <wrl/client.h>
  6. #include "Common/CommonTypes.h"
  7. #include "Common/WindowSystemInfo.h"
  8. #include "VideoBackends/D3DCommon/D3DCommon.h"
  9. #include "VideoCommon/TextureConfig.h"
  10. namespace D3DCommon
  11. {
  12. class SwapChain
  13. {
  14. public:
  15. SwapChain(const WindowSystemInfo& wsi, IDXGIFactory* dxgi_factory, IUnknown* d3d_device);
  16. virtual ~SwapChain();
  17. // Sufficient buffers for triple buffering.
  18. static const u32 SWAP_CHAIN_BUFFER_COUNT = 3;
  19. // Returns true if the stereo mode is quad-buffering.
  20. static bool WantsStereo();
  21. static bool WantsHDR();
  22. IDXGISwapChain* GetDXGISwapChain() const { return m_swap_chain.Get(); }
  23. AbstractTextureFormat GetFormat() const
  24. {
  25. return m_hdr ? m_texture_format_hdr : m_texture_format;
  26. }
  27. u32 GetWidth() const { return m_width; }
  28. u32 GetHeight() const { return m_height; }
  29. // Mode switches.
  30. bool GetFullscreen() const;
  31. void SetFullscreen(bool request);
  32. // Checks for loss of exclusive fullscreen.
  33. bool CheckForFullscreenChange();
  34. // Presents the swap chain to the screen.
  35. virtual bool Present();
  36. bool ChangeSurface(void* native_handle);
  37. bool ResizeSwapChain();
  38. void SetStereo(bool stereo);
  39. void SetHDR(bool hdr);
  40. protected:
  41. u32 GetSwapChainFlags() const;
  42. bool CreateSwapChain(bool stereo = false, bool hdr = false);
  43. void DestroySwapChain();
  44. virtual bool CreateSwapChainBuffers() = 0;
  45. virtual void DestroySwapChainBuffers() = 0;
  46. WindowSystemInfo m_wsi;
  47. Microsoft::WRL::ComPtr<IDXGIFactory> m_dxgi_factory;
  48. Microsoft::WRL::ComPtr<IDXGISwapChain> m_swap_chain;
  49. Microsoft::WRL::ComPtr<IUnknown> m_d3d_device;
  50. const AbstractTextureFormat m_texture_format = AbstractTextureFormat::RGB10_A2;
  51. const AbstractTextureFormat m_texture_format_hdr = AbstractTextureFormat::RGBA16F;
  52. u32 m_width = 1;
  53. u32 m_height = 1;
  54. bool m_stereo = false;
  55. bool m_hdr = false;
  56. bool m_allow_tearing_supported = false;
  57. bool m_has_fullscreen = false;
  58. bool m_fullscreen_request = false;
  59. };
  60. } // namespace D3DCommon