-
Notifications
You must be signed in to change notification settings - Fork 186
Fix cursor loading incorrect image size when ImageData is unavailable at requested zoom #2317
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
Fix cursor loading incorrect image size when ImageData is unavailable at requested zoom #2317
Conversation
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
f62bc87 to
e2e3d9b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems to work around an issue that comes from the wrong usage of DPIUtil::validateAndGetImageDataAtZoom by avoiding to call that method. Hence these questions:
- Would it be possible/worth it to fix the error inside the method instead?
- If the previous is not possible, shouldn't you also hide the method to avoid future errors like the one this PR tries to solve? You could simply move the method to the class where it is still used (there is only 1 left) and make it private.
- There is also the method
DPIUtil::validateAndGetImagePathAtZoom. Does it suffer from the same bug/issue (if yes, address it in a separate issue/PR)
The method currently behaves as described in its Javadoc: Given this, it seems the method is functioning as intended, no internal fix appears necessary for the method.
There are currently two usages of this method one in the GTK image class and another in the Windows image class. Moving the method to one of those classes and making it private would result in code duplication.
Same responses as above for this method as well. |
|
Good points, it seems the method does what it is supposed to (however inconvenient) and GTK compensates for that by resizing the data if necessary: eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java Lines 797 to 798 in 216f1ad
Would that be an option too in this PR? It would save us from creating and disposing an image. |
I think there is a misunderstanding here: the
You could do that, but why? The |
|
Thank you for the clarification. I assumed that creating an image to immediately dispose it would be wasteful but I agree that it is better than to rely in outdated code to do the resizing. That is a trade-off I can live with 👍 |
fedejeanne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after the clarification. @amartya4256 / @HeikoKlare any final thoughts? Shall we merge?
Previously, the cursor used DPIUtil.validateAndGetImageDataAtZoom() to retrieve image data, which may return Imagedata at a different zoom level than requested if ImageData for the exact zoom is unavailable. This led to incorrect scaling when the returned image data was treated as if it matched the requested zoom. This commit replaces that logic with a temporary Image and calling Image.getImageData(zoom) to retrieve image data for the requested zoom level.
e2e3d9b to
8776994
Compare
Description
Before this change, the cursor used DPIUtil.validateAndGetImageDataAtZoom() to get image data. However, this method could return image data at a different zoom level if the exact match wasn't available from the ImageDataProvider. As a result, the cursor could be scaled incorrectly, since the returned image data was assumed to match the requested zoom.
With this change, a temporary Image is created, and Image.getImageData(zoom) is called to get properly scaled image data for the requested zoom level.
Steps to reproduce:
Run the below snippet at 150% monitor zoom. The ImageDataProvider in the snippet returns image data only for zoom levels 100 and 200.
Without this change
When run without any
swt.autoScaleVM argument, the cursor size was incorrectly scaled to 60×60.When run with
-Dswt.autoScale=quarter, the cursor is 30x30.With this current fix applied
The cursor is now correctly sized (e.g., 45×45 at 150% zoom).
Note : This snippet is adapted from [issue #2057](#2057 (comment) to get the scales