vlc | branch: master | Steve Lhomme <[email protected]> | Mon May 13 13:34:26 2019 +0200| [cfaf7134b4b30e2bcecf17ad3c392930014c2f0e] | committer: Steve Lhomme
doc: D3D11 callbacks: set the rendering size when the window size changes > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cfaf7134b4b30e2bcecf17ad3c392930014c2f0e --- doc/libvlc/d3d11_player.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/doc/libvlc/d3d11_player.cpp b/doc/libvlc/d3d11_player.cpp index a287afbb4e..9f05080a01 100644 --- a/doc/libvlc/d3d11_player.cpp +++ b/doc/libvlc/d3d11_player.cpp @@ -39,6 +39,11 @@ struct render_context ID3D11Texture2D *texture; ID3D11ShaderResourceView *textureShaderInput; ID3D11RenderTargetView *textureRenderTarget; + + CRITICAL_SECTION sizeLock; // the ReportSize callback cannot be called during/after the Cleanup_cb is called + unsigned width, height; + void (*ReportSize)(void *ReportOpaque, unsigned width, unsigned height); + void *ReportOpaque; }; static bool UpdateOutput_cb( void *opaque, const libvlc_video_direct3d_cfg_t *cfg, libvlc_video_output_cfg_t *out ) @@ -185,12 +190,28 @@ static bool Setup_cb( void **opaque, const libvlc_video_direct3d_device_cfg_t *c { struct render_context *ctx = static_cast<struct render_context *>(*opaque); out->device_context = ctx->d3dctx; + + EnterCriticalSection(&ctx->sizeLock); + ctx->ReportSize = cfg->report_size_change; + ctx->ReportOpaque = cfg->report_opaque; + + if (ctx->ReportSize != nullptr) + { + /* report our initial size */ + ctx->ReportSize(ctx->ReportOpaque, ctx->width, ctx->height); + } + LeaveCriticalSection(&ctx->sizeLock); + return true; } static void Cleanup_cb( void *opaque ) { // here we can release all things Direct3D11 for good (if playing only one file) + struct render_context *ctx = static_cast<struct render_context *>( opaque ); + EnterCriticalSection(&ctx->sizeLock); + ctx->ReportSize = nullptr; + LeaveCriticalSection(&ctx->sizeLock); } static const char *shaderStr = "\ @@ -378,8 +399,33 @@ static void release_direct3d(struct render_context *ctx) 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 = LOWORD(lParam) * (BORDER_RIGHT - BORDER_LEFT) / 2.0f; /* remove the orange part ! */ + ctx->height = HIWORD(lParam) * (BORDER_TOP - BORDER_BOTTOM) / 2.0f; + EnterCriticalSection(&ctx->sizeLock); + if (ctx->ReportSize != nullptr) + ctx->ReportSize(ctx->ReportOpaque, ctx->width, ctx->height); + LeaveCriticalSection(&ctx->sizeLock); + } + break; + case WM_DESTROY: PostQuitMessage(0); return 0; @@ -417,6 +463,8 @@ int WINAPI WinMain(HINSTANCE hInstance, free( file_path ); p_mp = libvlc_media_player_new_from_media( p_media ); + InitializeCriticalSection(&Context.sizeLock); + ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); @@ -441,7 +489,7 @@ int WINAPI WinMain(HINSTANCE hInstance, NULL, NULL, hInstance, - p_mp); + &Context); ShowWindow(hWnd, nCmdShow); @@ -476,6 +524,7 @@ int WINAPI WinMain(HINSTANCE hInstance, libvlc_media_release( p_media ); libvlc_release( p_libvlc ); + DeleteCriticalSection(&Context.sizeLock); release_direct3d(&Context); return msg.wParam; _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
