Do fullscreen set on main thread

This commit is contained in:
Jack Andersen 2018-05-28 17:40:44 -10:00
parent 6ff4229f9b
commit fb91482282
3 changed files with 74 additions and 47 deletions

View File

@ -26,6 +26,8 @@ PFN_GetScaleFactorForMonitor MyGetScaleFactorForMonitor = nullptr;
#endif
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);
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()
{
g_mainThreadId = GetCurrentThreadId();
@ -357,7 +400,7 @@ public:
logvisor::RegisterThreadName(thrName.c_str());
CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
clientReturn = m_callback.appMain(this);
PostThreadMessage(g_mainThreadId, WM_USER+1, 0, 0);
PostThreadMessageW(g_mainThreadId, WM_USER+1, 0, 0);
});
/* Pump messages */
@ -372,11 +415,10 @@ public:
case WM_USER:
{
/* 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);
m_mwret = newWindow(*title);
lk.unlock();
m_nwcv.notify_one();
g_nwcv.notify_one();
continue;
}
case WM_USER+1:
@ -395,6 +437,14 @@ public:
/* ImmSetCompositionWindow call from client thread */
ImmSetCompositionWindow(HIMC(msg.wParam), LPCOMPOSITIONFORM(msg.lParam));
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;
}
}
@ -434,17 +484,15 @@ public:
return m_args;
}
std::mutex m_nwmt;
std::condition_variable m_nwcv;
std::shared_ptr<IWindow> m_mwret;
std::shared_ptr<IWindow> newWindow(SystemStringView title)
{
if (GetCurrentThreadId() != g_mainThreadId)
{
std::unique_lock<std::mutex> lk(m_nwmt);
if (!PostThreadMessage(g_mainThreadId, WM_USER, WPARAM(&title), 0))
std::unique_lock<std::mutex> lk(g_nwmt);
if (!PostThreadMessageW(g_mainThreadId, WM_USER, WPARAM(&title), 0))
Log.report(logvisor::Fatal, "PostThreadMessage error");
m_nwcv.wait(lk);
g_nwcv.wait(lk);
std::shared_ptr<IWindow> ret = std::move(m_mwret);
m_mwret.reset();
return ret;

View File

@ -16,6 +16,8 @@
#include "boo/graphicsdev/GL.hpp"
extern DWORD g_mainThreadId;
extern std::mutex g_nwmt;
extern std::condition_variable g_nwcv;
#if _WIN32_WINNT_WINBLUE && !WINDOWS_STORE
#include <ShellScalingApi.h>
@ -47,45 +49,22 @@ struct OGLContext
boo::GLContext m_glCtx;
};
template <class W>
static inline void SetFullscreen(W& win, bool fs)
#if !WINDOWS_STORE
static inline void SetFullscreen(OGLContext::Window& win, bool fs)
{
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 | 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;
}
std::unique_lock<std::mutex> lk(g_nwmt);
PostThreadMessageW(g_mainThreadId, WM_USER+5, WPARAM(&win), LPARAM(fs));
g_nwcv.wait(lk);
}
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
{
OGLContext m_ctxOgl;

View File

@ -1164,7 +1164,7 @@ public:
{
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");
return;
}
@ -1181,7 +1181,7 @@ public:
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");
return;
}