|
22 | 22 | import org.eclipse.swt.internal.DPIUtil.*;
|
23 | 23 | import org.eclipse.swt.internal.gdip.*;
|
24 | 24 | import org.eclipse.swt.internal.win32.*;
|
| 25 | +import org.eclipse.swt.widgets.*; |
25 | 26 |
|
26 | 27 | /**
|
27 | 28 | * Instances of this class are graphics which have been prepared
|
@@ -819,7 +820,10 @@ public static Long win32_getHandle (Image image, int zoom) {
|
819 | 820 | image.init(newData, zoom);
|
820 | 821 | }
|
821 | 822 | } else if (image.imageDataProvider != null) {
|
822 |
| - ElementAtZoom<ImageData> imageCandidate = DPIUtil.validateAndGetImageDataAtZoom (image.imageDataProvider, zoom); |
| 823 | + ElementAtZoom<ImageData> imageCandidate; |
| 824 | + try (StaticZoomUpdater unused = image.new StaticZoomUpdater(zoom)) { |
| 825 | + imageCandidate = DPIUtil.validateAndGetImageDataAtZoom (image.imageDataProvider, zoom); |
| 826 | + } |
823 | 827 | ImageData resizedData = DPIUtil.scaleImageData (image.device, imageCandidate.element(), zoom, imageCandidate.zoom());
|
824 | 828 | ImageData newData = image.adaptImageDataIfDisabledOrGray(resizedData);
|
825 | 829 | image.init(newData, zoom);
|
@@ -1443,7 +1447,10 @@ public ImageData getImageData (int zoom) {
|
1443 | 1447 | if (zoom == currentZoom) {
|
1444 | 1448 | return getImageDataAtCurrentZoom();
|
1445 | 1449 | } else if (imageDataProvider != null) {
|
1446 |
| - ElementAtZoom<ImageData> data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, zoom); |
| 1450 | + ElementAtZoom<ImageData> data; |
| 1451 | + try (StaticZoomUpdater unused = new StaticZoomUpdater(zoom)) { |
| 1452 | + data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, zoom); |
| 1453 | + } |
1447 | 1454 | return DPIUtil.scaleImageData (device, data.element(), zoom, data.zoom());
|
1448 | 1455 | } else if (imageFileNameProvider != null) {
|
1449 | 1456 | ElementAtZoom<String> fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, zoom);
|
@@ -2397,4 +2404,25 @@ public static Image win32_new(Device device, int type, long handle) {
|
2397 | 2404 | image.setHandleForZoomLevel(handle, image.getZoom());
|
2398 | 2405 | return image;
|
2399 | 2406 | }
|
| 2407 | + |
| 2408 | +// This class is only used for a workaround and will be removed again |
| 2409 | +private class StaticZoomUpdater implements AutoCloseable { |
| 2410 | + private final boolean updateStaticZoom; |
| 2411 | + private final int currentNativeDeviceZoom; |
| 2412 | + |
| 2413 | + private StaticZoomUpdater(int targetZoom) { |
| 2414 | + this.currentNativeDeviceZoom = DPIUtil.getNativeDeviceZoom(); |
| 2415 | + this.updateStaticZoom = this.currentNativeDeviceZoom != targetZoom && device instanceof Display display && display.isRescalingAtRuntime(); |
| 2416 | + if (updateStaticZoom) { |
| 2417 | + DPIUtil.setDeviceZoom(targetZoom); |
| 2418 | + } |
| 2419 | + } |
| 2420 | + |
| 2421 | + @Override |
| 2422 | + public void close() { |
| 2423 | + if (updateStaticZoom) { |
| 2424 | + DPIUtil.setDeviceZoom(currentNativeDeviceZoom); |
| 2425 | + } |
| 2426 | + } |
| 2427 | +} |
2400 | 2428 | }
|
0 commit comments