android获取GPU信息;android获取GPU渲染器、供应商、版本和扩展名等信息
效果:
1、布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="15dp"
tools:context=".FirstActivity">
<TextView
android:id="@+id/gpu_renderer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="renderer"
android:textSize="20dp"/>
<TextView
android:id="@+id/gpu_vendor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="vendor"
android:textSize="20dp"/>
<TextView
android:id="@+id/gpu_version"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="gpu_version"
android:textSize="20dp"/>
<TextView
android:id="@+id/gpu_extensions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="extensions"
android:textSize="20dp"/>
<android.opengl.GLSurfaceView
android:id="@+id/gl_surface_view"
android:layout_width="1dp"
android:layout_height="1dp"/>
</LinearLayout>
2、工具类
public class GpuInfoUtil implements GLSurfaceView.Renderer{
public static String glRenderer;
public static String glVendor;
public static String glVersion;
public static String glExtensions;
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
glRenderer = gl.glGetString(GL10.GL_RENDERER); //GPU 渲染器
glVendor = gl.glGetString(GL10.GL_VENDOR); //GPU 供应商
glVersion = gl.glGetString(GL10.GL_VERSION); //GPU 版本
glExtensions = gl.glGetString(GL10.GL_EXTENSIONS); //GPU 扩展名
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
}
@Override
public void onDrawFrame(GL10 gl) {
}
}
3、活动
public class FirstActivity extends AppCompatActivity {
private TextView glRenderer;
private TextView glVendor;
private TextView glVersion;
private TextView glExtensions;
private GLSurfaceView glSurfaceView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_activity);
initView();
setData();
}
@Override
protected void onResume() {
super.onResume();
//延迟100毫秒再刷新一次,确保获取到GPU各项属性
handler.postDelayed(runnable,100);
}
//更新界面数据
private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
public void run () {
setData();
}
};
private void setData(){
glRenderer.setText("GPU 渲染器: "+GpuInfoUtil.glRenderer);
glVendor.setText("GPU 供应商: "+GpuInfoUtil.glVendor);
glVersion.setText("GPU 版本: "+GpuInfoUtil.glVersion);
glExtensions.setText("GPU 扩展名: "+GpuInfoUtil.glExtensions);
}
private void initView(){
glRenderer = (TextView)findViewById(R.id.gpu_renderer);
glVendor = (TextView)findViewById(R.id.gpu_vendor);
glVersion = (TextView)findViewById(R.id.gpu_version);
glExtensions = (TextView)findViewById(R.id.gpu_extensions);
glSurfaceView= findViewById(R.id.gl_surface_view);
glSurfaceView.setEGLContextClientVersion(1);
glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0);
glSurfaceView.setRenderer(new GpuInfoUtil());
}
}