【问题标题】:How to find the best PixelFormat for an Android SurfaceView如何为 Android SurfaceView 找到最佳的 PixelFormat
【发布时间】:2016-06-26 22:53:06
【问题描述】:

我发现更改 SurfaceView 中的像素格式对帧速率有很大影响。但是,我似乎无法找到一种方法来为每台设备选择最佳格式。

例子:

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

这导致我的游戏在 Galaxy Nexus (ICS 4.0) 上运行得更快,但在摩托罗拉 Xoom (3.2.1) 上运行缓慢。

如果我更改为 PixelFormat.OPAQUE,情况就会逆转。 Nexus 很慢,而 Xoom 现在很快。所以我需要能够确定每个设备的最佳格式。我尝试过使用 getWindow().getAttributes().format 但这总是返回 -1 (OPAQUE)。

【问题讨论】:

    标签: android surfaceview


    【解决方案1】:

    我能够在办公时间在 Google IO 2012 上与 Romain Guy 交谈。不幸的是,没有合理的方法来检测要使用的最佳像素格式。您必须在每台设备上运行基准测试才能找到最佳格式。

    【讨论】:

      【解决方案2】:

      Display.getPixelFormat() 将获取您要显示的像素格式。我建议这样做。

      此方法不再受支持,将始终返回 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;
      }
      

      【讨论】:

      • Display.getPixelFormat() 在 Galaxy Nexus 上返回 5 并且与 PixelFormat 的任何常量都不匹配。
      • 如果您的设备没有返回正确的值,不确定如何为您提供帮助。我想您可以放入一个特定的案例来检测该设备并使用最快的那个。
      • @nmjohn 根据这篇帖子,返回的 5 实际上是 BGRA_8888,看看这个建议是否真的有很好的性能会很有趣。 stackoverflow.com/questions/11949709/confused-about-pixelformat
      猜你喜欢
      • 1970-01-01
      • 2018-03-17
      • 2017-03-22
      • 1970-01-01
      • 2020-03-17
      • 2017-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多