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

Commit 33ba3055 authored by Jorge E. Moreira's avatar Jorge E. Moreira Committed by android-build-merger
Browse files

Merge "Check GL extension is supported before using it in glwallpaper" into qt-r1-dev-plus-aosp

am: edc5888d

Change-Id: Iab4d2489f3dad9550dd5c723be059353eeba6616
parents 07068282 edc5888d
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];
@@ -190,8 +206,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;
        if (hasEglDisplay()) {
            mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, attrib_list, 0);
        } else {