Search code examples
androidsurfaceview

How to find the best PixelFormat for an Android SurfaceView


I have found that changing the pixel format in a SurfaceView has a large impact on frame rates. However I can't seem to find a way to select the best format on a per device basis.

Example:

@Override
public void surfaceCreated(final SurfaceHolder holder) {
    //This line seems to fix speed issue with his res devices
    holder.setFormat(PixelFormat.RGBA_8888);
    androidGame.setSurfaceHolder(holder);
}

This causes my game to run much faster on a Galaxy Nexus (ICS 4.0) but Slow on a Motorola Xoom (3.2.1).

If I change to PixelFormat.OPAQUE the situation reverses. The Nexus is slow and the Xoom is now fast. So I need to be able to determine the best format per device. I have tried using getWindow().getAttributes().format but this always returns -1 (OPAQUE).


Solution

  • I was able to talk to Romain Guy at Google IO 2012 during office hours. Unfortunately there is no reasonable way to detect the best pixel format to use. You would have to run a benchmark test on each device to find it's best format.