Skip to content

Commit 83b9fee

Browse files
HeikoKlareakurtakov
authored andcommitted
[GTK] Simplify logic for refreshing images on zoom change
The implementation for refreshing images on zoom change repeatedly checks the same conditions and sets the same values. This change replaces these repetitions with an early return and a unified post-processing.
1 parent b278afe commit 83b9fee

File tree

1 file changed

+17
-35
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics

1 file changed

+17
-35
lines changed

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

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -726,51 +726,33 @@ public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height)
726726
*
727727
* @noreference This function is not intended to be referenced by clients.
728728
*/
729-
public boolean internal_gtk_refreshImageForZoom() {
730-
return refreshImageForZoom();
729+
public void internal_gtk_refreshImageForZoom() {
730+
refreshImageForZoom();
731731
}
732732

733733
/**
734734
* Refresh the Image based on the zoom level, if required.
735-
*
736-
* @return true if image is refreshed
737735
*/
738-
boolean refreshImageForZoom () {
739-
boolean refreshed = false;
736+
void refreshImageForZoom () {
740737
int deviceZoom = DPIUtil.getDeviceZoom();
738+
if (deviceZoom == currentDeviceZoom) {
739+
return;
740+
}
741741
if (imageFileNameProvider != null) {
742-
int deviceZoomLevel = deviceZoom;
743-
if (deviceZoomLevel != currentDeviceZoom) {
744-
/* Release current native resources */
745-
destroy ();
746-
initFromFileNameProvider(deviceZoomLevel);
747-
init ();
748-
refreshed = true;
749-
currentDeviceZoom = deviceZoomLevel;
750-
}
742+
reinitializeImage(deviceZoom, zoom -> initFromFileNameProvider(zoom));
751743
} else if (imageDataProvider != null) {
752-
int deviceZoomLevel = deviceZoom;
753-
if (deviceZoomLevel != currentDeviceZoom) {
754-
/* Release current native resources */
755-
destroy ();
756-
initFromImageDataProvider(deviceZoomLevel);
757-
init();
758-
refreshed = true;
759-
currentDeviceZoom = deviceZoomLevel;
760-
}
744+
reinitializeImage(deviceZoom, zoom -> initFromImageDataProvider(zoom));
761745
} else if (imageGcDrawer != null) {
762-
int deviceZoomLevel = deviceZoom;
763-
if (deviceZoomLevel != currentDeviceZoom) {
764-
ImageData data = drawWithImageGcDrawer(width, height, deviceZoomLevel);
765-
/* Release current native resources */
766-
destroy ();
767-
init(data);
768-
init();
769-
refreshed = true;
770-
currentDeviceZoom = deviceZoomLevel;
771-
}
746+
reinitializeImage(deviceZoom, zoom -> init(drawWithImageGcDrawer(width, height, zoom)));
772747
}
773-
return refreshed;
748+
}
749+
750+
private void reinitializeImage(int zoom, IntConsumer initializerForZoom) {
751+
/* Release current native resources */
752+
destroy ();
753+
initializerForZoom.accept(zoom);
754+
init();
755+
currentDeviceZoom = zoom;
774756
}
775757

776758
void initNative(String filename) {

0 commit comments

Comments
 (0)