I would like to make a Per-Monitor DPI-Aware Direct2D application. I have extended Microsoft's "First Direct2D Program" example to handle WM_DPICHANGED
as explained in Kenny Kerr's MSDN article. This works when both monitors use one video card, but suffers from a glitch when using my laptop's NVIDIA Optimus setup.
I can reproduce the same glitch by running the Per-Monitor Aware WPF Sample with these steps:
(See video of this bug)
I have only seen this bug with the above example app, and when I try to add Kerr's WM_DPICHANGED handler to a simpler example. Suspiciously, I have seen other apps (Chrome, Visual Studio itself) show a similar black window, but only temporarily, if I drag between monitors and maximize them very quickly.
So - is anyone familiar with this glitch? Is it some bug in my display drivers? Or is there something other apps do to rectify it, which the example code does not?
NVIDIA Optimus you say? Those drivers are buggy as sin. Try initializing the render target with the D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS
flag.
This was something that took me forever to figure out back in 2014 when I was finishing up Paint.NET 4.0, and I've still got a comment in the code warning me to never turn it off:
private PresentOptions hwndPresentOptions =
PresentOptions.Immediately |
PresentOptions.RetainContents; // If we don't use RetainContents, then we get awful
// black flickering and mouse trails on some hardware
// (e.g. NVIDIA Optimus)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With