5

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).

theJosh
  • 2,894
  • 1
  • 28
  • 50

2 Answers2

6

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.

theJosh
  • 2,894
  • 1
  • 28
  • 50
2

Display.getPixelFormat() will get the pixel format for you're display. I would recommend doing it that way.

This method is no longer supported and will always return RGBA_8888.

/**
 * Gets the pixel format of the display.
 * @return One of the constants defined in {@link android.graphics.PixelFormat}.
 *
 * @deprecated This method is no longer supported.
 * The result is always {@link PixelFormat#RGBA_8888}.
 */
@Deprecated
public int getPixelFormat() {
    return PixelFormat.RGBA_8888;
}
z3ntu
  • 190
  • 7
  • 20
nmjohn
  • 1,432
  • 7
  • 16
  • Display.getPixelFormat() returns 5 on the Galaxy Nexus and Doesn't match any constants of PixelFormat. – theJosh Jan 13 '12 at 02:49
  • Not sure how to help you if your device isn't returning proper values. I guess you can put in a specific case to detect for that device and use the one that's fastest for it. – nmjohn Jan 13 '12 at 04:50
  • @nmjohn According to this post, the returned 5 is actually BGRA_8888, and it would be interesting to see if this suggestion actually had good performance. http://stackoverflow.com/questions/11949709/confused-about-pixelformat – Jay Snayder Apr 04 '14 at 10:09