How to find the best PixelFormat for an Android Su

2019-02-22 19:56发布

问题:

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

回答1:

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.



回答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;
}