1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-01 08:52:11 +01:00

[d3d8] Refactor D3D8Surface implementation

This commit is contained in:
WinterSnowfall 2025-01-09 10:38:16 +02:00 committed by Philip Rebohle
parent 9d37e4abb4
commit 13ec120289
3 changed files with 96 additions and 66 deletions

View File

@ -1,6 +1,7 @@
#pragma once
#include "d3d8_include.h"
#include "d3d8_options.h"
#include "d3d8_resource.h"
namespace dxvk {

View File

@ -2,8 +2,70 @@
#include "d3d8_surface.h"
#include "d3d8_device.h"
#include "d3d8_d3d9_util.h"
namespace dxvk {
D3D8Surface::D3D8Surface(
D3D8Device* pDevice,
IDirect3DBaseTexture8* pTexture,
Com<d3d9::IDirect3DSurface9>&& pSurface)
: D3D8SurfaceBase (pDevice, std::move(pSurface), pTexture) {
}
// A surface does not need to be attached to a texture
D3D8Surface::D3D8Surface(
D3D8Device* pDevice,
Com<d3d9::IDirect3DSurface9>&& pSurface)
: D3D8Surface (pDevice, nullptr, std::move(pSurface)) {
}
D3DRESOURCETYPE STDMETHODCALLTYPE D3D8Surface::GetType() {
return D3DRESOURCETYPE(GetD3D9()->GetType());
}
HRESULT STDMETHODCALLTYPE D3D8Surface::GetDesc(D3DSURFACE_DESC* pDesc) {
if (unlikely(pDesc == nullptr))
return D3DERR_INVALIDCALL;
d3d9::D3DSURFACE_DESC desc;
HRESULT res = GetD3D9()->GetDesc(&desc);
if (likely(SUCCEEDED(res)))
ConvertSurfaceDesc8(&desc, pDesc);
return res;
}
HRESULT STDMETHODCALLTYPE D3D8Surface::LockRect(
D3DLOCKED_RECT* pLockedRect,
CONST RECT* pRect,
DWORD Flags) {
return GetD3D9()->LockRect((d3d9::D3DLOCKED_RECT*)pLockedRect, pRect, Flags);
}
HRESULT STDMETHODCALLTYPE D3D8Surface::UnlockRect() {
return GetD3D9()->UnlockRect();
}
HRESULT STDMETHODCALLTYPE D3D8Surface::GetDC(HDC* phDC) {
return GetD3D9()->GetDC(phDC);
}
HRESULT STDMETHODCALLTYPE D3D8Surface::ReleaseDC(HDC hDC) {
return GetD3D9()->ReleaseDC(hDC);
}
// TODO: Consider creating only one texture to
// encompass all surface levels of a texture.
Com<d3d9::IDirect3DSurface9> D3D8Surface::GetBlitImage() {
if (unlikely(m_blitImage == nullptr)) {
m_blitImage = CreateBlitImage();
}
return m_blitImage;
}
Com<d3d9::IDirect3DSurface9> D3D8Surface::CreateBlitImage() {
d3d9::D3DSURFACE_DESC desc;
GetD3D9()->GetDesc(&desc);
@ -23,4 +85,5 @@ namespace dxvk {
return image;
}
}

View File

@ -2,7 +2,6 @@
#include "d3d8_include.h"
#include "d3d8_subresource.h"
#include "d3d8_d3d9_util.h"
namespace dxvk {
@ -16,72 +15,39 @@ namespace dxvk {
D3D8Surface(
D3D8Device* pDevice,
IDirect3DBaseTexture8* pTexture,
Com<d3d9::IDirect3DSurface9>&& pSurface)
: D3D8SurfaceBase (pDevice, std::move(pSurface), pTexture) {
}
Com<d3d9::IDirect3DSurface9>&& pSurface);
// A surface does not need to be attached to a texture
D3D8Surface(
D3D8Device* pDevice,
Com<d3d9::IDirect3DSurface9>&& pSurface)
: D3D8Surface (pDevice, nullptr, std::move(pSurface)) {
}
Com<d3d9::IDirect3DSurface9>&& pSurface);
D3DRESOURCETYPE STDMETHODCALLTYPE GetType() {
return D3DRESOURCETYPE(GetD3D9()->GetType());
}
D3DRESOURCETYPE STDMETHODCALLTYPE GetType();
HRESULT STDMETHODCALLTYPE GetDesc(D3DSURFACE_DESC* pDesc) {
if (unlikely(pDesc == nullptr))
return D3DERR_INVALIDCALL;
HRESULT STDMETHODCALLTYPE GetDesc(D3DSURFACE_DESC* pDesc);
d3d9::D3DSURFACE_DESC desc;
HRESULT res = GetD3D9()->GetDesc(&desc);
HRESULT STDMETHODCALLTYPE LockRect(
D3DLOCKED_RECT* pLockedRect,
CONST RECT* pRect,
DWORD Flags);
if (likely(SUCCEEDED(res)))
ConvertSurfaceDesc8(&desc, pDesc);
HRESULT STDMETHODCALLTYPE UnlockRect();
return res;
}
HRESULT STDMETHODCALLTYPE GetDC(HDC* phDC);
HRESULT STDMETHODCALLTYPE LockRect(D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
return GetD3D9()->LockRect((d3d9::D3DLOCKED_RECT*)pLockedRect, pRect, Flags);
}
HRESULT STDMETHODCALLTYPE UnlockRect() {
return GetD3D9()->UnlockRect();
}
HRESULT STDMETHODCALLTYPE GetDC(HDC* phDC) {
return GetD3D9()->GetDC(phDC);
}
HRESULT STDMETHODCALLTYPE ReleaseDC(HDC hDC) {
return GetD3D9()->ReleaseDC(hDC);
}
public:
HRESULT STDMETHODCALLTYPE ReleaseDC(HDC hDC);
/**
* \brief Allocate or reuse an image of the same size
* as this texture for performing blit into system mem.
*
* TODO: Consider creating only one texture to
* encompass all surface levels of a texture.
*/
Com<d3d9::IDirect3DSurface9> GetBlitImage() {
if (unlikely(m_blitImage == nullptr)) {
m_blitImage = CreateBlitImage();
}
return m_blitImage;
}
Com<d3d9::IDirect3DSurface9> GetBlitImage();
private:
Com<d3d9::IDirect3DSurface9> CreateBlitImage();
Com<d3d9::IDirect3DSurface9> m_blitImage = nullptr;
Com<d3d9::IDirect3DSurface9> m_blitImage;
};
}