WindowTop / WindowTop-App

Set window on top, make it dark, transparent and more
Other
1.12k stars 68 forks source link

[Dark & Glass Modes] Improve rendering performance by using Direct2D API #264

Closed gileli121 closed 1 year ago

gileli121 commented 1 year ago

This task is a subtest of the main goal - to improve the performance of these effects. The main mission is #105 In this task, I will implement the method to optimize the performance by using the Direct2D API


I found a new way how to improve the rendering performances! Until a few days ago, I was unaware of how to invert the colors of 8,294,400 pixels (the amount in 4K resolution) in GPU without using NVIDIA CUDA API (which requires NVIDIA GPU).

And recently, I found a way to do it! In Direct2D API, there is a GPU-accelerated method to do that, and because it is Direct2D, it is not exclusive to NVIDIA GPUs! It will work on even regular Intel GPUs. This finding means that every computer will use the GPU for this effect. Great stuff!

I made a POC that proves that it is possible to get 60+ frames per second on 4K using just intel GPU, and this is instead of 20-30 FPS.

Not only that, but this finding also comes with a new optimization advantage: because the OS API also does not send the captured frame to the CPU and because Direct2D will do its magic in GPU, now, unlike before, we will never need to move any frame data to CPU (unless the "filter images" option is enabled) so this fact also will help. This will also reduce a lot of battery usage because everything will be done natively by the GPU!

The idea in the message above (To use DOM API) may still be worth checking after this finding. It is still relevant because it tries to optimize the performances when the "filter images" option is enabled.

Originally posted by @gileli121 in https://github.com/BiGilSoft/WindowTop/issues/105#issuecomment-1263320841

gileli121 commented 1 year ago

Done. Version for testing: WindowTop 5.19.0-beta1 - setup.exe.zip

Dark mode renderer

gileli121 commented 1 year ago

WindowTop 5.19.0-beta3 - setup.exe.zip

gileli121 commented 1 year ago

This fix should resolve the bug: Issue with dark-mode and glass-mode on dual monitor configuration when DPI scaling is not the same for each monitor

In this version, I fixed a bug when the DPI of the second monitor was not the same as the DPI of the primary monitor. In this case, the window was rerendered to be dark, but the rerendered frame was not printed at the correct location on the screen.

Here is the fix: WindowTop 5.19.0-beta4 - setup.exe.zip

gileli121 commented 1 year ago

WindowTop 5.19.0-beta5 - setup.exe.zip

This version is an extra hotfix for the DPI bugs. This fixes a bug with Microsoft Edge / Chrome browser that when the window is maximized on a second monitor with a different DPI, the dark mode does not work.

gileli121 commented 1 year ago

WindowTop 5.19.0-beta6 - setup.exe.zip

gileli121 commented 1 year ago

WindowTop 5.19.0-beta7 - setup.exe.zip

gileli121 commented 1 year ago

This seems very unstable in Windows 10 (unlike in Windows 11). This will need more work

gileli121 commented 1 year ago

WindowTop 5.19.0-beta8 - setup.exe.zip

gileli121 commented 1 year ago

WindowTop 5.19.0-beta9 - setup.exe.zip

gileli121 commented 1 year ago

WindowTop 5.19.0-beta10 - setup.exe.zip

gileli121 commented 1 year ago

WindowTop 5.19.0-beta11 - setup.exe.zip

gileli121 commented 1 year ago

WindowTop 5.19.0-beta12 - setup.exe.zip

This is probably the final beta version of this effort. I will release it if we see that it is stable and works well enough.

gileli121 commented 1 year ago

WindowTop 5.19.0-beta13 - setup.exe.zip

gileli121 commented 1 year ago

WindowTop 5.19.0-beta15 - setup.exe.zip

gileli121 commented 1 year ago

WindowTop 5.19.0-beta16 - setup.exe.zip

gileli121 commented 1 year ago

WindowTop 5.19.0-beta17 - setup.exe.zip

gileli121 commented 1 year ago

Released https://github.com/BiGilSoft/WindowTop/releases/tag/v5.19.0