[surface sharing] first draft for win32 using window reparenting

This commit is contained in:
martinfouilleul 2023-03-02 09:54:12 +01:00
parent 2560ddd5b4
commit e58ae3ef52
5 changed files with 215 additions and 8 deletions

View File

@ -138,10 +138,8 @@ int child_main(int writeFd)
glUseProgram(program); glUseProgram(program);
//NOTE: create surface server and start sharing surface //NOTE: create surface server and start sharing surface
// mg_surface_server server = mg_surface_server_create(); mg_surface_server server = mg_surface_server_create();
// mg_surface_connection_id connectionID = mg_surface_server_start(server, surface); mg_surface_connection_id connectionID = mg_surface_server_start(server, surface);
mg_surface_connection_id connectionID = 123456789;
//NOTE: send context id to parent //NOTE: send context id to parent
write(writeFd, &connectionID, sizeof(connectionID)); write(writeFd, &connectionID, sizeof(connectionID));
@ -223,7 +221,7 @@ int main(int argc, char** argv)
mp_window window = mp_window_create(rect, "test", 0); mp_window window = mp_window_create(rect, "test", 0);
//NOTE: create surface client //NOTE: create surface client
// mg_surface surface = mg_surface_client_create_for_window(window); mg_surface surface = mg_surface_client_create_for_window(window);
//NOTE setup descriptors //NOTE setup descriptors
@ -244,7 +242,7 @@ int main(int argc, char** argv)
printf("received child connection id %llu\n", connectionID); printf("received child connection id %llu\n", connectionID);
//NOTE: connect the client //NOTE: connect the client
// mg_surface_client_connect(surface, connectionID); mg_surface_client_connect(surface, connectionID);
//NOTE: show the window //NOTE: show the window
mp_window_bring_to_front(window); mp_window_bring_to_front(window);

View File

@ -2,7 +2,7 @@
* *
* file: glsl_shaders.h * file: glsl_shaders.h
* note: string literals auto-generated by embed_text.py * note: string literals auto-generated by embed_text.py
* date: 01/032023 * date: 02/032023
* *
**********************************************************************/ **********************************************************************/
#ifndef __GLSL_SHADERS_H__ #ifndef __GLSL_SHADERS_H__

View File

@ -68,6 +68,8 @@
#include"egl_surface.c" #include"egl_surface.c"
#endif #endif
#include"win32_surface_sharing.c"
#elif defined(OS_MACOS) #elif defined(OS_MACOS)
//NOTE: macos application layer and graphics backends are defined in milepost.m //NOTE: macos application layer and graphics backends are defined in milepost.m
#else #else

View File

@ -2,7 +2,7 @@
* *
* @file: osx_surface_sharing.m * @file: osx_surface_sharing.m
* @author: Martin Fouilleul * @author: Martin Fouilleul
* @date: 19/08/2022 * @date: 01/03/2023
* @revision: * @revision:
* *
*****************************************************************/ *****************************************************************/

207
src/win32_surface_sharing.c Normal file
View File

@ -0,0 +1,207 @@
/************************************************************//**
*
* @file: win32_surface_sharing.c
* @author: Martin Fouilleul
* @date: 02/03/2023
* @revision:
*
*****************************************************************/
#include"graphics_internal.h"
//------------------------------------------------------------------------------------------------
// Surface server
//------------------------------------------------------------------------------------------------
typedef struct mg_surface_server_data
{
int dummy;
} mg_surface_server_data;
mg_surface_server_data* mg_surface_server_data_from_handle(mg_surface_server handle)
{
mg_surface_server_data* server = (mg_surface_server_data*)mg_data_from_handle(MG_HANDLE_SURFACE_SERVER, handle.h);
return(server);
}
MP_API mg_surface_server mg_surface_server_create(void)
{
mg_surface_server_data* server = malloc_type(mg_surface_server_data);
//TODO
mg_surface_server handle = (mg_surface_server){mg_handle_alloc(MG_HANDLE_SURFACE_SERVER, (void*)server)};
return(handle);
}
MP_API void mg_surface_server_destroy(mg_surface_server handle)
{
mg_surface_server_data* server = mg_surface_server_data_from_handle(handle);
if(server)
{
//TODO
free(server);
mg_handle_recycle(handle.h);
}
}
MP_API mg_surface_connection_id mg_surface_server_start(mg_surface_server handle, mg_surface surface)
{
mg_surface_connection_id res = 0;
mg_surface_server_data* server = mg_surface_server_data_from_handle(handle);
if(server)
{
//NOTE: just a quick test
res = (u64)mg_surface_native_layer(surface);
}
return(res);
}
MP_API void mg_surface_server_stop(mg_surface_server handle)
{
mg_surface_server_data* server = mg_surface_server_data_from_handle(handle);
if(server)
{
//TODO
}
}
//------------------------------------------------------------------------------------------------
// Surface client
//------------------------------------------------------------------------------------------------
typedef struct mg_win32_surface_client
{
mg_surface_data interface;
mp_layer layer;
} mg_win32_surface_client;
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_swap_interval(mg_surface_data* interface, int swap)
{
//TODO
}
vec2 mg_win32_surface_client_contents_scaling(mg_surface_data* interface)
{
mg_win32_surface_client* surface = (mg_win32_surface_client*)interface;
return(mp_layer_contents_scaling(&surface->layer));
}
mp_rect mg_win32_surface_client_get_frame(mg_surface_data* interface)
{
mg_win32_surface_client* surface = (mg_win32_surface_client*)interface;
return(mp_layer_get_frame(&surface->layer));
}
void mg_win32_surface_client_set_frame(mg_surface_data* interface, mp_rect frame)
{
mg_win32_surface_client* surface = (mg_win32_surface_client*)interface;
mp_layer_set_frame(&surface->layer, frame);
}
void mg_win32_surface_client_set_hidden(mg_surface_data* interface, bool hidden)
{
mg_win32_surface_client* surface = (mg_win32_surface_client*)interface;
mp_layer_set_hidden(&surface->layer, hidden);
}
bool mg_win32_surface_client_get_hidden(mg_surface_data* interface)
{
mg_win32_surface_client* surface = (mg_win32_surface_client*)interface;
return(mp_layer_get_hidden(&surface->layer));
}
void* mg_win32_surface_client_native_layer(mg_surface_data* interface)
{
mg_win32_surface_client* surface = (mg_win32_surface_client*)interface;
return(mp_layer_native_surface(&surface->layer));
}
void mg_win32_surface_client_destroy(mg_surface_data* interface)
{
mg_win32_surface_client* surface = (mg_win32_surface_client*)interface;
mp_layer_cleanup(&surface->layer);
//TODO...
free(surface);
}
mg_surface_data* mg_win32_surface_client_create_for_window(mp_window window)
{
mg_win32_surface_client* surface = 0;
mp_window_data* windowData = mp_window_ptr_from_handle(window);
if(windowData)
{
surface = malloc_type(mg_win32_surface_client);
if(surface)
{
mp_layer_init_for_window(&surface->layer, windowData);
surface->interface.backend = MG_BACKEND_REMOTE;
surface->interface.destroy = mg_win32_surface_client_destroy;
surface->interface.prepare = mg_win32_surface_client_prepare;
surface->interface.present = mg_win32_surface_client_present;
surface->interface.swapInterval = mg_win32_surface_client_swap_interval;
surface->interface.contentsScaling = mg_win32_surface_client_contents_scaling;
surface->interface.getFrame = mg_win32_surface_client_get_frame;
surface->interface.setFrame = mg_win32_surface_client_set_frame;
surface->interface.getHidden = mg_win32_surface_client_get_hidden;
surface->interface.setHidden = mg_win32_surface_client_set_hidden;
surface->interface.nativeLayer = mg_win32_surface_client_native_layer;
//TODO
}
}
return((mg_surface_data*)surface);
}
mg_surface mg_surface_client_create_for_window(mp_window window)
{
if(!__mgData.init)
{
mg_init();
}
mg_surface surfaceHandle = {0};
mg_surface_data* surface = mg_win32_surface_client_create_for_window(window);
if(surface)
{
surfaceHandle = mg_surface_handle_alloc(surface);
}
return(surfaceHandle);
}
MP_API void mg_surface_client_connect(mg_surface handle, mg_surface_connection_id ID)
{
mg_surface_data* interface = mg_surface_data_from_handle(handle);
if(interface && interface->backend == MG_BACKEND_REMOTE)
{
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);
}
}
MP_API void mg_surface_client_disconnect(mg_surface handle)
{
mg_surface_data* interface = mg_surface_data_from_handle(handle);
if(interface && interface->backend == MG_BACKEND_REMOTE)
{
//TODO
}
}