Reputation: 1810
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?
Upvotes: 6
Views: 534
Reputation: 3494
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)
Upvotes: 3