-
Notifications
You must be signed in to change notification settings - Fork 118
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
[macOS Sonoma] Control.setBackgroundImage - image is upside down and flipped #772
Comments
In the case of displaying the splash screen when launching Eclipse or an RCP app, the image initially appears correctly but is inverted after a second or two. AFAICS, this is because the initial display of the splash is done natively in the But then the trail goes to
Then
The code for this call is in public static NSColor colorWithPatternImage(NSImage image) {
long result = OS.objc_msgSend(OS.class_NSColor, OS.sel_colorWithPatternImage_, image != null ? image.id : 0);
return result != 0 ? new NSColor(result) : null;
} And another at line 1345:
So, there's either a bug in Apple's code or something has changed and a workaround is needed in SWT code. I can't do any more than offer this analysis, so please feel free to help. :-) |
The same problem with using a import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ImageTestWithPattern {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Image Test with Pattern");
shell.setLayout(new GridLayout());
Image image = new Image(display, ImageTestWithPattern.class.getResourceAsStream("splash.png"));
shell.setSize(image.getBounds().width, image.getBounds().height);
Pattern pattern = new Pattern(display, image);
shell.addPaintListener(e -> {
e.gc.setBackgroundPattern(pattern);
e.gc.fillRectangle(0, 0, shell.getSize().x, shell.getSize().y);
});
shell.open();
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
} |
This will be in macOS Sonoma final as the behaviour exists in the Release Candidate. |
A self-contained snippet: import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ImageTest {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Image Test");
shell.setLayout(new GridLayout());
shell.setSize(200, 200);
Image image = new Image(Display.getDefault(), 200, 200);
GC gc = new GC(image);
gc.setForeground(new Color(null, 0, 0, 0));
gc.drawText("Hello World", 50, 100);
gc.dispose();
shell.setBackgroundImage(image);
shell.open();
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
} |
I'm hoping this can be addressed asap; it will hold up our adoption of this latest release |
I've documented my analysis of the problem in the previous comments, but I don't know if this is an Apple bug (I have reported it) or something that needs to change in SWT. It needs someone else to answer that. |
I am experiencing the same problem on Sonoma/MacMini M2 Pro. It exists in Eclipse 2023-03 as well as 2023-09. In addition, the name of the application at the left side of the Menu Bar (just to the right of the Apple icon) says "New Application" instead of "Eclipse". |
Yes, that's because the problem lies in macOS 14.
Yes, and that has been reported (and fixed) here - #779 |
On macOS Sonoma 14.0, images that are set as background image on SWT controls are upside-down. See eclipse-platform/eclipse.platform.swt#772. The workaround checks for the presence of the bug and flips the splash screen background image such that it gets flipped back by the bug to its normal position. AP-21237 (Splash screen is displayed upside down)
On macOS Sonoma 14.0, images that are set as background image on SWT controls are upside-down. See eclipse-platform/eclipse.platform.swt#772. The workaround checks for the presence of the bug and flips the splash screen background image such that it gets flipped back by the bug to its normal position. AP-21237 (Splash screen is displayed upside down)
On macOS Sonoma 14.0, images that are set as background image on SWT controls are upside-down. See eclipse-platform/eclipse.platform.swt#772. The workaround checks for the presence of the bug and flips the splash screen background image such that it gets flipped back by the bug to its normal position. AP-21237 (Splash screen is displayed upside down)
On macOS Sonoma 14.0, images that are set as background image on SWT controls are upside-down. See eclipse-platform/eclipse.platform.swt#772. The workaround checks for the presence of the bug and flips the splash screen background image such that it gets flipped back by the bug to its normal position. AP-21237 (Splash screen is displayed upside down)
One of referenced commits from @enplotz above has a nice workaround for the splash screen if anyone is interested: The code flips the image which you can set in the splash handler's background image. I've re-purposed it to use in our RCP app's splash handler: private Image flipImage(Display display, Image srcImage) {
Rectangle bounds = srcImage.getBounds();
Image newImage = new Image(display, bounds.width, bounds.height);
GC gc = new GC(newImage);
gc.setAdvanced(true);
gc.setAntialias(SWT.ON);
gc.setInterpolation(SWT.HIGH);
Transform transform = new Transform(display);
transform.setElements(1, 0, 0, -1, 0, 0);
transform.translate(0, -bounds.height);
gc.setTransform(transform);
gc.drawImage(srcImage, 0, 0, bounds.width, bounds.height,
0, 0, bounds.width, bounds.height);
gc.dispose();
transform.dispose();
return newImage;
} Note that the method there I test for it like this: if(PlatformUtils.isMac() && PlatformUtils.compareOSVersion("14.0") >= 0) {
// Flip the image
shell.setBackgroundImage(flipImage(shell.getDisplay(), shell.getBackgroundImage()));
// We are now responsible for disposing of the new image
shell.addDisposeListener(e -> {
shell.getBackgroundImage().dispose();
});
} |
@Phillipus unfortunately the workaround doesn't work. I was testing on pre-Sonoma and seems flip-detection won't do the trick, unfortunately - see discussion -> |
@swtdev Yes, that's why I said "Note that the method there isFlipBugPresent() doesn't work so you'll have to test for whether the bug is present in another way." |
Lol would help if I'd read the whole comment 🙃 |
But, it would be better if a Mac expert could say why the image is flipped when calling the native ObjectiveC methods. Perhaps the co-ordinate system changed for |
I suspect that it's related to flipping in eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java Lines 1535 to 1538 in f37b9eb
|
Reason might be even simpler. When application starts, NSView created by native code have isFlipped marked as false, but later, all views created via SWTCanvasView.alloc() have isFlipped marked as true (which is strange, I cannot find reason why). So looks like there is "isFlipped" mix between views and display context |
Are you able to determine where this |
Image flipping was originally implemented back in 2008 [1,2]. Possibly as a workaround. It appears something has changed with macOS Sonoma (14.0), and this is no longer necessary. [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=254797 [2] ca92157 Resolves #772.
There is another flipped creation of the context in eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java Lines 2202 to 2203 in f37b9eb
I have provided a pull-request that fixes both of the snippets in #772 (comment) and #772 (comment) |
Ok, well, turns out this is way more complicated and doesn't solve all the issues... In fact, it causes line numbers in the editor to be flipped now. I found this: Looks like we are also in that case 3, as we configure eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java Line 2704 in 030807a
for some of the widgets:
The corresponding native code is eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c Lines 89 to 99 in 030807a
|
That clearly affects things. I commented out this line and the image displays correctly in the Snippets: eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java Line 2799 in 030807a
|
In general looks like flipped property isn't correctly overriden in SWTCanvasView and others (overriding getter is not enough in sonoma probably due SWIFT bindings), class_addProperty should be used |
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fix the splash screen flip issue in new Mac versions. Fixes:eclipse-platform/eclipse.platform.swt#772
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Fixes: eclipse-platform/eclipse.platform.swt#772 Due to a bug in MacOS Sonoma(eclipse-platform/eclipse.platform.swt#772) ,Splash Screen gets flipped.As a workaround the image is flipped and returned.
Describe the bug
Background images on SWT controls are inverted.
This was reported here but I've opened a dedicated issue as it's not to do with the splash screen but rather
Control#setBackgroundImage
.To Reproduce
Use this image for testing (rename to splash.png), or your own image if you prefer:
Expected behavior
The image should display the right way.
Screenshots
Run the snippet and see this:
Environment:
Additional OS info (e.g. OS version, Linux Desktop, etc)
macOS Sonoma 14
Mac Mini M1
JRE/JDK version
Temurin 17
The text was updated successfully, but these errors were encountered: