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

[win32] Create image handles on demand for width/height based constructors #1884

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

akoch-yatta
Copy link
Contributor

This PR refactors the Image constructor using width and height to create a bitmap to create the handles always on demand instead of creating its first handle in the constructor.

Copy link
Contributor

github-actions bot commented Mar 7, 2025

Test Results

   510 files  ±0     510 suites  ±0   10m 3s ⏱️ + 1m 37s
 4 345 tests ±0   4 331 ✅ ±0   14 💤 ±0  0 ❌ ±0 
16 613 runs  ±0  16 502 ✅ ±0  111 💤 ±0  0 ❌ ±0 

Results for commit 95cec51. ± Comparison against base commit 8f3fd02.

♻️ This comment has been updated with latest results.

@akoch-yatta akoch-yatta force-pushed the refactor-image-branch branch from 5eeb513 to 5eba21f Compare March 7, 2025 08:04
@akoch-yatta akoch-yatta marked this pull request as draft March 7, 2025 10:49
@akoch-yatta akoch-yatta force-pushed the refactor-image-branch branch 2 times, most recently from f8377ad to eae19e4 Compare March 10, 2025 07:42
@akoch-yatta akoch-yatta marked this pull request as ready for review March 10, 2025 07:55
@akoch-yatta akoch-yatta force-pushed the refactor-image-branch branch from eae19e4 to dd9b823 Compare March 10, 2025 11:16
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 have initial questions regarding the overall design, including duplication of logic and the proper usage of memGC.

@@ -330,8 +327,7 @@ public Image(Device device, Rectangle bounds) {
super(device);
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
bounds = DPIUtil.scaleUp (bounds, getZoom());
init(bounds.width, bounds.height);
this.imageProvider = new PlainImageProviderWrapper(bounds.width, bounds.height);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a (very low) risk that this leads to a change in behavior for consumers: when passing bounds with non-zero x/y, the DPIUtil.scaleUp for the bounds may produce a different result regarding width/height than when executing it with x=y=0. I guess we can accept that but given the fact that some of the bounds' values are not used anyway, this constructor is quite misleading. Should we directly deprecate it (and replace its known usages), either as preparatory PR or directly after?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree. But we have that already on the roadmap vi-eclipse/Eclipse-Platform#203

Comment on lines 2084 to 2086
if (memGC != null) {
return getImageDataAtCurrentZoom();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this wrong now? The image handle used by the GC is not created for the Image's initialNativeZoom anymore (for which this method call returns the according image data), but for the zoom used for the GC. Thus we have to use that specific image data, don't we? In addition, can't we keep the memGC handling at a central place? This is now duplicated code and comment, once in the getImageData(int) implementation of Image and once here. Same applies to the rest of the method code. Shouldn't that be put at some central place for all "static images" until all of them are refactored to use an ImageProvider implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't it the same behavior as before? getImageDataAtCurrentZoom calls getImageMetadata(getZoom()).getImageData() which uses initialNativeZoom
I agree to the duplication. Then I'll create a temporary method in Image that is used from both places

This commit refactors the Image constructor using width and height to
create a bitmap to create handles on demand instead of creating a first
handle in the constructor.
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.

Extract width/height based image into additional AbstractImageProviderWrapper to create handles on demand
3 participants