Commit 99081143 authored by Laurent Aimar's avatar Laurent Aimar Committed by Jean-Baptiste Kempf

Used a CPU memory fallback when Direct3DLockSurface/DirectXLock fails.

It fixes a segfault when the directx/direct3d device is lost at the wrong time
or cannot be restored soon enough (close #3647).
(cherry picked from commit 9381877a72a850aa13051a91a1e86938e19b3cac)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 2f9f4358
......@@ -221,9 +221,24 @@ void CommonDisplay(vout_display_t *vd)
/**
* It updates a picture data/pitches.
*/
void CommonUpdatePicture(picture_t *picture,
uint8_t *data, unsigned pitch)
int CommonUpdatePicture(picture_t *picture, picture_t **fallback,
uint8_t *data, unsigned pitch)
{
if (fallback) {
if (*fallback == NULL) {
*fallback = picture_NewFromFormat(&picture->format);
if (*fallback == NULL)
return VLC_EGENERIC;
}
for (int n = 0; n < picture->i_planes; n++) {
const plane_t *src = &(*fallback)->p[n];
plane_t *dst = &picture->p[n];
dst->p_pixels = src->p_pixels;
dst->i_pitch = src->i_pitch;
dst->i_lines = src->i_lines;
}
return VLC_SUCCESS;
}
/* fill in buffer info in first plane */
picture->p->p_pixels = data;
picture->p->i_pitch = pitch;
......@@ -249,6 +264,7 @@ void CommonUpdatePicture(picture_t *picture,
picture->p[2].p_pixels = p_tmp;
}
}
return VLC_SUCCESS;
}
void AlignRect(RECT *r, int align_boundary, int align_size)
......
......@@ -237,7 +237,7 @@ void CommonClean(vout_display_t *);
void CommonManage(vout_display_t *);
int CommonControl(vout_display_t *, int , va_list );
void CommonDisplay(vout_display_t *);
void CommonUpdatePicture(picture_t *, uint8_t *, unsigned);
int CommonUpdatePicture(picture_t *, picture_t **, uint8_t *, unsigned);
void UpdateRects (vout_display_t *,
const vout_display_cfg_t *,
......
......@@ -85,6 +85,7 @@ vlc_module_end ()
struct picture_sys_t
{
LPDIRECT3DSURFACE9 surface;
picture_t *fallback;
};
static int Open(vlc_object_t *);
......@@ -755,10 +756,10 @@ static int Direct3DLockSurface(picture_t *picture)
HRESULT hr = IDirect3DSurface9_LockRect(picture->p_sys->surface, &d3drect, NULL, 0);
if (FAILED(hr)) {
//msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
return VLC_EGENERIC;
return CommonUpdatePicture(picture, &picture->p_sys->fallback, NULL, 0);
}
CommonUpdatePicture(picture, d3drect.pBits, d3drect.Pitch);
CommonUpdatePicture(picture, NULL, d3drect.pBits, d3drect.Pitch);
return VLC_SUCCESS;
}
/**
......@@ -829,6 +830,7 @@ static int Direct3DCreatePool(vout_display_t *vd, video_format_t *fmt)
return VLC_ENOMEM;
}
rsc->p_sys->surface = surface;
rsc->p_sys->fallback = NULL;
for (int i = 0; i < PICTURE_PLANE_MAX; i++) {
rsc->p[i].p_pixels = NULL;
rsc->p[i].i_pitch = 0;
......@@ -867,7 +869,8 @@ static void Direct3DDestroyPool(vout_display_t *vd)
if (sys->pool) {
picture_resource_t *rsc = &sys->resource;
IDirect3DSurface9_Release(rsc->p_sys->surface);
if (rsc->p_sys->fallback)
picture_Release(rsc->p_sys->fallback);
picture_pool_Delete(sys->pool);
}
sys->pool = NULL;
......
......@@ -127,6 +127,7 @@ vlc_module_end()
struct picture_sys_t {
LPDIRECTDRAWSURFACE2 surface;
LPDIRECTDRAWSURFACE2 front_surface;
picture_t *fallback;
};
/*****************************************************************************
......@@ -1045,6 +1046,7 @@ static int DirectXCreatePictureResourceYuvOverlay(vout_display_t *vd,
picture_resource_t *rsc = &sys->resource;
rsc->p_sys->front_surface = front_surface;
rsc->p_sys->surface = surface;
rsc->p_sys->fallback = NULL;
return VLC_SUCCESS;
}
static int DirectXCreatePictureResourceYuv(vout_display_t *vd,
......@@ -1100,6 +1102,7 @@ static int DirectXCreatePictureResourceYuv(vout_display_t *vd,
picture_resource_t *rsc = &sys->resource;
rsc->p_sys->front_surface = surface;
rsc->p_sys->surface = surface;
rsc->p_sys->fallback = NULL;
return VLC_SUCCESS;
}
static int DirectXCreatePictureResourceRgb(vout_display_t *vd,
......@@ -1159,6 +1162,7 @@ static int DirectXCreatePictureResourceRgb(vout_display_t *vd,
picture_resource_t *rsc = &sys->resource;
rsc->p_sys->front_surface = surface;
rsc->p_sys->surface = surface;
rsc->p_sys->fallback = NULL;
return VLC_SUCCESS;
}
......@@ -1215,6 +1219,8 @@ static void DirectXDestroyPictureResource(vout_display_t *vd)
if (sys->resource.p_sys->front_surface != sys->resource.p_sys->surface)
DirectXDestroySurface(sys->resource.p_sys->surface);
DirectXDestroySurface(sys->resource.p_sys->front_surface);
if (sys->resource.p_sys->fallback)
picture_Release(sys->resource.p_sys->fallback);
}
static int DirectXLock(picture_t *picture)
......@@ -1222,9 +1228,9 @@ static int DirectXLock(picture_t *picture)
DDSURFACEDESC ddsd;
if (DirectXLockSurface(picture->p_sys->front_surface,
picture->p_sys->surface, &ddsd))
return VLC_EGENERIC;
return CommonUpdatePicture(picture, &picture->p_sys->fallback, NULL, 0);
CommonUpdatePicture(picture, ddsd.lpSurface, ddsd.lPitch);
CommonUpdatePicture(picture, NULL, ddsd.lpSurface, ddsd.lPitch);
return VLC_SUCCESS;
}
static void DirectXUnlock(picture_t *picture)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment