@@ -132,11 +132,6 @@ public final class Image extends Resource implements Drawable {
132132 */
133133 private RGB backgroundColor ;
134134
135- /**
136- * Attribute to cache current native zoom level
137- */
138- private int initialNativeZoom = 100 ;
139-
140135 /**
141136 * specifies the default scanline padding
142137 */
@@ -146,7 +141,6 @@ public final class Image extends Resource implements Drawable {
146141
147142private Image (Device device , int type , long handle , int nativeZoom ) {
148143 super (device );
149- initialNativeZoom = nativeZoom ;
150144 this .type = type ;
151145 this .imageProvider = new ExistingImageHandleProviderWrapper (handle , nativeZoom );
152146 this .isInitialized = true ;
@@ -189,13 +183,7 @@ private Image (Device device, int type, long handle, int nativeZoom) {
189183 * @see #dispose()
190184 */
191185public Image (Device device , int width , int height ) {
192- this (device , width , height , DPIUtil .getNativeDeviceZoom ());
193- }
194-
195-
196- private Image (Device device , int width , int height , int nativeZoom ) {
197186 super (device );
198- this .initialNativeZoom = nativeZoom ;
199187 this .imageProvider = new PlainImageProviderWrapper (width , height );
200188 init ();
201189 this .device .registerResourceWithZoomSupport (this );
@@ -243,7 +231,6 @@ public Image(Device device, Image srcImage, int flag) {
243231 ImageHandle imageMetadata ;
244232 if (srcImage == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
245233 if (srcImage .isDisposed ()) SWT .error (SWT .ERROR_INVALID_ARGUMENT );
246- initialNativeZoom = srcImage .initialNativeZoom ;
247234 this .type = srcImage .type ;
248235 this .imageProvider = srcImage .imageProvider .createCopy (this );
249236 this .styleFlag = srcImage .styleFlag | flag ;
@@ -352,7 +339,6 @@ public Image(Device device, Image srcImage, int flag) {
352339public Image (Device device , Rectangle bounds ) {
353340 super (device );
354341 if (bounds == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
355- initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
356342 this .imageProvider = new PlainImageProviderWrapper (bounds .width , bounds .height );
357343 init ();
358344 this .device .registerResourceWithZoomSupport (this );
@@ -384,7 +370,6 @@ public Image(Device device, Rectangle bounds) {
384370public Image (Device device , ImageData data ) {
385371 super (device );
386372 if (data == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
387- initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
388373 this .imageProvider = new PlainImageDataProviderWrapper (data );
389374 init ();
390375 this .device .registerResourceWithZoomSupport (this );
@@ -393,7 +378,6 @@ public Image(Device device, ImageData data) {
393378private Image (Device device , ImageData data , int zoom ) {
394379 super (device );
395380 if (data == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
396- initialNativeZoom = zoom ;
397381 this .imageProvider = new PlainImageDataProviderWrapper (data , zoom );
398382 init ();
399383 this .device .registerResourceWithZoomSupport (this );
@@ -436,7 +420,6 @@ public Image(Device device, ImageData source, ImageData mask) {
436420 if (source .width != mask .width || source .height != mask .height ) {
437421 SWT .error (SWT .ERROR_INVALID_ARGUMENT );
438422 }
439- initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
440423 this .imageProvider = new MaskedImageDataProviderWrapper (source , mask );
441424 init ();
442425 this .device .registerResourceWithZoomSupport (this );
@@ -498,7 +481,6 @@ public Image(Device device, ImageData source, ImageData mask) {
498481public Image (Device device , InputStream stream ) {
499482 super (device );
500483 if (stream == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
501- initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
502484 this .imageProvider = new ImageDataLoaderStreamProviderWrapper (stream );
503485 init ();
504486 this .device .registerResourceWithZoomSupport (this );
@@ -539,7 +521,6 @@ public Image (Device device, InputStream stream) {
539521public Image (Device device , String filename ) {
540522 super (device );
541523 if (filename == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
542- initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
543524 this .imageProvider = new ImageFileNameProviderWrapper (zoom -> {
544525 if (zoom == 100 ) {
545526 return filename ;
@@ -582,7 +563,6 @@ public Image (Device device, String filename) {
582563public Image (Device device , ImageFileNameProvider imageFileNameProvider ) {
583564 super (device );
584565 this .imageProvider = new ImageFileNameProviderWrapper (imageFileNameProvider );
585- initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
586566 if (imageFileNameProvider .getImagePath (100 ) == null ) {
587567 SWT .error (SWT .ERROR_INVALID_ARGUMENT , null ,
588568 ": ImageFileNameProvider [" + imageFileNameProvider + "] returns null fileName at 100% zoom." );
@@ -623,7 +603,6 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
623603public Image (Device device , ImageDataProvider imageDataProvider ) {
624604 super (device );
625605 this .imageProvider = new ImageDataProviderWrapper (imageDataProvider );
626- initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
627606 if (imageDataProvider .getImageData (100 ) == null ) {
628607 SWT .error (SWT .ERROR_INVALID_ARGUMENT , null ,
629608 ": ImageDataProvider [" + imageDataProvider + "] returns null ImageData at 100% zoom." );
@@ -653,7 +632,6 @@ public Image(Device device, ImageDataProvider imageDataProvider) {
653632public Image (Device device , ImageGcDrawer imageGcDrawer , int width , int height ) {
654633 super (device );
655634 this .imageProvider = new ImageGcDrawerWrapper (imageGcDrawer , width , height );
656- initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
657635 init ();
658636}
659637
@@ -848,10 +826,6 @@ public static void drawScaled(GC gc, Image original, int width, int height, floa
848826 0 , 0 , Math .round (width * scaleFactor ), Math .round (height * scaleFactor ), false );
849827}
850828
851- long [] createGdipImage () {
852- return createGdipImage (this .getZoom ());
853- }
854-
855829long [] createGdipImage (Integer zoom ) {
856830 long handle = Image .win32_getHandle (this , zoom );
857831 switch (type ) {
@@ -1035,9 +1009,7 @@ private void destroyHandles() {
10351009
10361010@ Override
10371011void destroyHandlesExcept (Set <Integer > zoomLevels ) {
1038- destroyHandles (zoom -> {
1039- return !zoomLevels .contains (zoom ) && zoom != DPIUtil .getZoomForAutoscaleProperty (initialNativeZoom );
1040- });
1012+ destroyHandles (zoom -> !zoomLevels .contains (zoom ) || !this .imageProvider .getPreservedZoomLevels ().contains (zoom ));
10411013}
10421014
10431015private void destroyHandles (Predicate <Integer > filter ) {
@@ -1067,7 +1039,7 @@ public boolean equals (Object object) {
10671039 if (object == this ) return true ;
10681040 if (!(object instanceof Image )) return false ;
10691041 Image image = (Image ) object ;
1070- if (device != image .device || transparentPixel != image .transparentPixel || getZoom () != image . getZoom () ) return false ;
1042+ if (device != image .device || transparentPixel != image .transparentPixel ) return false ;
10711043 return (styleFlag == image .styleFlag ) && imageProvider .equals (image .imageProvider );
10721044}
10731045
@@ -1833,9 +1805,6 @@ public void setBackground(Color color) {
18331805 zoomLevelToImageHandle .values ().forEach (imageHandle -> imageHandle .setBackground (backgroundColor ));
18341806}
18351807
1836- private int getZoom () {
1837- return DPIUtil .getZoomForAutoscaleProperty (initialNativeZoom );
1838- }
18391808/**
18401809 * Returns a string containing a concise, human-readable
18411810 * description of the receiver.
@@ -1885,6 +1854,10 @@ private abstract class AbstractImageProviderWrapper {
18851854
18861855 protected abstract Rectangle getBounds (int zoom );
18871856
1857+ public Collection <Integer > getPreservedZoomLevels () {
1858+ return Collections .emptySet ();
1859+ }
1860+
18881861 abstract ImageData newImageData (int zoom );
18891862
18901863 abstract AbstractImageProviderWrapper createCopy (Image image );
@@ -2091,6 +2064,7 @@ AbstractImageProviderWrapper createCopy(Image image) {
20912064private class PlainImageProviderWrapper extends AbstractImageProviderWrapper {
20922065 private final int width ;
20932066 private final int height ;
2067+ private int baseZoom ;
20942068
20952069 PlainImageProviderWrapper (int width , int height ) {
20962070 if (width <= 0 || height <= 0 ) {
@@ -2101,6 +2075,11 @@ private class PlainImageProviderWrapper extends AbstractImageProviderWrapper {
21012075 type = SWT .BITMAP ;
21022076 }
21032077
2078+ @ Override
2079+ public Collection <Integer > getPreservedZoomLevels () {
2080+ return Collections .singleton (baseZoom );
2081+ }
2082+
21042083 @ Override
21052084 protected Rectangle getBounds (int zoom ) {
21062085 Rectangle rectangle = new Rectangle (0 , 0 , width , height );
@@ -2125,6 +2104,7 @@ protected ImageHandle newImageHandle(int zoom) {
21252104
21262105 private ImageHandle createBaseHandle (int zoom ) {
21272106 long handle = initBaseHandle (zoom );
2107+ baseZoom = zoom ;
21282108 ImageHandle imageHandle = new ImageHandle (handle , zoom );
21292109 zoomLevelToImageHandle .put (zoom , imageHandle );
21302110 return imageHandle ;
@@ -2278,7 +2258,7 @@ protected ElementAtZoom<ImageData> loadImageData(int zoom) {
22782258
22792259 @ Override
22802260 public int hashCode () {
2281- return Objects .hash (provider , styleFlag , transparentPixel , getZoom () );
2261+ return Objects .hash (provider , styleFlag , transparentPixel );
22822262 }
22832263
22842264 @ Override
@@ -2521,7 +2501,6 @@ ImageData newImageData(int zoom) {
25212501
25222502 @ Override
25232503 protected ImageHandle newImageHandle (int zoom ) {
2524- initialNativeZoom = zoom ;
25252504 int gcStyle = drawer .getGcStyle ();
25262505 Image image ;
25272506 if ((gcStyle & SWT .TRANSPARENT ) != 0 ) {
@@ -2532,7 +2511,7 @@ protected ImageHandle newImageHandle(int zoom) {
25322511 resultData .alphaData = new byte [scaledWidth * scaledHeight ];
25332512 image = new Image (device , resultData , zoom );
25342513 } else {
2535- image = new Image (device , width , height , zoom );
2514+ image = new Image (device , width , height );
25362515 }
25372516 GC gc = new GC (new DrawableWrapper (image , zoom ), gcStyle );
25382517 try {
0 commit comments