Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image type SWT.ICON loses its type during re-scale #1790

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Feb 3, 2025

Image initialized as SWT.ICON in org.eclipse.swt.graphics.Image.Image(Device, ImageData, ImageData) loses its "Icon" properties, i.e. type, mask etc., when handle for different zoom level is requested. This change adapts the initialization of the image when the handle is requested for image type SWT.ICON to preserve the properties. The unit test is added that was failing before the fix. You can also see it in action in the snippet provided below:

Display display = new Display();
Shell shell = new Shell(display);

InputStream stream = ShellImageExample.class.getResourceAsStream("yourImage.png");
ImageData imageData = new ImageData(stream);
ImageData mask = imageData.getTransparencyMask();
Image icon = new Image(display, imageData, mask);
System.out.println("Icon Type = " + icon.type);
Image.win32_getHandle(icon, 200);
System.out.println("Icon Type After = " + icon.type);

Fixes #1805

@ShahzaibIbrahim ShahzaibIbrahim linked an issue Feb 3, 2025 that may be closed by this pull request
Copy link
Contributor

github-actions bot commented Feb 3, 2025

Test Results

   502 files  +8     502 suites  +8   11m 16s ⏱️ + 1m 15s
 4 334 tests +1   4 320 ✅ +1   14 💤 ±0  0 ❌ ±0 
16 575 runs  +1  16 466 ✅ +1  109 💤 ±0  0 ❌ ±0 

Results for commit 2630103. ± Comparison against base commit e2ae17b.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not completely understand the change. The assumption that an image with type SWT.ICON loses it's type when rescaling does not seem to be always true. The following snippet succeeds, even without this change:

		Image image = Display.getCurrent().getSystemImage(SWT.ICON_ERROR);
		assertEquals("Image type should stay to SWT.ICON", SWT.ICON, image.type);
		Image.win32_getHandle(image, 200);
		assertEquals("Image type should stay to SWT.ICON", SWT.ICON, image.type);

So the issue rather seems to be about specific ways in which images of type Icon are created. Is it safe to apply this new behavior for all of them, even for those that properly worked before with the existing implementation?

@ShahzaibIbrahim
Copy link
Contributor Author

So the issue rather seems to be about specific ways in which images of type Icon are created. Is it safe to apply this new behavior for all of them, even for those that properly worked before with the existing implementation?

The test were passing without the new changes because they were running without quarter scaling. I had my configuration done with quarter scaling on. Now I have move my test to different package as other "Resources Test" with correct settings.

@HeikoKlare
Copy link
Contributor

The test were passing without the new changes because they were running without quarter scaling. I had my configuration done with quarter scaling on. Now I have move my test to different package as other "Resources Test" with correct settings.

Can you explain why running the test with quarter scaling is necessary and why moving the test to a different bundle is necessary for that?

For me, it does not make any difference whether I run the test with quarter scaling or not. I always succeeds, with the change in this PR and without.

@ShahzaibIbrahim
Copy link
Contributor Author

For me, it does not make any difference whether I run the test with quarter scaling or not. I always succeeds, with the change in this PR and without.

I am not sure why, but when we start working on it the issue was only in quarter. I can still see the test failing without quarter scaling (also updateOnRunTime should not be true)

@HeikoKlare
Copy link
Contributor

Can you please post the exact configuration to execute the test without the fix so that it fails?
I am not able to reproduce it. I used different monitor scalings, I have removed the extension for monitor-specific zoom from the test, reverted the change in Image and executed the test with and without quarter. Everytime it succeeds:
image

@akoch-yatta
Copy link
Contributor

akoch-yatta commented Feb 5, 2025

Can you please post the exact configuration to execute the test without the fix so that it fails? I am not able to reproduce it. I used different monitor scalings, I have removed the extension for monitor-specific zoom from the test, reverted the change in Image and executed the test with and without quarter. Everytime it succeeds

