Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,23 @@ void apply() {
}

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) {
if (data.gdipGraphics != 0) {
//TODO - cache bitmap
long [] gdipImage = srcImage.createGdipImageFromHandle(tempImageHandle);
long img = gdipImage[0];
if (data.gdipGraphics == 0) {
switch (srcImage.type) {
case SWT.BITMAP:
drawBitmap(srcImage, tempImageHandle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight,
simple);
break;
case SWT.ICON:
drawIcon(tempImageHandle.handle(), srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
break;
}
return;
}

//TODO - cache bitmap
Image.GdipImage gdipImage = srcImage.createGdipImageFromHandle(tempImageHandle);
try {
long img = gdipImage.bitmap();
int imgWidth = Gdip.Image_GetWidth(img);
int imgHeight = Gdip.Image_GetHeight(img);

Expand Down Expand Up @@ -1380,21 +1393,8 @@ private void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int src
Gdip.Graphics_Restore(data.gdipGraphics, gstate);
}
Gdip.ImageAttributes_delete(attrib);
Gdip.Bitmap_delete(img);
if (gdipImage[1] != 0) {
long hHeap = OS.GetProcessHeap ();
OS.HeapFree(hHeap, 0, gdipImage[1]);
}
return;
}
switch (srcImage.type) {
case SWT.BITMAP:
drawBitmap(srcImage, tempImageHandle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight,
simple);
break;
case SWT.ICON:
drawIcon(tempImageHandle.handle(), srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
break;
} finally {
gdipImage.destroy();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,15 +969,22 @@ public static void drawAtSize(GC gc, ImageData imageData, int width, int height)
imageToDraw.dispose();
});
}
record GdipImage(long bitmap, long pixels) {
void destroy() {
Gdip.Bitmap_delete(bitmap);
if (pixels != 0) {
long hHeap = OS.GetProcessHeap();
OS.HeapFree(hHeap, 0, pixels);
}
}
}



long [] createGdipImage(Integer zoom) {
GdipImage createGdipImage(Integer zoom) {
ImageHandle handle = this.getHandle(zoom, zoom);
return createGdipImageFromHandle(handle);
}

long[] createGdipImageFromHandle(ImageHandle imageHandle) {
GdipImage createGdipImageFromHandle(ImageHandle imageHandle) {
long handle = imageHandle.handle();
int transparentPixel = imageHandle.transparentPixel();
switch (type) {
Expand Down Expand Up @@ -1071,9 +1078,9 @@ long[] createGdipImageFromHandle(ImageHandle imageHandle) {
OS.DeleteObject(memHdc);
OS.DeleteObject(memDib);
int pixelFormat = hasAlpha ? Gdip.PixelFormat32bppPARGB : Gdip.PixelFormat32bppARGB;
return new long []{Gdip.Bitmap_new(imgWidth, imgHeight, dibBM.bmWidthBytes, pixelFormat, pixels), pixels};
return new GdipImage(Gdip.Bitmap_new(imgWidth, imgHeight, dibBM.bmWidthBytes, pixelFormat, pixels), pixels);
}
return new long []{Gdip.Bitmap_new(handle, 0), 0};
return new GdipImage(Gdip.Bitmap_new(handle, 0), 0);
}
case SWT.ICON: {
/*
Expand Down Expand Up @@ -1139,7 +1146,7 @@ long[] createGdipImageFromHandle(ImageHandle imageHandle) {
}
if (iconInfo.hbmColor != 0) OS.DeleteObject(iconInfo.hbmColor);
if (iconInfo.hbmMask != 0) OS.DeleteObject(iconInfo.hbmMask);
return new long []{img, pixels};
return new GdipImage(img, pixels);
}
default: SWT.error(SWT.ERROR_INVALID_IMAGE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.swt.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gdip.*;
import org.eclipse.swt.internal.win32.*;

/**
* Instances of this class represent patterns to use while drawing. Patterns
Expand Down Expand Up @@ -300,7 +299,7 @@ long createHandle(int zoom) {
}

private class ImagePatternHandle extends PatternHandle {
private long[] gdipImage;
private Image.GdipImage gdipImage;

public ImagePatternHandle(int zoom) {
super(zoom);
Expand All @@ -309,7 +308,7 @@ public ImagePatternHandle(int zoom) {
@Override
long createHandle(int zoom) {
gdipImage = image.createGdipImage(zoom);
long img = gdipImage[0];
long img = gdipImage.bitmap();
int width = Gdip.Image_GetWidth(img);
int height = Gdip.Image_GetHeight(img);
long handle = Gdip.TextureBrush_new(img, Gdip.WrapModeTile, 0, 0, width, height);
Expand All @@ -327,13 +326,10 @@ protected void destroy() {
}

private void cleanupBitmap() {
if (gdipImage.length < 2) return;
long img = gdipImage[0];
Gdip.Bitmap_delete(img);
if (gdipImage[1] != 0) {
long hHeap = OS.GetProcessHeap ();
OS.HeapFree(hHeap, 0, gdipImage[1]);
}
if (gdipImage == null) return;
Image.GdipImage tempGdipImage = gdipImage;
gdipImage = null;
tempGdipImage.destroy();
}
}

Expand Down
Loading