Skip to content

Commit cc9165f

Browse files
Image.getHandle(): return ImageHandle instead of long
every image handle holds more than just the handle value and can be required by the caller to determine the characteristics of an Image.
1 parent d884e6b commit cc9165f

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.stream.*;
2121

2222
import org.eclipse.swt.*;
23+
import org.eclipse.swt.graphics.Image.*;
2324
import org.eclipse.swt.internal.*;
2425
import org.eclipse.swt.internal.gdip.*;
2526
import org.eclipse.swt.internal.win32.*;
@@ -1061,7 +1062,7 @@ void apply() {
10611062

10621063
private void drawImageInPixels(Image image, Point location) {
10631064
if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
1064-
long handle = Image.win32_getHandle(image, getZoom());
1065+
ImageHandle handle = image.getHandle(getZoom(), getZoom());
10651066
drawImage(image, 0, 0, -1, -1, location.x, location.y, -1, -1, true, handle);
10661067
}
10671068
}
@@ -1277,12 +1278,12 @@ private class DrawImageToImageOperation extends ImageOperation {
12771278

12781279
@Override
12791280
void apply() {
1280-
long handle = Image.win32_getHandle(getImage(), getZoom());
1281+
ImageHandle handle = getImage().getHandle(getZoom(), getZoom());
12811282
drawImage(getImage(), source.x, source.y, source.width, source.height, destination.x, destination.y, destination.width, destination.height, simple, handle);
12821283
}
12831284
}
12841285

