mirror of https://github.com/AxioDL/boo.git
Do fullscreen set on main thread
This commit is contained in:
parent
6ff4229f9b
commit
fb91482282
|
@ -26,6 +26,8 @@ PFN_GetScaleFactorForMonitor MyGetScaleFactorForMonitor = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DWORD g_mainThreadId = 0;
|
DWORD g_mainThreadId = 0;
|
||||||
|
std::mutex g_nwmt;
|
||||||
|
std::condition_variable g_nwcv;
|
||||||
|
|
||||||
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
pD3DCompile D3DCompilePROC = nullptr;
|
pD3DCompile D3DCompilePROC = nullptr;
|
||||||
|
@ -345,6 +347,47 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class W>
|
||||||
|
static void DoSetFullscreen(W& win, bool fs)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(g_nwmt);
|
||||||
|
if (fs)
|
||||||
|
{
|
||||||
|
win.m_fsStyle = GetWindowLong(win.m_hwnd, GWL_STYLE);
|
||||||
|
win.m_fsExStyle = GetWindowLong(win.m_hwnd, GWL_EXSTYLE);
|
||||||
|
GetWindowRect(win.m_hwnd, &win.m_fsRect);
|
||||||
|
|
||||||
|
SetWindowLong(win.m_hwnd, GWL_STYLE,
|
||||||
|
win.m_fsStyle & ~(WS_CAPTION | WS_THICKFRAME));
|
||||||
|
SetWindowLong(win.m_hwnd, GWL_EXSTYLE,
|
||||||
|
win.m_fsExStyle & ~(WS_EX_DLGMODALFRAME |
|
||||||
|
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
|
||||||
|
|
||||||
|
MONITORINFO monitor_info;
|
||||||
|
monitor_info.cbSize = sizeof(monitor_info);
|
||||||
|
GetMonitorInfo(MonitorFromWindow(win.m_hwnd, MONITOR_DEFAULTTONEAREST),
|
||||||
|
&monitor_info);
|
||||||
|
SetWindowPos(win.m_hwnd, NULL, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top,
|
||||||
|
monitor_info.rcMonitor.right - monitor_info.rcMonitor.left,
|
||||||
|
monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top,
|
||||||
|
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
|
||||||
|
|
||||||
|
win.m_fs = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetWindowLong(win.m_hwnd, GWL_STYLE, win.m_fsStyle);
|
||||||
|
SetWindowLong(win.m_hwnd, GWL_EXSTYLE, win.m_fsExStyle);
|
||||||
|
|
||||||
|
SetWindowPos(win.m_hwnd, NULL, win.m_fsRect.left, win.m_fsRect.top,
|
||||||
|
win.m_fsRect.right - win.m_fsRect.left, win.m_fsRect.bottom - win.m_fsRect.top,
|
||||||
|
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
|
||||||
|
|
||||||
|
win.m_fs = false;
|
||||||
|
}
|
||||||
|
g_nwcv.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
int run()
|
int run()
|
||||||
{
|
{
|
||||||
g_mainThreadId = GetCurrentThreadId();
|
g_mainThreadId = GetCurrentThreadId();
|
||||||
|
@ -357,7 +400,7 @@ public:
|
||||||
logvisor::RegisterThreadName(thrName.c_str());
|
logvisor::RegisterThreadName(thrName.c_str());
|
||||||
CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
|
CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
|
||||||
clientReturn = m_callback.appMain(this);
|
clientReturn = m_callback.appMain(this);
|
||||||
PostThreadMessage(g_mainThreadId, WM_USER+1, 0, 0);
|
PostThreadMessageW(g_mainThreadId, WM_USER+1, 0, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Pump messages */
|
/* Pump messages */
|
||||||
|
@ -372,11 +415,10 @@ public:
|
||||||
case WM_USER:
|
case WM_USER:
|
||||||
{
|
{
|
||||||
/* New-window message (coalesced onto main thread) */
|
/* New-window message (coalesced onto main thread) */
|
||||||
std::unique_lock<std::mutex> lk(m_nwmt);
|
std::lock_guard<std::mutex> lk(g_nwmt);
|
||||||
SystemStringView* title = reinterpret_cast<SystemStringView*>(msg.wParam);
|
SystemStringView* title = reinterpret_cast<SystemStringView*>(msg.wParam);
|
||||||
m_mwret = newWindow(*title);
|
m_mwret = newWindow(*title);
|
||||||
lk.unlock();
|
g_nwcv.notify_one();
|
||||||
m_nwcv.notify_one();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case WM_USER+1:
|
case WM_USER+1:
|
||||||
|
@ -395,6 +437,14 @@ public:
|
||||||
/* ImmSetCompositionWindow call from client thread */
|
/* ImmSetCompositionWindow call from client thread */
|
||||||
ImmSetCompositionWindow(HIMC(msg.wParam), LPCOMPOSITIONFORM(msg.lParam));
|
ImmSetCompositionWindow(HIMC(msg.wParam), LPCOMPOSITIONFORM(msg.lParam));
|
||||||
continue;
|
continue;
|
||||||
|
case WM_USER+5:
|
||||||
|
/* SetFullscreen call for OpenGL window */
|
||||||
|
DoSetFullscreen(*reinterpret_cast<OGLContext::Window*>(msg.wParam), msg.lParam);
|
||||||
|
continue;
|
||||||
|
case WM_USER+6:
|
||||||
|
/* SetFullscreen call for Vulkan window */
|
||||||
|
DoSetFullscreen(*reinterpret_cast<boo::VulkanContext::Window*>(msg.wParam), msg.lParam);
|
||||||
|
continue;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -434,17 +484,15 @@ public:
|
||||||
return m_args;
|
return m_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex m_nwmt;
|
|
||||||
std::condition_variable m_nwcv;
|
|
||||||
std::shared_ptr<IWindow> m_mwret;
|
std::shared_ptr<IWindow> m_mwret;
|
||||||
std::shared_ptr<IWindow> newWindow(SystemStringView title)
|
std::shared_ptr<IWindow> newWindow(SystemStringView title)
|
||||||
{
|
{
|
||||||
if (GetCurrentThreadId() != g_mainThreadId)
|
if (GetCurrentThreadId() != g_mainThreadId)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lk(m_nwmt);
|
std::unique_lock<std::mutex> lk(g_nwmt);
|
||||||
if (!PostThreadMessage(g_mainThreadId, WM_USER, WPARAM(&title), 0))
|
if (!PostThreadMessageW(g_mainThreadId, WM_USER, WPARAM(&title), 0))
|
||||||
Log.report(logvisor::Fatal, "PostThreadMessage error");
|
Log.report(logvisor::Fatal, "PostThreadMessage error");
|
||||||
m_nwcv.wait(lk);
|
g_nwcv.wait(lk);
|
||||||
std::shared_ptr<IWindow> ret = std::move(m_mwret);
|
std::shared_ptr<IWindow> ret = std::move(m_mwret);
|
||||||
m_mwret.reset();
|
m_mwret.reset();
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include "boo/graphicsdev/GL.hpp"
|
#include "boo/graphicsdev/GL.hpp"
|
||||||
|
|
||||||
extern DWORD g_mainThreadId;
|
extern DWORD g_mainThreadId;
|
||||||
|
extern std::mutex g_nwmt;
|
||||||
|
extern std::condition_variable g_nwcv;
|
||||||
|
|
||||||
#if _WIN32_WINNT_WINBLUE && !WINDOWS_STORE
|
#if _WIN32_WINNT_WINBLUE && !WINDOWS_STORE
|
||||||
#include <ShellScalingApi.h>
|
#include <ShellScalingApi.h>
|
||||||
|
@ -47,45 +49,22 @@ struct OGLContext
|
||||||
boo::GLContext m_glCtx;
|
boo::GLContext m_glCtx;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class W>
|
#if !WINDOWS_STORE
|
||||||
static inline void SetFullscreen(W& win, bool fs)
|
static inline void SetFullscreen(OGLContext::Window& win, bool fs)
|
||||||
{
|
{
|
||||||
if (fs)
|
std::unique_lock<std::mutex> lk(g_nwmt);
|
||||||
{
|
PostThreadMessageW(g_mainThreadId, WM_USER+5, WPARAM(&win), LPARAM(fs));
|
||||||
win.m_fsStyle = GetWindowLong(win.m_hwnd, GWL_STYLE);
|
g_nwcv.wait(lk);
|
||||||
win.m_fsExStyle = GetWindowLong(win.m_hwnd, GWL_EXSTYLE);
|
|
||||||
GetWindowRect(win.m_hwnd, &win.m_fsRect);
|
|
||||||
|
|
||||||
SetWindowLong(win.m_hwnd, GWL_STYLE,
|
|
||||||
win.m_fsStyle & ~(WS_CAPTION | WS_THICKFRAME));
|
|
||||||
SetWindowLong(win.m_hwnd, GWL_EXSTYLE,
|
|
||||||
win.m_fsExStyle & ~(WS_EX_DLGMODALFRAME |
|
|
||||||
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
|
|
||||||
|
|
||||||
MONITORINFO monitor_info;
|
|
||||||
monitor_info.cbSize = sizeof(monitor_info);
|
|
||||||
GetMonitorInfo(MonitorFromWindow(win.m_hwnd, MONITOR_DEFAULTTONEAREST),
|
|
||||||
&monitor_info);
|
|
||||||
SetWindowPos(win.m_hwnd, NULL, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top,
|
|
||||||
monitor_info.rcMonitor.right - monitor_info.rcMonitor.left,
|
|
||||||
monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top,
|
|
||||||
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS);
|
|
||||||
|
|
||||||
win.m_fs = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetWindowLong(win.m_hwnd, GWL_STYLE, win.m_fsStyle);
|
|
||||||
SetWindowLong(win.m_hwnd, GWL_EXSTYLE, win.m_fsExStyle);
|
|
||||||
|
|
||||||
SetWindowPos(win.m_hwnd, NULL, win.m_fsRect.left, win.m_fsRect.top,
|
|
||||||
win.m_fsRect.right - win.m_fsRect.left, win.m_fsRect.bottom - win.m_fsRect.top,
|
|
||||||
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS);
|
|
||||||
|
|
||||||
win.m_fs = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void SetFullscreen(boo::VulkanContext::Window& win, bool fs)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lk(g_nwmt);
|
||||||
|
PostThreadMessageW(g_mainThreadId, WM_USER+6, WPARAM(&win), LPARAM(fs));
|
||||||
|
g_nwcv.wait(lk);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct Boo3DAppContextWin32 : Boo3DAppContext
|
struct Boo3DAppContextWin32 : Boo3DAppContext
|
||||||
{
|
{
|
||||||
OGLContext m_ctxOgl;
|
OGLContext m_ctxOgl;
|
||||||
|
|
|
@ -1164,7 +1164,7 @@ public:
|
||||||
{
|
{
|
||||||
if (GetCurrentThreadId() != g_mainThreadId)
|
if (GetCurrentThreadId() != g_mainThreadId)
|
||||||
{
|
{
|
||||||
if (!PostThreadMessage(g_mainThreadId, WM_USER+3, WPARAM(m_imc), LPARAM(open)))
|
if (!PostThreadMessageW(g_mainThreadId, WM_USER+3, WPARAM(m_imc), LPARAM(open)))
|
||||||
Log.report(logvisor::Fatal, "PostThreadMessage error");
|
Log.report(logvisor::Fatal, "PostThreadMessage error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1181,7 +1181,7 @@ public:
|
||||||
|
|
||||||
if (GetCurrentThreadId() != g_mainThreadId)
|
if (GetCurrentThreadId() != g_mainThreadId)
|
||||||
{
|
{
|
||||||
if (!PostThreadMessage(g_mainThreadId, WM_USER+4, WPARAM(m_imc), LPARAM(&m_cForm)))
|
if (!PostThreadMessageW(g_mainThreadId, WM_USER+4, WPARAM(m_imc), LPARAM(&m_cForm)))
|
||||||
Log.report(logvisor::Fatal, "PostThreadMessage error");
|
Log.report(logvisor::Fatal, "PostThreadMessage error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue