[wip, win32 surface sharing] in surface sharing example, terminate child process when parent exits

This commit is contained in:
martinfouilleul 2023-03-02 12:23:10 +01:00
parent e58ae3ef52
commit 3ada8ece9a
3 changed files with 40 additions and 12 deletions

View File

@ -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 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 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 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

View File

@ -24,9 +24,16 @@
#define write _write #define write _write
#define itoa _itoa #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 #elif OS_MACOS
@ -213,7 +220,7 @@ int main(int argc, char** argv)
return(-1); return(-1);
} }
} }
setvbuf( stdout, NULL, _IONBF, 0 ); // setvbuf( stdout, NULL, _IONBF, 0 );
mp_init(); mp_init();
//NOTE: create main window //NOTE: create main window
@ -234,7 +241,7 @@ int main(int argc, char** argv)
itoa(fileDesc[1], writeDescStr, 10); itoa(fileDesc[1], writeDescStr, 10);
char* args[] = {"bin/example_surface_sharing", "--child", writeDescStr, 0}; 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 //NOTE: read the connection id
mg_surface_connection_id connectionID = 0; mg_surface_connection_id connectionID = 0;
@ -264,7 +271,12 @@ int main(int argc, char** argv)
break; break;
} }
} }
mg_surface_prepare(surface);
mg_surface_present(surface);
} }
terminate_child(child);
mp_terminate(); mp_terminate();
return(0); return(0);
} }

View File

@ -6,7 +6,6 @@
* @revision: * @revision:
* *
*****************************************************************/ *****************************************************************/
#include"graphics_internal.h" #include"graphics_internal.h"
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
@ -77,13 +76,34 @@ typedef struct mg_win32_surface_client
mg_surface_data interface; mg_surface_data interface;
mp_layer layer; mp_layer layer;
HWND remoteWnd;
} mg_win32_surface_client; } mg_win32_surface_client;
void mg_win32_surface_client_prepare(mg_surface_data* interface) void mg_win32_surface_client_prepare(mg_surface_data* interface)
{} {}
void mg_win32_surface_client_present(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) 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; mg_win32_surface_client* surface = (mg_win32_surface_client*)interface;
//NOTE:Quick test //NOTE:Quick test
surface->remoteWnd = (HWND)ID;
HWND parent = mp_layer_native_surface(&surface->layer);
HWND child = (HWND)ID;
SetParent(child, parent);
} }
} }