-
Notifications
You must be signed in to change notification settings - Fork 177
Refactor Cursor to lazy load Cursor handle #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
base: master
Are you sure you want to change the base?
Conversation
aed2cb3
to
8b591c8
Compare
Test Results 539 files - 7 539 suites - 7 31m 18s ⏱️ + 1m 45s For more details on these errors, see this check. Results for commit 09bfb02. ± Comparison against base commit 20d18aa. This pull request removes 54 tests.
♻️ This comment has been updated with latest results. |
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
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.source
is 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
- Removed the dedicated `handle` field from Cursor; all native handles are now stored in `zoomLevelToHandle`. - Updated hashCode, equals, isDisposed, and destroy to work with zoom-level handles.
2e64ec5
to
09bfb02
Compare
Problem
Currently, we have a logic to always initialize the first handle in a
handle
field. Instead of using it, we could switch to lazy loading via usingzoomLevelToHandle
map. The handle will only created whenwin32_getHandle
is called.Proposed Solution
To fix this, the
Cursor
class should be refactored to manage zoom-level-specific handles more robustly and safely. The following changes are needed:Remove
handle
FieldEliminate the dedicated
handle
field from the class. All handle accesses should go through thezoomLevelToHandle
map, 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
handle
field 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