• 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

Revisión97ab9f7550860d5c3ceddf59350e147542b611d8 (tree)
Tiempo2016-09-23 18:03:48
AutorPaulo Sergio Travaglia <pstglia@gmai...>
CommiterChih-Wei Huang

Log Message

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.

Cambiar Resumen

Diferencia incremental

--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -19,7 +19,18 @@ package com.android.settings;
1919 import android.app.Activity;
2020 import android.content.Context;
2121 import android.content.Intent;
22+
23+// Requirements for context creation
24+import android.graphics.SurfaceTexture;
25+import android.opengl.EGL14;
2226 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+
2334 import android.os.Build;
2435 import android.os.Bundle;
2536 import android.os.PersistableBundle;
@@ -105,10 +116,64 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
105116
106117 addPreferencesFromResource(R.xml.device_info_settings);
107118
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+
108166 String opengl_version = "GL Vendor: " + GLES20.glGetString(GLES20.GL_VENDOR) + "\n" +
109167 "GL Renderer: " + GLES20.glGetString(GLES20.GL_RENDERER) + "\n" +
110168 "GL Version: " + GLES20.glGetString(GLES20.GL_VERSION);
111169
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+
112177 setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE);
113178 findPreference(KEY_FIRMWARE_VERSION).setEnabled(true);
114179