[vlc-commits] direct3d9: Group pool related functions together
Hugo Beauzée-Luyssen
git at videolan.org
Wed Apr 5 19:31:03 CEST 2017
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Apr 5 19:06:29 2017 +0200| [67a73e86ca1a3e491256cb230a8214af20a52228] | committer: Hugo Beauzée-Luyssen
direct3d9: Group pool related functions together
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=67a73e86ca1a3e491256cb230a8214af20a52228
---
modules/video_output/win32/direct3d9.c | 269 ++++++++++++++++-----------------
1 file changed, 133 insertions(+), 136 deletions(-)
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 48dcd74..2faf44d 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -406,8 +406,7 @@ static picture_pool_t *Direct3D9CreateDirectRenderingPool(vout_display_t *vd, un
pool_cfg.picture = pictures;
vd->sys->sys.pool = picture_pool_NewExtended( &pool_cfg );
-
-error:
+ error:
if (vd->sys->sys.pool == NULL && pictures) {
for (unsigned i=0;i<picture_count; ++i)
DestroyPicture(pictures[i]);
@@ -415,6 +414,138 @@ error:
free(pictures);
return vd->sys->sys.pool;
}
+/**
+ * It locks the surface associated to the picture and get the surface
+ * descriptor which amongst other things has the pointer to the picture
+ * data and its pitch.
+ */
+static int Direct3D9LockSurface(picture_t *picture)
+{
+ /* Lock the surface to get a valid pointer to the picture buffer */
+ D3DLOCKED_RECT d3drect;
+ HRESULT hr = IDirect3DSurface9_LockRect(picture->p_sys->surface, &d3drect, NULL, 0);
+ if (FAILED(hr)) {
+ //msg_Dbg(vd, "Failed IDirect3DSurface9_LockRect: 0x%0lx", hr);
+ return CommonUpdatePicture(picture, &picture->p_sys->fallback, NULL, 0);
+ }
+
+ CommonUpdatePicture(picture, NULL, d3drect.pBits, d3drect.Pitch);
+ return VLC_SUCCESS;
+}
+/**
+ * It unlocks the surface associated to the picture.
+ */
+static void Direct3D9UnlockSurface(picture_t *picture)
+{
+ /* Unlock the Surface */
+ HRESULT hr = IDirect3DSurface9_UnlockRect(picture->p_sys->surface);
+ if (FAILED(hr)) {
+ //msg_Dbg(vd, "Failed IDirect3DSurface9_UnlockRect: 0x%0lx", hr);
+ }
+}
+
+/**
+ * It destroys the pool of picture and its resources.
+ */
+static void Direct3D9DestroyPool(vout_display_t *vd)
+{
+ vout_display_sys_t *sys = vd->sys;
+
+ if (sys->sys.pool) {
+ picture_sys_t *picsys = sys->picsys;
+ if ( picsys != NULL ) {
+ IDirect3DSurface9_Release(picsys->surface);
+ if (picsys->fallback)
+ picture_Release(picsys->fallback);
+ }
+ picture_pool_Release(sys->sys.pool);
+ }
+ sys->sys.pool = NULL;
+}
+
+/**
+ * It creates the pool of picture (only 1).
+ *
+ * Each picture has an associated offscreen surface in video memory
+ * depending on hardware capabilities the picture chroma will be as close
+ * as possible to the orginal render chroma to reduce CPU conversion overhead
+ * and delegate this work to video card GPU
+ */
+static picture_pool_t *Direct3D9CreateSimplePool(vout_display_t *vd, unsigned count)
+{
+ VLC_UNUSED(count);
+ vout_display_sys_t *sys = vd->sys;
+ video_format_t *fmt = &vd->fmt;
+ LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev;
+
+ assert( is_d3d9_opaque(fmt->i_chroma) == false );
+ if (sys->sys.pool)
+ return sys->sys.pool;
+
+ /* We create one picture.
+ * It is useless to create more as we can't be used for direct rendering */
+
+ /* Create a surface */
+ LPDIRECT3DSURFACE9 surface;
+ HRESULT hr = IDirect3DDevice9_CreateOffscreenPlainSurface(d3ddev,
+ fmt->i_width,
+ fmt->i_height,
+ sys->d3dtexture_format->format,
+ D3DPOOL_DEFAULT,
+ &surface,
+ NULL);
+ if (FAILED(hr)) {
+ msg_Err(vd, "Failed to create picture surface. (hr=0x%lx)", hr);
+ return NULL;
+ }
+
+#ifndef NDEBUG
+ msg_Dbg(vd, "Direct3D created offscreen surface: %ix%i",
+ fmt->i_width, fmt->i_height);
+#endif
+
+ /* fill surface with black color */
+ IDirect3DDevice9_ColorFill(d3ddev, surface, NULL, D3DCOLOR_ARGB(0xFF, 0, 0, 0));
+
+ /* Create the associated picture */
+ picture_sys_t *picsys = malloc(sizeof(*picsys));
+ if (unlikely(picsys == NULL)) {
+ IDirect3DSurface9_Release(surface);
+ return NULL;
+ }
+ picsys->surface = surface;
+ picsys->fallback = NULL;
+
+ picture_resource_t resource = { .p_sys = picsys };
+ for (int i = 0; i < PICTURE_PLANE_MAX; i++)
+ resource.p[i].i_lines = fmt->i_height / (i > 0 ? 2 : 1);
+
+ picture_t *picture = picture_NewFromResource(fmt, &resource);
+ if (!picture) {
+ msg_Err(vd, "Failed to create a picture from resources.");
+ IDirect3DSurface9_Release(surface);
+ free(picsys);
+ return NULL;
+ }
+ sys->picsys = picsys;
+
+ /* Wrap it into a picture pool */
+ picture_pool_configuration_t pool_cfg;
+ memset(&pool_cfg, 0, sizeof(pool_cfg));
+ pool_cfg.picture_count = 1;
+ pool_cfg.picture = &picture;
+ pool_cfg.lock = Direct3D9LockSurface;
+ pool_cfg.unlock = Direct3D9UnlockSurface;
+
+ sys->sys.pool = picture_pool_NewExtended(&pool_cfg);
+ if (!sys->sys.pool) {
+ picture_Release(picture);
+ IDirect3DSurface9_Release(surface);
+ }
+ msg_Err( vd, "Returning valid pool" );
+ return sys->sys.pool;
+}
+
static int Direct3D9LockSurface(picture_t *);
static void Direct3D9UnlockSurface(picture_t *);
@@ -956,8 +1087,6 @@ static int Direct3D9Reset(vout_display_t *vd)
}
/* */
-static void Direct3D9DestroyPool(vout_display_t *vd);
-
static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt);
static void Direct3D9DestroyScene(vout_display_t *vd);
@@ -1097,138 +1226,6 @@ static const d3d_format_t *Direct3DFindFormat(vout_display_t *vd, vlc_fourcc_t c
}
/**
- * It locks the surface associated to the picture and get the surface
- * descriptor which amongst other things has the pointer to the picture
- * data and its pitch.
- */
-static int Direct3D9LockSurface(picture_t *picture)
-{
- /* Lock the surface to get a valid pointer to the picture buffer */
- D3DLOCKED_RECT d3drect;
- HRESULT hr = IDirect3DSurface9_LockRect(picture->p_sys->surface, &d3drect, NULL, 0);
- if (FAILED(hr)) {
- //msg_Dbg(vd, "Failed IDirect3DSurface9_LockRect: 0x%0lx", hr);
- return CommonUpdatePicture(picture, &picture->p_sys->fallback, NULL, 0);
- }
-
- CommonUpdatePicture(picture, NULL, d3drect.pBits, d3drect.Pitch);
- return VLC_SUCCESS;
-}
-/**
- * It unlocks the surface associated to the picture.
- */
-static void Direct3D9UnlockSurface(picture_t *picture)
-{
- /* Unlock the Surface */
- HRESULT hr = IDirect3DSurface9_UnlockRect(picture->p_sys->surface);
- if (FAILED(hr)) {
- //msg_Dbg(vd, "Failed IDirect3DSurface9_UnlockRect: 0x%0lx", hr);
- }
-}
-
-/**
- * It creates the pool of picture (only 1).
- *
- * Each picture has an associated offscreen surface in video memory
- * depending on hardware capabilities the picture chroma will be as close
- * as possible to the orginal render chroma to reduce CPU conversion overhead
- * and delegate this work to video card GPU
- */
-static picture_pool_t *Direct3D9CreateSimplePool(vout_display_t *vd, unsigned count)
-{
- VLC_UNUSED(count);
- vout_display_sys_t *sys = vd->sys;
- video_format_t *fmt = &vd->fmt;
- LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev;
-
- assert( is_d3d9_opaque(fmt->i_chroma) == false );
- if (sys->sys.pool)
- return sys->sys.pool;
-
- /* We create one picture.
- * It is useless to create more as we can't be used for direct rendering */
-
- /* Create a surface */
- LPDIRECT3DSURFACE9 surface;
- HRESULT hr = IDirect3DDevice9_CreateOffscreenPlainSurface(d3ddev,
- fmt->i_width,
- fmt->i_height,
- sys->d3dtexture_format->format,
- D3DPOOL_DEFAULT,
- &surface,
- NULL);
- if (FAILED(hr)) {
- msg_Err(vd, "Failed to create picture surface. (hr=0x%lx)", hr);
- return NULL;
- }
-
-#ifndef NDEBUG
- msg_Dbg(vd, "Direct3D created offscreen surface: %ix%i",
- fmt->i_width, fmt->i_height);
-#endif
-
- /* fill surface with black color */
- IDirect3DDevice9_ColorFill(d3ddev, surface, NULL, D3DCOLOR_ARGB(0xFF, 0, 0, 0));
-
- /* Create the associated picture */
- picture_sys_t *picsys = malloc(sizeof(*picsys));
- if (unlikely(picsys == NULL)) {
- IDirect3DSurface9_Release(surface);
- return NULL;
- }
- picsys->surface = surface;
- picsys->fallback = NULL;
-
- picture_resource_t resource = { .p_sys = picsys };
- for (int i = 0; i < PICTURE_PLANE_MAX; i++)
- resource.p[i].i_lines = fmt->i_height / (i > 0 ? 2 : 1);
-
- picture_t *picture = picture_NewFromResource(fmt, &resource);
- if (!picture) {
- msg_Err(vd, "Failed to create a picture from resources.");
- IDirect3DSurface9_Release(surface);
- free(picsys);
- return NULL;
- }
- sys->picsys = picsys;
-
- /* Wrap it into a picture pool */
- picture_pool_configuration_t pool_cfg;
- memset(&pool_cfg, 0, sizeof(pool_cfg));
- pool_cfg.picture_count = 1;
- pool_cfg.picture = &picture;
- pool_cfg.lock = Direct3D9LockSurface;
- pool_cfg.unlock = Direct3D9UnlockSurface;
-
- sys->sys.pool = picture_pool_NewExtended(&pool_cfg);
- if (!sys->sys.pool) {
- picture_Release(picture);
- IDirect3DSurface9_Release(surface);
- }
- msg_Err( vd, "Returning valid pool" );
- return sys->sys.pool;
-}
-
-/**
- * It destroys the pool of picture and its resources.
- */
-static void Direct3D9DestroyPool(vout_display_t *vd)
-{
- vout_display_sys_t *sys = vd->sys;
-
- if (sys->sys.pool) {
- picture_sys_t *picsys = sys->picsys;
- if ( picsys != NULL ) {
- IDirect3DSurface9_Release(picsys->surface);
- if (picsys->fallback)
- picture_Release(picsys->fallback);
- }
- picture_pool_Release(sys->sys.pool);
- }
- sys->sys.pool = NULL;
-}
-
-/**
* It allocates and initializes the resources needed to render the scene.
*/
static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
More information about the vlc-commits
mailing list