OSDN Git Service

Add information about OpenGL driver version
authorChih-Wei Huang <cwhuang@linux.org.tw>
Tue, 12 Dec 2017 17:23:34 +0000 (01:23 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 27 Dec 2017 06:36:49 +0000 (14:36 +0800)
In order to get Mesa / OpenGL ES info, an EGL context is required.
Without it, GLES20.glGetString returns NULL.

res/values-zh-rCN/strings.xml
res/values-zh-rTW/strings.xml
res/values/strings.xml
res/xml/device_info_settings.xml
src/com/android/settings/DeviceInfoSettings.java
src/com/android/settings/deviceinfo/OpenGLVersionPreferenceController.java [new file with mode: 0644]

index dafec33..9a6dfad 100644 (file)
     <string name="fcc_equipment_id" msgid="149114368246356737">"设备 ID"</string>
     <string name="baseband_version" msgid="1848990160763524801">"基带版本"</string>
     <string name="kernel_version" msgid="9192574954196167602">"内核版本"</string>
+    <string name="opengl_version">"Open GL 驱动版本"</string>
     <string name="build_number" msgid="3075795840572241758">"版本号"</string>
     <string name="selinux_status" msgid="6212165375172061672">"SELinux 状态"</string>
     <string name="device_info_not_available" msgid="8062521887156825182">"无法获取"</string>
index dcd907c..031f27d 100644 (file)
     <string name="fcc_equipment_id" msgid="149114368246356737">"設備 ID"</string>
     <string name="baseband_version" msgid="1848990160763524801">"基頻版本"</string>
     <string name="kernel_version" msgid="9192574954196167602">"核心版本"</string>
+    <string name="opengl_version">"Open GL 驅動版本"</string>
     <string name="build_number" msgid="3075795840572241758">"版本號碼"</string>
     <string name="selinux_status" msgid="6212165375172061672">"SELinux 狀態"</string>
     <string name="device_info_not_available" msgid="8062521887156825182">"無法取得"</string>
index 3e7b9cb..5f118ac 100644 (file)
     <!-- About phone screen,  setting option name  [CHAR LIMIT=40] -->
     <string name="kernel_version">Kernel version</string>
     <!-- About phone screen,  setting option name  [CHAR LIMIT=40] -->
+    <string name="opengl_version">OpenGL driver version</string>
+    <!-- About phone screen,  setting option name  [CHAR LIMIT=40] -->
     <string name="build_number">Build number</string>
     <!-- About phone screen,  setting option name  [CHAR LIMIT=40] -->
     <string name="selinux_status">SELinux status</string>
index cf1a993..8e12bdc 100644 (file)
                 android:title="@string/kernel_version"
                 android:summary="@string/summary_placeholder"/>
 
+        <!-- OpenGL Version -->
+       <Preference
+                android:key="opengl_version"
+                android:title="@string/opengl_version"
+                android:summary="@string/device_info_default"/>
+
         <!-- Detailed build version -->
         <Preference
                 android:key="build_number"
index f1f3b6f..022c7f7 100644 (file)
@@ -35,6 +35,7 @@ import com.android.settings.deviceinfo.FeedbackPreferenceController;
 import com.android.settings.deviceinfo.FirmwareVersionPreferenceController;
 import com.android.settings.deviceinfo.KernelVersionPreferenceController;
 import com.android.settings.deviceinfo.ManualPreferenceController;
+import com.android.settings.deviceinfo.OpenGLVersionPreferenceController;
 import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
 import com.android.settings.deviceinfo.SELinuxStatusPreferenceController;
 import com.android.settings.deviceinfo.SafetyInfoPreferenceController;
@@ -124,6 +125,7 @@ public class DeviceInfoSettings extends DashboardFragment implements Indexable {
         controllers.add(new ManualPreferenceController(context));
         controllers.add(new FeedbackPreferenceController(fragment, context));
         controllers.add(new KernelVersionPreferenceController(context));
+        controllers.add(new OpenGLVersionPreferenceController(context));
         controllers.add(new BasebandVersionPreferenceController(context));
         controllers.add(new FirmwareVersionPreferenceController(context, lifecycle));
         controllers.add(new RegulatoryInfoPreferenceController(context));
diff --git a/src/com/android/settings/deviceinfo/OpenGLVersionPreferenceController.java b/src/com/android/settings/deviceinfo/OpenGLVersionPreferenceController.java
new file mode 100644 (file)
index 0000000..62c91d8
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2017 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;
+
+import android.content.Context;
+import android.graphics.SurfaceTexture;
+import android.opengl.EGL14;
+import android.opengl.GLES20;
+import android.opengl.GLSurfaceView.EGLConfigChooser;
+import android.support.v7.preference.Preference;
+import android.util.Log;
+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;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class OpenGLVersionPreferenceController extends AbstractPreferenceController
+        implements PreferenceControllerMixin {
+
+    private static final String KEY_OPENGL_VERSION = "opengl_version";
+    private static final String LOG_TAG = KEY_OPENGL_VERSION;
+
+    public OpenGLVersionPreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        super.updateState(preference);
+
+        // 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");
+        }
+
+        preference.setSummary(
+                "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);
+        }
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_OPENGL_VERSION;
+    }
+}