启用桌面组合时是否需要双缓冲?

发布于 2024-08-13 07:18:44 字数 1006 浏览 9 评论 0原文

启用桌面合成后还需要双缓冲吗?

在 Microsoft 的应用程序兼容性指南中:

图形设备接口 (GDI)

Windows Vista 和 Windows 之前的版本 Server 2008,窗口句柄(HWND) 直接绘制到屏幕上, 这有一定的好处,但是 限制 Windows 的显示方式和 管理顶级窗口。在 Windows 中 Vista 和 Windows Server 2008,全部 顶层窗口被渲染为 离屏位图(类似于 WS_EX_LAYERED) 和桌面窗口 经理将图像组合在一起 绘制桌面。

听起来所有渲染现在都是在离屏位图上完成的:

窗口被渲染为离屏位图

这是正确的吗?

我问的原因是因为我在标准绘画周期中仍然看到闪烁:

  • WM_ERASEBKGND
  • WM_PAINT

,同时启用桌面合成:

替代文字

我假设在调用之间

   BeginPaint(hWnd, paintStructure);
   ...
   EndPaint(hWnd, paintStructure);

所有绘画都会发生在后台缓冲区:

窗口被渲染为离屏位图

,同时前端缓冲区将不受影响。

Is double-buffering still required when Desktop Composition is enabled?

In Microsoft's Application Compatibility Guide:

Graphical Device Interface (GDI)

Prior to Windows Vista and Windows
Server 2008, a window handle (HWND)
was painted directly to the screen,
which had certain benefits, but
limited how Windows could display and
manage top-level windows. In Windows
Vista and Windows Server 2008, all
top-level windows are rendered to an
off-screen bitmap (similar to
WS_EX_LAYERED), and the Desktop Window
Manager combines the images together
to draw the desktop.

It sounds like all rendering is now done to an off-screen bitmap:

windows are rendered to an off-screen bitmap

Is this correct?

The reason i ask is because i still see flickering during the standard paint cycle:

  • WM_ERASEBKGND
  • WM_PAINT

while desktop composition is enabled:

alt text

i would have assumed that between the calls to

   BeginPaint(hWnd, paintStructure);
   ...
   EndPaint(hWnd, paintStructure);

that all painting would happen to a back buffer:

windows are rendered to an off-screen bitmap

Meanwhile the a front buffer would stay unaffected.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜`诱少女 2024-08-20 07:18:44

这是正确的吗?

是的(这就是缩略图如何向您显示当前被遮挡的窗口部分的方式)。

DWM 的屏幕渲染是双缓冲的。然而,如果它在擦除和绘画之间占据了你的缓冲区......它将显示为可见的人工制品。所以你仍然需要双缓冲。双缓冲发生在桌面上(即,它完全绘制下一个桌面视图,然后翻转),而不是在每个窗口绘制到的屏幕外缓冲区上。

Is this correct?

Yup (which is how the thumbnails can show you parts of the window that are currently obscured).

DWM's rendering of the screen is double-buffered. However, if it grabs your buffer betewen erasing and painting... it's going to show up as a visible artefact. So you still need to double buffer. The double buffering occurs on the desktop (i.e. it draws the next desktop view completely and then flips), not on the off-screen buffers that each window is drawn to.

jJeQQOZ5 2024-08-20 07:18:44

好吧,绘制到离屏位图只是使 DWM 能够按照自己的意愿组合窗口,而无需等待应用程序重新绘制(例如,当您将窗口移到另一个窗口上时,在 XP 中就是这种情况)。

这并不意味着绘制到屏幕外的表面会自动减少闪烁。如果您擦除窗口,然后重新绘制它,并且在这两个操作之间,DWM 重新绘制屏幕(每秒大约执行 60 次),那么您当然会看到闪烁。

它确实解决了应用程序重绘速度不够快时的“白窗口”问题,并且还减少了由于重叠窗口而导致的重绘。但它无助于防止闪烁。 DWM 无法知道您的绘制操作尚未完成,并且您希望在再次绘制内容之前显示窗口的旧图像。

Well, painting to an off-screen bitmap just enables the DWM to composite the windows as it likes to without having to wait for the application to redraw (as is the case in XP when you move windows over another, for example).

This does not mean that drawing to that off-screen surface automagically reduces flickering. If you erase the window and then redraw it and between both actions the DWM redraws the screen (which it does around 60 times per second), then of course you will see flickering.

It does solve the "white windows" problem when an application doesn't redraw fast enough and it also reduces redraw due to overlapping windows. But it doesn't help against flickering. The DWM has no way of knowing that your paint operation wasn't complete yet and that you wish to have the old image of the window displayed until after you have drawn the contents again.

年华零落成诗 2024-08-20 07:18:44

这在 Windows 10(至少 1903 年)中发生了变化。

启用 DWM 后,默认情况下所有内容都已正确双缓冲。即使以最基本的方式移动和调整控件大小,重新绘制/调整大小也不会闪烁。

现在,DWM 似乎仅在绘制完成后才显示新的位图,而不是在此之前。

This has changed in Windows 10 (1903, at least).

When DWM is enabled, everything is properly double-buffered now by default. There is no flicker on repaint/resize, even when moving and resizing controls in the most basic way.

The DWM now appears to only present a new bitmap once painting has finished, and not before.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文