Skip to content

Use the existing image to initialize the GC in ImageGcDrawerWrapper #2238

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ShahzaibIbrahim
Copy link
Contributor

In ImageGCDrawerWrapper#newImageHandle, we create a new image with existing data to initialize the GC, instead we could use the existing image object and the base handle should be created as it is done in PlainImageDataProvider.

Copy link
Contributor

github-actions bot commented Jun 16, 2025

Test Results

   536 files   -  9     536 suites   - 9   30m 39s ⏱️ - 1m 29s
 4 328 tests  - 73   4 307 ✅  - 76   13 💤  - 5  1 ❌ +1   7 🔥 + 7 
16 676 runs   - 52  16 524 ✅  - 64  136 💤  - 4  1 ❌ +1  15 🔥 +15 

For more details on these failures and errors, see this check.

Results for commit 24fbd72. ± Comparison against base commit cad131b.

This pull request removes 74 and adds 1 tests. Note that renamed tests count towards both.
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicASCII_dollarSign
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicASCII_emptyString
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicASCII_letterA
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicASCII_letters
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16LE_null
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_AsciiLetters
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_Asciiletter
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_LotsOfLetters
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_letter
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_letters
…
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_graphics_Image ‑ test_ImageWithImageGcDrawerWrapper

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

I've tested the behavior with the LineNumberRuler and that seems to be work fine with different zooms. But with this change we will see the following warnings when strict checks are enabled, which need to be resolved:

***WARNING: Images with handles created for multiple zooms should not be modified.  It should be created with an ImageGcDrawer (see SWT Snippet 384).

GC gc = new GC(new DrawableWrapper(image, zoom), gcStyle);
createBaseHandle(zoom, width, height);
};
GC gc = new GC(new DrawableWrapper(Image.this, zoom), gcStyle);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we then remove the DrawableWrapper and just call?

Suggested change
GC gc = new GC(new DrawableWrapper(Image.this, zoom), gcStyle);
GC gc = new GC(Image.this, gcStyle);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a scenario where it's needed when another GC can be called over this image from the outside. I am not 100% of the scenario but maybe @akoch-yatta can explain it bit better on why it was used in the first place.

@HeikoKlare
Copy link
Contributor

Is this something we can only do for the Windows implementation or may we adapt all the MacOS and Linux implementations of Image as well?

@ShahzaibIbrahim
Copy link
Contributor Author

***WARNING: Images with handles created for multiple zooms should not be modified. It should be created with an ImageGcDrawer (see SWT Snippet 384).

This error should go away once this PR is merged.

@ShahzaibIbrahim
Copy link
Contributor Author

Is this something we can only do for the Windows implementation or may we adapt all the MacOS and Linux implementations of Image as well?

Yes, it make sense to adapt the MacOS and Linux implementation of Image. But since I can't test the changes, I will wait until @fedejeanne is back and can test those changes with him.

In ImageGCDrawerWrapper#newImageHandle, we create a new image with existing data to initialize the GC, instead we could use the existing image object and the base handle should be created as it is done in PlainImageDataProvider.
Comment on lines +2562 to +2567
ImageData imageData = Image.this.getImageMetadata(zoom).getImageData();
drawer.postProcess(imageData);
ImageData newData = adaptImageDataIfDisabledOrGray(imageData);
return init(newData, zoom);
if(imageData.data != null) {
zoomLevelToImageHandle.get(zoom).destroy();
init(imageData, zoom);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I want initialize the imageData only if postProcess is called. That's why I have a default implementation that nullify the imageData in order to know here if it was not implemented. I know it's not a clean solution and I am open to hear suggestion.

My suggestions:

  1. Have some field to track if postProcess was called.
  2. Always call init regardless of postProcess calling.

@HeikoKlare

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.

Use the existing image to initialize the GC in ImageGcDrawerWrapper
2 participants