d3dvideosink: Add plugin

Fixes #651782.  Patch from various authors, by way of ossbuild.
This commit is contained in:
David Schleef 2011-06-04 18:43:45 -07:00
parent 7b12d4647a
commit 655e511a5c
22 changed files with 4174 additions and 2 deletions

View file

@ -454,6 +454,44 @@ int main ()
AC_SUBST(HAVE_DIRECTSOUND)
])
dnl Direct3D
translit(dnm, m, l) AM_CONDITIONAL(USE_DIRECT3D, true)
AG_GST_CHECK_FEATURE(DIRECT3D, [Direct3D plug-in], direct3dsink, [
HAVE_DIRECT3D="no"
save_CFLAGS="$CFLAGS"
save_LDFLAGS="$LDFLAGS"
save_LIBS="$LIBS"
CFLAGS="$CFLAGS $DIRECTX_CFLAGS"
LDFLAGS="$LDFLAGS $DIRECTX_LDFLAGS"
LIBS="$LIBS -ld3d -lgdi32"
AC_MSG_CHECKING(for Direct3D LDFLAGS)
AC_LINK_IFELSE([
#include <windows.h>
#include <d3d.h>
int main ()
{
GetStockObject(0);
Direct3DCreate(NULL, NULL, NULL);
return 0;
}
],
[HAVE_DIRECT3D="yes"],
[HAVE_DIRECT3D="no"])
AC_MSG_RESULT($HAVE_DIRECT3D)
CFLAGS=$save_CFLAGS
LDFLAGS=$save_LDFLAGS
LIBS=$save_LIBS
if test "x$HAVE_DIRECT3D" = "xyes"; then
dnl this is much more than we want
DIRECT3D_LIBS="-ld3d -ldxguid -lgdi32"
AC_SUBST(DIRECT3D_LIBS)
fi
AC_SUBST(HAVE_DIRECT3D)
])
dnl DirectDraw
translit(dnm, m, l) AM_CONDITIONAL(USE_DIRECTDRAW, true)
AG_GST_CHECK_FEATURE(DIRECTDRAW, [DirectDraw plug-in], directdrawsink, [
@ -1888,6 +1926,7 @@ sys/acmenc/Makefile
sys/acmmp3dec/Makefile
sys/applemedia/Makefile
sys/avc/Makefile
sys/d3dvideosink/Makefile
sys/decklink/Makefile
sys/directdraw/Makefile
sys/directsound/Makefile

View file

@ -22,6 +22,12 @@ endif
# CDROM_DIR=
# endif
if USE_DIRECT3D
D3DVIDEOSINK_DIR=d3dvideosink
else
D3DVIDEOSINK_DIR=
endif
if USE_DECKLINK
DECKLINK_DIR=decklink
else
@ -107,9 +113,9 @@ else
AVC_DIR=
endif
SUBDIRS = $(ACM_DIR) $(APPLE_MEDIA_DIR) $(AVC_DIR) $(DECKLINK_DIR) $(DIRECTDRAW_DIR) $(DIRECTSOUND_DIR) $(DVB_DIR) $(FBDEV_DIR) $(LINSYS_DIR) $(OSX_VIDEO_DIR) $(QT_DIR) $(SHM_DIR) $(VCD_DIR) $(VDPAU_DIR) $(WININET_DIR)
SUBDIRS = $(ACM_DIR) $(APPLE_MEDIA_DIR) $(AVC_DIR) $(D3DVIDEOSINK) $(DECKLINK_DIR) $(DIRECTDRAW_DIR) $(DIRECTSOUND_DIR) $(DVB_DIR) $(FBDEV_DIR) $(LINSYS_DIR) $(OSX_VIDEO_DIR) $(QT_DIR) $(SHM_DIR) $(VCD_DIR) $(VDPAU_DIR) $(WININET_DIR)
DIST_SUBDIRS = acmenc acmmp3dec applemedia avc decklink directdraw directsound dvb linsys fbdev dshowdecwrapper dshowsrcwrapper dshowvideosink \
DIST_SUBDIRS = acmenc acmmp3dec applemedia avc d3dvideosink decklink directdraw directsound dvb linsys fbdev dshowdecwrapper dshowsrcwrapper dshowvideosink \
osxvideo qtwrapper shm vcd vdpau wasapi wininet winks winscreencap
include $(top_srcdir)/common/parallel-subdirs.mak

View file

@ -0,0 +1,16 @@
plugin_LTLIBRARIES = libgstd3dvideosink.la
libgstd3dvideosink_la_SOURCES = d3dvideosink.c directx/d3d.c directx/dx.c \
directx/directx9/dx9.c directx/directx9/dx9_d3d.c \
directx/directx10/dx10.c directx/directx10/dx10_d3d.c \
directx/directx11/dx11.c directx/directx11/dx11_d3d.c
libgstd3dvideosink_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_CFLAGS)
libgstd3dvideosink_la_LIBADD = $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) \
-lgstvideo-$(GST_MAJORMINOR) -lgstinterfaces-$(GST_MAJORMINOR)
libgstd3dvideosink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -lgdi32
libgstd3dvideosink_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = d3dvideosink.h directx/d3d.h directx/dx.h directx/directx.h \
directx/directx9/dx9.h directx/directx9/dx9_d3d.h \
directx/directx10/dx10.h directx/directx10/dx10_d3d.h \
directx/directx11/dx11.h directx/directx11/dx11_d3d.h

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,106 @@
/* GStreamer
* Copyright (C) 2010 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __D3DVIDEOSINK_H__
#define __D3DVIDEOSINK_H__
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideosink.h>
#include <gst/interfaces/xoverlay.h>
#include <gst/interfaces/navigation.h>
#include <windows.h>
#include <d3d9.h>
#include <d3dx9tex.h>
#include "directx/directx.h"
#ifdef _MSC_VER
#pragma warning( disable : 4090 4024)
#endif
G_BEGIN_DECLS
#define GST_TYPE_D3DVIDEOSINK (gst_d3dvideosink_get_type())
#define GST_D3DVIDEOSINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_D3DVIDEOSINK,GstD3DVideoSink))
#define GST_D3DVIDEOSINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_D3DVIDEOSINK,GstD3DVideoSinkClass))
#define GST_D3DVIDEOSINK_GET_CLASS(obj) (GST_D3DVIDEOSINK_CLASS(G_OBJECT_GET_CLASS(obj)))
#define GST_IS_D3DVIDEOSINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_D3DVIDEOSINK))
#define GST_IS_D3DVIDEOSINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_D3DVIDEOSINK))
typedef struct _GstD3DVideoSink GstD3DVideoSink;
typedef struct _GstD3DVideoSinkClass GstD3DVideoSinkClass;
#define GST_D3DVIDEOSINK_SWAP_CHAIN_LOCK(sink) g_mutex_lock (GST_D3DVIDEOSINK (sink)->d3d_swap_chain_lock);
#define GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK(sink) g_mutex_unlock (GST_D3DVIDEOSINK (sink)->d3d_swap_chain_lock);
struct _GstD3DVideoSink
{
GstVideoSink sink;
/* source rectangle */
gint width;
gint height;
GstVideoFormat format;
gboolean enable_navigation_events;
gboolean keep_aspect_ratio;
GValue *par;
/* If the window is closed, we set this and error out */
gboolean window_closed;
/* The video window set through GstXOverlay */
HWND window_handle;
/* If we created the window, it needs to be closed in ::stop() */
gboolean is_new_window;
/* If we create our own window, we run it from another thread */
GThread *window_thread;
HANDLE window_created_signal;
/* If we use an app-supplied window, we need to hook its WNDPROC */
WNDPROC prevWndProc;
gboolean is_hooked;
GMutex *d3d_swap_chain_lock;
LPDIRECT3DSWAPCHAIN9 d3d_swap_chain;
LPDIRECT3DSURFACE9 d3d_offscreen_surface;
D3DFORMAT d3dformat;
D3DFORMAT d3dfourcc;
D3DTEXTUREFILTERTYPE d3dfiltertype;
};
struct _GstD3DVideoSinkClass
{
GstVideoSinkClass parent_class;
gboolean is_directx_supported;
gint directx_version;
DirectXAPI *directx_api;
};
GType gst_d3dvideosink_get_type (void);
G_END_DECLS
#endif /* __D3DVIDEOSINK_H__ */

