This discussion is archived
2 Replies Latest reply: Jun 9, 2010 5:18 PM by 843853 RSS

linux, framebuffer, no X, swing

843853 Newbie
Currently Being Moderated
When running a Java/Swing application on Linux, using X, I'm experiencing poor performance. This is partly caused by X. I'm therefore wondering if there is a possibility to directly use the video memory.

With java NIO you can map a file into a buffer and write directly to this buffer. You can force Swing to paint in this buffer.

Mapping to a normal file works, but mapping to /dev/fb0 fails. The size of this device file is 0.

Is there anybody who has tried the same thing? Or is there someone who runs a Java/Swing appication on Linux without X in some other way ?

Test program:
import java.nio.*;
import java.nio.channels.*;
import java.io.*;

public class MemoryMapTest {
    
    static String filename;
    
    public MemoryMapTest() {
        RandomAccessFile memFile;
        try {
            memFile = new RandomAccessFile(filename, "rw");
            FileChannel fileChannel = memFile.getChannel();
            try {
                MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 800);
                for (int i = 0; i < 800; i++) {
                    byte val = (byte)(255 - i);
                    buffer.put(i, val);
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            try {
                fileChannel.close();
                memFile.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
        
    }
    
    public static void main(String argv[]) {
        if (argv.length > 0) {
            filename = argv[0];
        } else {
            filename = "memfile";
        }
     new MemoryMapTest();
    }
}