Bug 576761 - SWT Canvas really slow on Mac with retina display
Summary: SWT Canvas really slow on Mac with retina display
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.21   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-20 08:29 EDT by Leif Geiger CLA
Modified: 2022-10-24 13:10 EDT (History)
6 users (show)

See Also:


Attachments
stripped-down example code (3.09 KB, application/octet-stream)
2021-10-20 08:29 EDT, Leif Geiger CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leif Geiger CLA 2021-10-20 08:29:59 EDT
Created attachment 287362 [details]
stripped-down example code

We are working on an OSS integration of a chromium-based browser in Eclipse.
The current prototype works by just copying the image rendered by an Electron browser into an SWT Canvas. Works fine on Windows and Linux but is very slow on Mac with retina display (not if no retina display is connected).

I have attached a stripped-down example that just copies images with random color to an SWT Canvas. This example runs with ~40 frames per second on my Windows machine and with ~3 FPS on an iMac with retina display. With an external monitor it runs much faster also on the iMac. Is there a way how I can improve this? Am I doing something wrong?

Help from the SWT experts out there would be very much appreciated.
Comment 1 Phil Beauvoir CLA 2022-04-12 11:39:58 EDT
I tested this on MacBook Pro (Retina), macOS 12.3.1, Java Temurin-11.0.13+8

I also get around 3-4 FPS, but around 90 FPS on Mac M1 with non-Retina display.

But I don't think it's specifically the Canvas class, as I get the same results with Composite or just painting to the Shell.
Comment 2 Phil Beauvoir CLA 2022-04-12 11:46:06 EDT
> but around 90 FPS on Mac M1 with non-Retina display.

That should be 60 FPS
Comment 3 Leif Geiger CLA 2022-04-12 13:51:50 EDT
> But I don't think it's specifically the Canvas class, as I get the same
> results with Composite or just painting to the Shell.

Good finding! I guess, I could have stripped down the example even further. Thanks for retesting!
Comment 4 Phil Beauvoir CLA 2022-04-13 05:51:52 EDT
Leif, it may not even be due to Mac and Retina display. It could just be due to the amount of pixels. Retina displays obviously have x4 more pixels.

Changing the values of the following line higher or lower will show this:

Point size = new Point(1500, 1000);
Comment 5 Leif Geiger CLA 2022-04-14 02:38:50 EDT
I aggree that the problem here is certainly caused by the 4x more pixels. I am not a Mac expert but I think there should be a way to paint a 1500x1000 square e.g. black at same speed as this is done under Windows. In my opinion the upscaling should be done by the GPU. At least I hope so.
Comment 6 Phil Beauvoir CLA 2022-04-14 04:29:52 EDT
Are you testing on Windows with hi-res display?
Comment 7 Leif Geiger CLA 2022-04-19 01:48:17 EDT
The biggest screen I have here is 2560x1440px. Of course, if I enlarge the Canvas, the framerate drops here as well (~19 FPS @ 2500x1400). But I guess a fixed size of 1500x1000px should have same speed on retina and non-retina displays regardless on how the presentation is done internally. Or would you say since it is 3000x2000px internally on retina this can not work faster?
Comment 8 Lakshmi P Shanmugam CLA 2022-04-24 13:53:42 EDT
I tried this on MacBookPro in both Retina and non-Retina mode and observe the same behavior - frame rate decreases as the resolution increases - in both modes. Most of the time is taken by the GC.drawImage() calls, but we only call the native NSImage.drawInRect() and do nothing specific to retina. Need to investigate further if performance can be improved here.
Comment 9 Martin Lippert CLA 2022-10-11 03:42:10 EDT
Any news on this? Leif, can you provide more details and/or insights to push this forward? Or is there anything specific that is blocking this?
Comment 10 Lakshmi P Shanmugam CLA 2022-10-13 06:24:27 EDT
(In reply to Martin Lippert from comment #9)
> Any news on this? Leif, can you provide more details and/or insights to push
> this forward? Or is there anything specific that is blocking this?

As noted before, the difference is coming from the native API itself - NSImage.drawInRect() [1]. Could find any options to tweak the performance for retina display.

@Alex, do you have any ideas on how to improve the performance of NSImage.drawInRect() for retina?

[1] - https://developer.apple.com/documentation/appkit/nsimage/1520067-drawinrect
Comment 11 Alexandr Miloslavskiy CLA 2022-10-15 06:11:28 EDT
Unfortunately I don't have a retina display for debugging.
Comment 12 Martin Lippert CLA 2022-10-24 13:10:45 EDT
(In reply to Alexandr Miloslavskiy from comment #11)
> Unfortunately I don't have a retina display for debugging.

Where are you located?