Why would you use JNI to paint on AWT's Canvas?

為{幸葍}努か 提交于 2019-12-23 11:56:56

问题


I'm pretty new to the JNI, and I stumbled across this while looking into the JNI:

Not only can native code interface with Java, it can also draw on a Java Canvas, which is possible with the Java AWT Native Interface

Is there a specific reason why this functionality was made specific/is available? Does it improve processing time on Windows system? Please elaborate why and when one would use such a feature


回答1:


Native performance rendering in Java... games would be the first thing to come to mind but really drawing anything that would be computationally intensive or that requires a high frame-rate would benefit.

Official Java Explanation:

The ability to draw directly into a Java Canvas from a native code library is extremely useful for developers planning to migrate a legacy software system to Java, especially one that includes a high-performance rendering engine. It makes it much easier to migrate in stages, leaving performance-sensitive rendering code alone, while other less-sensitive portions of code are converted to Java. The result can be a modern Java-centric application, providing the benefit of portability and development efficiency, but one that does not sacrifice an investment in performance of a key piece of native code.




回答2:


The most common use of AWT's JNI painting is 3D drawing with OpenGL or DirectX D3D. Some java 3D APIs, like Java3D and initial releases of JOGL, used Canvas.java as drawing surface. It can also be used for 2D native rendering, but Java drawings features are just enough for this task.



来源:https://stackoverflow.com/questions/24793593/why-would-you-use-jni-to-paint-on-awts-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!