packages/apps/Settings
Revisão | e1212cde43f244811dbeed6a25ee6ac3e0e33c69 (tree) |
---|---|
Hora | 2016-05-05 19:07:22 |
Autor | Paulo Sergio Travaglia <pstglia@gmai...> |
Commiter | Chih-Wei Huang |
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.
@@ -22,7 +22,18 @@ import android.content.Intent; | ||
22 | 22 | import android.content.pm.ApplicationInfo; |
23 | 23 | import android.content.pm.PackageManager; |
24 | 24 | import android.content.pm.ResolveInfo; |
25 | + | |
26 | +// Requirements for context creation | |
27 | +import android.graphics.SurfaceTexture; | |
28 | +import android.opengl.EGL14; | |
25 | 29 | 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 | + | |
26 | 37 | import android.os.Build; |
27 | 38 | import android.os.Bundle; |
28 | 39 | import android.os.PersistableBundle; |
@@ -108,10 +119,64 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In | ||
108 | 119 | |
109 | 120 | addPreferencesFromResource(R.xml.device_info_settings); |
110 | 121 | |
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 | + | |
111 | 169 | String opengl_version = "GL Vendor: " + GLES20.glGetString(GLES20.GL_VENDOR) + "\n" + |
112 | 170 | "GL Renderer: " + GLES20.glGetString(GLES20.GL_RENDERER) + "\n" + |
113 | 171 | "GL Version: " + GLES20.glGetString(GLES20.GL_VERSION); |
114 | 172 | |
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 | + | |
115 | 180 | setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE); |
116 | 181 | findPreference(KEY_FIRMWARE_VERSION).setEnabled(true); |
117 | 182 | String patch = Build.VERSION.SECURITY_PATCH; |