@@ -1388,6 +1388,9 @@ public ImageData getImageData (int zoom) {
13881388 return imageHandle .getImageData ();
13891389 }
13901390
1391+ if (this .imageProvider .isPersistentImageHandleRequriedForImageData ()) {
1392+ return imageHandleManager .getOrCreate (zoom , () -> imageProvider .newImageHandle (new ZoomContext (zoom ))).getImageData ();
1393+ }
13911394 return this .imageProvider .newImageData (zoom );
13921395}
13931396
@@ -2055,6 +2058,10 @@ public Collection<Integer> getPreservedZoomLevels() {
20552058 return Collections .emptySet ();
20562059 }
20572060
2061+ protected boolean isPersistentImageHandleRequriedForImageData () {
2062+ return false ;
2063+ }
2064+
20582065 protected abstract ElementAtZoom <ImageData > loadImageData (int zoom );
20592066
20602067 abstract ImageData newImageData (int zoom );
@@ -2076,10 +2083,7 @@ protected Optional<ImageData> loadImageDataAtExactSize(int width, int height) {
20762083 return Optional .empty (); // exact size not available
20772084 }
20782085
2079- protected DestroyableImageHandle newImageHandle (ZoomContext zoomContext ) {
2080- ImageData resizedData = getImageData (zoomContext .targetZoom ());
2081- return newImageHandle (resizedData , zoomContext );
2082- }
2086+ abstract DestroyableImageHandle newImageHandle (ZoomContext zoomContext );
20832087
20842088 protected final DestroyableImageHandle newImageHandle (ImageData data , ZoomContext zoomContext ) {
20852089 if (type == SWT .ICON && data .getTransparencyType () != SWT .TRANSPARENCY_MASK ) {
@@ -2136,6 +2140,12 @@ public Collection<Integer> getPreservedZoomLevels() {
21362140 protected ElementAtZoom <ImageData > loadImageData (int zoom ) {
21372141 return getClosestAvailableImageData (zoom );
21382142 }
2143+
2144+ @ Override
2145+ protected DestroyableImageHandle newImageHandle (ZoomContext zoomContext ) {
2146+ ImageData resizedData = newImageData (zoomContext .targetZoom ());
2147+ return newImageHandle (resizedData , zoomContext );
2148+ }
21392149}
21402150
21412151private abstract class ImageFromImageDataProviderWrapper extends AbstractImageProviderWrapper {
@@ -2262,7 +2272,7 @@ protected ElementAtZoom<ImageData> loadImageData(int zoom) {
22622272
22632273 @ Override
22642274 protected Rectangle getBounds (int zoom ) {
2265- ImageData scaledImageData = getImageData (zoom );
2275+ ImageData scaledImageData = newImageData (zoom );
22662276 return new Rectangle (0 , 0 , scaledImageData .width , scaledImageData .height );
22672277 }
22682278
@@ -2319,16 +2329,19 @@ protected Rectangle getBounds(int zoom) {
23192329 return Win32DPIUtils .pointToPixel (rectangle , zoom );
23202330 }
23212331
2332+ @ Override
2333+ protected boolean isPersistentImageHandleRequriedForImageData () {
2334+ // when requesting image data for a not-yet-calculated zoom on an image
2335+ // with a GC initialized on it (memGC != null), this data must not be
2336+ // acquired by resizing from another zoom but by creating a handle for
2337+ // the zoom and making the GC reapply its operations on it. For that reason,
2338+ // this methods returns true if there is a memGC and in case there is no
2339+ // handle yet, such that a handle must be created anyway.
2340+ return imageHandleManager .isEmpty () || memGC != null ;
2341+ }
2342+
23222343 @ Override
23232344 ImageData newImageData (int zoom ) {
2324- if (imageHandleManager .isEmpty ()) {
2325- return imageHandleManager .getOrCreate (zoom , () -> createBaseHandle (zoom )).getImageData ();
2326- }
2327- // if a GC is initialized with an Image (memGC != null), the image data must not be resized, because it would
2328- // be a destructive operation. Therefor, a new handle is created for the requested zoom
2329- if (memGC != null ) {
2330- return imageHandleManager .getOrCreate (zoom , () -> newImageHandle (new ZoomContext (zoom ))).getImageData ();
2331- }
23322345 return getScaledImageData (zoom );
23332346 }
23342347
@@ -2350,7 +2363,9 @@ protected DestroyableImageHandle newImageHandle(ZoomContext zoomContext) {
23502363 currentGC .refreshFor (new DrawableWrapper (Image .this , zoomContext ), imageHandle );
23512364 return imageHandle ;
23522365 }
2353- return super .newImageHandle (zoomContext );
2366+
2367+ ImageData resizedData = newImageData (targetZoom );
2368+ return newImageHandle (resizedData , zoomContext );
23542369 }
23552370 private DestroyableImageHandle createBaseHandle (int zoom ) {
23562371 baseZoom = zoom ;
@@ -2468,7 +2483,7 @@ private DestroyableImageHandle initializeHandleFromSource(int zoom) {
24682483
24692484 @ Override
24702485 protected Rectangle getBounds (int zoom ) {
2471- ImageData imageData = getImageData (zoom );
2486+ ImageData imageData = newImageData (zoom );
24722487 return new Rectangle (0 , 0 , imageData .width , imageData .height );
24732488 }
24742489}
0 commit comments