Jump to content

  • Log In with Google      Sign In   
  • Create Account


Windows Desktop Manager


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Ryan_001   Prime Members   -  Reputation: 1207

Like
0Likes
Like

Posted 08 October 2012 - 08:28 PM

Since Windows Vista all drawing to the screen has been done using the WDM. To my knowledge this creates a texture/back buffer on the video card for each top level window, and then uses these textures for compositing the final image we see. I've scoured MSDN (in particular here: http://msdn.microsof...0(v=vs.85).aspx and http://msdn.microsof...0(v=vs.85).aspx) and google, but cannot find the answers to a few basic questions.

Is there any way I can get direct access to the texture/back buffer for a particular window? The documentation seems to imply Direct3D applications write directly to this texture, but there's no documentation about it, or any description on the details. What happens when a window is resized? How does it handle double buffering/swap chains? How do I enable per-pixel transparency (which it should be able to do in real-time without the Layered Windows mess)? How do Layered Windows integrate into this?

If I can get direct access to the texture, is there any way to render to it via OpenGL, or am I stuck with Direct3d?

I know are kinda esoteric questions, but any links, documents, or thoughts are appreciated.

Thanks in advance and Happy Thanksgiving/Columbus day Posted Image

Sponsor:

#2 slicksk8te   Members   -  Reputation: 190

Like
0Likes
Like

Posted 09 October 2012 - 11:19 AM

First you can use OpenGL or Direct3D to do transparency and pixel manipulation. They give direct almost direct access to the texture.

Is there any way I can get direct access to the texture/back buffer for a particular window?


What do you need this for? Because the answer may be different based on what you require.
This is because transparency, and psuedo-direct pixel manipulation can be achieved in OpenGL, Direct3D, and GDI.

What happens when a window is resized? How does it handle double buffering/swap chains? How do I enable per-pixel transparency (which it should be able to do in real-time without the Layered Windows mess)? How do Layered Windows integrate into this?


All of these questions depend on what technology you are talking about.

#3 Ryan_001   Prime Members   -  Reputation: 1207

Like
0Likes
Like

Posted 09 October 2012 - 01:53 PM

First you can use OpenGL or Direct3D to do transparency and pixel manipulation. They give direct almost direct access to the texture.


Cool... how?


Is there any way I can get direct access to the texture/back buffer for a particular window?


What do you need this for? Because the answer may be different based on what you require.
This is because transparency, and psuedo-direct pixel manipulation can be achieved in OpenGL, Direct3D, and GDI.


Well for transparency (which you mentioned can be achieved without needing direct access), but also my other two questions remain. What happens when a window is resized? How does it handle double buffering/swap chains? For example is the back-buffer in a Direct3D swap chain the WDM texture? Does it blit from the swap chain to the WDM texture on Present()? It just seems I can save a fair amount of memory/time/hassle by rendering directly to the WDM texture and bypassing the rest of it.

#4 slicksk8te   Members   -  Reputation: 190

Like
0Likes
Like

Posted 09 October 2012 - 03:20 PM

What happens when a window is resized?


If you are working with DirectX you need to reinitialize the surface just as you initialized it but with a different resolution. Typically though in DirectX the window is static size and cannot be re-sized. OpenGL is about the same as DirectX in this respect because they both need to reinitialize the buffers and that is left to the programmer. If you are using the GDI however, you do not need to worry about any of the resizing because the OS will handle the surface (HDC) for you. To use transparent textures with GDI, check out AlphaBlend or TransparentBlit.

How does it handle double buffering/swap chains? For example is the back-buffer in a Direct3D swap chain the WDM texture? Does it blit from the swap chain to the WDM texture on Present()?


The swap chain is not the WDM texture but instead a secondary buffer. When you call Present, it copies this to the WDM Texture. This is a good thing because it forces windows to stay inside their drawing regions.

It just seems I can save a fair amount of memory/time/hassle by rendering directly to the WDM texture and bypassing the rest of it.


The amount of memory you are saving is very low on modern systems and will give you very very little gain. I would expect that it would take much more time/hassle to draw directly to the WDM texture because you would have to do all the drawing functions from scratch.

#5 Ryan_001   Prime Members   -  Reputation: 1207

Like
0Likes
Like

Posted 09 October 2012 - 11:58 PM


What happens when a window is resized?


If you are working with DirectX you need to reinitialize the surface just as you initialized it but with a different resolution. Typically though in DirectX the window is static size and cannot be re-sized. OpenGL is about the same as DirectX in this respect because they both need to reinitialize the buffers and that is left to the programmer. If you are using the GDI however, you do not need to worry about any of the resizing because the OS will handle the surface (HDC) for you. To use transparent textures with GDI, check out AlphaBlend or TransparentBlit.


I think you've missed the point, maybe I'm not being clear. I know what I have to do when a resize occurs with Direct3D/OpenGL. I'd like to know how the WDM handles a resize internally. There's seems to be little point in setting up a swap chain (and the buffers associated with it) and reintializing every time the window is resized when a simple device->SetRenderTarget(0,GetWDMTexture()); or equivalent would seem to suffice (I understand that swap chains handle a few other situations like multi-sampling and double/triple buffering which would have to be performed 'manually' if this technique were possible/used). Also I'm not interested in how to do transparency using GDI code, but rather how do I render with Direct3D/OpenGL to the WDM texture such that the alpha channel is preserved and causes the appropriate pixels on my window to be translucent?


How does it handle double buffering/swap chains? For example is the back-buffer in a Direct3D swap chain the WDM texture? Does it blit from the swap chain to the WDM texture on Present()?


The swap chain is not the WDM texture but instead a secondary buffer. When you call Present, it copies this to the WDM Texture. This is a good thing because it forces windows to stay inside their drawing regions.


This is probably true when not using the WDM, but when using the WDM each window has its own unique texture which is rendered to the screen by a pair of triangles (ie. a quad) with the texture mapped to it. Regardless of where on the sceen the window is, the WDM texture is the same. You couldn't render outside the drawing region without rendering outside the WDM texture regardless of a Windows position/placement on screen.

#6 krippy2k8   Members   -  Reputation: 642

Like
0Likes
Like

Posted 10 October 2012 - 01:25 AM

Basically, no you can't do what you want. Though I admit I can not say that I am 100% of certain of that (though I AM sure that you can't do it all), I am pretty sure. Some food for thought, some of which will answer some of your questions, and some of which may be useful to help you in your quest if you continue to pursue it:

1) It's DWM (Desktop Window Manager) not WDM. Not being pedantic, just thought it might help your searches if you use the right terminology ;)

2) When you setup a swap chain in Direct3D windows mode, DirectX coordinates with DWM to provide the surface that you are rendering to, which is the DWM surface. This is a video memory surface that is owned by DWM.exe but which is shared across process boundaries by virtue of the WDDM (Windows Display Driver Model). When you Present, the DWM is notified that the surface is "dirty" so it can be recomposited on the primary surface.

3) Preserving the alpha values would not help you do what you want anyway, because you don't have control of the shaders that are used when compositing your window on the primary surface.

#7 Ryan_001   Prime Members   -  Reputation: 1207

Like
0Likes
Like

Posted 10 October 2012 - 03:08 AM

Basically, no you can't do what you want. Though I admit I can not say that I am 100% of certain of that (though I AM sure that you can't do it all), I am pretty sure. Some food for thought, some of which will answer some of your questions, and some of which may be useful to help you in your quest if you continue to pursue it:

1) It's DWM (Desktop Window Manager) not WDM. Not being pedantic, just thought it might help your searches if you use the right terminology ;)


Ahh sorry, late night posting bites me again :) You are correct.

2) When you setup a swap chain in Direct3D windows mode, DirectX coordinates with DWM to provide the surface that you are rendering to, which is the DWM surface. This is a video memory surface that is owned by DWM.exe but which is shared across process boundaries by virtue of the WDDM (Windows Display Driver Model). When you Present, the DWM is notified that the surface is "dirty" so it can be recomposited on the primary surface.


Ya, I read that. I was unsure of how much of the 'swap chain' was shared, and how they interacted.

3) Preserving the alpha values would not help you do what you want anyway, because you don't have control of the shaders that are used when compositing your window on the primary surface.


True, the shaders though must allow some sort of transparency. I don't really see any reason for them to not use the alpha channel... I'm not saying your aren't correct (the devs at Microsoft have done weirder things), but it still would seem strange.

There's just so little documentation about the DWM in the MSDN library, I was hoping someone here might have seen, read, or heard something I hadn't. Even Raymond Chen said on his blog: "Yes, there's a new desktop window manager, but no, I don't know any more about it than you do" (and I thought he knew everything there was to know about Windows).

#8 jbadams   Senior Staff   -  Reputation: 16993

Like
0Likes
Like

Posted 10 October 2012 - 03:38 AM

Raymond Chen also regularly recommends you to stick to well documented public APIs rather than relying on implementation details not meant for external usage.

The specifics of how the DWM operates aren't documented on purpose because they're implementation details that might change at any time and break any software that relies on them.


Do you really want to trade-off the potential that an update may break your software without prior notice in exchange for a small performance gain that may or more not actually be achievable? It may well be possible to do what you're thinking about, but that doesn't make it a good idea.

//EDIT: If you're just investigating out of curiosity then I wish you luck in your search, but if you're writing production software please don't inflict the world with more fragile software that might suddenly stop working.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS