WPF 中的 StackPanel 性能不佳
我有一个在高分辨率显示器(1920x1080)上全屏运行的应用程序。 大约 25% 的屏幕是 StackPanel
,用于在屏幕上滚动图像。 (X 位置使用双动画进行动画处理)
滚动非常滞后和跳跃,并且有明显的撕裂。 它运行在一台全新的高端游戏笔记本电脑上,运行 Win7 64 位。
我不明白为什么性能这么差。我做错了什么吗?这种动画是在CPU上运行还是在GPU上运行?有没有更智能的方法在屏幕上滚动图像?
I have an application which runs fullscreen on a high resolution display (1920x1080).
About 25% of the screen is a StackPanel
that scrolls images across the screen.
(the X position is animated with double animation)
The scroll is very laggy and jumpy, and with visible tearing.
This is running on a brand new high-end gaming laptop, running Win7 64bit.
I don't understand why the performance is so poor. Am I doing something wrong? Does this kind of animation run on the CPU or GPU? Is there a smarter way to scroll images across the screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WPF 可以进行硬件加速,但仅限于较新的显卡驱动程序。一些板载的开箱即用驱动程序将默认返回软件渲染,这可能会让人感觉非常缓慢和笨重。至于撕裂,这是正常的显卡设置,称为垂直同步。我会尝试将显卡驱动程序更新为专有驱动程序(nVidia、AMD 等),并在卡上启用垂直同步。
您可以使用解释的方法检查它是否属于软件渲染或硬件渲染此处。
如果这不能解决问题,我能想到的唯一其他可能性是您的动画/渲染未同步到 GUI。
请参阅此 msdn 文章了解更多详细信息。
WPF can be hardware-accelerated, but only on newer video card drivers. Some of the onboard, out of box drivers, will default back to software rendering, which can feel really slow and clunky. As for the tearing, that's a normal video card setting, called V-Sync. I would try updating the video card drivers to a proprietary driver (nVidia, AMD, etc.), and enabling vertical sync on the card.
You can check to see if it falls into software, or hardware rendering using the methods explained here.
If that doesn't resolve the issue, the only other possibility I can think of is your animation/rendering is not synced to the GUI.
See this msdn article for more details.
我见过的一个可以解决这个问题的技巧是在页面上放置一个 3D 对象,从侧面查看它并旋转它,例如 4 个图像有一个立方体,每侧都有一个图像。
是的,旋转仍然需要 GPU 和处理器时间,但它是由 WPF 动画在内部处理的,因此一旦设置滚动,不需要与后面的代码进行交互。
A trick that I've seen that can get around this issue is to place a 3D object on your page, view it side on and rotate it e.g. for 4 images have a cube with an image set to each side.
Yes the rotation still requires GPU and processor time but it is taken care of internally by the WPF animation and so doesn't require interaction with code behind once set rolling.