Skip to content

Commit dfd19fc

Browse files
committed
[Win32] Remove obsolete HandleAtSizeConsumer
With latest refactorings, the HandleAtSizeConsumer inside Image became obsolete as the ImageHandle passed to it already contains the other information encapsulated in that consumer. Thus, this follow-up refactoring replaces the HandleAtSizeConsumer with a simple ImageHandle consumer. To do so, it properly encapsulates and exposes the width/height information in an ImageHandle. It also aligns the name of the method processing such a consumer to fit the actual behavior and the according MacOS implementation.
1 parent c422be8 commit dfd19fc

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,10 +1233,11 @@ void apply() {
12331233
}
12341234

12351235
private void drawImage(Image image, int destX, int destY, int destWidth, int destHeight, int imageZoom) {
1236-
Rectangle destPixels = Win32DPIUtils.pointToPixel(drawable, new Rectangle(destX, destY, destWidth, destHeight), imageZoom);
1237-
image.executeOnImageHandleAtSize((tempHandle, handleSize) -> {
1238-
drawImage(image, 0, 0, handleSize.x, handleSize.y, destPixels.x, destPixels.y, destPixels.width,
1239-
destPixels.height, false, tempHandle);
1236+
Rectangle destPixels = Win32DPIUtils.pointToPixel(drawable, new Rectangle(destX, destY, destWidth, destHeight),
1237+
imageZoom);
1238+
image.executeOnImageHandleAtBestFittingSize(tempHandle -> {
1239+
drawImage(image, 0, 0, tempHandle.getWidth(), tempHandle.getHeight(), destPixels.x, destPixels.y,
1240+
destPixels.width, destPixels.height, false, tempHandle);
12401241
}, destPixels.width, destPixels.height);
12411242
}
12421243

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -845,21 +845,15 @@ ImageHandle getHandle (int targetZoom, int nativeZoom) {
845845
return getImageMetadata(zoomContext);
846846
}
847847

848-
@FunctionalInterface
849-
interface HandleAtSizeConsumer {
850-
void accept(ImageHandle imageHandle, Point handleSize);
851-
}
852-
853-
void executeOnImageHandleAtSize(HandleAtSizeConsumer handleAtSizeConsumer, int widthHint, int heightHint) {
848+
void executeOnImageHandleAtBestFittingSize(Consumer<ImageHandle> handleAtSizeConsumer, int widthHint, int heightHint) {
854849
if (!lastRequestedHandle.isReusable(heightHint, widthHint)) {
855850
ImageData imageData;
856851
imageData = this.imageProvider.loadImageDataAtSize(widthHint, heightHint);
857852
lastRequestedHandle.destroy();
858853
ImageHandle handleContainer = init(imageData, -1);
859854
lastRequestedHandle = new CachedHandle(handleContainer, widthHint, heightHint);
860855
}
861-
handleAtSizeConsumer.accept(lastRequestedHandle.getHandle(),
862-
new Point(lastRequestedHandle.handleContainer().width, lastRequestedHandle.handleContainer().height));
856+
handleAtSizeConsumer.accept(lastRequestedHandle.getHandle());
863857
}
864858

865859
/**
@@ -2817,13 +2811,15 @@ public void internal_dispose_GC(long handle, GCData data) {
28172811
class ImageHandle {
28182812
private long handle;
28192813
private final int zoom;
2820-
private int height;
2821-
private int width;
2814+
private final int height;
2815+
private final int width;
28222816

2823-
public ImageHandle(long handle, int zoom) {
2817+
ImageHandle(long handle, int zoom) {
28242818
this.handle = handle;
28252819
this.zoom = zoom;
2826-
updateBoundsInPixelsFromNative();
2820+
Point bounds = getBoundsInPixelsFromNative();
2821+
this.width = bounds.x;
2822+
this.height = bounds.y;
28272823
if (backgroundColor != null) {
28282824
setBackground(backgroundColor);
28292825
}
@@ -2834,7 +2830,15 @@ long getHandle() {
28342830
return handle;
28352831
}
28362832

2837-
public Rectangle getBounds() {
2833+
int getWidth() {
2834+
return width;
2835+
}
2836+
2837+
int getHeight() {
2838+
return height;
2839+
}
2840+
2841+
Rectangle getBounds() {
28382842
return new Rectangle(0, 0, width, height);
28392843
}
28402844

@@ -2863,14 +2867,12 @@ private void setBackground(RGB color) {
28632867
device.internal_dispose_GC(hDC, null);
28642868
}
28652869

2866-
private void updateBoundsInPixelsFromNative() {
2870+
private Point getBoundsInPixelsFromNative() {
28672871
switch (type) {
28682872
case SWT.BITMAP:
28692873
BITMAP bm = new BITMAP();
28702874
OS.GetObject(handle, BITMAP.sizeof, bm);
2871-
width = bm.bmWidth;
2872-
height = bm.bmHeight;
2873-
return;
2875+
return new Point(bm.bmWidth, bm.bmHeight);
28742876
case SWT.ICON:
28752877
ICONINFO info = new ICONINFO();
28762878
OS.GetIconInfo(handle, info);
@@ -2881,11 +2883,10 @@ private void updateBoundsInPixelsFromNative() {
28812883
if (hBitmap == info.hbmMask) bm.bmHeight /= 2;
28822884
if (info.hbmColor != 0) OS.DeleteObject(info.hbmColor);
28832885
if (info.hbmMask != 0) OS.DeleteObject(info.hbmMask);
2884-
width = bm.bmWidth;
2885-
height = bm.bmHeight;
2886-
return;
2886+
return new Point(bm.bmWidth, bm.bmHeight);
28872887
default:
28882888
SWT.error(SWT.ERROR_INVALID_IMAGE);
2889+
return null;
28892890
}
28902891
}
28912892

0 commit comments

Comments
 (0)