View file

@ -0,0 +1,65 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "directx.h"
const DirectXD3D *
directx_d3d_create (const DirectXAPI * api)
{
if (!api)
return NULL;
return DIRECTX_D3D_CALL_API_FUNCTION (api, create, api);
}
gboolean
directx_d3d_resize (const DirectXD3D * d3d)
{
if (!d3d)
return FALSE;
return DIRECTX_D3D_CALL_FUNCTION (d3d, resize, d3d);
}
gboolean
directx_d3d_device_lost (const DirectXD3D * d3d)
{
if (!d3d)
return FALSE;
return DIRECTX_D3D_CALL_FUNCTION (d3d, device_lost, d3d);
}
gboolean
directx_d3d_notify_device_reset (const DirectXD3D * d3d)
{
if (!d3d)
return FALSE;
return DIRECTX_D3D_CALL_FUNCTION (d3d, notify_device_reset, d3d);
}
gboolean
directx_d3d_release (const DirectXD3D * d3d)
{
if (!d3d)
return FALSE;
return DIRECTX_D3D_CALL_FUNCTION (d3d, release, d3d);
}

View file

@ -0,0 +1,99 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIRECTX_D3D_H__
#define __DIRECTX_D3D_H__
#include <glib.h>
#include "dx.h"
G_BEGIN_DECLS
#define WM_DIRECTX_D3D_INIT_DEVICE WM_DIRECTX + 1
#define WM_DIRECTX_D3D_INIT_DEVICELOST WM_DIRECTX + 2
#define WM_DIRECTX_D3D_DEVICELOST WM_DIRECTX + 3
#define WM_DIRECTX_D3D_END_DEVICELOST WM_DIRECTX + 4
#define WM_DIRECTX_D3D_RESIZE WM_DIRECTX + 5
#define DIRECTX_D3D_API(version, dispatch_table, init_function, create_function, resize_function, device_lost_function, notify_device_reset_function, release_function) \
static gpointer DIRECTX_API_COMPONENT_D3D_ ## version ## _DISPATCH_TABLE = &dispatch_table; \
static DirectXAPIComponentD3D DIRECTX_API_COMPONENT_D3D_ ## version ## _INIT = { \
create_function /*create_function*/ \
, resize_function /*resize_function*/ \
, device_lost_function /*device_lost_function*/ \
, notify_device_reset_function /*notify_device_reset_function*/ \
, release_function /*release_function*/ \
, NULL /*private_data*/ \
}; \
static void init_directx_api_component_d3d_ ## version ## _(const DirectXAPI* api) { \
gpointer private_data = &DIRECTX_API_COMPONENT_D3D_ ## version ## _INIT; \
gpointer vtable = DIRECTX_API_COMPONENT_D3D_ ## version ## _DISPATCH_TABLE; \
DIRECTX_SET_COMPONENT_INIT(DIRECTX_D3D(api), init_function); \
DIRECTX_SET_COMPONENT_DATA(DIRECTX_D3D(api), private_data); \
DIRECTX_SET_COMPONENT_DISPATCH_TABLE(DIRECTX_D3D(api), vtable); \
}
#define INITIALIZE_DIRECTX_D3D_API(version, api) \
init_directx_api_component_d3d_ ## version ## _(api);
#define DIRECTX_D3D_FUNCTIONS(d3d) ((DirectXAPIComponentD3D*)d3d->d3d_component)
#define DIRECTX_D3D_API_FUNCTIONS(api) ((DirectXAPIComponentD3D*)DIRECTX_D3D_COMPONENT_DATA(api))
#define DIRECTX_D3D_CALL_FUNCTION(d3d, func_name, ...) (DIRECTX_D3D_FUNCTIONS(d3d)->func_name(__VA_ARGS__))
#define DIRECTX_D3D_CALL_API_FUNCTION(api, func_name, ...) (DIRECTX_D3D_API_FUNCTIONS(api)->func_name(__VA_ARGS__))
typedef struct _DirectXD3D DirectXD3D;
typedef struct _DirectXAPIComponentD3D DirectXAPIComponentD3D;
/* Function pointers */
typedef DirectXD3D* (*DirectXD3DCreateFunction) (const DirectXAPI* api);
typedef gboolean (*DirectXD3DResizeFunction) (const DirectXD3D* d3d);
typedef gboolean (*DirectXD3DDeviceLostFunction) (const DirectXD3D* d3d);
typedef gboolean (*DirectXD3DNotifyDeviceResetFunction) (const DirectXD3D* d3d);
typedef gboolean (*DirectXD3DReleaseFunction) (const DirectXD3D* d3d);
struct _DirectXAPIComponentD3D
{
DirectXD3DCreateFunction create;
DirectXD3DResizeFunction resize;
DirectXD3DDeviceLostFunction device_lost;
DirectXD3DNotifyDeviceResetFunction notify_device_reset;
DirectXD3DReleaseFunction release;
gpointer private_data;
};
struct _DirectXD3D
{
DirectXAPI* api;
DirectXAPIComponent* api_component;
DirectXAPIComponentD3D* d3d_component;
gpointer private_data;
};
const DirectXD3D* directx_d3d_create(const DirectXAPI* api);
gboolean directx_d3d_resize(const DirectXD3D* d3d);
gboolean directx_d3d_device_lost(const DirectXD3D* d3d);
gboolean directx_d3d_notify_device_reset(const DirectXD3D* d3d);
gboolean directx_d3d_release(const DirectXD3D* d3d);
G_END_DECLS
#endif /* __DIRECTX_D3D_H__ */

