From 3ada8ece9af1c6718207f320d8c9c146e0e1e71a Mon Sep 17 00:00:00 2001 From: martinfouilleul Date: Thu, 2 Mar 2023 12:23:10 +0100 Subject: [PATCH] [wip, win32 surface sharing] in surface sharing example, terminate child process when parent exits --- build.bat | 2 +- examples/surface_sharing/main.c | 20 ++++++++++++++++---- src/win32_surface_sharing.c | 30 +++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/build.bat b/build.bat index 494c0bf..b0e4dec 100644 --- a/build.bat +++ b/build.bat @@ -6,6 +6,6 @@ set glsl_shaders=src\glsl_shaders\common.glsl src\glsl_shaders\blit_vertex.glsl call python3 scripts\embed_text.py %glsl_shaders% --prefix=glsl_ --output src\glsl_shaders.h set INCLUDES=/I src /I src/util /I src/platform /I ext /I ext/angle_headers -set LIBS=user32.lib opengl32.lib gdi32.lib shcore.lib delayimp.lib /LIBPATH:./bin libEGL.dll.lib libGLESv2.dll.lib /DELAYLOAD:libEGL.dll /DELAYLOAD:libGLESv2.dll +set LIBS=user32.lib opengl32.lib gdi32.lib shcore.lib delayimp.lib dwmapi.lib /LIBPATH:./bin libEGL.dll.lib libGLESv2.dll.lib /DELAYLOAD:libEGL.dll /DELAYLOAD:libGLESv2.dll cl /we4013 /Zi /Zc:preprocessor /DMP_BUILD_DLL /std:c11 %INCLUDES% src/milepost.c /Fo:bin/milepost.o /LD /link %LIBS% /OUT:bin/milepost.dll /IMPLIB:bin/milepost.dll.lib diff --git a/examples/surface_sharing/main.c b/examples/surface_sharing/main.c index 81ba300..4a666e6 100644 --- a/examples/surface_sharing/main.c +++ b/examples/surface_sharing/main.c @@ -24,9 +24,16 @@ #define write _write #define itoa _itoa - void spawn_child(char* program, char** argv) + #define process_id HANDLE + + process_id spawn_child(char* program, char** argv) { - _spawnv(P_NOWAIT, program, argv); + return((process_id)_spawnv(P_NOWAIT, program, argv)); + } + + void terminate_child(process_id child) + { + TerminateProcess(child, 0); } #elif OS_MACOS @@ -213,7 +220,7 @@ int main(int argc, char** argv) return(-1); } } - setvbuf( stdout, NULL, _IONBF, 0 ); +// setvbuf( stdout, NULL, _IONBF, 0 ); mp_init(); //NOTE: create main window @@ -234,7 +241,7 @@ int main(int argc, char** argv) itoa(fileDesc[1], writeDescStr, 10); char* args[] = {"bin/example_surface_sharing", "--child", writeDescStr, 0}; - spawn_child(args[0], args); + process_id child = spawn_child(args[0], args); //NOTE: read the connection id mg_surface_connection_id connectionID = 0; @@ -264,7 +271,12 @@ int main(int argc, char** argv) break; } } + mg_surface_prepare(surface); + mg_surface_present(surface); } + + terminate_child(child); + mp_terminate(); return(0); } diff --git a/src/win32_surface_sharing.c b/src/win32_surface_sharing.c index e5d3a27..7b84fe4 100644 --- a/src/win32_surface_sharing.c +++ b/src/win32_surface_sharing.c @@ -6,7 +6,6 @@ * @revision: * *****************************************************************/ - #include"graphics_internal.h" //------------------------------------------------------------------------------------------------ @@ -77,13 +76,34 @@ typedef struct mg_win32_surface_client mg_surface_data interface; mp_layer layer; + HWND remoteWnd; + } mg_win32_surface_client; void mg_win32_surface_client_prepare(mg_surface_data* interface) {} void mg_win32_surface_client_present(mg_surface_data* interface) -{} +{ + mg_win32_surface_client* surface = (mg_win32_surface_client*)interface; + + HWND dstWindow = (HWND)mp_layer_native_surface(&surface->layer); + RECT dstRect; + GetClientRect(dstWindow, &dstRect); + + HDC dstDC = GetDC(dstWindow); + HDC srcDC = GetDC(surface->remoteWnd); + + int res = BitBlt(dstDC, + dstRect.left, + dstRect.top, + dstRect.right - dstRect.left, + dstRect.bottom - dstRect.top, + srcDC, + 0, + 0, + SRCCOPY); +} void mg_win32_surface_client_swap_interval(mg_surface_data* interface, int swap) { @@ -189,11 +209,7 @@ MP_API void mg_surface_client_connect(mg_surface handle, mg_surface_connection_i mg_win32_surface_client* surface = (mg_win32_surface_client*)interface; //NOTE:Quick test - - HWND parent = mp_layer_native_surface(&surface->layer); - HWND child = (HWND)ID; - - SetParent(child, parent); + surface->remoteWnd = (HWND)ID; } }