1285-
private void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, long tempImageHandle) {
1286+
private void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, ImageHandle tempImageHandle) {
12861287
if (data.gdipGraphics != 0) {
12871288
//TODO - cache bitmap
12881289
long [] gdipImage = srcImage.createGdipImageFromHandle(tempImageHandle);
@@ -1350,7 +1351,7 @@ private void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int src
13501351
simple);
13511352
break;
13521353
case SWT.ICON:
1353-
drawIcon(tempImageHandle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
1354+
drawIcon(tempImageHandle.handle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
13541355
break;
13551356
}
13561357
}
@@ -1489,9 +1490,10 @@ private void drawIcon(long imageHandle, int srcX, int srcY, int srcWidth, int sr
14891490
if (failed) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
14901491
}
14911492

1492-
private void drawBitmap(Image srcImage, long imageHandle, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
1493+
private void drawBitmap(Image srcImage, ImageHandle imageHandle, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
14931494
BITMAP bm = new BITMAP();
1494-
OS.GetObject(imageHandle, BITMAP.sizeof, bm);
1495+
long handle = imageHandle.handle;
1496+
OS.GetObject(handle, BITMAP.sizeof, bm);
14951497
int imgWidth = bm.bmWidth;
14961498
int imgHeight = bm.bmHeight;
14971499
if (srcWidth == 0 && srcHeight == 0) {
@@ -1523,14 +1525,14 @@ private void drawBitmap(Image srcImage, long imageHandle, int srcX, int srcY, in
15231525
boolean isDib = bm.bmBits != 0;
15241526
int depth = bm.bmPlanes * bm.bmBitsPixel;
15251527
if (isDib && depth == 32) {
1526-
drawBitmapAlpha(imageHandle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
1528+
drawBitmapAlpha(handle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
15271529
} else if (srcImage.transparentPixel != -1) {
15281530
drawBitmapTransparent(srcImage, imageHandle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);
15291531
} else {
1530-
drawBitmapColor(imageHandle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
1532+
drawBitmapColor(handle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
15311533
}
15321534
if (mustRestore) {
1533-
long hOldBitmap = OS.SelectObject(memGC.handle, imageHandle);
1535+
long hOldBitmap = OS.SelectObject(memGC.handle, handle);
15341536
memGC.data.hNullBitmap = hOldBitmap;
15351537
}
15361538
}
@@ -1785,11 +1787,11 @@ private void drawBitmapMask(long srcColor, long srcMask, int srcX, int srcY, int
17851787
OS.DeleteDC(srcHdc);
17861788
}
17871789

1788-
private void drawBitmapTransparent(Image srcImage, long imageHandle, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, BITMAP bm, int imgWidth, int imgHeight) {
1790+
private void drawBitmapTransparent(Image srcImage, ImageHandle imageHandle, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, BITMAP bm, int imgWidth, int imgHeight) {
17891791

17901792
/* Find the RGB values for the transparent pixel. */
17911793
boolean isDib = bm.bmBits != 0;
1792-
long hBitmap = imageHandle;
1794+
long hBitmap = imageHandle.handle;
17931795
long srcHdc = OS.CreateCompatibleDC(handle);
17941796
long oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap);
17951797
byte[] originalColors = null;
@@ -1834,7 +1836,7 @@ private void drawBitmapTransparent(Image srcImage, long imageHandle, int srcX, i
18341836
bmiHeader.biBitCount = bm.bmBitsPixel;
18351837
byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4];
18361838
OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
1837-
OS.GetDIBits(srcHdc, imageHandle, 0, 0, null, bmi, OS.DIB_RGB_COLORS);
1839+
OS.GetDIBits(srcHdc, imageHandle.handle, 0, 0, null, bmi, OS.DIB_RGB_COLORS);
18381840
int offset = BITMAPINFOHEADER.sizeof + 4 * srcImage.transparentPixel;
18391841
transRed = bmi[offset + 2] & 0xFF;
18401842
transGreen = bmi[offset + 1] & 0xFF;
@@ -1907,7 +1909,7 @@ private void drawBitmapTransparent(Image srcImage, long imageHandle, int srcX, i
19071909
OS.DeleteObject(maskBitmap);
19081910
}
19091911
OS.SelectObject(srcHdc, oldSrcBitmap);
1910-
if (hBitmap != imageHandle) OS.DeleteObject(hBitmap);
1912+
if (hBitmap != imageHandle.handle) OS.DeleteObject(hBitmap);
19111913
OS.DeleteDC(srcHdc);
19121914
}
19131915

@@ -4483,7 +4485,7 @@ private void init(Drawable drawable, GCData data, long hDC) {
44834485
}
44844486
Image image = data.image;
44854487
if (image != null) {
4486-
data.hNullBitmap = OS.SelectObject(hDC, image.getHandle(data.imageZoom, data.nativeZoom));
4488+
data.hNullBitmap = OS.SelectObject(hDC, image.getHandle(data.imageZoom, data.nativeZoom).handle);
44874489
image.memGC = this;
44884490
}
44894491
int layout = data.layout;

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,8 @@ public boolean isReusable(int height, int width) {
158158

159159
}
160160

161-
public long getHandle() {
162-
if (handleContainer != null) {
163-
return handleContainer.handle;
164-
}
165-
return -1;
161+
public ImageHandle getHandle() {
162+
return handleContainer;
166163
}
167164
};
168165

@@ -837,20 +834,20 @@ private ImageHandle getImageMetadata(ZoomContext zoomContext) {
837834
* @noreference This method is not intended to be referenced by clients.
838835
*/
839836
public static long win32_getHandle (Image image, int zoom) {
840-
return image.getHandle(zoom, zoom);
837+
return image.getHandle(zoom, zoom).handle;
841838
}
842839

843-
long getHandle (int targetZoom, int nativeZoom) {
840+
ImageHandle getHandle (int targetZoom, int nativeZoom) {
844841
if (isDisposed()) {
845-
return 0L;
842+
return null;
846843
}
847844
ZoomContext zoomContext = imageProvider.getFittingZoomContext(targetZoom, nativeZoom);
848-
return getImageMetadata(zoomContext).handle;
845+
return getImageMetadata(zoomContext);
849846
}
850847

851848
@FunctionalInterface
852849
interface HandleAtSizeConsumer {
853-
void accept(long imageHandle, Point handleSize);
850+
void accept(ImageHandle imageHandle, Point handleSize);
854851
}
855852

856853
void executeOnImageHandleAtSize(HandleAtSizeConsumer handleAtSizeConsumer, int widthHint, int heightHint) {
@@ -892,11 +889,12 @@ public static void drawAtSize(GC gc, ImageData imageData, int width, int height)
892889

893890

894891
long [] createGdipImage(Integer zoom) {
895-
long handle = Image.win32_getHandle(this, zoom);
892+
ImageHandle handle = this.getHandle(zoom, zoom);
896893
return createGdipImageFromHandle(handle);
897894
}
898895

899-
long[] createGdipImageFromHandle(long handle) {
896+
long[] createGdipImageFromHandle(ImageHandle imageHandle) {
897+
long handle = imageHandle.handle;
900898
switch (type) {
901899
case SWT.BITMAP: {
902900
BITMAP bm = new BITMAP();
@@ -2816,8 +2814,8 @@ public void internal_dispose_GC(long handle, GCData data) {
28162814
}
28172815
}
28182816

2819-
private class ImageHandle {
2820-
private long handle;
2817+
class ImageHandle {
2818+
long handle;
28212819
private final int zoom;
28222820
private int height;
28232821
private int width;

0 commit comments

Comments
 (0)