Skip to content

Commit 57720db

Browse files
committed
[win32] Utilize temporary image handles
This commit adapts all places, where operation where executed with OS handles created for a specific zoom that could use any zoom. Therefor now any existing handle is used or, if none exists yet, a temporary handle is created and destroyed afterwards.
1 parent 48a2524 commit 57720db

File tree

1 file changed

+23
-2
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+23
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,9 @@ Rectangle getBounds(int zoom) {
11761176
*/
11771177
@Deprecated
11781178
public Rectangle getBoundsInPixels() {
1179-
return getBounds(getZoom());
1179+
return applyUsingAnyHandle(imageHandle -> {
1180+
return imageHandle.getBounds();
1181+
});
11801182
}
11811183

11821184
/**
@@ -1258,7 +1260,9 @@ public ImageData getImageData (int zoom) {
12581260
*/
12591261
@Deprecated
12601262
public ImageData getImageDataAtCurrentZoom() {
1261-
return getImageMetadata(getZoom()).getImageData();
1263+
return applyUsingAnyHandle(imageHandle -> {
1264+
return imageHandle.getImageData();
1265+
});
12621266
}
12631267

12641268
/**
@@ -1832,6 +1836,19 @@ public String toString () {
18321836
return "Image {" + zoomLevelToImageHandle + "}";
18331837
}
18341838

1839+
<T> T applyUsingAnyHandle(Function<ImageHandle, T> function) {
1840+
if (zoomLevelToImageHandle.isEmpty()) {
1841+
ImageHandle temporaryHandle = this.imageProvider.newImageHandle(DPIUtil.getDeviceZoom());
1842+
try {
1843+
return function.apply(temporaryHandle);
1844+
} finally {
1845+
temporaryHandle.destroy();
1846+
}
1847+
} else {
1848+
return function.apply(zoomLevelToImageHandle.values().iterator().next());
1849+
}
1850+
}
1851+
18351852
/**
18361853
* Invokes platform specific functionality to allocate a new image.
18371854
* <p>
@@ -2558,6 +2575,10 @@ public ImageHandle(long handle, int zoom) {
25582575
setImageMetadataForHandle(this, zoom);
25592576
}
25602577

2578+
public Rectangle getBounds() {
2579+
return new Rectangle(0, 0, width, height);
2580+
}
2581+
25612582
private void setBackground(RGB color) {
25622583
if (transparentPixel == -1) return;
25632584

0 commit comments

Comments
 (0)