| 1 | // Copyright 2019 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "VideoBackends/D3D/D3DSwapChain.h" |
| 5 | |
| 6 | #include "Common/Assert.h" |
| 7 | |
| 8 | #include "VideoBackends/D3D/DXTexture.h" |
| 9 | |
| 10 | namespace DX11 |
| 11 | { |
| 12 | SwapChain::SwapChain(const WindowSystemInfo& wsi, IDXGIFactory* dxgi_factory, |
| 13 | ID3D11Device* d3d_device) |
| 14 | : D3DCommon::SwapChain(wsi, dxgi_factory, d3d_device) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | SwapChain::~SwapChain() = default; |
| 19 | |
| 20 | std::unique_ptr<SwapChain> SwapChain::Create(const WindowSystemInfo& wsi) |
| 21 | { |
| 22 | std::unique_ptr<SwapChain> swap_chain = |
| 23 | std::make_unique<SwapChain>(wsi, D3D::dxgi_factory.Get(), D3D::device.Get()); |
| 24 | if (!swap_chain->CreateSwapChain(WantsStereo(), WantsHDR())) |
| 25 | return nullptr; |
| 26 | |
| 27 | return swap_chain; |
| 28 | } |
| 29 | |
| 30 | bool SwapChain::CreateSwapChainBuffers() |
| 31 | { |
| 32 | ComPtr<ID3D11Texture2D> texture; |
| 33 | HRESULT hr = m_swap_chain->GetBuffer(0, IID_PPV_ARGS(&texture)); |
| 34 | ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to get swap chain buffer: {}", DX11HRWrap(hr)); |
| 35 | if (FAILED(hr)) |
| 36 | return false; |
| 37 | |
| 38 | m_texture = DXTexture::CreateAdopted(std::move(texture)); |
| 39 | if (!m_texture) |
| 40 | return false; |
| 41 | |
| 42 | m_framebuffer = DXFramebuffer::Create(m_texture.get(), nullptr, {}); |
| 43 | if (!m_framebuffer) |
| 44 | return false; |
| 45 | |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | void SwapChain::DestroySwapChainBuffers() |
| 50 | { |
| 51 | m_framebuffer.reset(); |
| 52 | m_texture.reset(); |
| 53 | } |
| 54 | } // namespace DX11 |