From ee20787c5e95ef0100e763f5a634b7086ca1fecf Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 5 Sep 2021 14:34:54 -0400 Subject: [PATCH] Retain GLUtil.maxTextureSize --- .../eu/kanade/tachiyomi/util/system/GLUtil.kt | 67 +++++++++---------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/GLUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/GLUtil.kt index 739ce709d..59876e002 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/GLUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/GLUtil.kt @@ -5,50 +5,43 @@ import javax.microedition.khronos.egl.EGLConfig import javax.microedition.khronos.egl.EGLContext import kotlin.math.max -class GLUtil private constructor() { - companion object { - // Safe minimum default size - private const val IMAGE_MAX_BITMAP_DIMENSION = 2048 +object GLUtil { + val maxTextureSize: Int by lazy { + // Get EGL Display + val egl = EGLContext.getEGL() as EGL10 + val display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY) - val maxTextureSize: Int - get() { - // Get EGL Display - val egl = EGLContext.getEGL() as EGL10 - val display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY) + // Initialise + val version = IntArray(2) + egl.eglInitialize(display, version) - // Initialise - val version = IntArray(2) - egl.eglInitialize(display, version) + // Query total number of configurations + val totalConfigurations = IntArray(1) + egl.eglGetConfigs(display, null, 0, totalConfigurations) - // Query total number of configurations - val totalConfigurations = IntArray(1) - egl.eglGetConfigs(display, null, 0, totalConfigurations) + // Query actual list configurations + val configurationsList = arrayOfNulls(totalConfigurations[0]) + egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations) - // Query actual list configurations - val configurationsList = arrayOfNulls(totalConfigurations[0]) - egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations) + val textureSize = IntArray(1) + var maximumTextureSize = 0 - val textureSize = IntArray(1) - var maximumTextureSize = 0 + // Iterate through all the configurations to located the maximum texture size + for (i in 0 until totalConfigurations[0]) { + // Only need to check for width since opengl textures are always squared + egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize) - // Iterate through all the configurations to located the maximum texture size - for (i in 0 until totalConfigurations[0]) { - // Only need to check for width since opengl textures are always squared - egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize) + // Keep track of the maximum texture size + if (maximumTextureSize < textureSize[0]) maximumTextureSize = textureSize[0] + } - // Keep track of the maximum texture size - if (maximumTextureSize < textureSize[0]) maximumTextureSize = textureSize[0] - } + // Release + egl.eglTerminate(display) - // Release - egl.eglTerminate(display) - - // Return largest texture size found, or default - return max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION) - } - } - - init { - throw InstantiationException("This class is not for instantiation") + // Return largest texture size found, or default + max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION) } } + +// Safe minimum default size +private const val IMAGE_MAX_BITMAP_DIMENSION = 2048