简体   繁体   English

Windows中的蒙皮引擎:仅绘制“脏”区域还是一次绘制整个窗口?

[英]A skinning engine in Windows: draw “dirty” regions only or the whole window at once?

I want to make a skinning engine capable of drawing custom-shaped windows with alpha blending. 我想制作一个能够通过alpha混合绘制自定义形状窗口的蒙皮引擎。 That is, it'll use layered windows ( UpdateLayeredWindow ). 也就是说,它将使用分层窗口( UpdateLayeredWindow )。 A typical window will contain among its background a couple dozens of other bitmaps ranging from 10×10 to, say, 300×150 pixels. 一个典型的窗口将在其背景中包含数十个其他位图,范围从10×10到300×150像素。 In the worst case most of these elements will have smooth animation up to 30 fps. 在最坏的情况下,大多数这些元素将具有高达30 fps的平滑动画。 Everything will be alpha-blended and I am going to use Direct2D for this (yes, I know older Windows versions doesn't support it). 一切都将进行alpha混合,为此,我将使用Direct2D(是的,我知道较早的Windows版本不支持它)。 In general, Winamp's modern skin engine is the closest example. 通常,Winamp的现代皮肤引擎是最接近的例子。

Given all this and taking in account modern PCs performance, can I just redraw the whole window every single frame or do I have to constrain to some sort of clip rectangle? 考虑到所有这些因素,并考虑到现代PC的性能,我是否可以仅在每帧中重绘整个窗口,还是必须限制在某种剪辑矩形中?

D2D required you to render with WM_Paint messages Honneslty, use The IAnimation interface, and just let D2D and windows worry about how often to redraw , though i will let you know , winamp is done with adobe air, and layerd windows with d2d causes issues. D2D要求您使用WM_Paint消息渲染Honneslty,使用IAnimation界面,只是让D2D和Windows担心重绘的频率,尽管我会让您知道,winamp是用Adobe Air完成的,而使用d2d的分层窗口会引起问题。 (Kinda think you have to use a DXGI render target, but with the window being layerd it needs a DC to be returned to an end paint call so it can update it's alpha channel) (Kinda认为您必须使用DXGI渲染目标,但是将窗口分层时,需要DC才能返回到结束绘制调用,以便可以更新其Alpha通道)

I have some experience with this. 我对此有一些经验。

If you need to support Windows XP, using UpdateLayeredWindow is the only choice available for solving this problem. 如果需要支持Windows XP,则使用UpdateLayeredWindow是解决此问题的唯一选择。 The documentation for this call says it copies the whole bitmap to the screen each time it is called and this bottleneck showed up in my benchmarking as the real limiting factor. 该调用的文档说,每次调用都会将整个位图复制到屏幕上,而这个瓶颈在我的基准测试中显示为真正的限制因素。 If your window is 300x300 you pay that price on every update, even if you are careful to modify only a couple of pixels. 如果您的窗口是300x300,则即使您只修改几个像素,也要为每次更新支付该价格。 It would be very easy to over-optimize the rendering side for no real benefit so implement something simple, measure, and then decide if you need to optimize. 过度优化渲染方面并没有真正的好处是非常容易的,因此请实施一些简单的措施,然后确定是否需要优化。

If you can drop support for Windows XP then you can avoid UpdateLayeredWindow completely and use DwmExtendFrameIntoClientArea to create the same effect as a layered window. 如果可以放弃对Windows XP的支持,则可以完全避免UpdateLayeredWindow,并使用DwmExtendFrameIntoClientArea创建与分层窗口相同的效果。 You'll write less code, avoid the UpdateLayeredWindow bottleneck, and D2D will be easier to work with. 您将编写更少的代码,避免出现UpdateLayeredWindow瓶颈,并且D2D会更易于使用。

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

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