mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-05 03:50:07 +00:00
Windows: Correctly set the DPI-awareness of OpenGL worker threads
This commit is contained in:
parent
f95d9ea8df
commit
a37b918082
2 changed files with 35 additions and 1 deletions
|
|
@ -4095,6 +4095,27 @@ JUCE_API bool shouldScaleGLWindow (void* hwnd)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
JUCE_API void setThreadDPIAwareness (void* hwnd)
|
||||||
|
{
|
||||||
|
if (setThreadDPIAwarenessContext != nullptr)
|
||||||
|
{
|
||||||
|
if (! JUCEApplicationBase::isStandaloneApp())
|
||||||
|
{
|
||||||
|
if (hwnd != nullptr)
|
||||||
|
setThreadDPIAwarenessContext (isPerMonitorDPIAwareWindow ((HWND) hwnd) ? DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
|
||||||
|
: DPI_AWARENESS_CONTEXT_UNAWARE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
|
||||||
|
setThreadDPIAwarenessContext (DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
|
||||||
|
#else
|
||||||
|
setThreadDPIAwarenessContext (DPI_AWARENESS_CONTEXT_UNAWARE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JUCE_IMPLEMENT_SINGLETON (HWNDComponentPeer::WindowClassHolder)
|
JUCE_IMPLEMENT_SINGLETON (HWNDComponentPeer::WindowClassHolder)
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ extern bool shouldScaleGLWindow (void* hwnd);
|
||||||
void setProcessDPIAwarenessIfNecessary (void*);
|
void setProcessDPIAwarenessIfNecessary (void*);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void setThreadDPIAwareness (void*);
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
class OpenGLContext::NativeContext
|
class OpenGLContext::NativeContext
|
||||||
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
|
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
|
||||||
|
|
@ -109,6 +111,8 @@ public:
|
||||||
setProcessDPIAwarenessIfNecessary (nativeWindow->getNativeHandle());
|
setProcessDPIAwarenessIfNecessary (nativeWindow->getNativeHandle());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
updateThreadDPIAwareness();
|
||||||
|
|
||||||
context = &c;
|
context = &c;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +120,7 @@ public:
|
||||||
void shutdownOnRenderThread() { deactivateCurrentContext(); context = nullptr; }
|
void shutdownOnRenderThread() { deactivateCurrentContext(); context = nullptr; }
|
||||||
|
|
||||||
static void deactivateCurrentContext() { wglMakeCurrent (0, 0); }
|
static void deactivateCurrentContext() { wglMakeCurrent (0, 0); }
|
||||||
bool makeActive() const noexcept { return isActive() || wglMakeCurrent (dc, renderContext) != FALSE; }
|
bool makeActive() const noexcept { updateThreadDPIAwareness(); return isActive() || wglMakeCurrent (dc, renderContext) != FALSE; }
|
||||||
bool isActive() const noexcept { return wglGetCurrentContext() == renderContext; }
|
bool isActive() const noexcept { return wglGetCurrentContext() == renderContext; }
|
||||||
void swapBuffers() const noexcept { SwapBuffers (dc); }
|
void swapBuffers() const noexcept { SwapBuffers (dc); }
|
||||||
|
|
||||||
|
|
@ -336,6 +340,15 @@ private:
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateThreadDPIAwareness() const
|
||||||
|
{
|
||||||
|
if (nativeWindow.get() != nullptr)
|
||||||
|
setThreadDPIAwareness (nativeWindow->getNativeHandle());
|
||||||
|
else
|
||||||
|
setThreadDPIAwareness (nullptr);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext)
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue