1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-14 09:23:53 +01:00
dxvk/src/d3d9/d3d9_surface.h
Joshua Ashton 9f4baf3f55 [d3d9] Fix swapchain surface refs once and for all
The refcounting for d3d9 swapchain surfaces is very funny.
They don't actually hold any form of reference to their parent, unlike the surface->texture relationship.

When a swapchain is destroyed, the surfaces become orphans (like offscreen rendertargets) if they are still reffed.

Calling GetContainer on them when orphaned will return E_NOINTERFACE and nullptr for __uuidof(IDirect3DSwapChain)

Fixes some potential lingering refs on the device.
2020-04-26 13:32:22 +01:00

66 lines
1.6 KiB
C++

#pragma once
#include "d3d9_subresource.h"
#include "d3d9_common_texture.h"
#include "../util/util_gdi.h"
#include <algorithm>
namespace dxvk {
using D3D9GDIDesc = D3DKMT_DESTROYDCFROMMEMORY;
using D3D9SurfaceBase = D3D9Subresource<IDirect3DSurface9>;
class D3D9Surface final : public D3D9SurfaceBase {
public:
D3D9Surface(
D3D9DeviceEx* pDevice,
const D3D9_COMMON_TEXTURE_DESC* pDesc,
IUnknown* pContainer);
D3D9Surface(
D3D9DeviceEx* pDevice,
D3D9CommonTexture* pTexture,
UINT Face,
UINT MipLevel,
IDirect3DBaseTexture9* pBaseTexture);
void AddRefPrivate();
void ReleasePrivate();
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
D3DRESOURCETYPE STDMETHODCALLTYPE GetType() final;
HRESULT STDMETHODCALLTYPE GetDesc(D3DSURFACE_DESC *pDesc) final;
HRESULT STDMETHODCALLTYPE LockRect(D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) final;
HRESULT STDMETHODCALLTYPE UnlockRect() final;
HRESULT STDMETHODCALLTYPE GetDC(HDC *phDC) final;
HRESULT STDMETHODCALLTYPE ReleaseDC(HDC hDC) final;
inline VkExtent2D GetSurfaceExtent() const {
const auto* desc = m_texture->Desc();
return VkExtent2D {
std::max(1u, desc->Width >> GetMipLevel()),
std::max(1u, desc->Height >> GetMipLevel())
};
}
void ClearContainer();
private:
D3D9GDIDesc m_dcDesc;
};
}