-
Notifications
You must be signed in to change notification settings - Fork 189
[Refactoring] Streamline calls to Image#adaptImageDataIfDisabledOrGray() #2795
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?
[Refactoring] Streamline calls to Image#adaptImageDataIfDisabledOrGray() #2795
Conversation
4c8ed71 to
2f08cde
Compare
Enabling a consistent pattern to apply disablement or graying of an Image. They are applied whenever a handle is being created from init method. Ensuring streamline usage and avoid double calls to this method.
2f08cde to
91c9747
Compare
| case SWT.IMAGE_DISABLE: | ||
| case SWT.IMAGE_GRAY: { | ||
| for (ImageHandle imageHandle : srcImage.zoomLevelToImageHandle.values()) { | ||
| Rectangle rect = imageHandle.getBounds(); | ||
| ImageData data = srcImage.getImageData(imageHandle.zoom); | ||
| ImageData newData = applyGrayImageData(data, rect.height, rect.width); | ||
| init (newData, imageHandle.zoom); | ||
| srcImage.getImageData(imageHandle.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.
Now we only need to reload the data for other handle if exist in order to apply gray or disable image data.
| ImageData imageData = image.getImageData(targetZoom); | ||
| drawer.postProcess(imageData); | ||
| ImageData newData = adaptImageDataIfDisabledOrGray(imageData); | ||
| ImageData newData = adaptImageDataIfDisabledOrGray(imageData, styleFlag); |
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 still have to keep it because a new image is created here with plainImageDataProvider which loads the data directly from handle. I am open to suggestions here.
|
@akoch-yatta @HeikoKlare Please review the PR and comments, It might not be in final shape but here I could use some suggestions. |
Test Results 111 files ±0 111 suites ±0 17m 48s ⏱️ +7s For more details on these failures, see this check. Results for commit eb0405c. ± Comparison against base commit 63d5582. ♻️ This comment has been updated with latest results. |
|
@akoch-yatta can you please have a look/review if you got time? |
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.
Can you please explain the underlying pattern where the application of gray/disablement is supposed to be done now? The PR description states:
In this way we can achieve one common place to call adaptImageDataIfDisabledOrGray from.
But I see calls of that method from at least:
- initializeHandleFromSource
- newImageData
- getOrCreateImageHandleAtClosestSize
To assess if this is a good concept/systematics where to apply gray/disablement, it would be helpful to have a description of that concept.
In addition to that, the PR seems to contain unnecessary changes (e.g., addition of unused parameters, duplicate application of adaptImageDataIfDisabledOrGray) and also seems to remove crucial code (handle initialization in copy constructor).
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
Outdated
Show resolved
Hide resolved
| if (imageData.isPresent()) { | ||
| ImageData adaptedData = adaptImageDataIfDisabledOrGray(imageData.get()); | ||
| ImageHandle imageHandle = init(adaptedData, -1); | ||
| ImageHandle imageHandle = init(imageData.get(), -1); |
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.
Why don't we apply gray/disablement here anymore?
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.
Because data will already be loaded with disablement/gray properties.
| ImageData data = srcImage.getImageData(imageHandle.zoom); | ||
| ImageData newData = applyGrayImageData(data, rect.height, rect.width); | ||
| init (newData, imageHandle.zoom); | ||
| srcImage.getImageData(imageHandle.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.
Wny do we remove the gray/disabled adaptation and, especially, the init call here? Won't this lead to the new image not being initalized with appropriate handles anymore?
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.
Since the logic to apply gray/disablement is moved to whenever image data is loaded, we don't need to apply adaptions here (also the init method).
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.
This is an image constructor, which copied/adapts the handles of the original image. Not doing that will leave the new image empty. How should that work, e.g., in case you have an image based on an existing handle? The new Image instance with GRAY/DISABLED flag would simply be empty.
| return loadImageDataWithGrayOrDisablement(zoomContext.targetZoom()).element(); | ||
| } | ||
|
|
||
| @Override | ||
| protected ElementAtZoom<ImageData> loadImageData(int targetZoom) { | ||
| if (zoomLevelToImageHandle.isEmpty()) { | ||
| return createBaseHandle(targetZoom).getImageData(); | ||
| return new ElementAtZoom<> (createBaseHandle(targetZoom).getImageData(), targetZoom); | ||
| } | ||
| // if a GC is initialized with an Image (memGC != null), the image data must not be resized, because it would | ||
| // be a destructive operation. Therefor, a new handle is created for the requested zoom | ||
| if (memGC != null) { | ||
| return newImageHandle(zoomContext).getImageData(); | ||
| return new ElementAtZoom<> (newImageHandle(new ZoomContext(targetZoom)).getImageData(), targetZoom); | ||
| } | ||
| return getScaledImageData(targetZoom); | ||
| } | ||
|
|
||
| @Override | ||
| protected ElementAtZoom<ImageData> loadImageData(int zoom) { | ||
| return getClosestAvailableImageData(zoom); | ||
| return new ElementAtZoom<> (getScaledImageData(targetZoom), targetZoom); |
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.
Why is this semantics change of the methods necessary? In case of a PlainImageProviderWrapper there is no need to apply any gray/disabled if we just create an empty handle. And if we rescale an existing handle, that one should already have gray/disablement applied.
Enabling a consistent pattern to apply disablement or graying of an Image. They are applied whenever a handle is being created from init method. Ensuring streamline usage and avoid double calls to this method.
How to test
Snippet382with following VM Argument:swt.autoScale.updateOnRuntime=trueThis adaption is made on the basis of this comment: #2737 (comment)
Instead of calling the adaptImageDataIfDisabledOrGray method from init method (which could be executed even when temporary handle is created) we will now call it only when data is loaded for the first time. So instead of calling loadImageData, all providers must call loadImageDataWithGrayOrDisablement and also provide loadImageData implementation of its own. In this way we can achieve one common place to call adaptImageDataIfDisabledOrGray from.