View file

@ -0,0 +1,33 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIRECTX_DIRECTX_H__
#define __DIRECTX_DIRECTX_H__
#include "dx.h"
#include "d3d.h"
/* TODO: Remove these headers -- they should not be publically distributed. */
/* They're included for now only for expediancy in getting d3dvideosink */
/* out the door. */
#include "directx9/dx9.h"
#include "directx10/dx10.h"
#include "directx11/dx11.h"
#endif /* __DIRECTX_DIRECTX_H__ */

View file

@ -0,0 +1,27 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dx10.h"
void
dx10_init (const DirectXAPI * api)
{
DIRECTX_DEBUG ("Initializing DirectX10 API");
INITIALIZE_DIRECTX_D3D_API (DIRECTX_10, api);
}

View file

@ -0,0 +1,39 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIRECTX_DIRECTX10_DX10_H__
#define __DIRECTX_DIRECTX10_DX10_H__
#include "../dx.h"
#include "dx10_d3d.h"
/* Function declarations */
void dx10_init(const DirectXAPI* api);
DIRECTX_API(
DIRECTX_10,
dx10_init,
"d3d10",
"D3D10CreateDevice",
"DirectX10Description",
"DirectX 10.0"
)
#endif /* __DIRECTX_DIRECTX10_DX10_H__ */

View file

@ -0,0 +1,77 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#define CINTERFACE
#define D3D10_IGNORE_SDK_LAYERS
#include <windows.h>
#include <d3d10.h>
#include "dx10_d3d.h"
void
dx10_d3d_init (DirectXAPIComponent * component, gpointer data)
{
DIRECTX_DEBUG ("Initializing Direct3D");
DIRECTX_OPEN_COMPONENT_MODULE (component, "d3d10");
DIRECTX_DEBUG ("Completed Initializing Direct3D");
DIRECTX_DEBUG ("Setting Direct3D dispatch table");
DIRECTX_OPEN_COMPONENT_SYMBOL (component, D3D10DispatchTable,
D3D10CreateDevice);
//{
// ID3D10Device* pDevice = NULL;
// DIRECTX_DEBUG("Calling D3D10CreateDevice");
// DX10_D3D_COMPONENT_CALL_FUNC(component, D3D10CreateDevice, NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &pDevice);
// DIRECTX_DEBUG("Releasing D3D10 device");
// ID3D10Device_Release(pDevice);
// DIRECTX_DEBUG("Released D3D10 device");
//}
}
DirectXD3D *
dx10_d3d_create (const DirectXAPI * api)
{
return NULL;
}
gboolean
dx10_d3d_resize (const DirectXD3D * d3d)
{
return TRUE;
}
gboolean
dx10_d3d_device_lost (const DirectXD3D * d3d)
{
return TRUE;
}
gboolean
dx10_d3d_notify_device_reset (const DirectXD3D * d3d)
{
return TRUE;
}
gboolean
dx10_d3d_release (const DirectXD3D * d3d)
{
return TRUE;
}

View file

@ -0,0 +1,72 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIRECTX_DIRECTX10_DX10_D3D_H__
#define __DIRECTX_DIRECTX10_DX10_D3D_H__
#include <windows.h>
#include "../d3d.h"
#define DX10_D3D_API_CALL_FUNC(api, func_name, ...) (DIRECTX_CALL_COMPONENT_SYMBOL(DIRECTX_D3D(api), D3D10DispatchTable, func_name, __VA_ARGS__))
#define DX10_D3D_COMPONENT_CALL_FUNC(component, func_name, ...) (DIRECTX_CALL_COMPONENT_SYMBOL(component, D3D10DispatchTable, func_name, __VA_ARGS__))
/* Structs */
typedef struct _D3D10 D3D10;
typedef struct _D3D10DispatchTable D3D10DispatchTable;
/* Functions */
/* Courtesy http://code.google.com/p/theaimworldeditor/source/browse/trunk/DXUT/Core/DXUTmisc.cpp */
typedef HRESULT (WINAPI *LPD3D10CREATEDEVICE)(gpointer /* IDXGIAdapter* */, UINT /* D3D10_DRIVER_TYPE */, HMODULE, UINT, UINT32, gpointer* /* ID3D10Device** */ );
struct _D3D10DispatchTable
{
LPD3D10CREATEDEVICE D3D10CreateDevice;
};
/* Global data */
struct _D3D10
{
D3D10DispatchTable vtable;
};
/* Global vars */
static D3D10 dx10_d3d;
/* Function declarations */
void dx10_d3d_init(DirectXAPIComponent* component, gpointer data);
DirectXD3D* dx10_d3d_create(const DirectXAPI* api);
gboolean dx10_d3d_resize(const DirectXD3D* d3d);
gboolean dx10_d3d_device_lost(const DirectXD3D* d3d);
gboolean dx10_d3d_notify_device_reset(const DirectXD3D* d3d);
gboolean dx10_d3d_release(const DirectXD3D* d3d);
DIRECTX_D3D_API(
DIRECTX_10,
dx10_d3d.vtable,
dx10_d3d_init,
dx10_d3d_create,
dx10_d3d_resize,
dx10_d3d_device_lost,
dx10_d3d_notify_device_reset,
dx10_d3d_release
)
#endif /* __DIRECTX_DIRECTX10_DX10_D3D_H__ */

View file

@ -0,0 +1,27 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dx11.h"
void
dx11_init (const DirectXAPI * api)
{
DIRECTX_DEBUG ("Initializing DirectX11 API");
INITIALIZE_DIRECTX_D3D_API (DIRECTX_11, api);
}

View file

@ -0,0 +1,39 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIRECTX_DIRECTX11_DX11_H__
#define __DIRECTX_DIRECTX11_DX11_H__
#include "../dx.h"
#include "dx11_d3d.h"
/* Function declarations */
void dx11_init(const DirectXAPI* api);
DIRECTX_API(
DIRECTX_11,
dx11_init,
"d3d11",
"D3D11CreateDevice",
"DirectX11Description",
"DirectX 11.0"
)
#endif /* __DIRECTX_DIRECTX10_DX10_H__ */

View file

@ -0,0 +1,75 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#define CINTERFACE
#include <windows.h>
//#include <d3d11.h>
#include "dx11_d3d.h"
void
dx11_d3d_init (DirectXAPIComponent * component, gpointer data)
{
DIRECTX_DEBUG ("Initializing Direct3D");
DIRECTX_OPEN_COMPONENT_MODULE (component, "d3d11");
DIRECTX_DEBUG ("Completed Initializing Direct3D");
DIRECTX_DEBUG ("Setting Direct3D dispatch table");
//DIRECTX_OPEN_COMPONENT_SYMBOL(component, D3D11DispatchTable, D3D11CreateDevice);
//{
// ID3D11Device* pDevice = NULL;
// DIRECTX_DEBUG("Calling D3D11CreateDevice");
// DX11_D3D_COMPONENT_CALL_FUNC(component, D3D11CreateDevice, NULL, D3D11_DRIVER_TYPE_HARDWARE, NULL, 0, D3D11_SDK_VERSION, &pDevice);
// DIRECTX_DEBUG("Releasing D3D11 device");
// ID3D11Device_Release(pDevice);
// DIRECTX_DEBUG("Released D3D11 device");
//}
}
DirectXD3D *
dx11_d3d_create (const DirectXAPI * api)
{
return NULL;
}
gboolean
dx11_d3d_resize (const DirectXD3D * d3d)
{
return TRUE;
}
gboolean
dx11_d3d_device_lost (const DirectXD3D * d3d)
{
return TRUE;
}
gboolean
dx11_d3d_notify_device_reset (const DirectXD3D * d3d)
{
return TRUE;
}
gboolean
dx11_d3d_release (const DirectXD3D * d3d)
{
return TRUE;
}

View file

@ -0,0 +1,72 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIRECTX_DIRECTX11_DX11_D3D_H__
#define __DIRECTX_DIRECTX11_DX11_D3D_H__
#include <windows.h>
#include "../d3d.h"
#define DX11_D3D_API_CALL_FUNC(api, func_name, ...) (DIRECTX_CALL_COMPONENT_SYMBOL(DIRECTX_D3D(api), D3D11DispatchTable, func_name, __VA_ARGS__))
#define DX11_D3D_COMPONENT_CALL_FUNC(component, func_name, ...) (DIRECTX_CALL_COMPONENT_SYMBOL(component, D3D11DispatchTable, func_name, __VA_ARGS__))
/* Structs */
typedef struct _D3D11 D3D11;
typedef struct _D3D11DispatchTable D3D11DispatchTable;
/* Functions */
/* Courtesy http://code.google.com/p/theaimworldeditor/source/browse/trunk/DXUT/Core/DXUTmisc.cpp */
typedef HRESULT (WINAPI *LPD3D11CREATEDEVICE)(gpointer /* IDXGIAdapter* */, UINT /* D3D11_DRIVER_TYPE */, HMODULE, UINT, UINT32, gpointer* /* ID3D11Device** */ );
struct _D3D11DispatchTable
{
LPD3D11CREATEDEVICE D3D11CreateDevice;
};
/* Global data */
struct _D3D11
{
D3D11DispatchTable vtable;
};
/* Global vars */
static D3D11 dx11_d3d;
/* Function declarations */
void dx11_d3d_init(DirectXAPIComponent* component, gpointer data);
DirectXD3D* dx11_d3d_create(const DirectXAPI* api);
gboolean dx11_d3d_resize(const DirectXD3D* d3d);
gboolean dx11_d3d_device_lost(const DirectXD3D* d3d);
gboolean dx11_d3d_notify_device_reset(const DirectXD3D* d3d);
gboolean dx11_d3d_release(const DirectXD3D* d3d);
DIRECTX_D3D_API(
DIRECTX_11,
dx11_d3d.vtable,
dx11_d3d_init,
dx11_d3d_create,
dx11_d3d_resize,
dx11_d3d_device_lost,
dx11_d3d_notify_device_reset,
dx11_d3d_release
)
#endif /* __DIRECTX_DIRECTX11_DX11_D3D_H__ */

