Skip to content

Conversation

@al-noori
Copy link
Contributor

@al-noori al-noori commented Dec 26, 2025

The GC#drawImage method takes
(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight)
as arguments and crops and scales from the source region to the destination
region.

Passing an image drawn via ImageGCDrawer led to the following issue:

The image handle from the subcall is resolved using the monitor zoom
(data.nativeZoom) and the calculated scaledImageZoom (gcZoom * scaleFactor).
This handle corresponds to an ImageData initialized at scaledImageZoom,
whereas the drawings of the second GC are performed using the monitor zoom,
subject to the auto-scale property.

This mismatch results in unaligned sizing of drawings. For example, a 200%
monitor zoom combined with a scale factor of 0.5 produces a scaledImageZoom of
100%. As a result, the ImageData is initialized at 100%, while drawing occurs
at 200%.

Furthermore, the calculation of scaledImageZoom uses fallback logic that only
allows 100% and 200% as possible outcomes, which is clearly unintended in this
context.

The fix delegates resolving the correct handle to the Image class by passing
the width/height of the full image scaled by the scaledImageZoom. This
is a space on where scaled src coordinates/width/height lie. A callback
then creates a new handle for the height/width and respects the auto-scale property.

If the returned handle matches the full image scaled to the requested
scaledImageZoom in width and height, the source region
coordinates/width/height are passed directly in pixels at that zoom. Otherwise,
the internal zoom factor is derived from the returned handle’s width relative to
the full image, and the source region coordinates are converted to pixel values
using this internal zoom.

Note: Snippet 10 used to demonstrate that method. Although the sizing issue is fixed, the method is replaced by GC#drawImage(destX, destY, destWidth, destHeight) as the use case here is only scaling and not cropping. Currently, a new snippet is in progress which will be developed to address the cropping + scaling scenario (see #2912 as a first version without drawings via the ImageGcDrawer).

@github-actions
Copy link
Contributor

Test Results

  176 files  ±0    176 suites  ±0   26m 36s ⏱️ -41s
4 672 tests ±0  4 650 ✅ ±0  22 💤 ±0  0 ❌ ±0 
  482 runs  ±0    476 ✅ ±0   6 💤 ±0  0 ❌ ±0 

Results for commit 53c83c8. ± Comparison against base commit 47e2587.

ImageHandle imageHandle = lastRequestedHandle.getOrCreateImageHandleAtClosestSizeAtZoom(scaledZoom);
handleAtSizeConsumer.accept(imageHandle);
}
void executeOnImageHandleAtSizeOrZoom(BiConsumer<ImageHandle, Point> handleAtSizeConsumer, int targetWidth, int targetHeight, int zoom) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this used anywhere?

return Optional.empty();
}

public ImageHandle getOrCreateImageHandleAtClosestSizeAtZoom(int scaledZoom) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldnt this be private


private void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY,
int destWidth, int destHeight, int imageZoom, int scaledImageZoom) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

Rectangle fullImageBounds = image.getBounds();
Rectangle targetSrc = Win32DPIUtils.pointToPixel(drawable, fullImageBounds, scaledImageZoom);
Rectangle startSrc = new Rectangle(srcX, srcY, srcWidth, srcHeight);
image.executeOnImageHandleAtBestFittingSizeAtZoom((tempHandle) -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it is better to have an additional override for Image#executeOnImageHandleAtBestFittingSize() which takes source dimensions in addition to destination dimensions so the GC#calculateZoomForImage() can be removed and the calculation of zoom becomes the responsibility of the Image class.

}
}
drawImage(image, src.x, src.y, src.width, src.height, dest.x, dest.y, dest.width, dest.height, false, image.getHandle(scaledImageZoom, data.nativeZoom));
Rectangle fullImageBounds = image.getBounds();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can see image.getBounds is called above in case the zoom!=100 can you see if the hack still makes sense, It would make sense to consider if we can stream line these calls

@al-noori al-noori force-pushed the al-noori/FixSizingWithIGCD branch from 53c83c8 to 804f78d Compare January 2, 2026 10:51
@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Test Results (win32)

   34 files  ±0     34 suites  ±0   4m 46s ⏱️ +29s
4 628 tests ±0  4 555 ✅ ±0  73 💤 ±0  0 ❌ ±0 
  167 runs  ±0    164 ✅ ±0   3 💤 ±0  0 ❌ ±0 

Results for commit 6ae439d. ± Comparison against base commit 383ed2a.

♻️ This comment has been updated with latest results.

The GC#drawImage method takes
(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight)
as arguments and crops and scales from the source region to the destination
region.

Passing an image drawn via ImageGCDrawer led to the following issue:

The image handle from the subcall is resolved using the monitor zoom
(data.nativeZoom) and the calculated scaledImageZoom (gcZoom * scaleFactor).
This handle corresponds to an ImageData initialized at scaledImageZoom,
whereas the drawings of the second GC are performed using the monitor zoom,
subject to the auto-scale property.

This mismatch results in unaligned sizing of drawings. For example, a 200%
monitor zoom combined with a scale factor of 0.5 produces a scaledImageZoom of
100%. As a result, the ImageData is initialized at 100%, while drawing occurs
at 200%. This exact case is demonstrated in
vi-eclipse/Eclipse-Platform#554
.

Furthermore, the calculation of scaledImageZoom uses fallback logic that only
allows 100% and 200% as possible outcomes, which is clearly unintended in this
context.

The fix delegates resolving the correct handle to the Image class by passing
the width/height of the full image scaled by the scaledImageZoom. This
is a space on where scaled src coordinates/width/height lie. A callback
then creates a new handle for the height/width and respects the auto-scale property.

If the returned handle matches the full image scaled to the requested
scaledImageZoom in width and height, the source region
coordinates/width/height are passed directly in pixels at that zoom. Otherwise,
the internal zoom factor is derived from the returned handle’s width relative to
the full image, and the source region coordinates are converted to pixel values
using this internal zoom.
@al-noori al-noori force-pushed the al-noori/FixSizingWithIGCD branch from 804f78d to 6ae439d Compare January 2, 2026 12:57
@al-noori
Copy link
Contributor Author

al-noori commented Jan 2, 2026

@arunjose696 i edited the PR such that the drawImage(srcX,srcY,...) method uses the same callback image.executeOnImageHandleAtBestFittingSize via width and height of the scaled full image as the other drawImage method.
That is why i would hesitate to write an additional overwrite. I thereby intend to capture a quick adoption mentioned in: vi-eclipse/Eclipse-Platform#468 (comment). This also made any changes to the image class redundant and i could leave out my additional methods. What is your opinion on this?

Regarding that hack: it seems to me that i does not make sense. The hack is motivated by potential rounding errors, but without further investigation, i assume that passing correct source coordinates/width/height which lie in the space of the full image, the statement src.intersect(fullImageBoundsScaled) will always return src with equal attributes as before regardless of errors.
I streamlined the getBounds call as you mentioned and would leave the hack as it is for this PR. Investigating the hack and why it was introduced in the first place might be useful in the context of a different PR.

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.

Unexpected sizing when drawing an Image with ImageGcDrawer on a GC on zoom != 100

2 participants