From a7cfb9b2da3a316e5917cf2dca0cdd524464db7e Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang Date: Wed, 13 Dec 2017 01:23:34 +0800 Subject: [PATCH] Add information about OpenGL driver version In order to get Mesa / OpenGL ES info, an EGL context is required. Without it, GLES20.glGetString returns NULL. --- res/layout/dialog_firmware_version.xml | 12 +++ res/values-zh-rCN/strings.xml | 1 + res/values-zh-rTW/strings.xml | 1 + res/values/strings.xml | 2 + .../FirmwareVersionDialogFragment.java | 1 + .../OpenGLVersionDialogController.java | 98 ++++++++++++++++++++++ 6 files changed, 115 insertions(+) create mode 100644 src/com/android/settings/deviceinfo/firmwareversion/OpenGLVersionDialogController.java diff --git a/res/layout/dialog_firmware_version.xml b/res/layout/dialog_firmware_version.xml index 874d7af006..b7505af4df 100644 --- a/res/layout/dialog_firmware_version.xml +++ b/res/layout/dialog_firmware_version.xml @@ -77,6 +77,18 @@ + + + "设备 ID" "基带版本" "内核版本" + "Open GL 驱动版本" "版本号" "无法获取" "状态信息" diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml index 24de4b1a4a..faede05092 100644 --- a/res/values-zh-rTW/strings.xml +++ b/res/values-zh-rTW/strings.xml @@ -1205,6 +1205,7 @@ "設備 ID" "基頻版本" "核心版本" + "Open GL 驅動版本" "版本號碼" "無法取得" "狀態" diff --git a/res/values/strings.xml b/res/values/strings.xml index 5e3b0d5b34..99c38e4d5d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2783,6 +2783,8 @@ Kernel version + OpenGL driver version + Build number diff --git a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogFragment.java b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogFragment.java index 0087444605..01674ad902 100644 --- a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogFragment.java +++ b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogFragment.java @@ -88,6 +88,7 @@ public class FirmwareVersionDialogFragment extends InstrumentedDialogFragment { new SecurityPatchLevelDialogController(this).initialize(); new BasebandVersionDialogController(this).initialize(); new KernelVersionDialogController(this).initialize(); + new OpenGLVersionDialogController(this).initialize(); new BuildNumberDialogController(this).initialize(); } } diff --git a/src/com/android/settings/deviceinfo/firmwareversion/OpenGLVersionDialogController.java b/src/com/android/settings/deviceinfo/firmwareversion/OpenGLVersionDialogController.java new file mode 100644 index 0000000000..7dfc1b5cfd --- /dev/null +++ b/src/com/android/settings/deviceinfo/firmwareversion/OpenGLVersionDialogController.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2019 The Android-x86 Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.deviceinfo.firmwareversion; + +import android.graphics.SurfaceTexture; +import android.opengl.EGL14; +import android.opengl.GLES20; +import android.util.Log; +import com.android.settings.R; +import javax.microedition.khronos.egl.EGL10; +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.egl.EGLContext; +import javax.microedition.khronos.egl.EGLDisplay; +import javax.microedition.khronos.egl.EGLSurface; + +public class OpenGLVersionDialogController { + + private static final int OPENGL_VERSION_VALUE_ID = R.id.opengl_version_value; + private static final String LOG_TAG = "opengl_version"; + + private final FirmwareVersionDialogFragment mDialog; + + public OpenGLVersionDialogController(FirmwareVersionDialogFragment dialog) { + mDialog = dialog; + } + + public void initialize() { + // Create an EGL Context + // References: + // [1] http://wlog.flatlib.jp/archive/1/2013-12-22 + // [2] packages/apps/Camera2/src/com/android/camera/SurfaceTextureRenderer.java + + EGL10 egl = (EGL10) EGLContext.getEGL(); + EGLSurface eglSurface = null; + EGLContext eglContext = null; + + // Initialize display + EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); + if (eglDisplay == EGL10.EGL_NO_DISPLAY) { + Log.w(LOG_TAG, "eglGetDisplay failed"); + } + int[] iparam = new int[2]; + if (!egl.eglInitialize(eglDisplay, iparam)) { + Log.w(LOG_TAG, "eglInitialize failed"); + } + + // Choose config + EGLConfig[] eglConfigs = new EGLConfig[1]; + final int[] configSpec = { EGL10.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE }; + if (egl.eglChooseConfig(eglDisplay, configSpec, eglConfigs, 1, iparam) && iparam[0] > 0) { + // create surface + SurfaceTexture surfaceTexture = new SurfaceTexture(0); + eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfigs[0], surfaceTexture, null); + if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) { + Log.w(LOG_TAG, "eglCreateWindowSurface failed"); + } else { + // Create context + final int[] attribList = { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE }; + eglContext = egl.eglCreateContext( + eglDisplay, eglConfigs[0], EGL10.EGL_NO_CONTEXT, attribList); + if (eglContext == null || eglContext == EGL10.EGL_NO_CONTEXT) { + Log.w(LOG_TAG, "eglCreateContext failed"); + } + + // Bind context + if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { + Log.w(LOG_TAG, "eglMakeCurrent failed"); + } + } + } else { + Log.w(LOG_TAG, "eglChooseConfig failed"); + } + + mDialog.setText(OPENGL_VERSION_VALUE_ID, + "GL Vendor: " + GLES20.glGetString(GLES20.GL_VENDOR) + "\n" + + "GL Renderer: " + GLES20.glGetString(GLES20.GL_RENDERER) + "\n" + + "GL Version: " + GLES20.glGetString(GLES20.GL_VERSION)); + + if (eglContext != null) { + egl.eglMakeCurrent(eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); + egl.eglDestroyContext(eglDisplay, eglContext); + egl.eglDestroySurface(eglDisplay, eglSurface); + } + } +} -- 2.11.0