Skip to content

Commit f3b211c

Browse files
committed
[win32] Remove Image#initialNativeZoom
This commit removes Image#initialNativeZoom in the windows implementation. To achieve this all usages of this field are replaces by either using a concrete zoom values or by creating a temporary handle.
1 parent 004719a commit f3b211c

File tree

1 file changed

+4
-36
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+4
-36
lines changed

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

+4-36
Original file line numberDiff line numberDiff line change
@@ -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

147142
private 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
*/
191185
public 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) {
352339
public 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) {
384370
public 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) {
393378
private 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) {
498481
public 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) {
539521
public 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) {
582563
public 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) {
623603
public 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) {
653632
public 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-
855829
long [] createGdipImage(Integer zoom) {
856830
long handle = Image.win32_getHandle(this, zoom);
857831
switch (type) {
@@ -1035,9 +1009,7 @@ private void destroyHandles() {
10351009

10361010
@Override
10371011
void destroyHandlesExcept(Set<Integer> zoomLevels) {
1038-
destroyHandles(zoom -> {
1039-
return !zoomLevels.contains(zoom) && zoom != DPIUtil.getZoomForAutoscaleProperty(initialNativeZoom);
1040-
});
1012+
destroyHandles(zoom -> !zoomLevels.contains(zoom));
10411013
}
10421014

10431015
private 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.
@@ -2278,7 +2247,7 @@ protected ElementAtZoom<ImageData> loadImageData(int zoom) {
22782247

22792248
@Override
22802249
public int hashCode() {
2281-
return Objects.hash(provider, styleFlag, transparentPixel, getZoom());
2250+
return Objects.hash(provider, styleFlag, transparentPixel);
22822251
}
22832252

22842253
@Override
@@ -2521,7 +2490,6 @@ ImageData newImageData(int zoom) {
25212490

25222491
@Override
25232492
protected ImageHandle newImageHandle(int zoom) {
2524-
initialNativeZoom = zoom;
25252493
int gcStyle = drawer.getGcStyle();
25262494
Image image;
25272495
if ((gcStyle & SWT.TRANSPARENT) != 0) {
@@ -2532,7 +2500,7 @@ protected ImageHandle newImageHandle(int zoom) {
25322500
resultData.alphaData = new byte [scaledWidth * scaledHeight];
25332501
image = new Image(device, resultData, zoom);
25342502
} else {
2535-
image = new Image(device, width, height, zoom);
2503+
image = new Image(device, width, height);
25362504
}
25372505
GC gc = new GC(new DrawableWrapper(image, zoom), gcStyle);
25382506
try {

0 commit comments

Comments
 (0)