@@ -98,6 +98,11 @@ public final class Image extends Resource implements Drawable {
98
98
*/
99
99
private boolean isInitialized ;
100
100
101
+ /**
102
+ * this field is used to mark destroyed images
103
+ */
104
+ private boolean isDestroyed ;
105
+
101
106
/**
102
107
* specifies the transparent pixel
103
108
*/
@@ -521,7 +526,7 @@ public Image (Device device, String filename) {
521
526
}
522
527
return null ;
523
528
});
524
- if (imageProvider .getImageData (100 ) == null ) {
529
+ if (imageProvider .newImageData (100 ) == null ) {
525
530
SWT .error (SWT .ERROR_INVALID_ARGUMENT , null ,
526
531
": [" + filename + "] returns null ImageData at 100% zoom." );
527
532
}
@@ -562,7 +567,7 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
562
567
super (device );
563
568
this .imageProvider = new ImageFileNameProviderWrapper (imageFileNameProvider );
564
569
initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
565
- if (imageProvider .getImageData (100 ) == null ) {
570
+ if (imageProvider .newImageData (100 ) == null ) {
566
571
SWT .error (SWT .ERROR_INVALID_ARGUMENT , null ,
567
572
": ImageFileNameProvider [" + imageFileNameProvider + "] returns null ImageData at 100% zoom." );
568
573
}
@@ -1003,7 +1008,7 @@ public static void drawScaled(GC gc, Image original, int width, int height, floa
1003
1008
void destroy () {
1004
1009
device .deregisterResourceWithZoomSupport (this );
1005
1010
if (memGC != null ) memGC .dispose ();
1006
- this .imageProvider . destroy () ;
1011
+ this .isDestroyed = true ;
1007
1012
destroyHandle ();
1008
1013
memGC = null ;
1009
1014
}
@@ -1229,7 +1234,10 @@ public ImageData getImageData() {
1229
1234
*/
1230
1235
public ImageData getImageData (int zoom ) {
1231
1236
if (isDisposed ()) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
1232
- return imageProvider .getImageData (zoom );
1237
+ if (zoomLevelToImageHandle .containsKey (zoom )) {
1238
+ return zoomLevelToImageHandle .get (zoom ).getImageData ();
1239
+ }
1240
+ return this .imageProvider .newImageData (zoom );
1233
1241
}
1234
1242
1235
1243
@@ -1766,7 +1774,7 @@ public void internal_dispose_GC (long hDC, GCData data) {
1766
1774
*/
1767
1775
@ Override
1768
1776
public boolean isDisposed () {
1769
- return this . imageProvider . isDisposed () ;
1777
+ return ! isInitialized || isDestroyed ;
1770
1778
}
1771
1779
1772
1780
/**
@@ -1850,17 +1858,9 @@ public static Image win32_new(Device device, int type, long handle, int nativeZo
1850
1858
}
1851
1859
1852
1860
private abstract class AbstractImageProviderWrapper {
1853
- private boolean isDestroyed ;
1854
1861
1855
1862
protected abstract Rectangle getBounds (int zoom );
1856
1863
1857
- protected final ImageData getImageData (int zoom ) {
1858
- if (zoomLevelToImageHandle .containsKey (zoom )) {
1859
- return zoomLevelToImageHandle .get (zoom ).getImageData ();
1860
- }
1861
- return newImageData (zoom );
1862
- }
1863
-
1864
1864
abstract ImageData newImageData (int zoom );
1865
1865
1866
1866
abstract AbstractImageProviderWrapper createCopy (Image image );
@@ -1892,14 +1892,6 @@ protected final ImageHandle newImageHandle(ImageData data, int zoom) {
1892
1892
return init (data , zoom );
1893
1893
}
1894
1894
}
1895
-
1896
- protected boolean isDisposed () {
1897
- return !isInitialized || isDestroyed ;
1898
- }
1899
-
1900
- protected void destroy () {
1901
- this .isDestroyed = true ;
1902
- }
1903
1895
}
1904
1896
1905
1897
private class ExistingImageHandleProviderWrapper extends AbstractImageProviderWrapper {
0 commit comments