Is your primary monitor 200%? we probably should extend the test to explicitly request multiple zoom setting like:

	Image.win32_getHandle(icon, 200);
	assertEquals("Image type should stay to SWT.ICON", SWT.ICON, icon.type);
	Image.win32_getHandle(icon, 150);
	assertEquals("Image type should stay to SWT.ICON", SWT.ICON, icon.type);
	Image.win32_getHandle(icon, 100);
	assertEquals("Image type should stay to SWT.ICON", SWT.ICON, icon.type);

That should definitely fail

@HeikoKlare
Copy link
Contributor

I tested with primary monitor at 100%, 125% and 200%. All succeed.

Even with the previous extension, it succeeds for me.
image

Seems like I am missing some configuration, if it fails for all of you. But actually, I run the test with default configuration and on 100% (which is the configuration that should by used by any CI environment as well).

@akoch-yatta
Copy link
Contributor

akoch-yatta commented Feb 5, 2025

Hmm, very confusing. I'm pretty sure your test is not executed in monitor-specific-scaling setting.
I didn't configure anything, just executed the test via context menu.

I just tried reverting the image change and let the Github runner execute the build and I get the expected result:
image



Image initialized as SWT.ICON in Image(Device, ImageData, ImageData)
loses its "Icon" properties, i.e. type, mask etc., when a handle for a
different zoom level is requested and "SMOOTH" scaling is used. This
change adapts the initialization of the image when the handle is
requested for image type SWT.ICON to preserve the properties.

Fixes eclipse-platform#1805
Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change has the expected effect. I tested different documented scenarios and both linked issues are resolved by the change.
We will address an underlying issue (losing properties of the image such as transparency mask when autpscaling image data with "SMOOTH" mode in DPIUtil) as a follow-up

@HeikoKlare HeikoKlare merged commit 920fe85 into eclipse-platform:master Feb 5, 2025
14 checks passed
@HeikoKlare HeikoKlare deleted the bug/master-71 branch February 5, 2025 13:53
@HeikoKlare HeikoKlare linked an issue Feb 5, 2025 that may be closed by this pull request
@fedejeanne
Copy link
Contributor

Regarding the test, Shahzahib and I debugged and found the problem: he uses 150% zoom which ends up using the auto scale method SMOOTH and his test follows a different path than mine (and probably @HeikoKlare's).

So the solution would be to either change the monitor zoom in the test (probably not possible in the CI) or setting -Dswt.autoScale.method=smooth early in the test, before Display is initialized. We're looking into that.

@HeikoKlare
Copy link
Contributor

Indeed, see: vi-eclipse/Eclipse-Platform#228

That will be resolved via: vi-eclipse/Eclipse-Platform#227

And in Tycho runs, smooth scaling seems to be activated anyway, as there are tests previously executed setting the device zoom and thus enabling smooth scaling as a "side effect" (again, see vi-eclipse/Eclipse-Platform#227).

fedejeanne added a commit to vi-eclipse/eclipse.platform.swt that referenced this pull request Feb 5, 2025
Set it to "smooth" so the test works as a proper regression test.

Contributes to
eclipse-platform#1790
@fedejeanne
Copy link
Contributor

How about setting it explicitly? That way we don't need to rely on the environment and one could run the test locally too. See #1807

@HeikoKlare
Copy link
Contributor

The test either wants to test monitor-specific scaling (like suggested right now), then we need to fix how monitor-specific enables smooth scaling (see vi-eclipse/Eclipse-Platform#227) or it is supposed to test smooth scaling behavior, then the test needs to be rephrased and the existing extension regarding monitor-specific scaling needs to be removed.

fedejeanne added a commit to vi-eclipse/eclipse.platform.swt that referenced this pull request Feb 5, 2025
- Rename ImagesWin32Tests to ImageSmoothScalingWin32Tests
- Set system property "swt.autoScale.method=smooth" so the test works as
a proper regression test.

Contributes to
eclipse-platform#1790
fedejeanne added a commit to vi-eclipse/eclipse.platform.swt that referenced this pull request Feb 5, 2025
- Rename ImagesWin32Tests to ImageSmoothScalingWin32Tests
- Set system property "swt.autoScale.method=smooth" so the test works as
a proper regression test.

Contributes to
eclipse-platform#1790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants