Skip to content

Commit 361644c

Browse files
committed
[Win32] Avoid unnecessary handle creation for image of ImageGcDrawer
With an Image based on an ImageGcDrawer, a call to #getImageData() will always create a handle for the requested zoom. For all other kinds of images, this will at most create a temporary handle and only cache the image data to avoid unnecessary handles for zooms you may never need. This change adapts the ImageGcDrawerWrapper implementation to not create a handle when requesting image data for a zoom for which no handle exists yet.
1 parent f7fb840 commit 361644c

File tree

1 file changed

+8
-5
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,11 +2789,10 @@ ImageData newImageData(int zoom) {
27892789

27902790
@Override
27912791
protected ElementAtZoom<ImageData> loadImageData(int zoom) {
2792-
return new ElementAtZoom<>(getImageMetadata(new ZoomContext(zoom)).getImageData(), zoom);
2792+
return new ElementAtZoom<>(loadImageData(new ZoomContext(zoom)), zoom);
27932793
}
27942794

2795-
@Override
2796-
protected DestroyableImageHandle newImageHandle(ZoomContext zoomContext) {
2795+
private ImageData loadImageData(ZoomContext zoomContext) {
27972796
currentZoom = zoomContext;
27982797
int targetZoom = zoomContext.targetZoom();
27992798
int gcStyle = drawer.getGcStyle();
@@ -2813,14 +2812,18 @@ protected DestroyableImageHandle newImageHandle(ZoomContext zoomContext) {
28132812
drawer.drawOn(gc, width, height);
28142813
ImageData imageData = image.getImageData(targetZoom);
28152814
drawer.postProcess(imageData);
2816-
ImageData newData = adaptImageDataIfDisabledOrGray(imageData);
2817-
return init(newData, targetZoom);
2815+
return adaptImageDataIfDisabledOrGray(imageData);
28182816
} finally {
28192817
gc.dispose();
28202818
image.dispose();
28212819
}
28222820
}
28232821

2822+
@Override
2823+
protected DestroyableImageHandle newImageHandle(ZoomContext zoomContext) {
2824+
return init(loadImageData(zoomContext), zoomContext.targetZoom);
2825+
}
2826+
28242827
@Override
28252828
Object getProvider() {
28262829
return drawer;

0 commit comments

Comments
 (0)