JavaFX 2绘图性能 [英] JavaFX 2 drawing performance

查看:143
本文介绍了JavaFX 2绘图性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得JavaFX 2的绘图性能比Swing差。我认为原因之一是您如何绘制事物,例如绘制线条时,必须创建线条对象添加到某个容器中,而在Swing中,只获取一次Graphics2D,然后执行drawLine而不每次都创建一个新对象。因此,是否还有使用JavaFX 2进行绘制的更高效的方式,例如如果必须绘制约3000弧?最好的绘图表面是什么?目前,我正在使用 Group

I feel that the drawing performance of JavaFX 2 is worse than those of Swing. I think one of the reasons is how you draw things, e.g. when drawing a Line, one has to create a Line object for each line and add it to some container while in Swing one just gets the Graphics2D once and then does drawLine without creating a new object each time. So, is there any more performant way to draw using JavaFX 2, e.g. if you have to draw about 3000 Arcs? What's the best "drawing surface"? Currently I am using a Group. Thanks for any hint!

推荐答案

您当前使用Group的方法可能很好,并且您可能会发现其性能您的应用程序用户完全可以在组中绘制3000个弧。

Your current approach of using a Group, is likely fine, and you will probably find that the performance of drawing 3000 arcs within your Group is perfectly acceptable for your application users.

使用组的当前替代方法是使用布局窗格,该窗格将添加一些便捷的功能,但要增加一层额外的开销,当您有成千上万个易于手动放置的对象时,这是不必要的。

A current alternative to using a Group would be to use layout Panes which would add some convenient functionality, but add an extra layer of overhead, which is unnecessary when you have thousands of easily manually laid out objects.

请参见 JavaFX邮件列表档案,用于讨论即将到来的直接绘图界面(称为画布节点)对于JavaFX 2.2及其含义。

See the JavaFX mailing list archive for a discussion of an upcoming direct draw interface (called the Canvas Node) for JavaFX 2.2 and it's implications.

尽管将对象粘贴到容器中的性能似乎较低,但是容器实现可以根据需要使用加速保留模式内置的渲染硬件现代GPU。还要注意,JavaFX体系结构在内部跟踪脏区并缓存昂贵的渲染操作的结果以提高性能。因此,使用容器本身并不能暗示其性能可能比直接绘图界面慢,后者可能依赖于即时模式实现。

Although it may seem less performant to stick objects in a container, the container implementation can, if it wishes, make use of accelerated retained mode rendering hardware built into modern gpus. Also note that the JavaFX architecture internally keeps track of dirty areas and caches the results of expensive rendering operations to increase performance. Therefore, the use of a container does not, in and of itself, imply slower performance than a direct draw interface which might rely on an immediate mode implementation.

选择绘图表面将取决于应用。对于大多数JavaFX应用程序而言,最好的表面是场景图形节点而不是画布节点的集合。通常,在场景图中使用多个节点而不是使用单个Canvas节点将更容易进行开发,并且性能完全可以接受。

Choosing a drawing surface will depend on the application. The best surface for most JavaFX apps will be a collection of scenegraph nodes rather than a canvas node. Using many nodes in a scenegraph rather than a single Canvas node will (usually) be easier to develop for and the performance will be perfectly acceptable.

最终,很可能将撰写大量博客文章来比较Canvas与许多Scenegraph对象的性能,并可能与其他框架(例如html canvas,java2d,swing等)进行比较。因此,及时地,回答这个问题将变得更加容易。

Eventually, it is likely that numerous blog articles will be written to compare performance of Canvas vs many scenegraph objects and perhaps against other frameworks such as html canvas, java2d, swing, etc. So in time, it will be easier to answer such a question.

相关

Osvaldo的 JavaFX性能分析(尽管年代久远)还包括对问题中提出的一些问题的深入讨论

Osvaldo's JavaFX performance analysis, though old, also includes a in depth discussion of some of the issues raised in your question.

按照noreferrer> openjfx Wiki

There is a nice section on Performance Tips and Tricks in the openjfx wiki.

还有一些与StackOverflow JavaFX相关的性能问题:

There are some related StackOverflow JavaFX performance questions:

  • JavaFX 2 path drawing performance
  • What is the best way to display millions of images in Java?

这篇关于JavaFX 2绘图性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