Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix high CPU usage when window is occluded on macOS Native (#1003)
My app is used a lot in the background, and I noticed high CPU usage in the native macOS version. With this PR, CPU usage is reduced when window is invisible by disabling drawing. This was already implemented for the JVM, and that behaviour is now copied to native macOS. So the code is similar to JVM parts in: - https://github.com/JetBrains/skiko/blob/master/skiko/src/awtMain/kotlin/org/jetbrains/skiko/redrawer/MetalRedrawer.kt - https://github.com/JetBrains/skiko/blob/master/skiko/src/awtMain/objectiveC/macos/MetalRedrawer.mm The draw function is now suspend, which required moving some other functions around. I tried to keep the implementation similar to the JVM version. # Testing Tested using `./gradlew runNative` in `samples/SkiaMultiplatformSample`. Now the CPU usage is reduced a lot when moving another (non transparent) app over the window. # Old behaviour https://github.com/user-attachments/assets/60ad3398-3f44-4e2f-aca7-44a4607d0840 # New behaviour with 300ms timeout See reduction in CPU usage when window is invisible https://github.com/user-attachments/assets/106efdeb-0044-4411-9b26-5a6b8886ff04 # New behaviour without 300ms timeout https://github.com/user-attachments/assets/b986548b-d7ab-497b-9ddb-5b46ca016f83
- Loading branch information