Extract dialog workflow, bootstrap, and canvas tail helpers

This commit is contained in:
2026-06-16 12:09:53 +02:00
parent 01854f9b10
commit 3407daff08
8 changed files with 586 additions and 534 deletions

View File

@@ -43,6 +43,15 @@ namespace pp::platform::windows {
void unlock_async_render_context();
void swap_async_render_context();
}
extern HRESULT(*GetDpiForMonitor_fn)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT* dpiX, UINT* dpiY);
extern HRESULT(*SetProcessDpiAwareness_fn)(PROCESS_DPI_AWARENESS value);
bool win32_renderdoc_init();
void win32_renderdoc_frame_start();
void win32_renderdoc_frame_end();
void init_shcore_API();
std::string GetLastErrorAsString();
void _pre_call_callback(const char* name, void* funcptr, int len_args, ...);
void _post_call_callback(const char* name, void* funcptr, int len_args, ...);
struct RetainedState
{
HINSTANCE hInst{};
@@ -120,71 +129,6 @@ void pp_windows_enqueue_main_task(std::packaged_task<void()> task)
std::atomic<int> running{-1};
#ifdef USE_RENDERDOC
RENDERDOC_API_1_4_0* rdoc_api = NULL;
bool win32_renderdoc_init()
{
// At init, on windows
if (HMODULE mod = GetModuleHandleA("renderdoc.dll"))
{
pRENDERDOC_GetAPI RENDERDOC_GetAPI =
(pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI");
return RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void**)&rdoc_api);
}
return false;
}
void win32_renderdoc_frame_start()
{
if (rdoc_api)
rdoc_api->StartFrameCapture(NULL, NULL);
}
void win32_renderdoc_frame_end()
{
if (rdoc_api)
rdoc_api->EndFrameCapture(NULL, NULL);
}
#else
void win32_renderdoc_frame_start() { }
void win32_renderdoc_frame_end() { }
#endif
HRESULT(*GetDpiForMonitor_fn)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT* dpiX, UINT* dpiY);
HRESULT(*SetProcessDpiAwareness_fn)(PROCESS_DPI_AWARENESS value);
void init_shcore_API()
{
HMODULE dll = LoadLibrary(L"Shcore.dll");
if (!dll)
{
LOG("cannot load Shcore.dll");
return;
}
LOG("loaded Shcore.dll");
GetDpiForMonitor_fn = (decltype(GetDpiForMonitor_fn))GetProcAddress(dll, "GetDpiForMonitor");
SetProcessDpiAwareness_fn = (decltype(SetProcessDpiAwareness_fn))GetProcAddress(dll, "SetProcessDpiAwareness");
}
//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
std::string GetLastErrorAsString()
{
//Get the error message, if any.
DWORD errorMessageID = ::GetLastError();
if (errorMessageID == 0)
return std::string(); //No error message has been recorded
LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
std::string message(messageBuffer, size);
//Free the buffer.
LocalFree(messageBuffer);
return message;
}
void destroy_window()
{
auto& state = retained_state();
@@ -531,36 +475,6 @@ void win32_save_window_state()
p.rcNormalPosition.right,
p.rcNormalPosition.bottom });
}
BOOL UnadjustWindowRectEx(LPRECT prc, DWORD dwStyle, BOOL fMenu, DWORD dwExStyle)
{
RECT rc;
SetRectEmpty(&rc);
BOOL fRc = AdjustWindowRectEx(&rc, dwStyle, fMenu, dwExStyle);
if (fRc) {
prc->left -= rc.left;
prc->top -= rc.top;
prc->right -= rc.right;
prc->bottom -= rc.bottom;
}
return fRc;
}
void _pre_call_callback(const char* name, void* funcptr, int len_args, ...)
{
assert(App::I->is_render_thread());
}
void _post_call_callback(const char* name, void* funcptr, int len_args, ...)
{
GLenum error_code;
error_code = glad_glGetError();
if (error_code != pp::renderer::gl::no_error_code())
{
LOG("ERROR %d in %s\n", error_code, name);
}
}
int main(int argc, char** argv)
{
auto& state = retained_state();