简体   繁体   English

setCache()和CacheHint如何在JavaFX中协同工作?

[英]How do setCache() and CacheHint work together in JavaFX?

With regard to JavaFX, I have the following questions: 关于JavaFX,我有以下问题:

  1. Do I need to use setCache(true) on a Node for a cache hint set by setCacheHint() to actually have any effect? 我是否需要在Node上使用setCache(true)来设置由setCacheHint()设置的缓存提示才能实际产生任何效果?

  2. Should calling setCache actually improve performance ie frame rate some or most of the time? 是否应该调用setCache实际上提高性能,即帧速率的某些时间或大部分时间? I am unable to observe any change in frame rate when I use setCache(true) and I apply scaling and other transforms. 当我使用setCache(true)并且我应用缩放和其他变换时,我无法观察到帧速率的任何变化。

Do I need to use setCache(true) on a Node for a cache hint set by setCacheHint() to actually have any effect? 我是否需要在Node上使用setCache(true)来设置由setCacheHint()设置的缓存提示才能实际产生任何效果?

Yes. 是。

The cache property is a hint to the system whether the node rendering should be cached (as an internal image) at all or not. 缓存属性是系统提示是否应该缓存节点渲染(作为内部图像)的提示。

The cacheHint property is a hint to the system of what transforms are expected on the node so that the caching operation can be optimized for those transform types, (eg the cache hints rotate, scale or speed, etc). cacheHint属性向系统提示节点上预期的变换,以便可以针对那些变换类型优化高速缓存操作(例如,高速缓存提示旋转,缩放或速度等)。

If the node is not set to be cached at all, the cacheHint is irrelevant. 如果节点根本没有设置为高速缓存,则cacheHint无关紧要。

Should calling setCache actually improve performance ie frame rate some or most of the time? 是否应该调用setCache实际上提高性能,即帧速率的某些时间或大部分时间?

Not necessarily. 不必要。 JavaFX has a default frame rate cap of 60fps, so if performance is good enough that the frame rate is reached even without any cache hints, you won't see any visible difference. JavaFX的默认帧速率上限为60fps,因此如果性能足够好,即使没有任何缓存提示也达不到帧速率,您将看不到任何明显的差异。 This is the case for many basic animations and transforms. 这是许多基本动画和变换的情况。

Even if frame rate is not improved, the cache hint may make each transform a bit more efficient to perform so that it is less CPU or GPU intensive (usually by trading visual quality). 即使帧速率没有提高,缓存提示也可以使每个变换的执行效率更高,从而减少CPU或GPU密集度(通常通过交易视觉质量)。

There may be other things which have a far greater impact on your frame rate. 可能还有其他因素会对您的帧速率产生更大的影响。 These things may have nothing to do with rendering speed of cacheable items (for example a long running operation executed on the JavaFX application thread during a game loop or constantly changing node content). 这些事情可能与可缓存项的渲染速度无关(例如,在游戏循环期间在JavaFX应用程序线程上执行的长时间运行操作或不断变化的节点内容)。


I have used a combination of setCache(true) and setCacheHint(CacheHint.SPEED) in small games I have written that featured multiple simultaneously animated nodes with multiple effects and translucency applied to the nodes. 我在我编写的小游戏中使用了setCache(true)setCacheHint(CacheHint.SPEED)的组合,其中包含多个同时动画节点,其中多个效果和半透明应用于节点。 The settings did speed things up a lot (Mac OS X, Macbook Air 2012, Java FX 2.2). 这些设置确实加快了速度(Mac OS X,Macbook Air 2012,Java FX 2.2)。


Rather than relying on hints to the rendering system, you can also manually take a snapshot of a node tree and manually replace the node tree with the snapshot Image. 您还可以手动获取节点树的快照 ,并使用快照Image手动替换节点树,而不是依赖于渲染系统的提示。 This snapshot technique is not always the best way to go, but it does give you an alternative if the hints aren't working out well in your case. 这种快照技术并不总是最好的方法,但如果提示在您的情况下效果不佳,它确实可以为您提供替代方案。

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

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