Skip to content

[Win32] Properly encapsulate cursor handle creation and disposal #2403

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

Merged

Conversation

HeikoKlare
Copy link
Contributor

Currently, the Cursorimplementation has a design flaw related to the isIcon field:

  • It is used by handle provider implementations to distinguish ways in which a handle shall be created, which requires access of the provider to data of a cursor and requires some instantiations to pass dummy values (mask==null).
  • It defines how handles for that cursor have to be created and destroyed, without any guarantee that creation and destroyal are implemented in a conforming way.

This change gets rid of the isIcon field by two means:

  • It introduces a CursorHandle class that encapsulates the destroy logic for a handle and assign it upon creation of the handle, such that destroy logic fits to how the handle was created.
  • It also introduces an ImageDataWithMaskHandleProvider that properly handles the case that a Cursor was created with a mask which was yet only identified by the isIcon field of a cursor.

It is split up into to commits addressing each of the above concerns but with the common goal of getting rid of the isIcon field.

Copy link
Contributor

github-actions bot commented Aug 10, 2025

Test Results

   546 files     546 suites   33m 44s ⏱️
 4 425 tests  4 408 ✅  17 💤 0 ❌
16 746 runs  16 619 ✅ 127 💤 0 ❌

Results for commit 6cd670a.

♻️ This comment has been updated with latest results.

@@ -120,7 +119,7 @@ public final class Cursor extends Resource {
public Cursor(Device device, int style) {
super(device);
this.cursorHandleProvider = new StyleCursorHandleProvider(style);
this.handle = this.cursorHandleProvider.createHandle(this, DEFAULT_ZOOM);
this.handle = this.cursorHandleProvider.createHandle(device, DEFAULT_ZOOM).getHandle();
Copy link
Contributor

@arunjose696 arunjose696 Aug 11, 2025

Choose a reason for hiding this comment

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

just a Nit: The handle field still stores the raw long, while zoomLevelToHandle stores the CursorHandle. This introduces a risk of the two becoming out-of-sync if the logic changes in the future. IMO It might be cleaner to store the CursorHandle directly in handle and call this.handle.getHandle() (or rename the method to getNativeHandle() for clarity) wherever the long handle is needed @HeikoKlare

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's true that the two values may get out of sync but that's actually not different from the current state. CursorHandle is immutable, so it will be as consistent to the current handle value as it was before. We need to get rid of the handle, but that's something that will be done with the lazy generation of handles implemented by Shahzaib.

@ShahzaibIbrahim
Copy link
Contributor

I have tried with different zoom levels (100/150/175) and changes looks good to me

Currently, the distinction of how to create a cursor handle inside
image-data-based providers depends on state of a given cursor instance
and requires dummy values to be passed (such as `mask==null`).
This change extracts the according behaviors into separate classes that
encapsulate the required data and functionality.
Currently, cursor handles are destroyed in different ways depending on
whether the `isIcon` field is set. This field is set in cases when the
handle is created for an OS icon handle. This contract has to be ensured
implicitly and can easily be broken.

With this change, the cursor handle creation creates an according
CursorHandle type that is capable of executing the associated disposal
logic.
@HeikoKlare HeikoKlare force-pushed the cursor-disposal-CursorHandle branch from 7500742 to 6cd670a Compare August 11, 2025 15:02
@HeikoKlare HeikoKlare merged commit e3c0392 into eclipse-platform:master Aug 11, 2025
17 checks passed
@HeikoKlare HeikoKlare deleted the cursor-disposal-CursorHandle branch August 11, 2025 15:20
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.

Clean up Cursor handle provider and disposal implementation
3 participants