Improve EglExtensionProvider
This commit is contained in:
committed by
Aayush Gupta
parent
59b404309a
commit
25aea3766a
@@ -14,118 +14,109 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.aurora.store.data.providers
|
package com.aurora.store.data.providers
|
||||||
|
|
||||||
import android.opengl.GLES10
|
import android.opengl.GLES10
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import java.util.Collections
|
|
||||||
import javax.microedition.khronos.egl.EGL10
|
import javax.microedition.khronos.egl.EGL10
|
||||||
import javax.microedition.khronos.egl.EGLConfig
|
import javax.microedition.khronos.egl.EGLConfig
|
||||||
import javax.microedition.khronos.egl.EGLContext
|
import javax.microedition.khronos.egl.EGLContext
|
||||||
import javax.microedition.khronos.egl.EGLDisplay
|
import javax.microedition.khronos.egl.EGLDisplay
|
||||||
|
|
||||||
object EglExtensionProvider {
|
object EglExtensionProvider {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val eglExtensions: List<String>
|
val eglExtensions: List<String>
|
||||||
get() {
|
get() {
|
||||||
val glExtensions: MutableSet<String> = HashSet()
|
val extensions = mutableSetOf<String>()
|
||||||
val egl10 = EGLContext.getEGL() as EGL10
|
val egl = EGLContext.getEGL() as EGL10
|
||||||
val display = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY)
|
val display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY)
|
||||||
egl10.eglInitialize(display, IntArray(2))
|
|
||||||
val cf = IntArray(1)
|
egl.eglInitialize(display, null)
|
||||||
if (egl10.eglGetConfigs(display, null, 0, cf)) {
|
val configCount = IntArray(1)
|
||||||
val configs = arrayOfNulls<EGLConfig>(cf[0])
|
|
||||||
if (egl10.eglGetConfigs(display, configs, cf[0], cf)) {
|
if (egl.eglGetConfigs(display, null, 0, configCount)) {
|
||||||
val a1 = intArrayOf(
|
val configs = arrayOfNulls<EGLConfig>(configCount[0])
|
||||||
EGL10.EGL_WIDTH,
|
if (egl.eglGetConfigs(display, configs, configCount[0], configCount)) {
|
||||||
EGL10.EGL_PBUFFER_BIT,
|
val pbufferAttribs = intArrayOf(
|
||||||
EGL10.EGL_HEIGHT,
|
EGL10.EGL_WIDTH, EGL10.EGL_PBUFFER_BIT,
|
||||||
EGL10.EGL_PBUFFER_BIT,
|
EGL10.EGL_HEIGHT, EGL10.EGL_PBUFFER_BIT,
|
||||||
EGL10.EGL_NONE
|
EGL10.EGL_NONE
|
||||||
)
|
)
|
||||||
val a2 = intArrayOf(12440, EGL10.EGL_PIXMAP_BIT, EGL10.EGL_NONE)
|
val contextAttributes = intArrayOf(12440, EGL10.EGL_PIXMAP_BIT, EGL10.EGL_NONE)
|
||||||
val a3 = IntArray(1)
|
|
||||||
for (i in 0 until cf[0]) {
|
for (config in configs) {
|
||||||
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_CONFIG_CAVEAT, a3)
|
if (isValidConfig(egl, display, config)) {
|
||||||
if (a3[0] != EGL10.EGL_SLOW_CONFIG) {
|
addExtensionsForConfig(
|
||||||
egl10.eglGetConfigAttrib(
|
egl,
|
||||||
display,
|
display,
|
||||||
configs[i],
|
config,
|
||||||
EGL10.EGL_SURFACE_TYPE,
|
pbufferAttribs,
|
||||||
a3
|
null,
|
||||||
|
extensions
|
||||||
|
)
|
||||||
|
addExtensionsForConfig(
|
||||||
|
egl,
|
||||||
|
display,
|
||||||
|
config,
|
||||||
|
pbufferAttribs,
|
||||||
|
contextAttributes,
|
||||||
|
extensions
|
||||||
)
|
)
|
||||||
if (1 and a3[0] != 0) {
|
|
||||||
egl10.eglGetConfigAttrib(
|
|
||||||
display,
|
|
||||||
configs[i],
|
|
||||||
EGL10.EGL_RENDERABLE_TYPE,
|
|
||||||
a3
|
|
||||||
)
|
|
||||||
if (1 and a3[0] != 0) {
|
|
||||||
addExtensionsForConfig(
|
|
||||||
egl10,
|
|
||||||
display,
|
|
||||||
configs[i],
|
|
||||||
a1,
|
|
||||||
null,
|
|
||||||
glExtensions
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (4 and a3[0] != 0) {
|
|
||||||
addExtensionsForConfig(
|
|
||||||
egl10,
|
|
||||||
display,
|
|
||||||
configs[i],
|
|
||||||
a1,
|
|
||||||
a2,
|
|
||||||
glExtensions
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
egl10.eglTerminate(display)
|
|
||||||
val sorted: List<String> = ArrayList(glExtensions)
|
egl.eglTerminate(display)
|
||||||
Collections.sort(sorted)
|
return extensions.sorted()
|
||||||
return sorted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isValidConfig(egl: EGL10, display: EGLDisplay, config: EGLConfig?): Boolean {
|
||||||
|
val configAttrib = IntArray(1)
|
||||||
|
egl.eglGetConfigAttrib(display, config, EGL10.EGL_CONFIG_CAVEAT, configAttrib)
|
||||||
|
if (configAttrib[0] == EGL10.EGL_SLOW_CONFIG) return false
|
||||||
|
|
||||||
|
egl.eglGetConfigAttrib(display, config, EGL10.EGL_SURFACE_TYPE, configAttrib)
|
||||||
|
if (configAttrib[0] and 1 == 0) return false
|
||||||
|
|
||||||
|
egl.eglGetConfigAttrib(display, config, EGL10.EGL_RENDERABLE_TYPE, configAttrib)
|
||||||
|
return configAttrib[0] and 1 != 0
|
||||||
|
}
|
||||||
|
|
||||||
private fun addExtensionsForConfig(
|
private fun addExtensionsForConfig(
|
||||||
egl10: EGL10,
|
egl: EGL10,
|
||||||
eglDisplay: EGLDisplay,
|
display: EGLDisplay,
|
||||||
eglConfig: EGLConfig?,
|
config: EGLConfig?,
|
||||||
ai: IntArray,
|
pbufferAttribs: IntArray,
|
||||||
ai1: IntArray?,
|
contextAttribs: IntArray?,
|
||||||
set: MutableSet<String>
|
extensions: MutableSet<String>
|
||||||
) {
|
) {
|
||||||
val eglContext = egl10.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, ai1)
|
val context = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, contextAttribs)
|
||||||
if (eglContext === EGL10.EGL_NO_CONTEXT) {
|
if (context == EGL10.EGL_NO_CONTEXT) return
|
||||||
|
|
||||||
|
val surface = egl.eglCreatePbufferSurface(display, config, pbufferAttribs)
|
||||||
|
if (surface == EGL10.EGL_NO_SURFACE) {
|
||||||
|
egl.eglDestroyContext(display, context)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val eglSurface = egl10.eglCreatePbufferSurface(eglDisplay, eglConfig, ai)
|
|
||||||
if (eglSurface === EGL10.EGL_NO_SURFACE) {
|
egl.eglMakeCurrent(display, surface, surface, context)
|
||||||
egl10.eglDestroyContext(eglDisplay, eglContext)
|
val extensionString = GLES10.glGetString(GLES10.GL_EXTENSIONS)
|
||||||
} else {
|
|
||||||
egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)
|
if (!TextUtils.isEmpty(extensionString)) {
|
||||||
val s = GLES10.glGetString(7939)
|
extensions.addAll(extensionString.split(" "))
|
||||||
if (!TextUtils.isEmpty(s)) {
|
|
||||||
val `as` = s.split(" ".toRegex()).toTypedArray()
|
|
||||||
val i = `as`.size
|
|
||||||
set.addAll(listOf(*`as`).subList(0, i))
|
|
||||||
}
|
|
||||||
egl10.eglMakeCurrent(
|
|
||||||
eglDisplay,
|
|
||||||
EGL10.EGL_NO_SURFACE,
|
|
||||||
EGL10.EGL_NO_SURFACE,
|
|
||||||
EGL10.EGL_NO_CONTEXT
|
|
||||||
)
|
|
||||||
egl10.eglDestroySurface(eglDisplay, eglSurface)
|
|
||||||
egl10.eglDestroyContext(eglDisplay, eglContext)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
egl.eglMakeCurrent(
|
||||||
|
display,
|
||||||
|
EGL10.EGL_NO_SURFACE,
|
||||||
|
EGL10.EGL_NO_SURFACE,
|
||||||
|
EGL10.EGL_NO_CONTEXT
|
||||||
|
)
|
||||||
|
egl.eglDestroySurface(display, surface)
|
||||||
|
egl.eglDestroyContext(display, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user