How to find the best PixelFormat for an Android SurfaceView

丶灬走出姿态 提交于 2019-12-01 17:36:46

问题


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


来源:https://stackoverflow.com/questions/8829943/how-to-find-the-best-pixelformat-for-an-android-surfaceview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!