packages/apps/Settings
Revision | d78096f59ae505b0f9d342a3f027b2304ee42909 (tree) |
---|---|
Zeit | 2015-12-18 18:35:55 |
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.
@@ -23,6 +23,17 @@ import android.content.pm.ApplicationInfo; | ||
23 | 23 | import android.content.pm.PackageManager; |
24 | 24 | import android.content.pm.ResolveInfo; |
25 | 25 | import android.opengl.GLES20; |
26 | + | |
27 | +// Requirements for context creation | |
28 | +import android.graphics.SurfaceTexture; | |
29 | +import android.opengl.EGL14; | |
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.Binder; |
27 | 38 | import android.os.Build; |
28 | 39 | import android.os.Bundle; |
@@ -96,10 +107,66 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In | ||
96 | 107 | |
97 | 108 | addPreferencesFromResource(R.xml.device_info_settings); |
98 | 109 | |
110 | + // Create an EGL Context | |
111 | + // References: | |
112 | + // [1] http://wlog.flatlib.jp/archive/1/2013-12-22 | |
113 | + // [2] packages/apps/Camera2/src/com/android/camera/SurfaceTextureRenderer.java | |
114 | + | |
115 | + EGL10 egl = (EGL10) EGLContext.getEGL(); | |
116 | + EGLSurface eglSurface = null; | |
117 | + EGLContext eglContext = null; | |
118 | + | |
119 | +Log.i(LOG_TAG, "is64Bit="+Integer.SIZE); | |
120 | + | |
121 | + // initialize display | |
122 | + EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); | |
123 | + if (eglDisplay == EGL10.EGL_NO_DISPLAY) { | |
124 | + Log.w(LOG_TAG, "eglGetDisplay failed"); | |
125 | + } | |
126 | + int[] iparam = new int[2]; | |
127 | + if (!egl.eglInitialize(eglDisplay, iparam)) { | |
128 | + Log.w(LOG_TAG, "eglInitialize failed"); | |
129 | + } | |
130 | + | |
131 | + // choose config | |
132 | + EGLConfig[] eglConfigs = new EGLConfig[1]; | |
133 | + final int[] configSpec = { EGL10.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE }; | |
134 | + if (egl.eglChooseConfig(eglDisplay, configSpec, eglConfigs, 1, iparam) && iparam[0] > 0) { | |
135 | + // create surface | |
136 | + SurfaceTexture surfaceTexture = new SurfaceTexture(0); | |
137 | + eglSurface = egl.eglCreateWindowSurface( | |
138 | + eglDisplay, eglConfigs[0], surfaceTexture, null); | |
139 | + if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) { | |
140 | + Log.w(LOG_TAG, "eglCreateWindowSurface failed"); | |
141 | + } else { | |
142 | + // create context | |
143 | + final int[] attribList = { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE }; | |
144 | + eglContext = egl.eglCreateContext( | |
145 | + eglDisplay, eglConfigs[0], EGL10.EGL_NO_CONTEXT, attribList); | |
146 | + if (eglContext == null || eglContext == EGL10.EGL_NO_CONTEXT) { | |
147 | + Log.w(LOG_TAG, "eglCreateContext failed"); | |
148 | + } | |
149 | + | |
150 | + // bind context | |
151 | + if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { | |
152 | + Log.w(LOG_TAG, "eglMakeCurrent failed"); | |
153 | + } | |
154 | + } | |
155 | + } else { | |
156 | + Log.w(LOG_TAG, "eglChooseConfig failed"); | |
157 | + } | |
158 | + | |
99 | 159 | String opengl_version = "GL Vendor: " + GLES20.glGetString(GLES20.GL_VENDOR) + "\n" + |
100 | 160 | "GL Renderer: " + GLES20.glGetString(GLES20.GL_RENDERER) + "\n" + |
101 | 161 | "GL Version: " + GLES20.glGetString(GLES20.GL_VERSION); |
102 | 162 | |
163 | + if (eglContext != null) { | |
164 | + // release | |
165 | + egl.eglMakeCurrent(eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); | |
166 | + egl.eglDestroyContext(eglDisplay, eglContext); | |
167 | + egl.eglDestroySurface(eglDisplay, eglSurface); | |
168 | + } | |
169 | + | |
103 | 170 | setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE); |
104 | 171 | findPreference(KEY_FIRMWARE_VERSION).setEnabled(true); |
105 | 172 | String patch = Build.VERSION.SECURITY_PATCH; |