Commit c513cf2a authored by Laurent Aimar's avatar Laurent Aimar

Cached texture created for subpicture rendering (direct3d).

It avoids creating/destroying texture uselessly.
parent f65874cb
...@@ -182,6 +182,8 @@ struct vout_display_sys_t ...@@ -182,6 +182,8 @@ struct vout_display_sys_t
// scene objects // scene objects
LPDIRECT3DTEXTURE9 d3dtex; LPDIRECT3DTEXTURE9 d3dtex;
LPDIRECT3DVERTEXBUFFER9 d3dvtc; LPDIRECT3DVERTEXBUFFER9 d3dvtc;
int d3dregion_count;
struct d3d_region_t *d3dregion;
picture_resource_t resource; picture_resource_t resource;
......
...@@ -125,11 +125,16 @@ typedef struct ...@@ -125,11 +125,16 @@ typedef struct
} CUSTOMVERTEX; } CUSTOMVERTEX;
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1) #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
typedef struct { typedef struct d3d_region_t {
D3DFORMAT format;
unsigned width;
unsigned height;
CUSTOMVERTEX vertex[4]; CUSTOMVERTEX vertex[4];
LPDIRECT3DTEXTURE9 texture; LPDIRECT3DTEXTURE9 texture;
} d3d_region_t; } d3d_region_t;
static void Direct3DDeleteRegions(int, d3d_region_t *);
static int Direct3DImportPicture(vout_display_t *vd, d3d_region_t *, LPDIRECT3DSURFACE9 surface); static int Direct3DImportPicture(vout_display_t *vd, d3d_region_t *, LPDIRECT3DSURFACE9 surface);
static void Direct3DImportSubpicture(vout_display_t *vd, int *, d3d_region_t **, subpicture_t *); static void Direct3DImportSubpicture(vout_display_t *vd, int *, d3d_region_t **, subpicture_t *);
...@@ -316,9 +321,9 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic ...@@ -316,9 +321,9 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
Direct3DRenderScene(vd, &picture_region, Direct3DRenderScene(vd, &picture_region,
subpicture_region_count, subpicture_region); subpicture_region_count, subpicture_region);
for (int i = 0; i < subpicture_region_count; i++) Direct3DDeleteRegions(sys->d3dregion_count, sys->d3dregion);
IDirect3DTexture9_Release(subpicture_region[i].texture); sys->d3dregion_count = subpicture_region_count;
free(subpicture_region); sys->d3dregion = subpicture_region;
} }
} }
...@@ -1015,6 +1020,9 @@ static int Direct3DCreateScene(vout_display_t *vd, const video_format_t *fmt) ...@@ -1015,6 +1020,9 @@ static int Direct3DCreateScene(vout_display_t *vd, const video_format_t *fmt)
sys->d3dtex = d3dtex; sys->d3dtex = d3dtex;
sys->d3dvtc = d3dvtc; sys->d3dvtc = d3dvtc;
sys->d3dregion_count = 0;
sys->d3dregion = NULL;
// Texture coordinates outside the range [0.0, 1.0] are set // Texture coordinates outside the range [0.0, 1.0] are set
// to the texture color at 0.0 or 1.0, respectively. // to the texture color at 0.0 or 1.0, respectively.
IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
...@@ -1085,6 +1093,8 @@ static void Direct3DDestroyScene(vout_display_t *vd) ...@@ -1085,6 +1093,8 @@ static void Direct3DDestroyScene(vout_display_t *vd)
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
Direct3DDeleteRegions(sys->d3dregion_count, sys->d3dregion);
LPDIRECT3DVERTEXBUFFER9 d3dvtc = sys->d3dvtc; LPDIRECT3DVERTEXBUFFER9 d3dvtc = sys->d3dvtc;
if (d3dvtc) if (d3dvtc)
IDirect3DVertexBuffer9_Release(d3dvtc); IDirect3DVertexBuffer9_Release(d3dvtc);
...@@ -1095,6 +1105,10 @@ static void Direct3DDestroyScene(vout_display_t *vd) ...@@ -1095,6 +1105,10 @@ static void Direct3DDestroyScene(vout_display_t *vd)
sys->d3dvtc = NULL; sys->d3dvtc = NULL;
sys->d3dtex = NULL; sys->d3dtex = NULL;
sys->d3dregion_count = 0;
sys->d3dregion = NULL;
msg_Dbg(vd, "Direct3D scene released successfully"); msg_Dbg(vd, "Direct3D scene released successfully");
} }
...@@ -1179,6 +1193,15 @@ static int Direct3DImportPicture(vout_display_t *vd, ...@@ -1179,6 +1193,15 @@ static int Direct3DImportPicture(vout_display_t *vd,
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void Direct3DDeleteRegions(int count, d3d_region_t *region)
{
for (int i = 0; i < count; i++) {
if (region[i].texture)
IDirect3DTexture9_Release(region[i].texture);
}
free(region);
}
static void Direct3DImportSubpicture(vout_display_t *vd, static void Direct3DImportSubpicture(vout_display_t *vd,
int *count_ptr, d3d_region_t **region, int *count_ptr, d3d_region_t **region,
subpicture_t *subpicture) subpicture_t *subpicture)
...@@ -1202,22 +1225,39 @@ static void Direct3DImportSubpicture(vout_display_t *vd, ...@@ -1202,22 +1225,39 @@ static void Direct3DImportSubpicture(vout_display_t *vd,
HRESULT hr; HRESULT hr;
d3dr->texture = NULL; d3dr->texture = NULL;
hr = IDirect3DDevice9_CreateTexture(sys->d3ddev, for (int j = 0; j < sys->d3dregion_count; j++) {
r->fmt.i_visible_width, r->fmt.i_visible_height, d3d_region_t *cache = &sys->d3dregion[j];
1, if (cache->texture &&
D3DUSAGE_DYNAMIC, cache->format == D3DFMT_A8R8G8B8 &&
D3DFMT_A8R8G8B8, cache->width == r->fmt.i_visible_width &&
D3DPOOL_DEFAULT, cache->height == r->fmt.i_visible_height) {
&d3dr->texture, msg_Dbg(vd, "Reusing %dx%d texture for OSD",
NULL); cache->width, cache->height);
if (FAILED(hr)) { *d3dr = *cache;
d3dr->texture = NULL; memset(cache, 0, sizeof(*cache));
msg_Err(vd, "Failed to create %dx%d texture for OSD", }
}
if (!d3dr->texture) {
d3dr->format = D3DFMT_A8R8G8B8;
d3dr->width = r->fmt.i_visible_width;
d3dr->height = r->fmt.i_visible_height;
hr = IDirect3DDevice9_CreateTexture(sys->d3ddev,
d3dr->width, d3dr->height,
1,
D3DUSAGE_DYNAMIC,
d3dr->format,
D3DPOOL_DEFAULT,
&d3dr->texture,
NULL);
if (FAILED(hr)) {
d3dr->texture = NULL;
msg_Err(vd, "Failed to create %dx%d texture for OSD",
d3dr->width, d3dr->height);
continue;
}
msg_Dbg(vd, "Created %dx%d texture for OSD",
r->fmt.i_visible_width, r->fmt.i_visible_height); r->fmt.i_visible_width, r->fmt.i_visible_height);
continue;
} }
msg_Dbg(vd, "Created %dx%d texture for OSD",
r->fmt.i_visible_width, r->fmt.i_visible_height);
D3DLOCKED_RECT lock; D3DLOCKED_RECT lock;
hr = IDirect3DTexture9_LockRect(d3dr->texture, 0, &lock, NULL, 0); hr = IDirect3DTexture9_LockRect(d3dr->texture, 0, &lock, NULL, 0);
......
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