Skip to content

Conversation

ShahzaibIbrahim
Copy link
Contributor

When creating a custom cursor using source and mask ImageData, the transparency mask does not scale correctly when applying DPIUtil.autoScaleImageData() in a multi-monitor setup with different DPI settings. With this change we use scaleTo method to scale the data.

How to test

  • Run the Snippet386 with following VM arguments

    -Dswt.autoScale=quarter
    -Dswt.autoScale.updateOnRuntime=true
    
  • On 100% monitor zoom, choose the Cursor(Device, ImageData, ImageData, int, int) option from the dropdown

  • You will see the dotted square (a transparent pixel after each solid pixel)

  • Move the shell to another monitor with different zoom e.g. 150%

  • Previously you would lose the transparency completely when it was scaled with DPIUtil.scaleImageData

Comparison of mask data before and after scaling with and without this PR

Before

Zoom = 100
Scaled Mask:
Mask pixels (x,y):
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
Zoom = 150
Scaled Mask:
Mask pixels (x,y):
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 
0 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -707406592 707406336 -2139062272 -256 

After:

Zoom = 100
Scaled Mask:
Mask pixels (x,y):
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1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 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 1 
0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 1 
0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 1 
0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 1 
0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 1 
0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 1 
0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 1 
0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 1 

P.S: With this change we will not get smooth scaling for the cursor created with source and mask data. That's why we will deprecate the Cursor(Device, ImageData, ImageData, int, int) constructor in another PR, see vi-eclipse/Eclipse-Platform#462. Instead, we will recommend using: Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX, int hotspotY) as this provides better results with multi-monitor DPI scaling.

Copy link
Contributor

github-actions bot commented Sep 30, 2025

Test Results

  118 files  ±0    118 suites  ±0   13m 1s ⏱️ + 1m 8s
4 583 tests ±0  4 566 ✅ ±0  17 💤 ±0  0 ❌ ±0 
  330 runs  ±0    326 ✅ ±0   4 💤 ±0  0 ❌ ±0 

Results for commit e424717. ± Comparison against base commit 1eabfa3.

♻️ This comment has been updated with latest results.

@arunjose696
Copy link
Contributor

Tested the changes. The modification switches the cursor to use blurry scaling instead of smooth scaling, as smooth scaling does not account for the mask when displaying the cursor. This results in a better appearance for cursors with masks compared to the master branch (for example, at 150% zoom in the master branch, the mask is not visible, whereas with this change, the mask is applied). The scaled version is still not perfect, so the deprecation PR is reasonable. I am approving this change, as the code works correctly and provides a reasonable fix for the soon-to-be-deprecated constructor.

When creating a custom cursor using source and mask ImageData, the
transparency mask does not scale correctly when applying
DPIUtil.autoScaleImageData() in a multi-monitor setup with different DPI
settings. With this change we use scaleTo method to scale the data.
@fedejeanne fedejeanne merged commit 6fa4ee7 into eclipse-platform:master Oct 10, 2025
17 checks passed
@fedejeanne fedejeanne deleted the master-461 branch October 10, 2025 09:27
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.

Losing transparency for Icon when creating an icon with source and mask

3 participants