Commit c7369881 authored by Steve Lhomme's avatar Steve Lhomme Committed by Jean-Baptiste Kempf

direct3d9: move D3D9_Create/D3D9_Destroy in libd3d9_cmmon

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent d0e6e149
...@@ -171,3 +171,65 @@ int D3D9_FillPresentationParameters(vlc_object_t *o, d3d9_handle_t *hd3d, UINT A ...@@ -171,3 +171,65 @@ int D3D9_FillPresentationParameters(vlc_object_t *o, d3d9_handle_t *hd3d, UINT A
return VLC_SUCCESS; return VLC_SUCCESS;
} }
void D3D9_Destroy(d3d9_handle_t *hd3d)
{
if (hd3d->obj)
{
IDirect3D9_Release(hd3d->obj);
hd3d->obj = NULL;
}
if (hd3d->hdll)
{
FreeLibrary(hd3d->hdll);
hd3d->hdll = NULL;
}
}
/**
* It initializes an instance of Direct3D9
*/
#undef D3D9_Create
int D3D9_Create(vlc_object_t *o, d3d9_handle_t *hd3d)
{
hd3d->hdll = LoadLibrary(TEXT("D3D9.DLL"));
if (!hd3d->hdll) {
msg_Warn(o, "cannot load d3d9.dll, aborting");
return VLC_EGENERIC;
}
LPDIRECT3D9 (WINAPI *OurDirect3DCreate9)(UINT SDKVersion);
OurDirect3DCreate9 =
(void *)GetProcAddress(hd3d->hdll, "Direct3DCreate9");
if (!OurDirect3DCreate9) {
msg_Err(o, "Cannot locate reference to Direct3DCreate9 ABI in DLL");
goto error;
}
HRESULT (WINAPI *OurDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
OurDirect3DCreate9Ex =
(void *)GetProcAddress(hd3d->hdll, "Direct3DCreate9Ex");
/* Create the D3D object. */
hd3d->use_ex = false;
if (OurDirect3DCreate9Ex) {
HRESULT hr = OurDirect3DCreate9Ex(D3D_SDK_VERSION, &hd3d->objex);
if(!FAILED(hr)) {
msg_Dbg(o, "Using Direct3D9 Extended API!");
hd3d->use_ex = true;
}
}
if (!hd3d->obj)
{
hd3d->obj = OurDirect3DCreate9(D3D_SDK_VERSION);
if (!hd3d->obj) {
msg_Err(o, "Could not create Direct3D9 instance.");
goto error;
}
}
return VLC_SUCCESS;
error:
D3D9_Destroy( hd3d );
return VLC_EGENERIC;
}
...@@ -78,6 +78,10 @@ HRESULT D3D9_CreateDevice(vlc_object_t *, d3d9_handle_t *, HWND, ...@@ -78,6 +78,10 @@ HRESULT D3D9_CreateDevice(vlc_object_t *, d3d9_handle_t *, HWND,
#define D3D9_CreateDevice(a,b,c,d,e) D3D9_CreateDevice( VLC_OBJECT(a), b, c, d, e ) #define D3D9_CreateDevice(a,b,c,d,e) D3D9_CreateDevice( VLC_OBJECT(a), b, c, d, e )
void D3D9_ReleaseDevice(d3d9_device_t *); void D3D9_ReleaseDevice(d3d9_device_t *);
int D3D9_Create(vlc_object_t *, d3d9_handle_t *);
#define D3D9_Create(a,b) D3D9_Create( VLC_OBJECT(a), b )
void D3D9_Destroy(d3d9_handle_t *);
int D3D9_FillPresentationParameters(vlc_object_t *, d3d9_handle_t *, UINT AdapterToUse, HWND, int D3D9_FillPresentationParameters(vlc_object_t *, d3d9_handle_t *, UINT AdapterToUse, HWND,
const video_format_t *, d3d9_device_t *out); const video_format_t *, d3d9_device_t *out);
......
...@@ -184,7 +184,6 @@ static picture_pool_t*DisplayPool(vout_display_t *, unsigned); ...@@ -184,7 +184,6 @@ static picture_pool_t*DisplayPool(vout_display_t *, unsigned);
static int Control(vout_display_t *, int, va_list); static int Control(vout_display_t *, int, va_list);
static void Manage (vout_display_t *); static void Manage (vout_display_t *);
static int D3D9_Create(vlc_object_t *, d3d9_handle_t *);
static int Direct3D9Reset (vout_display_t *); static int Direct3D9Reset (vout_display_t *);
static void Direct3D9Destroy(struct d3dctx *); static void Direct3D9Destroy(struct d3dctx *);
...@@ -265,7 +264,7 @@ static int Open(vlc_object_t *object) ...@@ -265,7 +264,7 @@ static int Open(vlc_object_t *object)
if (!sys) if (!sys)
return VLC_ENOMEM; return VLC_ENOMEM;
if (D3D9_Create(VLC_OBJECT(vd), &sys->d3dctx.hd3d)) { if (D3D9_Create(vd, &sys->d3dctx.hd3d)) {
msg_Err(vd, "Direct3D9 could not be initialized"); msg_Err(vd, "Direct3D9 could not be initialized");
free(sys); free(sys);
return VLC_EGENERIC; return VLC_EGENERIC;
...@@ -734,73 +733,12 @@ static void Manage (vout_display_t *vd) ...@@ -734,73 +733,12 @@ static void Manage (vout_display_t *vd)
} }
} }
static void D3D9_Release(d3d9_handle_t *hd3d)
{
if (hd3d->obj)
{
IDirect3D9_Release(hd3d->obj);
hd3d->obj = NULL;
}
if (hd3d->hdll)
{
FreeLibrary(hd3d->hdll);
hd3d->hdll = NULL;
}
}
/**
* It initializes an instance of Direct3D9
*/
static int D3D9_Create(vlc_object_t *o, d3d9_handle_t *hd3d)
{
hd3d->hdll = LoadLibrary(TEXT("D3D9.DLL"));
if (!hd3d->hdll) {
msg_Warn(o, "cannot load d3d9.dll, aborting");
return VLC_EGENERIC;
}
LPDIRECT3D9 (WINAPI *OurDirect3DCreate9)(UINT SDKVersion);
OurDirect3DCreate9 =
(void *)GetProcAddress(hd3d->hdll, "Direct3DCreate9");
if (!OurDirect3DCreate9) {
msg_Err(o, "Cannot locate reference to Direct3DCreate9 ABI in DLL");
goto error;
}
HRESULT (WINAPI *OurDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
OurDirect3DCreate9Ex =
(void *)GetProcAddress(hd3d->hdll, "Direct3DCreate9Ex");
/* Create the D3D object. */
hd3d->use_ex = false;
if (OurDirect3DCreate9Ex) {
HRESULT hr = OurDirect3DCreate9Ex(D3D_SDK_VERSION, &hd3d->objex);
if(!FAILED(hr)) {
msg_Dbg(o, "Using Direct3D9 Extended API!");
hd3d->use_ex = true;
}
}
if (!hd3d->obj)
{
hd3d->obj = OurDirect3DCreate9(D3D_SDK_VERSION);
if (!hd3d->obj) {
msg_Err(o, "Could not create Direct3D9 instance.");
goto error;
}
}
return VLC_SUCCESS;
error:
D3D9_Release( hd3d );
return VLC_EGENERIC;
}
/** /**
* It releases an instance of Direct3D9 * It releases an instance of Direct3D9
*/ */
static void Direct3D9Destroy(struct d3dctx *d3dctx) static void Direct3D9Destroy(struct d3dctx *d3dctx)
{ {
D3D9_Release( &d3dctx->hd3d ); D3D9_Destroy( &d3dctx->hd3d );
if (d3dctx->hxdll) if (d3dctx->hxdll)
{ {
......
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