View file

@ -0,0 +1,27 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dx9.h"
void
dx9_init (const DirectXAPI * api)
{
DIRECTX_DEBUG ("Initializing DirectX9 API");
INITIALIZE_DIRECTX_D3D_API (DIRECTX_9, api);
}

View file

@ -0,0 +1,38 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIRECTX_DIRECTX9_DX10_H__
#define __DIRECTX_DIRECTX9_DX10_H__
#include "../dx.h"
#include "dx9_d3d.h"
void dx9_init(const DirectXAPI* api);
DIRECTX_API(
DIRECTX_9,
dx9_init,
"d3d9",
"Direct3DCreate9",
"DirectX9Description",
"DirectX 9.0"
)
#endif /* __DIRECTX_DIRECTX9_DX10_H__ */

View file

@ -0,0 +1,73 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <d3d9.h>
#include <d3dx9tex.h>
#include "dx9_d3d.h"
void
dx9_d3d_init (DirectXAPIComponent * component, gpointer data)
{
DIRECTX_DEBUG ("Initializing Direct3D");
DIRECTX_OPEN_COMPONENT_MODULE (component, "d3d9");
DIRECTX_DEBUG ("Setting Direct3D dispatch table");
DIRECTX_OPEN_COMPONENT_SYMBOL (component, D3D9DispatchTable, Direct3DCreate9);
//{
// IDirect3D9* blah;
// DIRECTX_DEBUG("CALLING CREATE9!");
// //blah = DX9_CALL_FUNC(data, Direct3DCreate9, D3D_SDK_VERSION);
// blah = DX9_D3D_COMPONENT_CALL_FUNC(component, Direct3DCreate9, D3D_SDK_VERSION);
// DIRECTX_DEBUG("RELEASING CREATE9!");
// IDirect3D9_Release(blah);
// DIRECTX_DEBUG("RELEASED CREATE9!");
//}
}
DirectXD3D *
dx9_d3d_create (const DirectXAPI * api)
{
return NULL;
}
gboolean
dx9_d3d_resize (const DirectXD3D * d3d)
{
return TRUE;
}
gboolean
dx9_d3d_device_lost (const DirectXD3D * d3d)
{
return TRUE;
}
gboolean
dx9_d3d_notify_device_reset (const DirectXD3D * d3d)
{
return TRUE;
}
gboolean
dx9_d3d_release (const DirectXD3D * d3d)
{
return TRUE;
}

View file

@ -0,0 +1,71 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIRECTX_DIRECTX9_DX9_D3D_H__
#define __DIRECTX_DIRECTX9_DX9_D3D_H__
#include <windows.h>
#include "../d3d.h"
#define DX9_D3D_API_CALL_FUNC(api, func_name, ...) (DIRECTX_CALL_COMPONENT_SYMBOL(DIRECTX_D3D(api), D3D9DispatchTable, func_name, __VA_ARGS__))
#define DX9_D3D_COMPONENT_CALL_FUNC(component, func_name, ...) (DIRECTX_CALL_COMPONENT_SYMBOL(component, D3D9DispatchTable, func_name, __VA_ARGS__))
/* Structs */
typedef struct _D3D9 D3D9;
typedef struct _D3D9DispatchTable D3D9DispatchTable;
/* Functions */
typedef gpointer /* IDirect3D9* */ (WINAPI *LPDIRECT3DCREATE9) (UINT);
struct _D3D9DispatchTable
{
LPDIRECT3DCREATE9 Direct3DCreate9;
};
/* Global data */
struct _D3D9
{
D3D9DispatchTable vtable;
};
/* Global vars */
static D3D9 dx9_d3d;
/* Function declarations */
void dx9_d3d_init(DirectXAPIComponent* component, gpointer data);
DirectXD3D* dx9_d3d_create(const DirectXAPI* api);
gboolean dx9_d3d_resize(const DirectXD3D* d3d);
gboolean dx9_d3d_device_lost(const DirectXD3D* d3d);
gboolean dx9_d3d_notify_device_reset(const DirectXD3D* d3d);
gboolean dx9_d3d_release(const DirectXD3D* d3d);
DIRECTX_D3D_API(
DIRECTX_9,
dx9_d3d.vtable,
dx9_d3d_init,
dx9_d3d_create,
dx9_d3d_resize,
dx9_d3d_device_lost,
dx9_d3d_notify_device_reset,
dx9_d3d_release
)
#endif /* __DIRECTX_DIRECTX9_DX9_D3D_H__ */

View file

