Create d3d_surface_lock_rect

This commit is contained in:
twinaphex 2017-10-02 00:45:33 +02:00
parent 0559be4e72
commit 95d035883c
3 changed files with 35 additions and 2 deletions

View File

@ -113,6 +113,35 @@ void d3d_texture_free(LPDIRECT3DTEXTURE tex)
}
}
bool d3d_surface_lock_rect(void *data, void *data2)
{
LPDIRECT3DSURFACE surf = (LPDIRECT3DSURFACE)data;
#if defined(HAVE_D3D9) && !defined(__cplusplus)
if (FAILED(IDirect3DSurface9_LockRect(surf, (D3DLOCKED_RECT*)data2, NULL, D3DLOCK_READONLY)))
#elif defined(HAVE_D3D8) && !defined(__cplusplus)
if (FAILED(IDirect3DSurface8_LockRect(surf, (D3DLOCKED_RECT*)data2, NULL, D3DLOCK_READONLY)))
#else
if (FAILED(surf->LockRect((D3DLOCKED_RECT*)data2, NULL, D3DLOCK_READONLY)))
#endif
return false;
return true;
}
void d3d_surface_unlock_rect(void *data)
{
LPDIRECT3DSURFACE surf = (LPDIRECT3DSURFACE)data;
if (surf)
{
#if defined(HAVE_D3D9) && !defined(__cplusplus)
IDirect3DSurface9_UnlockRect(surf);
#elif defined(HAVE_D3D8) && !defined(__cplusplus)
IDirect3DSurface8_UnlockRect(surf);
#else
surf->UnlockRect();
#endif
}
}
void d3d_surface_free(void *data)
{
LPDIRECT3DSURFACE surf = (LPDIRECT3DSURFACE)data;

View File

@ -133,6 +133,10 @@ bool d3d_device_create_offscreen_plain_surface(
void **surf_data,
void *data);
bool d3d_surface_lock_rect(void *data, void *data2);
void d3d_surface_unlock_rect(void *data);
bool d3d_reset(LPDIRECT3DDEVICE dev, D3DPRESENT_PARAMETERS *d3dpp);
void d3d_device_free(LPDIRECT3DDEVICE dev, LPDIRECT3D pd3d);

View File

@ -1562,7 +1562,7 @@ static bool d3d9_cg_renderchain_read_viewport(
goto end;
}
if (SUCCEEDED(dest->LockRect(&rect, NULL, D3DLOCK_READONLY)))
if (d3d_surface_lock_rect(dest, (void*)&rect))
{
unsigned x, y;
unsigned pitchpix = rect.Pitch / 4;
@ -1582,7 +1582,7 @@ static bool d3d9_cg_renderchain_read_viewport(
}
}
dest->UnlockRect();
d3d_surface_unlock_rect((void*)dest);
}
else
ret = false;