Graphics.Draw*、AutoScroll 和剔除
我在 C#/Winforms 中实现了一个自定义控件,它可以执行诸如语法突出显示和语法突出显示之类的操作。自动完成。我使用 AutoScroll 来管理滚动,效果很好。
目前我根本没有优化(当然优化很重要,但我最后才做;功能是我首先追求的),我正在渲染巨大的文档,每次按键都会重新解析受影响的行以确保语法高亮是一致的。
现在,在我的大型绘制方法中,我正在绘制每个字符串、关键字等,即使它位于剪辑区域之外。但无论文档有多大&有多少种关键字/突出显示位的组合我拥有的部分,它仍然运行得非常快,没有太多的内存和内存。 CPU 开销。
所以我的问题 - Graphics.Draw* 方法是否会进行任何类型的剔除?例如:如果 AutoScrollPosition 位于文档的下方,则我 Graphics.DrawString(在绘图区域之外插入一些坐标),是否正在完成任何实际工作?另请注意,我在 VM 内的 Win 7 上运行 VS,并且它仍然运行得很快。现在这并不是一个问题,但在以后优化阶段时最好记住这一点。 :D
干杯, 亚伦
I've implemented a custom control in C#/Winforms which does things like syntax highlighting & autocomplete. I'm using AutoScroll to manage scrolling and it works nicely.
Currently I have not optimized at all (sure optimization is important, but I'm doing that last; functionality is what I'm after first), I am rendering huge documents, and each keypress will re-parse the affected line to make sure syntax highlighting is consistent.
Right now in my big meaty paint method, I am painting every string, keyword, etc, even if it is outside of the clip region. But regardless of how big the document is & how many combinations of keywords/highlighted bits & pieces I have, it still runs bloody fast with not much memory & CPU overhead.
So my question - do the Graphics.Draw* methods do any kind of culling? Eg: If the AutoScrollPosition is way down the document & I Graphics.DrawString(insert some coordinates outside the draw region), is any actual work being done? Also note I'm running VS on Win 7 inside a VM, and it is still running fast. Not that it's an issue now, but it would be nice to keep in mind for later when it comes to the optimization phase. :D
Cheers,
Aaron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据编写使用 Graphics.Draw* 方法的游戏的个人经验,如果您在调用绘图方法之前执行自己的边界检查,您会注意到速度有所提高。
尝试在屏幕外绘制内容比在屏幕上绘制内容要快,但仍然比根本不绘制要慢得多。
From personal experience writing games that use Graphics.Draw* methods, you will notice a speed increase if you perform your own bounds checking before calling the drawing methods.
Attempting to draw things offscreen is faster than drawing things onscreen, but its still noticeably slower than not drawing them at all.
我想建议使用WPF代替Winform,性能更好等等。
I would like to suggest to use WPF instead Winform, better performence and so on.