【问题标题】:Is there any way to get GPU information?有什么方法可以获取 GPU 信息吗?
【发布时间】:2013-03-26 02:57:49
【问题描述】:

我知道如何在/proc/ 中获取 CPU 信息,但是有什么方法可以获取 GPU 信息吗? CPU 之类的?

【问题讨论】:

  • 你真的没说什么就投了反对票?

标签: android gpu


【解决方案1】:

更简单的方法: 亚行外壳转储系统 | grep GLES

【讨论】:

  • 稍作修改的版本adb shell dumpsys SurfaceFlinger |grep GLES 运行时间更短
【解决方案2】:

有,可以通过OpenGL获取GPU信息:

    Log.d("GL", "GL_RENDERER = "   + gl.glGetString( GL10.GL_RENDERER   ));
    Log.d("GL", "GL_VENDOR = "     + gl.glGetString( GL10.GL_VENDOR     ));
    Log.d("GL", "GL_VERSION = "    + gl.glGetString( GL10.GL_VERSION    ));
    Log.i("GL", "GL_EXTENSIONS = " + gl.glGetString( GL10.GL_EXTENSIONS ));

欲了解更多信息,请参阅:https://developer.android.com/guide/topics/graphics/opengl.html

【讨论】:

【解决方案3】:

这是一个获取 GPU 信息的 SampleActivity:

public class MainActivity extends Activity implements GLSurfaceView.Renderer{
    private TextView textView;
    private GLSurfaceView glSurfaceView;
    private StringBuilder sb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = (TextView) findViewById(R.id.textView);

        final ActivityManager activityManager =  (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
        final ConfigurationInfo configurationInfo = activityManager
                .getDeviceConfigurationInfo();
        sb=new StringBuilder();
        sb.append("GL version:").append(configurationInfo.getGlEsVersion()).append("\n");

        textView.setText(sb.toString());
        this.glSurfaceView = new GLSurfaceView(this);
        this.glSurfaceView.setRenderer(this);
        ((ViewGroup)textView.getParent()).addView(this.glSurfaceView);
    }

    @Override
    public void onClick(View v) {
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
       sb.append("RENDERER").append(gl.glGetString(GL10.GL_RENDERER)).append("\n");
        sb.append("VENDOR").append( gl.glGetString(GL10.GL_VENDOR)).append("\n");
        sb.append("VERSION").append(gl.glGetString(GL10.GL_VERSION)).append("\n");
        sb.append("EXTENSIONS").append(gl.glGetString(GL10.GL_EXTENSIONS));
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                textView.setText(sb.toString());
                glSurfaceView.setVisibility(View.GONE);
            }
        });
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
    }

    @Override
    public void onDrawFrame(GL10 gl) {
    }
}

【讨论】:

  • 获取 GPU 信息的完美示例。如何在作为 jar 文件包含在 android 应用程序中的 java 库项目中实现相同的功能。
  • 您不能使用 JAR(Java 存档)来执行此操作,因为它需要 Android SDK。您可以将其开发为 Android 库模块 (AAR)。
  • 我实现了这个。有用。但在某些设备上,它会出现此错误。致命异常:java.lang.RuntimeException createContext 失败:EGL_BAD_ALLOC
【解决方案4】:

我希望它对你有用.. 首先这段代码检查设备是否支持GPU。

 // Check if the system supports OpenGL ES 2.0.
  final ActivityManager activityManager =  (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    final ConfigurationInfo configurationInfo = activityManager
            .getDeviceConfigurationInfo();
    final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;

    if (supportsEs2) {
        Log.i("JO", "configurationInfo.reqGlEsVersion:"
                + configurationInfo.reqGlEsVersion + "supportsEs2:"
                + supportsEs2);
        // Request an OpenGL ES 2.0 compatible context.
        myGlsurfaceView.setEGLContextClientVersion(2);

        final DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

        // Set the renderer to our demo renderer, defined below.
        myRenderer = new MyRenderer(this, myGlsurfaceView);
        myGlsurfaceView.setRenderer(myRenderer, displayMetrics.density);
        myGlsurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    } else {
        // This is where you could create an OpenGL ES 1.x compatible
        // renderer if you wanted to support both ES 1 and ES 2.
        return;
    }

第二个:这段代码给出了GPU信息..

把它放在 MyRenderer 类里面的这段代码中..

 public void determineGraphicSupport(GL10 gl){
    int _graphicEngine = GRAPHICS_CANVAS;

    String extensions = gl.glGetString(GLES20.GL_EXTENSIONS); 
    //String version = GLES10.glGetString(GL10.GL_VERSION);
    String version = GLES20.glGetString(GLES20.GL_VERSION);

    //String renderer = gl.glGetString(GL10.GL_RENDERER);
    String renderer = GLES20.glGetString(GLES20.GL_RENDERER);

    boolean isSoftwareRenderer = renderer.contains("PixelFlinger");
    boolean supportsDrawTexture = extensions.contains("draw_texture");

    int[] arGlMaxTextureSize = new int[1];

    gl.glGetIntegerv( GLES20.GL_MAX_TEXTURE_SIZE, arGlMaxTextureSize, 0 );

    if( !isSoftwareRenderer && supportsDrawTexture && _width >= 480 && _height >= 800 
            && arGlMaxTextureSize[0] >= 4096 )
        _graphicEngine = GRAPHICS_OPENGL_DRAW_TEXTURE;
    else
        _graphicEngine = GRAPHICS_CANVAS;

 }

【讨论】:

    猜你喜欢
    • 2019-01-11
    • 1970-01-01
    • 2013-10-25
    • 2019-10-06
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    相关资源
    最近更新 更多