Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is WPF Hardware-accelerated when Window AllowsTransparency = true?

I have been looking at making my own window frame in WPF, similar to Visual Studio. I have read that setting AllowsTransparency = true would force WPF to render in software-mode. This example is the source of my confusion (emphasis mine), which states:

Complete customization of WPF window can be done only when AllowsTransparency is set to "True", which causes that the window is software rendered which might be not as fast GPU rendering.

However, I've read elsewhere that with window layering you can have hardware-acceleration and this is what WPF does. I also find it hard to imagine that Visual Studio 2013 -with its custom frame and transparent border blur- would be software-rendered.

Is there a definitive answer to the question (assuming Windows 7 onwards), Is WPF Hardware-accelerated when Window AllowsTransparency is true?

like image 595
Meirion Hughes Avatar asked Feb 05 '14 11:02

Meirion Hughes


2 Answers

It seems that transparent windows (AllowsTransparency = true) are hardware accelerated for Windows Vista and upper: HW Acceleration of Layered Windows

There is also an hotfix to make it work under windows XP as well: http://support.microsoft.com/kb/937106/en-us

like image 160
Alberto Avatar answered Oct 07 '22 08:10

Alberto


I'll add my two cents too.

Yes, it's true. From Vista onwards, we have hardware acceleration for layered windows, and there seems to be a hotfix for XP aswell.

This is where the good news stop.

Don't try and use AllowsTransparency - trust me, there's just so much that can and WILL go wrong, despite it being hardware accelerated. Ofcourse, think about your use case: if it's simple hobby project, not an enterprise level application, then, go ahead.

Some of the problems I've personally experienced:

  • major performance, believe or not, "performance problems with AllowsTransparency" is not made up concept. Animations suck.
  • Integration with other technologies. I remember integrating DirectShow solution to a window that had AllowsTransparency true. It did not work, as DirectShow does not support rendering to a window that is layered.

This guy seems to be even talking that software rendering is sometimes faster than hardware, for layered windows, which I kind of agree. My experience has also shown that "hardware acceleration" is nothing spectacular on WPF.

I remember switching to software rendering, and saw no performance loss. In fact, I suggest to disable hardware rendering because it's complex, and it causes visual bugs, if you're targeting wide area of different configurations (XP, XP64, Vista, Win7, different video cards) - famous black spots.

By the way, VS2010 SP1 disables hardware rendering for visual studio on XP, even if it supports it. Why? "A significant number of crash reports stemming from the hardware acceleration"

That said, Visual Studio2013 does not use AllowsTransparency - correct me if I am wrong, but Snoop revealed that the main window has AllowsTransparency set false.

How can you have a custom chrome window, that is not layered & PERFORMS well? This is quite complex subject, but you can get started if you google for "WPF Custom Chrome library". I suspect VS does something similiar.

like image 37
Erti-Chris Eelmaa Avatar answered Oct 07 '22 10:10

Erti-Chris Eelmaa