Skip to content

Commit a3e8026

Browse files
committedSep 20, 2023
8294427: Check boxes and radio buttons have rendering issues on Windows in High DPI env
Reviewed-by: phh Backport-of: a63afa4aa62863d1a199a0fb7d2f56ff8fcd04fd
1 parent d2045f9 commit a3e8026

File tree

5 files changed

+162
-98
lines changed

5 files changed

+162
-98
lines changed
 

‎src/java.desktop/share/classes/sun/swing/CachedPainter.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -314,8 +314,9 @@ public int getHeight(ImageObserver observer) {
314314

315315
@Override
316316
public Image getResolutionVariant(double destWidth, double destHeight) {
317-
int w = (int) Math.ceil(destWidth);
318-
int h = (int) Math.ceil(destHeight);
317+
int w = (int) Math.floor(destWidth + 0.5);
318+
int h = (int) Math.floor(destHeight + 0.5);
319+
319320
return getImage(PainterMultiResolutionCachedImage.class,
320321
c, baseWidth, baseHeight, w, h, args);
321322
}

‎src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/TMSchema.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,10 +40,13 @@
4040

4141
package com.sun.java.swing.plaf.windows;
4242

43-
import java.awt.*;
44-
import java.util.*;
45-
46-
import javax.swing.*;
43+
import java.awt.Color;
44+
import java.awt.Component;
45+
import java.awt.Dimension;
46+
import java.awt.Insets;
47+
import java.awt.Point;
48+
import java.util.EnumMap;
49+
import javax.swing.JComponent;
4750

4851
import sun.awt.windows.ThemeReader;
4952

@@ -55,7 +58,7 @@
5558
*
5659
* @author Leif Samuelsson
5760
*/
58-
class TMSchema {
61+
public final class TMSchema {
5962

6063
/**
6164
* An enumeration of the various Windows controls (also known as

‎src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/XPStyle.java

+46-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,23 +40,52 @@
4040

4141
package com.sun.java.swing.plaf.windows;
4242

43-
import java.awt.*;
44-
import java.awt.image.*;
43+
import java.awt.Color;
44+
import java.awt.Component;
45+
import java.awt.Dimension;
46+
import java.awt.Graphics;
47+
import java.awt.Graphics2D;
48+
import java.awt.GraphicsConfiguration;
49+
import java.awt.Image;
50+
import java.awt.Insets;
51+
import java.awt.Point;
52+
import java.awt.Rectangle;
53+
import java.awt.Toolkit;
54+
import java.awt.geom.AffineTransform;
55+
import java.awt.image.BufferedImage;
56+
import java.awt.image.DataBufferInt;
57+
import java.awt.image.WritableRaster;
4558
import java.security.AccessController;
46-
import java.util.*;
47-
48-
import javax.swing.*;
49-
import javax.swing.border.*;
50-
import javax.swing.plaf.*;
59+
import java.util.HashMap;
60+
61+
import javax.swing.AbstractButton;
62+
import javax.swing.CellRendererPane;
63+
import javax.swing.JButton;
64+
import javax.swing.JCheckBox;
65+
import javax.swing.JComboBox;
66+
import javax.swing.JComponent;
67+
import javax.swing.JRadioButton;
68+
import javax.swing.JToolBar;
69+
import javax.swing.SwingUtilities;
70+
import javax.swing.UIManager;
71+
import javax.swing.border.AbstractBorder;
72+
import javax.swing.border.Border;
73+
import javax.swing.border.EmptyBorder;
74+
import javax.swing.border.LineBorder;
75+
import javax.swing.plaf.ColorUIResource;
76+
import javax.swing.plaf.InsetsUIResource;
77+
import javax.swing.plaf.UIResource;
5178
import javax.swing.text.JTextComponent;
5279

5380
import sun.awt.image.SunWritableRaster;
5481
import sun.awt.windows.ThemeReader;
5582
import sun.security.action.GetPropertyAction;
5683
import sun.swing.CachedPainter;
5784

58-
import static com.sun.java.swing.plaf.windows.TMSchema.*;
59-
85+
import static com.sun.java.swing.plaf.windows.TMSchema.Part;
86+
import static com.sun.java.swing.plaf.windows.TMSchema.Prop;
87+
import static com.sun.java.swing.plaf.windows.TMSchema.State;
88+
import static com.sun.java.swing.plaf.windows.TMSchema.TypeEnum;
6089

6190
/**
6291
* Implements Windows XP Styles for the Windows Look and Feel.
@@ -675,14 +704,20 @@ protected void paintToImage(Component c, Image image, Graphics g,
675704
w = bi.getWidth();
676705
h = bi.getHeight();
677706

707+
// Get DPI to pass further to ThemeReader.paintBackground()
708+
Graphics2D g2d = (Graphics2D) g;
709+
AffineTransform at = g2d.getTransform();
710+
int dpi = (int)(at.getScaleX() * 96);
711+
678712
WritableRaster raster = bi.getRaster();
679713
DataBufferInt dbi = (DataBufferInt)raster.getDataBuffer();
680714
// Note that stealData() requires a markDirty() afterwards
681715
// since we modify the data in it.
682716
ThemeReader.paintBackground(SunWritableRaster.stealData(dbi, 0),
683717
part.getControlName(c), part.getValue(),
684718
State.getValue(part, state),
685-
0, 0, w, h, w);
719+
0, 0, w, h, w, dpi);
720+
686721
SunWritableRaster.markDirty(dbi);
687722
}
688723

‎src/java.desktop/windows/classes/sun/awt/windows/ThemeReader.java

+85-43
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,11 +30,14 @@
3030
import java.awt.Insets;
3131
import java.awt.Point;
3232
import java.util.HashMap;
33+
import java.util.List;
3334
import java.util.Map;
3435
import java.util.concurrent.locks.Lock;
3536
import java.util.concurrent.locks.ReadWriteLock;
3637
import java.util.concurrent.locks.ReentrantReadWriteLock;
3738

39+
import static com.sun.java.swing.plaf.windows.TMSchema.Part;
40+
3841
/**
3942
* Implements Theme Support for Windows XP.
4043
*
@@ -44,7 +47,24 @@
4447
*/
4548
public final class ThemeReader {
4649

47-
private static final Map<String, Long> widgetToTheme = new HashMap<>();
50+
private static final int defaultDPI = 96;
51+
52+
/**
53+
* List of widgets for which we need to get the part size for the current DPI.
54+
*/
55+
private static final List<String> partSizeWidgets =
56+
List.of("MENU", "BUTTON");
57+
58+
/**
59+
* List of widget parts for which we need to get the part size for the current DPI.
60+
*/
61+
private static final List<Integer> partSizeWidgetParts =
62+
List.of(Part.BP_RADIOBUTTON.getValue(),
63+
Part.BP_CHECKBOX.getValue(),
64+
Part.MP_POPUPCHECK.getValue());
65+
66+
private static final Map<Integer, Map<String, Long>> dpiAwareWidgetToTheme
67+
= new HashMap<>();
4868

4969
// lock for the cache
5070
// reading should be done with readLock
@@ -80,28 +100,30 @@ public static boolean isXPStyleEnabled() {
80100
return xpStyleEnabled;
81101
}
82102

103+
private static Long openThemeImpl(String widget, int dpi) {
104+
Long theme;
105+
int i = widget.indexOf("::");
106+
if (i > 0) {
107+
// We're using the syntax "subAppName::controlName" here, as used by msstyles.
108+
// See documentation for SetWindowTheme on MSDN.
109+
setWindowTheme(widget.substring(0, i));
110+
theme = openTheme(widget.substring(i + 2), dpi);
111+
setWindowTheme(null);
112+
} else {
113+
theme = openTheme(widget, dpi);
114+
}
115+
return theme;
116+
}
117+
83118
// this should be called only with writeLock held
84-
private static Long getThemeImpl(String widget) {
85-
Long theme = widgetToTheme.get(widget);
86-
if (theme == null) {
87-
int i = widget.indexOf("::");
88-
if (i > 0) {
89-
// We're using the syntax "subAppName::controlName" here, as used by msstyles.
90-
// See documentation for SetWindowTheme on MSDN.
91-
setWindowTheme(widget.substring(0, i));
92-
theme = openTheme(widget.substring(i+2));
93-
setWindowTheme(null);
94-
} else {
95-
theme = openTheme(widget);
96-
}
97-
widgetToTheme.put(widget, theme);
98-
}
99-
return theme;
119+
private static Long getThemeImpl(String widget, int dpi) {
120+
return dpiAwareWidgetToTheme.computeIfAbsent(dpi, key -> new HashMap<>())
121+
.computeIfAbsent(widget, w -> openThemeImpl(widget, dpi));
100122
}
101123

102124
// returns theme value
103125
// this method should be invoked with readLock locked
104-
private static Long getTheme(String widget) {
126+
private static Long getTheme(String widget, int dpi) {
105127
if (!isThemed) {
106128
throw new IllegalStateException("Themes are not loaded");
107129
}
@@ -111,10 +133,12 @@ private static Long getTheme(String widget) {
111133
try {
112134
if (!valid) {
113135
// Close old themes.
114-
for (Long value : widgetToTheme.values()) {
115-
closeTheme(value);
136+
for (Map<String, Long> dpiVal : dpiAwareWidgetToTheme.values()) {
137+
for (Long value : dpiVal.values()) {
138+
closeTheme(value);
139+
}
116140
}
117-
widgetToTheme.clear();
141+
dpiAwareWidgetToTheme.clear();
118142
valid = true;
119143
}
120144
} finally {
@@ -123,13 +147,20 @@ private static Long getTheme(String widget) {
123147
}
124148
}
125149

150+
Long theme = null;
151+
152+
Map<String, Long> widgetToTheme = dpiAwareWidgetToTheme.get(dpi);
153+
154+
if (widgetToTheme != null) {
155+
theme = widgetToTheme.get(widget);
156+
}
157+
126158
// mostly copied from the javadoc for ReentrantReadWriteLock
127-
Long theme = widgetToTheme.get(widget);
128159
if (theme == null) {
129160
readLock.unlock();
130161
writeLock.lock();
131162
try {
132-
theme = getThemeImpl(widget);
163+
theme = getThemeImpl(widget, dpi);
133164
} finally {
134165
readLock.lock();
135166
writeLock.unlock();// Unlock write, still hold read
@@ -139,14 +170,23 @@ private static Long getTheme(String widget) {
139170
}
140171

141172
private static native void paintBackground(int[] buffer, long theme,
142-
int part, int state, int x,
143-
int y, int w, int h, int stride);
173+
int part, int state,
174+
int rectRight, int rectBottom,
175+
int w, int h, int stride);
144176

145177
public static void paintBackground(int[] buffer, String widget,
146-
int part, int state, int x, int y, int w, int h, int stride) {
178+
int part, int state, int x, int y, int w, int h, int stride, int dpi) {
147179
readLock.lock();
148180
try {
149-
paintBackground(buffer, getTheme(widget), part, state, x, y, w, h, stride);
181+
/* For widgets and parts in the lists, we get the part size
182+
for the current screen DPI to scale them better. */
183+
Dimension d = (partSizeWidgets.contains(widget)
184+
&& partSizeWidgetParts.contains(Integer.valueOf(part)))
185+
? getPartSize(getTheme(widget, dpi), part, state)
186+
: new Dimension(w, h);
187+
188+
paintBackground(buffer, getTheme(widget, dpi), part, state,
189+
d.width, d.height, w, h, stride);
150190
} finally {
151191
readLock.unlock();
152192
}
@@ -158,7 +198,7 @@ private static native Insets getThemeMargins(long theme, int part,
158198
public static Insets getThemeMargins(String widget, int part, int state, int marginType) {
159199
readLock.lock();
160200
try {
161-
return getThemeMargins(getTheme(widget), part, state, marginType);
201+
return getThemeMargins(getTheme(widget, defaultDPI), part, state, marginType);
162202
} finally {
163203
readLock.unlock();
164204
}
@@ -169,7 +209,7 @@ public static Insets getThemeMargins(String widget, int part, int state, int mar
169209
public static boolean isThemePartDefined(String widget, int part, int state) {
170210
readLock.lock();
171211
try {
172-
return isThemePartDefined(getTheme(widget), part, state);
212+
return isThemePartDefined(getTheme(widget, defaultDPI), part, state);
173213
} finally {
174214
readLock.unlock();
175215
}
@@ -181,7 +221,7 @@ private static native Color getColor(long theme, int part, int state,
181221
public static Color getColor(String widget, int part, int state, int property) {
182222
readLock.lock();
183223
try {
184-
return getColor(getTheme(widget), part, state, property);
224+
return getColor(getTheme(widget, defaultDPI), part, state, property);
185225
} finally {
186226
readLock.unlock();
187227
}
@@ -193,7 +233,7 @@ private static native int getInt(long theme, int part, int state,
193233
public static int getInt(String widget, int part, int state, int property) {
194234
readLock.lock();
195235
try {
196-
return getInt(getTheme(widget), part, state, property);
236+
return getInt(getTheme(widget, defaultDPI), part, state, property);
197237
} finally {
198238
readLock.unlock();
199239
}
@@ -205,7 +245,7 @@ private static native int getEnum(long theme, int part, int state,
205245
public static int getEnum(String widget, int part, int state, int property) {
206246
readLock.lock();
207247
try {
208-
return getEnum(getTheme(widget), part, state, property);
248+
return getEnum(getTheme(widget, defaultDPI), part, state, property);
209249
} finally {
210250
readLock.unlock();
211251
}
@@ -218,7 +258,7 @@ public static boolean getBoolean(String widget, int part, int state,
218258
int property) {
219259
readLock.lock();
220260
try {
221-
return getBoolean(getTheme(widget), part, state, property);
261+
return getBoolean(getTheme(widget, defaultDPI), part, state, property);
222262
} finally {
223263
readLock.unlock();
224264
}
@@ -229,7 +269,7 @@ public static boolean getBoolean(String widget, int part, int state,
229269
public static boolean getSysBoolean(String widget, int property) {
230270
readLock.lock();
231271
try {
232-
return getSysBoolean(getTheme(widget), property);
272+
return getSysBoolean(getTheme(widget, defaultDPI), property);
233273
} finally {
234274
readLock.unlock();
235275
}
@@ -241,7 +281,7 @@ private static native Point getPoint(long theme, int part, int state,
241281
public static Point getPoint(String widget, int part, int state, int property) {
242282
readLock.lock();
243283
try {
244-
return getPoint(getTheme(widget), part, state, property);
284+
return getPoint(getTheme(widget, defaultDPI), part, state, property);
245285
} finally {
246286
readLock.unlock();
247287
}
@@ -254,7 +294,7 @@ public static Dimension getPosition(String widget, int part, int state,
254294
int property) {
255295
readLock.lock();
256296
try {
257-
return getPosition(getTheme(widget), part,state,property);
297+
return getPosition(getTheme(widget, defaultDPI), part,state,property);
258298
} finally {
259299
readLock.unlock();
260300
}
@@ -266,13 +306,13 @@ private static native Dimension getPartSize(long theme, int part,
266306
public static Dimension getPartSize(String widget, int part, int state) {
267307
readLock.lock();
268308
try {
269-
return getPartSize(getTheme(widget), part, state);
309+
return getPartSize(getTheme(widget, defaultDPI), part, state);
270310
} finally {
271311
readLock.unlock();
272312
}
273313
}
274314

275-
private static native long openTheme(String widget);
315+
private static native long openTheme(String widget, int dpi);
276316

277317
private static native void closeTheme(long theme);
278318

@@ -285,8 +325,9 @@ public static long getThemeTransitionDuration(String widget, int part,
285325
int stateFrom, int stateTo, int propId) {
286326
readLock.lock();
287327
try {
288-
return getThemeTransitionDuration(getTheme(widget),
289-
part, stateFrom, stateTo, propId);
328+
return getThemeTransitionDuration(getTheme(widget, defaultDPI),
329+
part, stateFrom, stateTo,
330+
propId);
290331
} finally {
291332
readLock.unlock();
292333
}
@@ -299,8 +340,9 @@ public static Insets getThemeBackgroundContentMargins(String widget,
299340
int part, int state, int boundingWidth, int boundingHeight) {
300341
readLock.lock();
301342
try {
302-
return getThemeBackgroundContentMargins(getTheme(widget),
303-
part, state, boundingWidth, boundingHeight);
343+
return getThemeBackgroundContentMargins(getTheme(widget, defaultDPI),
344+
part, state,
345+
boundingWidth, boundingHeight);
304346
} finally {
305347
readLock.unlock();
306348
}

‎src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp

+18-35
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ typedef HRESULT(__stdcall *PFNCLOSETHEMEDATA)(HTHEME hTheme);
5252
typedef HRESULT(__stdcall *PFNDRAWTHEMEBACKGROUND)(HTHEME hTheme, HDC hdc,
5353
int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect);
5454

55-
typedef HTHEME(__stdcall *PFNOPENTHEMEDATA)(HWND hwnd, LPCWSTR pszClassList);
55+
typedef HTHEME(__stdcall *PFNOPENTHEMEDATAFORDPI)(HWND hwnd, LPCWSTR pszClassList, UINT dpi);
5656

5757
typedef HRESULT (__stdcall *PFNDRAWTHEMETEXT)(HTHEME hTheme, HDC hdc,
5858
int iPartId, int iStateId, LPCWSTR pszText, int iCharCount,
@@ -96,7 +96,7 @@ typedef HRESULT (__stdcall *PFNGETTHEMETRANSITIONDURATION)
9696
(HTHEME hTheme, int iPartId, int iStateIdFrom, int iStateIdTo,
9797
int iPropId, DWORD *pdwDuration);
9898

99-
static PFNOPENTHEMEDATA OpenThemeDataFunc = NULL;
99+
static PFNOPENTHEMEDATAFORDPI OpenThemeDataForDpiFunc = NULL;
100100
static PFNDRAWTHEMEBACKGROUND DrawThemeBackgroundFunc = NULL;
101101
static PFNCLOSETHEMEDATA CloseThemeDataFunc = NULL;
102102
static PFNDRAWTHEMETEXT DrawThemeTextFunc = NULL;
@@ -122,8 +122,8 @@ BOOL InitThemes() {
122122
DTRACE_PRINTLN1("InitThemes hModThemes = %x\n", hModThemes);
123123
if(hModThemes) {
124124
DTRACE_PRINTLN("Loaded UxTheme.dll\n");
125-
OpenThemeDataFunc = (PFNOPENTHEMEDATA)GetProcAddress(hModThemes,
126-
"OpenThemeData");
125+
OpenThemeDataForDpiFunc = (PFNOPENTHEMEDATAFORDPI)GetProcAddress(
126+
hModThemes, "OpenThemeDataForDpi");
127127
DrawThemeBackgroundFunc = (PFNDRAWTHEMEBACKGROUND)GetProcAddress(
128128
hModThemes, "DrawThemeBackground");
129129
CloseThemeDataFunc = (PFNCLOSETHEMEDATA)GetProcAddress(
@@ -158,7 +158,7 @@ BOOL InitThemes() {
158158
(PFNGETTHEMETRANSITIONDURATION)GetProcAddress(hModThemes,
159159
"GetThemeTransitionDuration");
160160

161-
if(OpenThemeDataFunc
161+
if(OpenThemeDataForDpiFunc
162162
&& DrawThemeBackgroundFunc
163163
&& CloseThemeDataFunc
164164
&& DrawThemeTextFunc
@@ -177,9 +177,12 @@ BOOL InitThemes() {
177177
&& GetThemeTransitionDurationFunc
178178
) {
179179
DTRACE_PRINTLN("Loaded function pointers.\n");
180-
// We need to make sure we can load the Theme. This may not be
181-
// the case on a WinXP machine with classic mode enabled.
182-
HTHEME hTheme = OpenThemeDataFunc(AwtToolkit::GetInstance().GetHWnd(), L"Button");
180+
// We need to make sure we can load the Theme.
181+
// Use the default DPI value of 96 on windows.
182+
constexpr unsigned int defaultDPI = 96;
183+
HTHEME hTheme = OpenThemeDataForDpiFunc (
184+
AwtToolkit::GetInstance().GetHWnd(),
185+
L"Button", defaultDPI);
183186
if(hTheme) {
184187
DTRACE_PRINTLN("Loaded Theme data.\n");
185188
CloseThemeDataFunc(hTheme);
@@ -242,7 +245,7 @@ static void assert_result(HRESULT hres, JNIEnv *env) {
242245
* Signature: (Ljava/lang/String;)J
243246
*/
244247
JNIEXPORT jlong JNICALL Java_sun_awt_windows_ThemeReader_openTheme
245-
(JNIEnv *env, jclass klass, jstring widget) {
248+
(JNIEnv *env, jclass klass, jstring widget, jint dpi) {
246249

247250
LPCTSTR str = (LPCTSTR) JNU_GetStringPlatformChars(env, widget, NULL);
248251
if (str == NULL) {
@@ -251,7 +254,9 @@ JNIEXPORT jlong JNICALL Java_sun_awt_windows_ThemeReader_openTheme
251254
}
252255
// We need to open the Theme on a Window that will stick around.
253256
// The best one for that purpose is the Toolkit window.
254-
HTHEME htheme = OpenThemeDataFunc(AwtToolkit::GetInstance().GetHWnd(), str);
257+
HTHEME htheme = OpenThemeDataForDpiFunc(
258+
AwtToolkit::GetInstance().GetHWnd(),
259+
str, dpi);
255260
JNU_ReleaseStringPlatformChars(env, widget, str);
256261
return (jlong) htheme;
257262
}
@@ -384,7 +389,7 @@ static void copyDIBToBufferedImage(int *pDstBits, int *pSrcBits,
384389
*/
385390
JNIEXPORT void JNICALL Java_sun_awt_windows_ThemeReader_paintBackground
386391
(JNIEnv *env, jclass klass, jintArray array, jlong theme, jint part, jint state,
387-
jint x, jint y, jint w, jint h, jint stride) {
392+
jint rectRight, jint rectBottom, jint w, jint h, jint stride) {
388393

389394
int *pDstBits=NULL;
390395
int *pSrcBits=NULL;
@@ -430,8 +435,8 @@ JNIEXPORT void JNICALL Java_sun_awt_windows_ThemeReader_paintBackground
430435

431436
rect.left = 0;
432437
rect.top = 0;
433-
rect.bottom = h;
434-
rect.right = w;
438+
rect.bottom = rectBottom;
439+
rect.right = rectRight;
435440

436441
ZeroMemory(pSrcBits,(BITS_PER_PIXEL>>3)*w*h);
437442

@@ -720,27 +725,6 @@ JNIEXPORT jobject JNICALL Java_sun_awt_windows_ThemeReader_getPosition
720725
return NULL;
721726
}
722727

723-
void rescale(SIZE *size) {
724-
static int dpiX = -1;
725-
static int dpiY = -1;
726-
if (dpiX == -1 || dpiY == -1) {
727-
HWND hWnd = ::GetDesktopWindow();
728-
HDC hDC = ::GetDC(hWnd);
729-
dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
730-
dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
731-
::ReleaseDC(hWnd, hDC);
732-
}
733-
734-
if (dpiX !=0 && dpiX != 96) {
735-
float invScaleX = 96.0f / dpiX;
736-
size->cx = ROUND_TO_INT(size->cx * invScaleX);
737-
}
738-
if (dpiY != 0 && dpiY != 96) {
739-
float invScaleY = 96.0f / dpiY;
740-
size->cy = ROUND_TO_INT(size->cy * invScaleY);
741-
}
742-
}
743-
744728
/*
745729
* Class: sun_awt_windows_ThemeReader
746730
* Method: getPartSize
@@ -767,7 +751,6 @@ JNIEXPORT jobject JNICALL Java_sun_awt_windows_ThemeReader_getPartSize
767751
CHECK_NULL_RETURN(dimMID, NULL);
768752
}
769753

770-
rescale(&size);
771754
jobject dimObj = env->NewObject(dimClassID, dimMID, size.cx, size.cy);
772755
if (safe_ExceptionOccurred(env)) {
773756
env->ExceptionDescribe();

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Sep 20, 2023

@openjdk-notifier[bot]
Please sign in to comment.