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.

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.
Copy link
Contributor

Test Results

  118 files  ±0    118 suites  ±0   11m 47s ⏱️ -9s
4 582 tests ±0  4 546 ✅ ±0  36 💤 ±0  0 ❌ ±0 
  330 runs  ±0    307 ✅ ±0  23 💤 ±0  0 ❌ ±0 

Results for commit c1ee9dd. ± Comparison against base commit ce98326.

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
1 participant