@ -0,0 +1,282 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <glib.h>
#include <glib/gprintf.h>
#include <gmodule.h>
#include "dx.h"
#include "directx9/dx9.h"
#include "directx10/dx10.h"
#include "directx11/dx11.h"
static void
init_supported_apis (void)
{
/* Gather information we'll need about each version of DirectX. */
/* Insert in reverse order of desired priority due to the g_list_prepend() call in directx_determine_best_available_api(). */
INITIALIZE_SUPPORTED_DIRECTX_API (DIRECTX_9);
/* TODO: Add DirectX 10 support. */
/*INITIALIZE_SUPPORTED_DIRECTX_API(DIRECTX_10); */
/* TODO: Add DirectX 11 support. */
/*INITIALIZE_SUPPORTED_DIRECTX_API(DIRECTX_11); */
}
/* Function declarations */
static DirectXAPI *directx_determine_best_available_api (void);
/* Mutex macros */
#define DIRECTX_LOCK g_static_rec_mutex_lock (&dx_lock);
#define DIRECTX_UNLOCK g_static_rec_mutex_unlock (&dx_lock);
typedef struct _DirectXInfo DirectXInfo;
struct _DirectXInfo
{
gboolean initialized;
gboolean supported;
DirectXInitParams *init_params;
DirectXAPI *best_api;
GList *supported_api_list;
gint32 supported_api_count;
};
/* Private vars */
static DirectXInfo dx;
static GStaticRecMutex dx_lock = G_STATIC_REC_MUTEX_INIT;
gboolean
directx_initialize (DirectXInitParams * init_params)
{
DIRECTX_LOCK if (dx.initialized)
goto success;
dx.init_params = NULL;
dx.init_params = init_params;
init_supported_apis ();
dx.best_api = directx_determine_best_available_api ();
dx.supported = (dx.best_api != NULL
&& !DIRECTX_VERSION_IS_UNKNOWN (dx.best_api->version));
dx.initialized = TRUE;
success:
DIRECTX_UNLOCK return TRUE;
}
gboolean
directx_api_initialize (DirectXAPI * api)
{
if (!api)
return FALSE;
DIRECTX_LOCK if (!directx_is_initialized ())
goto error;
if (api->initialized)
goto success;
/* API init */
api->initialize (api);
/* Component initialization */
DIRECTX_COMPONENT_INIT (DIRECTX_D3D (api));
DIRECTX_COMPONENT_INIT (DIRECTX_DINPUT (api));
DIRECTX_COMPONENT_INIT (DIRECTX_DSOUND (api));
DIRECTX_COMPONENT_INIT (DIRECTX_DWRITE (api));
DIRECTX_COMPONENT_INIT (DIRECTX_D2D (api));
DIRECTX_COMPONENT_INIT (DIRECTX_DCOMPUTE (api));
/* All done */
api->initialized = TRUE;
success:
DIRECTX_UNLOCK return TRUE;
error:
DIRECTX_UNLOCK return FALSE;
}
gboolean
directx_initialize_best_available_api (void)
{
return directx_api_initialize (directx_get_best_available_api ());
}
gboolean
directx_is_initialized (void)
{
gboolean initialized = FALSE;
DIRECTX_LOCK initialized = dx.initialized;
DIRECTX_UNLOCK return initialized;
}
gboolean
directx_api_is_initialized (const DirectXAPI * api)
{
if (!api)
return FALSE;
{
gboolean initialized;
DIRECTX_LOCK initialized = api->initialized;
DIRECTX_UNLOCK return initialized;
}
}
gboolean
directx_best_available_api_is_initialized (void)
{
return directx_api_is_initialized (directx_get_best_available_api ());
}
gboolean
directx_is_supported (void)
{
return dx.supported;
}
GList *
directx_get_supported_apis (void)
{
return dx.supported_api_list;
}
gint32
directx_get_supported_api_count (void)
{
return dx.supported_api_count;
}
DirectXAPI *
directx_get_best_available_api (void)
{
return dx.best_api;
}
void
directx_log_debug (const gchar * file, const gchar * function, gint line,
const gchar * format, ...)
{
if (!dx.init_params || !dx.init_params->log_debug)
return;
{
va_list args;
va_start (args, format);
dx.init_params->log_debug (file, function, line, format, args);
va_end (args);
}
}
void
directx_log_warning (const gchar * file, const gchar * function, gint line,
const gchar * format, ...)
{
if (!dx.init_params || !dx.init_params->log_warning)
return;
{
va_list args;
va_start (args, format);
dx.init_params->log_warning (file, function, line, format, args);
va_end (args);
}
}
void
directx_log_error (const gchar * file, const gchar * function, gint line,
const gchar * format, ...)
{
if (!dx.init_params || !dx.init_params->log_error)
return;
{
va_list args;
va_start (args, format);
dx.init_params->log_error (file, function, line, format, args);
va_end (args);
}
}
/* This should only be called through use of the DIRECTX_API() macro. It should never be called directly. */
gboolean
directx_add_supported_api (DirectXAPI * api)
{
if (!api)
return FALSE;
DIRECTX_LOCK {
/* Add to our GList containing all of our supported APIs. */
/* GLists are doubly-linked lists and calling prepend() prevents it from having to traverse the entire list just to add one item. */
dx.supported_api_list = g_list_prepend (dx.supported_api_list, api);
dx.supported_api_count++;
}
/*success:*/
DIRECTX_UNLOCK return TRUE;
}
static DirectXAPI *
directx_determine_best_available_api (void)
{
if (!g_module_supported ())
return NULL;
{
GList *item;
GModule *lib;
DirectXAPI *dxlib = NULL;
DIRECTX_LOCK {
/* Search supported APIs (DirectX9, DirectX10, etc.) looking for the first one that works. */
DIRECTX_DEBUG
("Searching supported DirectX APIs for the best (most recent) one available");
for (item = g_list_first (dx.supported_api_list); item; item = item->next) {
if ((dxlib = (DirectXAPI *) item->data) == NULL)
continue;
DIRECTX_DEBUG ("Determining support for %s", dxlib->description);
DIRECTX_DEBUG ("Searching for module \"%s\" with the symbol \"%s\"",
dxlib->module_test, dxlib->symbol_test);
/* Can we locate and open a Direct3D library (e.g. d3d9.dll or d3d10.dll)? */
if ((lib =
g_module_open (dxlib->module_test,
G_MODULE_BIND_LAZY)) != NULL) {
/* Look for a symbol/function (e.g. "Direct3DCreate9") in the module and if it exists, we found one! */
gpointer symbol;
if (g_module_symbol (lib, dxlib->symbol_test, &symbol)) {
g_module_close (lib);
DIRECTX_DEBUG ("Selected %s", dxlib->description);
goto done;
}
/* Ensure we don't have a mem leak. */
g_module_close (lib);
}
}
}
done:
DIRECTX_UNLOCK return dxlib;
}
}

