]> git.sesse.net Git - vlc/blobdiff - modules/video_output/msw/direct3d.c
Release the display mode when we are done with it.
[vlc] / modules / video_output / msw / direct3d.c
index c1c59568d39fe359f82aea423eab865c6e254372..9237c30d480deb8b73dbbdcfac5f8a16a6fd7b93 100644 (file)
@@ -87,6 +87,7 @@ vlc_module_end ()
 struct picture_sys_t
 {
     LPDIRECT3DSURFACE9 surface;
+    picture_t          *fallback;
 };
 
 static int  Open(vlc_object_t *);
@@ -184,7 +185,10 @@ static int Open(vlc_object_t *object)
 
     return VLC_SUCCESS;
 error:
-    Close(VLC_OBJECT(vd));
+    Direct3DClose(vd);
+    CommonClean(vd);
+    Direct3DDestroy(vd);
+    free(vd->sys);
     return VLC_EGENERIC;
 }
 
@@ -251,8 +255,6 @@ static void Prepare(vout_display_t *vd, picture_t *picture)
     Direct3DUnlockSurface(picture);
 
     Direct3DRenderScene(vd, surface);
-
-    Direct3DLockSurface(picture);
 #endif
 }
 
@@ -269,10 +271,12 @@ static void Display(vout_display_t *vd, picture_t *picture)
     if (FAILED(hr)) {
         msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
     }
+
 #if 0
     VLC_UNUSED(picture);
 #else
     /* XXX See Prepare() */
+    Direct3DLockSurface(picture);
     picture_Release(picture);
 #endif
 
@@ -510,9 +514,9 @@ static int Direct3DFillPresentationParameters(vout_display_t *vd)
     d3dpp->Flags                  = D3DPRESENTFLAG_VIDEO;
     d3dpp->Windowed               = TRUE;
     d3dpp->hDeviceWindow          = vd->sys->hvideownd;
-    d3dpp->BackBufferWidth        = __MAX(GetSystemMetrics(SM_CXVIRTUALSCREEN),
+    d3dpp->BackBufferWidth        = __MAX((unsigned int)GetSystemMetrics(SM_CXVIRTUALSCREEN),
                                           d3ddm.Width);
-    d3dpp->BackBufferHeight       = __MAX(GetSystemMetrics(SM_CYVIRTUALSCREEN),
+    d3dpp->BackBufferHeight       = __MAX((unsigned int)GetSystemMetrics(SM_CYVIRTUALSCREEN),
                                           d3ddm.Height);
     d3dpp->SwapEffect             = D3DSWAPEFFECT_COPY;
     d3dpp->MultiSampleType        = D3DMULTISAMPLE_NONE;
@@ -548,8 +552,27 @@ static int Direct3DOpen(vout_display_t *vd, video_format_t *fmt)
 
     // Create the D3DDevice
     LPDIRECT3DDEVICE9 d3ddev;
-    HRESULT hr = IDirect3D9_CreateDevice(d3dobj, D3DADAPTER_DEFAULT,
-                                         D3DDEVTYPE_HAL, sys->hvideownd,
+
+    UINT AdapterToUse = D3DADAPTER_DEFAULT;
+    D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
+
+#ifndef NDEBUG
+    // Look for 'NVIDIA PerfHUD' adapter
+    // If it is present, override default settings
+    for (UINT Adapter=0; Adapter< IDirect3D9_GetAdapterCount(d3dobj); ++Adapter) {
+        D3DADAPTER_IDENTIFIER9 Identifier;
+        HRESULT Res;
+        Res = IDirect3D9_GetAdapterIdentifier(d3dobj,Adapter,0,&Identifier);
+        if (strstr(Identifier.Description,"PerfHUD") != 0) {
+            AdapterToUse = Adapter;
+            DeviceType = D3DDEVTYPE_REF;
+            break;
+        }
+    }
+#endif
+
+    HRESULT hr = IDirect3D9_CreateDevice(d3dobj, AdapterToUse,
+                                         DeviceType, sys->hvideownd,
                                          D3DCREATE_SOFTWARE_VERTEXPROCESSING|
                                          D3DCREATE_MULTITHREADED,
                                          &sys->d3dpp, &d3ddev);
@@ -755,32 +778,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);
     }
 
-    /* fill in buffer info in first plane */
-    picture->p->p_pixels = d3drect.pBits;
-    picture->p->i_pitch  = d3drect.Pitch;
-
-    /*  Fill chroma planes for planar YUV */
-    if (picture->format.i_chroma == VLC_CODEC_I420 ||
-        picture->format.i_chroma == VLC_CODEC_J420 ||
-        picture->format.i_chroma == VLC_CODEC_YV12) {
-
-        for (int n = 1; n < picture->i_planes; n++) {
-            const plane_t *o = &picture->p[n-1];
-            plane_t *p = &picture->p[n];
-
-            p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
-            p->i_pitch  = d3drect.Pitch / 2;
-        }
-        /* The d3d buffer is always allocated as YV12 */
-        if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
-            uint8_t *p_tmp = picture->p[1].p_pixels;
-            picture->p[1].p_pixels = picture->p[2].p_pixels;
-            picture->p[2].p_pixels = p_tmp;
-        }
-    }
+    CommonUpdatePicture(picture, NULL, d3drect.pBits, d3drect.Pitch);
     return VLC_SUCCESS;
 }
 /**
@@ -851,6 +852,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;
@@ -889,7 +891,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;
@@ -1085,7 +1088,7 @@ static void Direct3DRenderScene(vout_display_t *vd, LPDIRECT3DSURFACE9 surface)
 
     /* Update the vertex buffer */
     CUSTOMVERTEX *vertices;
-    hr = IDirect3DVertexBuffer9_Lock(d3dvtc, 0, 0, &vertices, D3DLOCK_DISCARD);
+    hr = IDirect3DVertexBuffer9_Lock(d3dvtc, 0, 0, (void **)&vertices, D3DLOCK_DISCARD);
     if (FAILED(hr)) {
         msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
         return;