Mac OS X上Java 7中的慢Java2D双线性插值 [英] Slow Java2D bilinear interpolation in Java 7 on Mac OS X

查看:116
本文介绍了Mac OS X上Java 7中的慢Java2D双线性插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Mac OS X上用Java 7测试我的应用程序。它运行明显缓慢。我使用VisualVM尝试追踪瓶颈的位置,发现线性插值是罪魁祸首:

I've been testing my app in Java 7 on Mac OS X. It's running noticeable sluggish. I used VisualVM to try and track down where the bottleneck was and found linear interpolation to be the culprit:

g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

在某种程度上,这当然是有道理的。使用插值会降低速度。但是我没有看到在OS X上使用和不使用Java 6中的插值之间的这种显着差异。在Java 6中,差异几乎可以忽略不计。 (下图显示了在我的应用程序中运行标准动画后, paintComponent()的VisualVM配置文件。)

To some degree this makes sense of course. Using interpolation will slow things down. But I do not see this kind of dramatic difference between using and not using interpolation in Java 6 on OS X. In Java 6, the difference was almost negligible. (The images below represent the VisualVM profile of paintComponent() after running through a standard animation in my app.)

使用插值:

无插值:

但在OS X上的Java 7中,差异更明显:

But in Java 7 on OS X, the difference is much more noticeable:

使用插值:

无插值:

我猜测问题在于硬件加速以及从Apple到Oracle的过渡。也许Apple的Java 6使用硬件加速来进行插值,而现在Oracle的Java 7则没有。这解释了吗?有解决方案吗?我试过 sun.java2d.opengl = true

I'm guessing the issue lies in hardware acceleration and the transition from Apple to Oracle. Perhaps Apple's Java 6 was using hardware acceleration to do the interpolation and now Oracle's Java 7 is not. Does this explain it? Is there a solution? I've tried sun.java2d.opengl=true.

更新:我发现问题只出现在使用 setRenderingHints()来应用插值。如果使用其他方法插入图像,例如 AffineTransformOp ,则性能下降消失。例如:

Update: I found that the issue only appears when using setRenderingHints() to apply interpolation. If you use another method to interpolate the image, such as AffineTransformOp, then the performance drop disappears. For example:

g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
AffineTransformOp scaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
scaleOp.filter(screenSliceFiltered, screenSliceFilteredScaled);


推荐答案

我觉得你已经敲了敲头。 Apple很可能提供了JVM杠杆硬件加速。您可能会询问Mac端口子项目的 Porters group 邮件列表。 OpenJDK。

I think you've hit the nail on the head. In all likelihood the Apple provided JVM leveraged hardware acceleration. You might ask over on the Porters group mailing list of the Mac Port sub-project of OpenJDK.

这篇关于Mac OS X上Java 7中的慢Java2D双线性插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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