View file

@ -0,0 +1,265 @@
/* GStreamer
* Copyright (C) 2011 David Hoyt <dhoyt@hoytsoft.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIRECTX_DX_H__
#define __DIRECTX_DX_H__
#include <glib.h>
#include <gmodule.h>
G_BEGIN_DECLS
#define WM_DIRECTX WM_USER + 500
#define DIRECTX_VERSION_UNKNOWN 0
#define DIRECTX_VERSION_ENCODE_FULL(major, minor, micro) ( \
((major) * 10000) \
+ ((minor) * 100) \
+ ((micro) * 1))
#define DIRECTX_VERSION_ENCODE(major) \
DIRECTX_VERSION_ENCODE_FULL(major, 0, 0)
typedef enum
{
DIRECTX_UNKNOWN = DIRECTX_VERSION_UNKNOWN,
DIRECTX_9 = DIRECTX_VERSION_ENCODE(9),
DIRECTX_10 = DIRECTX_VERSION_ENCODE(10),
DIRECTX_10_1 = DIRECTX_VERSION_ENCODE_FULL(10, 1, 0),
DIRECTX_11 = DIRECTX_VERSION_ENCODE(11)
} DirectXVersion;
#define DIRECTX_API(version, initialization_function, module_test, symbol_test, i18n_key, description) \
static DirectXAPIComponent DIRECTX_ ## version ## _DIRECT3D_COMPONENT = { \
NULL /*api*/ \
, FALSE /*initialized*/ \
, NULL /*initialize*/ \
, NULL /*module*/ \
, NULL /*module_name*/ \
, NULL /*private_data*/ \
}; \
static DirectXAPIComponent DIRECTX_ ## version ## _DIRECTINPUT_COMPONENT = { \
NULL /*api*/ \
, FALSE /*initialized*/ \
, NULL /*initialize*/ \
, NULL /*module*/ \
, NULL /*module_name*/ \
, NULL /*private_data*/ \
}; \
static DirectXAPIComponent DIRECTX_ ## version ## _DIRECTSOUND_COMPONENT = { \
NULL /*api*/ \
, FALSE /*initialized*/ \
, NULL /*initialize*/ \
, NULL /*module*/ \
, NULL /*module_name*/ \
, NULL /*private_data*/ \
}; \
static DirectXAPIComponent DIRECTX_ ## version ## _DIRECTWRITE_COMPONENT = { \
NULL /*api*/ \
, FALSE /*initialized*/ \
, NULL /*initialize*/ \
, NULL /*module*/ \
, NULL /*module_name*/ \
, NULL /*private_data*/ \
}; \
static DirectXAPIComponent DIRECTX_ ## version ## _DIRECT2D_COMPONENT = { \
NULL /*api*/ \
, FALSE /*initialized*/ \
, NULL /*initialize*/ \
, NULL /*module*/ \
, NULL /*module_name*/ \
, NULL /*private_data*/ \
}; \
static DirectXAPIComponent DIRECTX_ ## version ## _DIRECTCOMPUTE_COMPONENT = { \
NULL /*api*/ \
, FALSE /*initialized*/ \
, NULL /*initialize*/ \
, NULL /*module*/ \
, NULL /*module_name*/ \
, NULL /*private_data*/ \
}; \
static DirectXAPI DIRECTX_ ## version ## _API = { \
version \
, module_test "." G_MODULE_SUFFIX \
, symbol_test \
, i18n_key \
, description \
, FALSE \
, initialization_function \
, &DIRECTX_ ## version ## _DIRECT3D_COMPONENT \
, &DIRECTX_ ## version ## _DIRECTINPUT_COMPONENT \
, &DIRECTX_ ## version ## _DIRECTSOUND_COMPONENT \
, &DIRECTX_ ## version ## _DIRECTWRITE_COMPONENT \
, &DIRECTX_ ## version ## _DIRECT2D_COMPONENT \
, &DIRECTX_ ## version ## _DIRECTCOMPUTE_COMPONENT \
, {NULL, NULL, NULL} /*reserved*/ \
}; \
static void init_directx_ ## version ## _supported_api(void) { \
DirectXAPI* api; \
api = &DIRECTX_ ## version ## _API; \
api->d3d->api = api; \
api->dinput->api = api; \
api->dsound->api = api; \
api->dwrite->api = api; \
api->d2d->api = api; \
api->dcompute->api = api; \
directx_add_supported_api(api); \
}
#define INITIALIZE_SUPPORTED_DIRECTX_API(version) \
init_directx_ ## version ## _supported_api();
#define DIRECTX_COMPONENT_INIT(component) \
{ \
if (component != NULL && component->initialize != NULL && !component->initialized) { \
component->initialize(component, DIRECTX_COMPONENT_DATA(component)); \
} \
}
#define DIRECTX_OPEN_COMPONENT_MODULE(component, component_module_name) \
{ \
GModule* lib; \
if (component && component->module == NULL && (lib = g_module_open(component_module_name "." G_MODULE_SUFFIX, G_MODULE_BIND_LAZY)) != NULL) { \
component->module_name = component_module_name "." G_MODULE_SUFFIX; \
component->module = lib; \
} \
}
#define DIRECTX_OPEN_COMPONENT_SYMBOL(component, dispatch_table_type, component_symbol_name) \
{ \
gpointer symbol; \
if (component && component->module && g_module_symbol(component->module, #component_symbol_name, &symbol)) { \
((dispatch_table_type*)component->vtable)->component_symbol_name = symbol; \
} \
}
#define DIRECTX_CALL_COMPONENT_SYMBOL(component, dispatch_table_type, component_symbol_name, ...) \
(((dispatch_table_type*)component->vtable)->component_symbol_name(__VA_ARGS__))
/* Borrowed from GST_FUNCTION */
#ifndef DIRECTX_FUNCTION
#if defined (__GNUC__) || (defined (_MSC_VER) && _MSC_VER >= 1300)
# define DIRECTX_FUNCTION ((const char*) (__FUNCTION__))
#elif defined (__STDC__) && defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define DIRECTX_FUNCTION ((const char*) (__func__))
#else
# define DIRECTX_FUNCTION ((const char*) ("???"))
#endif
#endif
#define DIRECTX_DEBUG(...) (directx_log_debug(__FILE__, DIRECTX_FUNCTION, __LINE__, ##__VA_ARGS__))
#define DIRECTX_WARNING(...) (directx_log_warning(__FILE__, DIRECTX_FUNCTION, __LINE__, ##__VA_ARGS__))
#define DIRECTX_ERROR(...) (directx_log_error(__FILE__, DIRECTX_FUNCTION, __LINE__, ##__VA_ARGS__))
#define DIRECTX_COMPONENT_API(component) (component->api)
#define DIRECTX_COMPONENT_DATA(component) (component->private_data)
#define DIRECTX_SET_COMPONENT_DATA(component, data) (component->private_data = data)
#define DIRECTX_SET_COMPONENT_INIT(component, init_function) (component->initialize = init_function)
#define DIRECTX_SET_COMPONENT_DISPATCH_TABLE(component, dispatch_table) (component->vtable = dispatch_table)
#define DIRECTX_VERSION_IS_UNKNOWN(version) (version == DIRECTX_VERSION_UNKNOWN)
#define DIRECTX_SUPPORTED_API_IS_LAST(lib) (lib == NULL || lib->version == DIRECTX_VERSION_UNKNOWN || lib->module_name == NULL)
typedef struct _DirectXInitParams DirectXInitParams;
typedef struct _DirectXAPI DirectXAPI;
typedef struct _DirectXAPIComponent DirectXAPIComponent;
/* Function pointers */
typedef void (*DirectXInitializationFunction) (const DirectXAPI* api);
typedef void (*DirectXLogFunction) (const gchar* file, const gchar* function, gint line, const gchar* format, va_list args); /* vprintf-style logging function */
struct _DirectXInitParams
{
DirectXLogFunction log_debug;
DirectXLogFunction log_warning;
DirectXLogFunction log_error;
};
struct _DirectXAPI
{
gint version;
const gchar* module_test;
const gchar* symbol_test;
const gchar* i18n_key;
const gchar* description;
gboolean initialized;
DirectXInitializationFunction initialize;
DirectXAPIComponent* d3d;
DirectXAPIComponent* dinput;
DirectXAPIComponent* dsound;
DirectXAPIComponent* dwrite;
DirectXAPIComponent* d2d;
DirectXAPIComponent* dcompute;
gpointer reserved[3];
};
#define DIRECTX_D3D(api) (api->d3d)
#define DIRECTX_DINPUT(api) (api->dinput)
#define DIRECTX_DSOUND(api) (api->dsound)
#define DIRECTX_DWRITE(api) (api->dwrite)
#define DIRECTX_D2D(api) (api->d2d)
#define DIRECTX_DCOMPUTE(api) (api->dcompute)
#define DIRECTX_D3D_COMPONENT_DATA(api) (DIRECTX_COMPONENT_DATA(DIRECTX_D3D(api)))
#define DIRECTX_DINPUT_COMPONENT_DATA(api) (DIRECTX_COMPONENT_DATA(DIRECTX_DINPUT(api)))
#define DIRECTX_DSOUND_COMPONENT_DATA(api) (DIRECTX_COMPONENT_DATA(DIRECTX_DSOUND(api)))
#define DIRECTX_DWRITE_COMPONENT_DATA(api) (DIRECTX_COMPONENT_DATA(DIRECTX_DWRITE(api)))
#define DIRECTX_D2D_COMPONENT_DATA(api) (DIRECTX_COMPONENT_DATA(DIRECTX_D2D(api)))
#define DIRECTX_DCOMPUTE_COMPONENT_DATA(api) (DIRECTX_COMPONENT_DATA(DIRECTX_DCOMPUTE(api)))
/* DirectX component function table */
typedef void (*DirectXComponentInitializeFunction) (DirectXAPIComponent* d3d, gpointer data);
struct _DirectXAPIComponent
{
DirectXAPI* api;
gboolean initialized;
DirectXComponentInitializeFunction initialize;
GModule* module;
const gchar* module_name;
gpointer vtable;
gpointer private_data;
};
gboolean directx_initialize (DirectXInitParams* init_params);
gboolean directx_is_initialized (void);
gboolean directx_is_supported (void);
void directx_log_debug(const gchar* file, const gchar* function, gint line, const gchar * format, ...);
void directx_log_warning(const gchar* file, const gchar* function, gint line, const gchar * format, ...);
void directx_log_error(const gchar* file, const gchar* function, gint line, const gchar * format, ...);
GList* directx_get_supported_apis (void);
gint32 directx_get_supported_api_count (void);
gboolean directx_add_supported_api (DirectXAPI* api);
DirectXAPI* directx_get_best_available_api (void);
gboolean directx_initialize_best_available_api (void);
gboolean directx_best_available_api_is_initialized (void);
gboolean directx_api_initialize (DirectXAPI* api);
gboolean directx_api_is_initialized (const DirectXAPI* api);
G_END_DECLS
#endif /* __DIRECTX_DX_H__ */