-
Notifications
You must be signed in to change notification settings - Fork 156
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
Create handles for ImageDataProvider and ImageFilenameProvider on demand #1898
base: master
Are you sure you want to change the base?
Conversation
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Show resolved
Hide resolved
91c2e3b
to
20ec82f
Compare
20ec82f
to
592917e
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.
Just a NIT: width
and height
could be final
(also in ImageGcDrawerWrapper
)
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Show resolved
Hide resolved
private boolean isDestroyed; | ||
private int width; | ||
private int height; |
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.
Wouldn't it make sense to store these values in the AbstractImageProviderWrapper, now that all it's subclasses have such properties? You could also move the concrete implementations for isDisposed()
and destroy()
into the superclass then.
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.
When testing the branch I noticed a weird behavior. When smooth scaling is involved we can run into exceptions with these changes and I am questioning, what the proper expectation here is. So, in smooth scaling we are doing this:
Image original = new Image (device, (ImageDataProvider) zoom -> imageData);
This returns for each zoom the same ImageData. As we are using the ImageData at zoom 100 to define width and height, we have a problem now, because the bounds of the Image at 150% will no longer match the ImageData size at 150%, because getBounds scales the width and height up.
For this concrete case you could argue the ImageDataProvider implementation should be adapted, but in general I think we need to go the less efficient route and not store width and height, but always calculate them on demand with a proper handle. We can not guarantee, that there is a linear relation between the ImageData returned from an ImageDataProvider or an ImageFileNameProvider and the zoom.
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 understand and agree that we probably have to calculate height/width for the according handle.
Even if we could argue and reasonably assume that image data is scaled according to the zoom, there might different ways of rounding the sizes which can then lead to off-by-one errors in the sizes. Thus the bounds probably need to be calculated from the actual image handle / image data to be safe here.
But it would still be better to do that either on demand or or first request, as it would avoid the initial creation of a potentially unused handle.
Currently, when an image is instantiated using
ImageDataProvider
orImageFileNameProvider
, a handle is created immediately. We aim to optimize this by deferring handle creation until it is explicitly needed. To achieve this,getBounds()
will return the bounds of a 100% zoomed image when called after instantiation, without requiring a handle to be created upfront. This change improves efficiency by reducing unnecessary resource allocation during image initialization.Attaching the snippet to test the use cases after this change: