mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JRE-119 [Dynamically set DPI-awareness level to enable backward compatible HiDPI behavior]
Adopted: rely on java.manifest
(cherry picked from commit d00cfa4dc62a14a4cf89df9d4c4899970c9fc9e8)
Adopted
(cherry picked from commit 60be76b725)
This commit is contained in:
@@ -51,6 +51,11 @@ import sun.java2d.windows.WindowsFlags;
|
||||
|
||||
public final class Win32GraphicsEnvironment extends SunGraphicsEnvironment {
|
||||
|
||||
// [tav] the values match the native ones
|
||||
private final static int PROCESS_DPI_UNAWARE = 0;
|
||||
private final static int PROCESS_SYSTEM_DPI_AWARE = 1;
|
||||
private final static int PROCESS_PER_MONITOR_DPI_AWARE = 2;
|
||||
|
||||
static final float debugScaleX;
|
||||
static final float debugScaleY;
|
||||
|
||||
@@ -92,6 +97,7 @@ public final class Win32GraphicsEnvironment extends SunGraphicsEnvironment {
|
||||
public static void initDisplayWrapper() {
|
||||
if (!displayInitialized) {
|
||||
displayInitialized = true;
|
||||
if (!isUIScaleEnabled()) setProcessDPIAwareness(PROCESS_SYSTEM_DPI_AWARE);
|
||||
initDisplay();
|
||||
}
|
||||
}
|
||||
@@ -99,6 +105,7 @@ public final class Win32GraphicsEnvironment extends SunGraphicsEnvironment {
|
||||
public Win32GraphicsEnvironment() {
|
||||
}
|
||||
|
||||
private native static void setProcessDPIAwareness(int level);
|
||||
protected native int getNumScreens();
|
||||
private native int getDefaultScreen();
|
||||
|
||||
|
||||
@@ -40,6 +40,14 @@
|
||||
|
||||
extern COLORREF DesktopColor2RGB(int colorIndex);
|
||||
|
||||
#ifndef PROCESS_DPI_AWARENESS //_WIN32_WINNT_WINBLUE
|
||||
typedef enum _PROCESS_DPI_AWARENESS {
|
||||
PROCESS_DPI_UNAWARE = 0,
|
||||
PROCESS_SYSTEM_DPI_AWARE = 1,
|
||||
PROCESS_PER_MONITOR_DPI_AWARE = 2
|
||||
} PROCESS_DPI_AWARENESS;
|
||||
#endif
|
||||
|
||||
class AwtObject;
|
||||
typedef AwtObject* PDATA;
|
||||
|
||||
|
||||
@@ -77,6 +77,28 @@ SetProcessDPIAwareProperty()
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SetProcessDPIAwareness(PROCESS_DPI_AWARENESS level)
|
||||
{
|
||||
typedef HRESULT(WINAPI SetProcessDpiAwarenessFunc)(int);
|
||||
static HMODULE hLibSHCoreDll = NULL;
|
||||
static SetProcessDpiAwarenessFunc *lpSetProcessDpiAwareness = NULL;
|
||||
|
||||
if (hLibSHCoreDll == NULL) {
|
||||
hLibSHCoreDll = JDK_LoadSystemLibrary("shcore.dll");
|
||||
if (hLibSHCoreDll != NULL) {
|
||||
lpSetProcessDpiAwareness = (SetProcessDpiAwarenessFunc*)GetProcAddress(
|
||||
hLibSHCoreDll, "SetProcessDpiAwareness");
|
||||
}
|
||||
::FreeLibrary(hLibSHCoreDll);
|
||||
hLibSHCoreDll = NULL;
|
||||
}
|
||||
|
||||
if (lpSetProcessDpiAwareness != NULL) {
|
||||
lpSetProcessDpiAwareness(level);
|
||||
}
|
||||
}
|
||||
|
||||
#define DWM_COMP_UNDEFINED (~(TRUE|FALSE))
|
||||
static int dwmIsCompositionEnabled = DWM_COMP_UNDEFINED;
|
||||
|
||||
@@ -345,3 +367,14 @@ JNIEXPORT jboolean JNICALL Java_sun_awt_Win32GraphicsEnvironment_isVistaOS
|
||||
{
|
||||
return IS_WINVISTA;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: sun_awt_Win32GraphicsEnvironment
|
||||
* Method: setProcessDPIAwareness
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_sun_awt_Win32GraphicsEnvironment_setProcessDPIAwareness
|
||||
(JNIEnv *env, jclass wgeclass, jint level)
|
||||
{
|
||||
SetProcessDPIAwareness(static_cast<PROCESS_DPI_AWARENESS>(level));
|
||||
}
|
||||
Reference in New Issue
Block a user