简体   繁体   English

Window 的合成引擎 (DWM) 中的背景颜色伪影

[英]Background Color Artifact in Window's Composition Engine (DWM)

Context from Kenny Kerr's blog :来自Kenny Kerr 博客的上下文:

Windows Vista introduced a service called the Desktop Window Manager. Windows Vista 引入了一个名为 Desktop Window Manager 的服务。 The name was and continues to be misleading.这个名字过去和现在都具有误导性。 Think of it as the Windows composition engine or compositor.将其视为 Windows 合成引擎或合成器。 This composition engine completely changed the way application windows are rendered on the desktop.这个合成引擎完全改变了应用程序 windows 在桌面上呈现的方式。 Rather than allowing each window to render directly to the display, or display adapter, every window renders to an off-screen surface or buffer.不是让每个 window 直接渲染到显示器或显示适配器,而是每个 window 渲染到屏幕外表面或缓冲区。 The system allocates one such surface per top-level window and all GDI, Direct3D and, of course, Direct2D graphics are rendered to these surfaces.系统为每个顶层 window 分配一个这样的表面,所有 GDI、Direct3D,当然还有 Direct2D 图形都被渲染到这些表面。 These off-screen surfaces are called redirection surfaces because GDI drawing commands and even Direct3D swap chain presentation requests are redirected or copied (within the GPU) to the redirection surface.这些屏幕外表面称为重定向表面,因为 GDI 绘图命令甚至 Direct3D 交换链表示请求都被重定向或复制(在 GPU 内)到重定向表面。

At some point, independent of any given window, the composition engine decides it's time to compose the desktop given the latest batch of changes.在某些时候,独立于任何给定的 window,组合引擎会根据最新的一批更改决定是时候组合桌面了。 This involves composing all of these redirection surfaces together, adding the non-client areas (often called window chrome), perhaps adding some shadows and other effects, and presenting the final result to the display adapter.这涉及将所有这些重定向表面组合在一起,添加非客户区域(通常称为 window chrome),可能添加一些阴影和其他效果,并将最终结果呈现给显示适配器。


Background from previous SO question (see pictures) : 上一个 SO 问题的背景(见图片)

When resizing down in DirectX there is an artifact of the win32 background appearing at the right/bottom edges.在 DirectX 中调整大小时,在右/下边缘会出现 win32 背景的伪影。 This can be corrected by applying the WS_EX_NOREDIRECTIONBITMAP style.这可以通过应用WS_EX_NOREDIRECTIONBITMAP样式来纠正。 Since it doesn't matter whether the swapchain is smaller or larger than the window, it appears that without WS_EX_NOREDIRECTIONBITMAP the Composition Engine copies too small a rectangle to the Redirection Surface (because the window size lags behind the mouse position/"Drag rectangle").由于交换链比 window 小还是大都没有关系,看来没有WS_EX_NOREDIRECTIONBITMAP组合引擎将太小的矩形复制到重定向表面(因为 window 大小滞后于鼠标位置/“拖动矩形”) .


Actual Question实际问题

However, WS_EX_NOREDIRECTIONBITMAP only works for top level windows and I'm trying to embed DirectX as a child window into WPF, and the artifact from the child window's background is still coming through.但是, WS_EX_NOREDIRECTIONBITMAP仅适用于顶级 windows 并且我正在尝试将 DirectX 作为子 window 嵌入到 WPF 背景中,并且仍然来自子窗口的背景。 This leads me to some relate questions:这让我想到了一些相关的问题:

  1. (Optional) When when the swapchain is smaller than the window size, the remainder of the window is filled in black ( see pictures ). (可选)当交换链小于 window 大小时,window 的其余部分用黑色填充( 见图)。 Is this a result of the copy from the swapchain to the Redirection Surface where the remainder of the destination stride (after the source width) is zeroed out?这是从交换链复制到重定向表面的结果,其中目标步幅的剩余部分(在源宽度之后)被清零?
  2. (Optional) How is the artifact from the win32 background appearing? (可选)win32后台的神器是怎么出现的? Is the Redirection Surface filled with this color before the copy from the swapchain?在从交换链复制之前,重定向表面是否填充了这种颜色?
  3. (Optional) Are the Redirection Surfaces being resized every-time the window is resized? (可选)是否每次调整 window 的大小时都会调整重定向表面的大小?
  4. (Required) Does each child window have a Redirection Surface that in turn gets copied to the top level window's Redirection Surface. (必需)每个子 window 是否有一个重定向表面,该重定向表面又被复制到顶层窗口的重定向表面。 If not, how is the child's win32 background artifact appearing?如果没有,孩子的win32后台神器是怎么出现的?
  5. (Required) Does this mean that the frame rate a win32 window embedded into WPF is limited to WPF's variable frame rate? (必填)这是否意味着嵌入WPF的win32 window的帧率受限于WPF的可变帧率? (The purpose of embedding a DirectX window into WPF was to get a constant 60fps frame rate) (将 DirectX window 嵌入 WPF 的目的是获得恒定的 60fps 帧速率)

What I missed was that there are two paths for pixels to get to the screen我错过的是像素有两条路径到达屏幕

  1. through a Redirection Surface通过重定向表面
  2. through the Flip Presentation model通过翻转演示 model

Without WS_EX_NOREDIRECTIONBITMAP the swapchain's contents get copied over the Redirection Surface's content.如果没有WS_EX_NOREDIRECTIONBITMAP ,交换链的内容会被复制到重定向表面的内容上。 However, there is a bug when resizing down and the clipping to prevent the swapchain's contents, from extending past the window, clip too small a rectangle allowing the Redirection Surface to be seen.但是,在调整大小和剪辑以防止交换链的内容超出 window 时出现错误,将矩形剪辑得太小而无法看到重定向表面。 I realized this when I got the exact same behavior using CreateSwapChainForComposition() with DirectComposition as I got for CreateSwapChainForHwnd() .当我使用带有 DirectComposition 的CreateSwapChainForHwnd() CreateSwapChainForComposition()获得与 CreateSwapChainForHwnd() 完全相同的行为时,我意识到了这一点。

To answer my required questions: No, using the flip presentation model from a HwndHost does not limit your to WPF's refresh rate.要回答我需要的问题:不,使用来自 HwndHost 的翻转演示HwndHost不会限制您使用 WPF 的刷新率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM