Skip to content

Commit f8cbe80

Browse files
akoch-yattaHeikoKlare
authored andcommitted
[win32] No handle creation on Image::getBounds
This commit adapts the bounds calculation in Image to not create any handle, but use and scale the bounds of an existing handle if no handle for the desired zoom is available Fixes eclipse-platform#1639
1 parent 2ece1af commit f8cbe80

File tree

1 file changed

+11
-4
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+11
-4
lines changed

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public final class Image extends Resource implements Drawable {
127127
*/
128128
static final int DEFAULT_SCANLINE_PAD = 4;
129129

130-
private HashMap<Integer, ImageHandle> zoomLevelToImageHandle = new HashMap<>();
130+
private Map<Integer, ImageHandle> zoomLevelToImageHandle = new HashMap<>();
131131

132132
/**
133133
* Prevents uninitialized instances from being created outside the package.
@@ -1303,8 +1303,14 @@ public Rectangle getBounds() {
13031303

13041304
Rectangle getBounds(int zoom) {
13051305
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
1306-
ImageHandle imageMetadata = getImageMetadata(zoom);
1307-
return new Rectangle(0, 0, imageMetadata.width, imageMetadata.height);
1306+
ImageHandle imageMetadata;
1307+
if (zoomLevelToImageHandle.containsKey(zoom)) {
1308+
imageMetadata = zoomLevelToImageHandle.get(zoom);
1309+
} else {
1310+
imageMetadata = zoomLevelToImageHandle.values().iterator().next();
1311+
}
1312+
Rectangle rectangle = new Rectangle(0, 0, imageMetadata.width, imageMetadata.height);
1313+
return DPIUtil.scaleBounds(rectangle, zoom, imageMetadata.zoom);
13081314
}
13091315

13101316
/**
@@ -2084,18 +2090,19 @@ public void close() {
20842090

20852091
private class ImageHandle {
20862092
final long handle;
2093+
final int zoom;
20872094
int height;
20882095
int width;
20892096

20902097
public ImageHandle(long handle, int zoom) {
20912098
Rectangle bounds = getBoundsInPixelsFromNative(handle);
20922099
this.handle = handle;
2100+
this.zoom = zoom;
20932101
this.height = bounds.height;
20942102
this.width = bounds.width;
20952103
setImageMetadataForHandle(this, zoom);
20962104
}
20972105

2098-
20992106
private Rectangle getBoundsInPixelsFromNative(long handle) {
21002107
switch (type) {
21012108
case SWT.BITMAP:

0 commit comments

Comments
 (0)