-
Notifications
You must be signed in to change notification settings - Fork 187
[Win32] Lazy load Cursor handles #2362
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
Conversation
aed2cb3 to
8b591c8
Compare
|
CI fails as Added tests uses windows only API, they should be probably moved to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please split to up into multiple commits or even PRs to make it easier to review and (hopefully not necessary) to find regressions? I see three changes combined here that we could split up:
- Fixing the hotspot coordinate calculation
- Refactoring the constructors (moving initialization logic to other methods)
- Managing multiple handles for different zooms
8b591c8 to
a1434cb
Compare
As you proposed, I have 3 PRs for the following
|
6eba22f to
4308424
Compare
HeikoKlare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for splitting up this PR! Now with the reduced complexity, it sstill seems to be a combination of multiple changes:
- Proper initialization of the handles for other zooms by not creating a new Cursor instance
- Bug that caused the ImageDataProvider not to be used when requesting a handle for another zoom (as
cursor.sourceis not null then, thus this will be used) - Proper handling of multiple zoom handles instead of having one default handle (probably including full on-demand handle creation, see below)
So it would again be good to split this up accordingly.
What I do not understand with the current change is why we need to create handles for default zoom upon cursor instantiation. All other resources create their handles only on demand and since consumers need to use win32_getHandle anyway, we could create the handle when first calling that method. That would even remove the duplication of calling initialization logic inside constructors and in win32_getHandle.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
I am not sure what bug is it you're talking about. |
b66799b to
345aa4b
Compare
a4b81de to
2e64ec5
Compare
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
09bfb02 to
f5050ee
Compare
HeikoKlare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that the simple removal of eager handle creation from the constructors will violates the existing contracts. There are exceptions specified, which (except for the ERROR_NO_HANDLES ones) must still be thrown in the constructor and not on a lazy handle request.
Here's all the contracts tested on Cursor object creation |
....swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java
Outdated
Show resolved
Hide resolved
....swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java
Outdated
Show resolved
Hide resolved
....swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java
Outdated
Show resolved
Hide resolved
....swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java
Outdated
Show resolved
Hide resolved
....swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java
Outdated
Show resolved
Hide resolved
....swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java
Outdated
Show resolved
Hide resolved
....swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java
Outdated
Show resolved
Hide resolved
....swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java
Outdated
Show resolved
Hide resolved
26fec81 to
da22b08
Compare
akurtakov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't speak for the win32 specific change but the tests change look good.
da22b08 to
96fa026
Compare
HeikoKlare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, the change looks good. But there is at least one potential behavorial change beyond the lazy handle creation in there that we need to clarify or resolve.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
....swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Show resolved
Hide resolved
18bcf47 to
e62283d
Compare
|
This pull request changes some projects for the first time in this development cycle. Warning 🚧 This PR cannot be modified by maintainers because edits are disabled or it is created from an organization repository. To obtain the required changes apply the git patch manually as an additional commit. Git patchFurther information are available in Common Build Issues - Missing version increments. |
HeikoKlare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest change introduced a regression that will make the cursor setup fail when passing a null mask.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Show resolved
Hide resolved
0f1e6d1 to
690dcd8
Compare
HeikoKlare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change is almost fine now. Please also adapt the commit message as it currently states that it adds per-zoom handle support, but that was part of a previous change and this is about lazy instantiation. Please also extend the description with some explanation on such an essential change.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
Outdated
Show resolved
Hide resolved
79c5417 to
af030ab
Compare
af030ab to
3112feb
Compare
This change updates the Win32 implementation of the Cursor class to defer creation of the native cursor handle until first use, enabling lazy loading instead of initializing the handle at construction time. Key changes: - Move initialization of the first handle creation from the constructors to the first handle retrieval. - Update equals(), hashCode(), isDisposed(), and toString() to work with zoom-aware handles and a new isDestroyed flag. - Add comprehensive unit tests for invalid constructor arguments to improve coverage and guard against improper usage. This change reduces unnecessary resource creation.
3112feb to
a3be4bd
Compare
HeikoKlare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now. With the latest push I have just adapted the faulty commit message, as it still referred to adding multi-handle support which is not part of this change but was implemented already before.
Problem
Currently, we have a logic to always initialize the first handle in a
handlefield. Instead of using it, we could switch to lazy loading via usingzoomLevelToHandlemap. The handle will only created whenwin32_getHandleis called.Proposed Solution
To fix this, the
Cursorclass should be refactored to manage zoom-level-specific handles more robustly and safely. The following changes are needed:Remove
handleFieldEliminate the dedicated
handlefield from the class. All handle accesses should go through thezoomLevelToHandlemap, which now acts as the single source of truth for all zoom levels.Update All Related Methods
Refactor all methods that previously relied on the
handlefield to instead usezoomLevelToHandle. This includes:hashCode()equals(Object obj)isDisposed()destroy()Benefits
Example
Output
Note that for the Cursor 1, we always get the same handle from OS but it's scaled correctly for all zoom levels.
Fixes: #2355