Question

I'm painting a rather complex "image" (which often needs to be refreshed and has many drawing primitives) in a WPF window by overriding the OnRender method of a separate UIElement and using the DrawingContext to directly draw the primitives.

My question is, what exactly happens behind the scenes? As far as I understand this is not using the retained mode (which would be the case if I were placing Shapes into the control). I'm asking the question because I am anxious that drawing like this will actually just use GDI+ at the back which brings with its own problems (e.g. printing stuff drawn with GDI+ has already cost us time and effort).

Are there any good resources (besides the obvious MSDN resources which haven't seemed to be able to enlighten me?

Or have I got everything completely wrong?

Thanks for any answers pointing me in the right direction. [edit: spelling]

Was it helpful?

Solution

You are still using retained mode, you're just not using high level objects (no animating objects, etc..), but instead simple points, lines, etc..

I've dug into the sources of DrawingContext and from what I can tell, it seems to be pushing all those DrawXYZ commands into a queue using some low-level wizardry (the queue itself consists of arbitrarily sized structs, each denoting a certain command).

WPF then processes this queue on another thread, denoted the rendering thread in this question. I haven't verified this, but I'm guessing that WPF uses the StreamingContext for all its drawing.

Furthermore, WPF is using DirectX for rendering, as can be seen by this bogpost, which takes a better look at what WPF actually does.

I hope this clarifies things for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top