views:

351

answers:

3

Hello Guys,

I am a little surprised that JavaFX do consume my CPU by showing simple floating text on a screen.

My question is there any option tweaks to turn on hardware acceleration for nodes like Text? To Use GPU and not CPU when rendering 2D primitives?

Here is the simple example that consume up to 40% cpu on my 2.53Mhz core 2 duo + Nvidia 9600M GT. OS: Mac Os X. JavaFX 1.2; JRE 1.5

Edit: I put animation in the example to just simulate text scrolling. You can try and achieve the same CPU consuming by scrolling ListBox or some picture with no stopping.

package text2dacceleration;

import javafx.stage.Stage;

import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.transform.Transform;
import javafx.scene.text.Text;
import javafx.animation.*;

def longLine = for (i in [1..45]) "{i}";
def textNodes = for (i in [1..64]) Text{content: "{longLine} line number {i}"};
var yoffset = 0.0;

Timeline {
   repeatCount: Timeline.INDEFINITE
   autoReverse: true
   keyFrames: [
      KeyFrame { time: 0s values: [yoffset => 0.0]}
      KeyFrame { time: 1s values: [yoffset => 10.0]}]
}.play();

Stage {
    title: "Text nodes"
    width: 800
    height: 600
    resizable: false
    scene: Scene {
       content: [
         VBox {
            content: textNodes
            transforms: bind Transform.translate(0, yoffset);
         }]}}
A: 

Have you played with Timeline's framerate variable? Lowering that might help.

(The framerate description: The maximum framerate at which this animation will run, in frames per second.)

Probably won't have an impact but KeyFrame has a "canSkip" option.

Refactor
Frame rate is good. Everything is smooth as it supposed to be. But why consume CPU and not GPU?
Mykola Golubyev
(WinXP run, Java FX 1.2, Java 1.6) If the mouse is moving on the window, framerate, even of 10, seems to make little difference. High cpu. If mouse is off window, cpu runs less, and lower with lower framerates. This suggest to me that the issue really is not the rendering of the frames.
Refactor
Putting all the text into a single Text node and displaying that still has the same CPU problem when the mouse moves over the window (though the image, on my system is definitely smoother, even at framerate of 10.). blocksmouse: true makes no difference.
Refactor
Replacing Text with Labels slightly reduce CPU. Probably because of the default font or font settings Labels use. Moving mouse very quickly over text nodes consume up to 100% CPU (of one core) on windows XP.
Mykola Golubyev
A: 

Sun did a lot of work on this starting at 1.5 and through 6 but I don't know how much of it filtered through to Apple's JRE implementation. For comparison is it possible for you to update to a newer JRE such as 1.6? If you can't run the latest version of OSX and therefore can't do you have a Windows machine available on boot camp or whatever it might be worth trying one of the later Sun reference ones to see how you get on.

It might also be worth a post to the JavaFX forum - http://forums.sun.com/forum.jspa?forumID=932

Sun are usually pretty good at responding to these.

I ran this sample on the WinXp with similar Hardware characteristics and achieve almost the same result when put the mouse on the text.
Mykola Golubyev
A: 

VBox { cache: true content: textNodes transforms: bind Transform.translate(0, yoffset); ...

--

cache: A performance hint to the system to indicate that this Node should be cached as a bitmap.

Good one! But as I mentioned the sample just to simulate text scrolling, so text elements will be changed all the time while text is scrolling.
Mykola Golubyev