Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f5ca753 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Check GL extension is supported before using it in glwallpaper"

parents d0056373 b7e474b8
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.opengl.EGL14.EGL_CONFIG_CAVEAT;
import static android.opengl.EGL14.EGL_CONTEXT_CLIENT_VERSION;
import static android.opengl.EGL14.EGL_DEFAULT_DISPLAY;
import static android.opengl.EGL14.EGL_DEPTH_SIZE;
import static android.opengl.EGL14.EGL_EXTENSIONS;
import static android.opengl.EGL14.EGL_GREEN_SIZE;
import static android.opengl.EGL14.EGL_NONE;
import static android.opengl.EGL14.EGL_NO_CONTEXT;
@@ -41,6 +42,7 @@ import static android.opengl.EGL14.eglGetDisplay;
import static android.opengl.EGL14.eglGetError;
import static android.opengl.EGL14.eglInitialize;
import static android.opengl.EGL14.eglMakeCurrent;
import static android.opengl.EGL14.eglQueryString;
import static android.opengl.EGL14.eglSwapBuffers;
import static android.opengl.EGL14.eglTerminate;

@@ -63,6 +65,7 @@ public class EglHelper {
    // Below two constants make drawing at low priority, so other things can preempt our drawing.
    private static final int EGL_CONTEXT_PRIORITY_LEVEL_IMG = 0x3100;
    private static final int EGL_CONTEXT_PRIORITY_LOW_IMG = 0x3103;
    private static final String EGL_IMG_CONTEXT_PRIORITY = "EGL_IMG_context_priority";

    private EGLDisplay mEglDisplay;
    private EGLConfig mEglConfig;
@@ -70,6 +73,7 @@ public class EglHelper {
    private EGLSurface mEglSurface;
    private final int[] mEglVersion = new int[2];
    private boolean mEglReady;
    private boolean mContextPrioritySupported;

    /**
     * Initialize EGL and prepare EglSurface.
@@ -105,10 +109,22 @@ public class EglHelper {
            return false;
        }

        mContextPrioritySupported = isContextPrioritySuppported();

        mEglReady = true;
        return true;
    }

    private boolean isContextPrioritySuppported() {
        String[] extensions = eglQueryString(mEglDisplay, EGL_EXTENSIONS).split(" ");
        for (String extension : extensions) {
            if (extension.equals(EGL_IMG_CONTEXT_PRIORITY)) {
                return true;
            }
        }
        return false;
    }

    private EGLConfig chooseEglConfig() {
        int[] configsCount = new int[1];
        EGLConfig[] configs = new EGLConfig[1];
@@ -184,8 +200,15 @@ public class EglHelper {
     * @return true if EglContext is ready.
     */
    public boolean createEglContext() {
        int[] attrib_list = new int[] {EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_LOW_IMG, EGL_NONE};
        int[] attrib_list = new int[5];
        int idx = 0;
        attrib_list[idx++] = EGL_CONTEXT_CLIENT_VERSION;
        attrib_list[idx++] = 2;
        if (mContextPrioritySupported) {
            attrib_list[idx++] = EGL_CONTEXT_PRIORITY_LEVEL_IMG;
            attrib_list[idx++] = EGL_CONTEXT_PRIORITY_LOW_IMG;
        }
        attrib_list[idx++] = EGL_NONE;
        mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, attrib_list, 0);
        if (mEglContext == EGL_NO_CONTEXT) {
            Log.w(TAG, "eglCreateContext failed: " + GLUtils.getEGLErrorString(eglGetError()));