• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Revisãoe1212cde43f244811dbeed6a25ee6ac3e0e33c69 (tree)
Hora2016-05-05 19:07:22
AutorPaulo Sergio Travaglia <pstglia@gmai...>
CommiterChih-Wei Huang

Mensagem de Log

Create an EGL context for DeviceInfoSettings

In order to get Mesa / OpenGL ES info, an EGL context is required.
Without it, GLES20.glGetString returns NULL.

Mudança Sumário

Diff

--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -22,7 +22,18 @@ import android.content.Intent;
2222 import android.content.pm.ApplicationInfo;
2323 import android.content.pm.PackageManager;
2424 import android.content.pm.ResolveInfo;
25+
26+// Requirements for context creation
27+import android.graphics.SurfaceTexture;
28+import android.opengl.EGL14;
2529 import android.opengl.GLES20;
30+import android.opengl.GLSurfaceView.EGLConfigChooser;
31+import javax.microedition.khronos.egl.EGL10;
32+import javax.microedition.khronos.egl.EGLConfig;
33+import javax.microedition.khronos.egl.EGLContext;
34+import javax.microedition.khronos.egl.EGLDisplay;
35+import javax.microedition.khronos.egl.EGLSurface;
36+
2637 import android.os.Build;
2738 import android.os.Bundle;
2839 import android.os.PersistableBundle;
@@ -108,10 +119,64 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
108119
109120 addPreferencesFromResource(R.xml.device_info_settings);
110121
122+ // Create an EGL Context
123+ // References:
124+ // [1] http://wlog.flatlib.jp/archive/1/2013-12-22
125+ // [2] packages/apps/Camera2/src/com/android/camera/SurfaceTextureRenderer.java
126+
127+ EGL10 egl = (EGL10) EGLContext.getEGL();
128+ EGLSurface eglSurface = null;
129+ EGLContext eglContext = null;
130+
131+ // initialize display
132+ EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
133+ if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
134+ Log.w(LOG_TAG, "eglGetDisplay failed");
135+ }
136+ int[] iparam = new int[2];
137+ if (!egl.eglInitialize(eglDisplay, iparam)) {
138+ Log.w(LOG_TAG, "eglInitialize failed");
139+ }
140+
141+ // choose config
142+ EGLConfig[] eglConfigs = new EGLConfig[1];
143+ final int[] configSpec = { EGL10.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE };
144+ if (egl.eglChooseConfig(eglDisplay, configSpec, eglConfigs, 1, iparam) && iparam[0] > 0) {
145+ // create surface
146+ SurfaceTexture surfaceTexture = new SurfaceTexture(0);
147+ eglSurface = egl.eglCreateWindowSurface(
148+ eglDisplay, eglConfigs[0], surfaceTexture, null);
149+ if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
150+ Log.w(LOG_TAG, "eglCreateWindowSurface failed");
151+ } else {
152+ // create context
153+ final int[] attribList = { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
154+ eglContext = egl.eglCreateContext(
155+ eglDisplay, eglConfigs[0], EGL10.EGL_NO_CONTEXT, attribList);
156+ if (eglContext == null || eglContext == EGL10.EGL_NO_CONTEXT) {
157+ Log.w(LOG_TAG, "eglCreateContext failed");
158+ }
159+
160+ // bind context
161+ if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
162+ Log.w(LOG_TAG, "eglMakeCurrent failed");
163+ }
164+ }
165+ } else {
166+ Log.w(LOG_TAG, "eglChooseConfig failed");
167+ }
168+
111169 String opengl_version = "GL Vendor: " + GLES20.glGetString(GLES20.GL_VENDOR) + "\n" +
112170 "GL Renderer: " + GLES20.glGetString(GLES20.GL_RENDERER) + "\n" +
113171 "GL Version: " + GLES20.glGetString(GLES20.GL_VERSION);
114172
173+ if (eglContext != null) {
174+ // release
175+ egl.eglMakeCurrent(eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
176+ egl.eglDestroyContext(eglDisplay, eglContext);
177+ egl.eglDestroySurface(eglDisplay, eglSurface);
178+ }
179+
115180 setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE);
116181 findPreference(KEY_FIRMWARE_VERSION).setEnabled(true);
117182 String patch = Build.VERSION.SECURITY_PATCH;