Skip to content

[win32] Move of unified code from Wrapper to Image #2069

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

Merged

Conversation

akoch-yatta
Copy link
Contributor

This PR is a simple refactoring and just moves the code that is equal to all AbstractImageProviderWrapper implementations back to Image.

@akoch-yatta akoch-yatta force-pushed the win32-move-image-getimagedata branch from aad5ca0 to 31730f4 Compare April 27, 2025 11:28
Copy link
Contributor

github-actions bot commented Apr 27, 2025

Test Results

   545 files  ±0     545 suites  ±0   28m 36s ⏱️ -32s
 4 374 tests ±0   4 356 ✅ ±0   18 💤 ±0  0 ❌ ±0 
16 638 runs  ±0  16 498 ✅ ±0  140 💤 ±0  0 ❌ ±0 

Results for commit 7d05313. ± Comparison against base commit 4bafcb3.

♻️ 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.

The change looks generally good to me. I Just found two issues not directly related to the refactoring. I propose to maybe fix them in a separate PR (to make clear that that's a behavioral fix compared to this refactoring) to be merged before this one?

@@ -562,7 +567,7 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
super(device);
this.imageProvider = new ImageFileNameProviderWrapper(imageFileNameProvider);
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
if (imageProvider.getImageData(100) == null) {
if (imageProvider.newImageData(100) == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if we could avoid/improve this, as it's quite some potentially unnecessary effort to load image data at 100% if they are never used. Then I saw that the documentation says:

ERROR_INVALID_ARGUMENT - if the fileName provided by ImageFileNameProvider is null at 100% zoom

So the current implementation is even wrong: it should not be tested if image data at 100% can be loaded but if the passed imageFileNameProvider returns a non-null value at 100%.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem are the other exceptions mentioned:

 *    <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li>
 *    <li>ERROR_UNSUPPORTED_DEPTH - if the image file describes an image with an unsupported depth</li>
 *    <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>

Those will only be detected if the ImageData is loaded once. If we remove that call here it would fail later, which would change the behavior

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Since we are now caching the already loaded image data, it might make sense to then not use zoom 100 here but instead retrieve some data that we will likely use?

Still, in my opinion we throw the mentioned exception in the wrong case: it should not be thrown when no image data can be generated but when the fileName provided by the file name provider at 100% is null. But maybe that just happens in the same situations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, now I fully get, what you mean. I just took a short look into the history. Before we only used getImageMetadata that seemed to trigger the exceptions, we could probably do a newImageHandle + immediatly destroy if afterwards. I will try to have a look tomorrow.

@@ -521,7 +526,7 @@ public Image (Device device, String filename) {
}
return null;
});
if (imageProvider.getImageData(100) == null) {
if (imageProvider.newImageData(100) == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I just saw that there is no documentation about this kind of check and it's also not present in the other OS implementations. So probably we should just remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above implicitly checking other exception mentioned in the javadoc, e.g.

* <li>ERROR_IO - if an IO error occurs while reading from the file</li>

Copy link
Contributor

Choose a reason for hiding this comment

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

But like above: the exception we throw does not seem to be documented. So I guess it would be more correct to just call imageProvider.newImageData() without throwing a exception if the result is null?

This commit moves the code that is equal to all AbstractImageProviderWrapper
implementations back to Image.
@akoch-yatta akoch-yatta force-pushed the win32-move-image-getimagedata branch from 31730f4 to 7d05313 Compare April 29, 2025 09:05
@HeikoKlare
Copy link
Contributor

HeikoKlare commented Apr 29, 2025

Everything related to the above discussion has been extracted into #2070, so this is fine now.

Failing version increment check is due to infrastructure issues and no version increment is required here.

@HeikoKlare HeikoKlare merged commit c76cd99 into eclipse-platform:master Apr 29, 2025
9 of 10 checks passed
@HeikoKlare HeikoKlare deleted the win32-move-image-getimagedata branch April 29, 2025 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants