From 31fd8051ab731f82f8df0fd9110c6bdee4445627 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Wed, 8 Jul 2026 21:01:24 +0200 Subject: [PATCH] [Win32] Store 100% handle when drawing single-zoom bitmap The GC.drawImage() operations use an Image mechanism that creates temporary handles for the requested size in case the image can be rendered at precisely the requested size or if no existing handle with a fitting size is found. While it is reasonable to not store persistent handles for arbitrary zooms, this may not be the optimal decision when requesting the 100% version of the image. For example, an image for which just a single bitmap exists, such that it can only be reasonably used at 100% scale, it is not beneficial to not persist the handle for its 100% version, as the next request will definitely request that same size again. This change thus improves the image loading mechanism for GC.drawImage() operations by persisting the 100% handle in case the image is requested at exactly 100% for that drawImage() operation. Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/3419 --- .../Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index 12a78ed8464..71d473e68e8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -249,6 +249,9 @@ private InternalImageHandle getOrCreateImageHandleAtClosestSize(int widthHint, i int imageZoomForWidth = 100 * widthHint / bounds.width; int imageZoomForHeight = 100 * heightHint / bounds.height; int imageZoom = DPIUtil.getZoomForAutoscaleProperty(Math.max(imageZoomForWidth, imageZoomForHeight)); + if (imageZoom == 100) { + return getHandleInternal(100, 100); + } InternalImageHandle bestFittingHandle = imageHandleManager.get(imageZoom); if (bestFittingHandle == null) { ImageData bestFittingImageData = imageProvider.loadImageData(imageZoom).element(); @@ -957,6 +960,10 @@ public static long win32_getHandle (Image image, int zoom) { } ImageHandle getHandle (int targetZoom, int nativeZoom) { + return getHandleInternal(targetZoom, nativeZoom); +} + +private InternalImageHandle getHandleInternal(int targetZoom, int nativeZoom) { if (isDisposed()) { return null; }