[vlc-devel] [PATCH 8/8] doc: D3D9 callbacks: set the rendering size when the window size changes

Steve Lhomme robux4 at ycbcr.xyz
Mon May 13 13:54:53 CEST 2019


---
 doc/libvlc/d3d9_player.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/doc/libvlc/d3d9_player.c b/doc/libvlc/d3d9_player.c
index 043fca777f..59c984e706 100644
--- a/doc/libvlc/d3d9_player.c
+++ b/doc/libvlc/d3d9_player.c
@@ -34,6 +34,10 @@ struct render_context
     IDirect3DSurface9 *backBuffer;
 
     IDirect3DVertexBuffer9 *rectangleFVFVertexBuf;
+
+    unsigned width, height;
+    void (*ReportSize)(void *ReportOpaque, unsigned width, unsigned height);
+    void *ReportOpaque;
 };
 
 struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;
@@ -238,6 +242,14 @@ static bool Setup_cb( void **opaque, const libvlc_video_direct3d_device_cfg_t *c
 {
     struct render_context *ctx = *opaque;
     out->device_context = ctx->libvlc_d3d;
+    ctx->ReportSize = cfg->repot_size_change;
+    ctx->ReportOpaque = cfg->report_opaque;
+
+    if (ctx->ReportSize != NULL)
+    {
+        /* report our initial size */
+        ctx->ReportSize(ctx->ReportOpaque, ctx->width, ctx->height);
+    }
     return true;
 }
 
@@ -273,8 +285,31 @@ static bool StartRendering_cb( void *opaque, bool enter, const libvlc_video_dire
 
 static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
+    if( message == WM_CREATE )
+    {
+        /* Store p_mp for future use */
+        CREATESTRUCT *c = (CREATESTRUCT *)lParam;
+        SetWindowLongPtr( hWnd, GWLP_USERDATA, (LONG_PTR)c->lpCreateParams );
+        return 0;
+    }
+
+    LONG_PTR p_user_data = GetWindowLongPtr( hWnd, GWLP_USERDATA );
+    if( p_user_data == 0 )
+        return DefWindowProc(hWnd, message, wParam, lParam);
+    struct render_context *ctx = (struct render_context *)p_user_data;
+
     switch(message)
     {
+        case WM_SIZE:
+        {
+            /* tell libvlc that our size has changed */
+            ctx->width  = (BORDER_RIGHT - BORDER_LEFT) * LOWORD(lParam) / SCREEN_WIDTH; /* remove the orange part ! */
+            ctx->height = (BORDER_BOTTOM - BORDER_TOP) * HIWORD(lParam) / SCREEN_HEIGHT;
+            if (ctx->ReportSize != NULL)
+                ctx->ReportSize(ctx->ReportOpaque, ctx->width, ctx->height);
+        }
+        break;
+
         case WM_DESTROY:
             {
                 PostQuitMessage(0);
@@ -339,7 +374,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
                           NULL,
                           NULL,
                           hInstance,
-                          p_mp);
+                          &Context);
 
     ShowWindow(hWnd, nCmdShow);
 
-- 
2.17.1



More information about the vlc-devel mailing list