packages/apps/Settings
Revisión | 97ab9f7550860d5c3ceddf59350e147542b611d8 (tree) |
---|---|
Tiempo | 2016-09-23 18:03:48 |
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.
@@ -19,7 +19,18 @@ package com.android.settings; | ||
19 | 19 | import android.app.Activity; |
20 | 20 | import android.content.Context; |
21 | 21 | import android.content.Intent; |
22 | + | |
23 | +// Requirements for context creation | |
24 | +import android.graphics.SurfaceTexture; | |
25 | +import android.opengl.EGL14; | |
22 | 26 | import android.opengl.GLES20; |
27 | +import android.opengl.GLSurfaceView.EGLConfigChooser; | |
28 | +import javax.microedition.khronos.egl.EGL10; | |
29 | +import javax.microedition.khronos.egl.EGLConfig; | |
30 | +import javax.microedition.khronos.egl.EGLContext; | |
31 | +import javax.microedition.khronos.egl.EGLDisplay; | |
32 | +import javax.microedition.khronos.egl.EGLSurface; | |
33 | + | |
23 | 34 | import android.os.Build; |
24 | 35 | import android.os.Bundle; |
25 | 36 | import android.os.PersistableBundle; |
@@ -105,10 +116,64 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In | ||
105 | 116 | |
106 | 117 | addPreferencesFromResource(R.xml.device_info_settings); |
107 | 118 | |
119 | + // Create an EGL Context | |
120 | + // References: | |
121 | + // [1] http://wlog.flatlib.jp/archive/1/2013-12-22 | |
122 | + // [2] packages/apps/Camera2/src/com/android/camera/SurfaceTextureRenderer.java | |
123 | + | |
124 | + EGL10 egl = (EGL10) EGLContext.getEGL(); | |
125 | + EGLSurface eglSurface = null; | |
126 | + EGLContext eglContext = null; | |
127 | + | |
128 | + // initialize display | |
129 | + EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); | |
130 | + if (eglDisplay == EGL10.EGL_NO_DISPLAY) { | |
131 | + Log.w(LOG_TAG, "eglGetDisplay failed"); | |
132 | + } | |
133 | + int[] iparam = new int[2]; | |
134 | + if (!egl.eglInitialize(eglDisplay, iparam)) { | |
135 | + Log.w(LOG_TAG, "eglInitialize failed"); | |
136 | + } | |
137 | + | |
138 | + // choose config | |
139 | + EGLConfig[] eglConfigs = new EGLConfig[1]; | |
140 | + final int[] configSpec = { EGL10.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE }; | |
141 | + if (egl.eglChooseConfig(eglDisplay, configSpec, eglConfigs, 1, iparam) && iparam[0] > 0) { | |
142 | + // create surface | |
143 | + SurfaceTexture surfaceTexture = new SurfaceTexture(0); | |
144 | + eglSurface = egl.eglCreateWindowSurface( | |
145 | + eglDisplay, eglConfigs[0], surfaceTexture, null); | |
146 | + if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) { | |
147 | + Log.w(LOG_TAG, "eglCreateWindowSurface failed"); | |
148 | + } else { | |
149 | + // create context | |
150 | + final int[] attribList = { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE }; | |
151 | + eglContext = egl.eglCreateContext( | |
152 | + eglDisplay, eglConfigs[0], EGL10.EGL_NO_CONTEXT, attribList); | |
153 | + if (eglContext == null || eglContext == EGL10.EGL_NO_CONTEXT) { | |
154 | + Log.w(LOG_TAG, "eglCreateContext failed"); | |
155 | + } | |
156 | + | |
157 | + // bind context | |
158 | + if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { | |
159 | + Log.w(LOG_TAG, "eglMakeCurrent failed"); | |
160 | + } | |
161 | + } | |
162 | + } else { | |
163 | + Log.w(LOG_TAG, "eglChooseConfig failed"); | |
164 | + } | |
165 | + | |
108 | 166 | String opengl_version = "GL Vendor: " + GLES20.glGetString(GLES20.GL_VENDOR) + "\n" + |
109 | 167 | "GL Renderer: " + GLES20.glGetString(GLES20.GL_RENDERER) + "\n" + |
110 | 168 | "GL Version: " + GLES20.glGetString(GLES20.GL_VERSION); |
111 | 169 | |
170 | + if (eglContext != null) { | |
171 | + // release | |
172 | + egl.eglMakeCurrent(eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); | |
173 | + egl.eglDestroyContext(eglDisplay, eglContext); | |
174 | + egl.eglDestroySurface(eglDisplay, eglSurface); | |
175 | + } | |
176 | + | |
112 | 177 | setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE); |
113 | 178 | findPreference(KEY_FIRMWARE_VERSION).setEnabled(true); |
114 | 179 |