Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Canvas performance

john16384Sep 2 2012 — edited Sep 6 2012
I've been testing Canvas performance on a very fast machine (quad core Xeon) with a one of the latest NVidia graphics boards, but I'm unable to render full screen 1920x1080 video with this setup using the Canvas.

Is this simply too much to hope for or am I missing some obvious performance improvements?

Here's the code I used:
import java.nio.ByteBuffer;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritablePixelFormat;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import uk.co.caprica.vlcj.component.DirectMediaPlayerComponent;

import com.sun.jna.Memory;
import com.sun.jna.NativeLibrary;

public class VLCDirectTest extends Application {

  public static void main(final String[] args) {
    Application.launch(args);
  }

  private DirectMediaPlayerComponent mp;

  @Override
  public void start(Stage primaryStage) throws Exception {
    NativeLibrary.addSearchPath("libvlc", "c:/program files (x86)/videolan/vlc");

    BorderPane borderPane = new BorderPane();
    final Canvas canvas = new Canvas(1920, 1080);
    borderPane.setCenter(canvas);
    System.out.println(">>> " + canvas.getGraphicsContext2D().getPixelWriter().getPixelFormat());
    Scene scene = new Scene(borderPane);
    final PixelWriter pixelWriter = canvas.getGraphicsContext2D().getPixelWriter();
    final WritablePixelFormat<ByteBuffer> byteBgraInstance = PixelFormat.getByteBgraInstance();

    mp = new DirectMediaPlayerComponent("RV32", 1920, 1080, 1920*4) {
      @Override
      public void display(Memory nativeBuffer) {
        ByteBuffer byteBuffer = nativeBuffer.getByteBuffer(0, nativeBuffer.size());
        pixelWriter.setPixels(0, 0, 1920, 1080, byteBgraInstance, byteBuffer, 1920*4);
      }
    };

    mp.getMediaPlayer().playMedia("L:\\test-movies\\2012.mkv");

    primaryStage.setScene(scene);
    primaryStage.show();
  }
}
It works, but it hickups and distorts a lot when it hickups. Lowering the resolution to say 1600x900 makes it almost smooth. Lowering it further gets the expected 24 frames per second.
This post has been answered by 935214 on Sep 2 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2012
Added on Sep 2 2012
9 comments
17,369 views