package com.bef.effectsdk;

import X.C05700Lw;
import com.bytedance.covode.number.Covode;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;

public abstract class GLTextureView$BaseConfigChooser implements GLTextureView$EGLConfigChooser {
    public int[] mConfigSpec;
    public final /* synthetic */ C05700Lw this$0;

    static {
        Covode.recordClassIndex(2785);
    }

    public abstract EGLConfig chooseConfig(EGL10 egl10, EGLDisplay eGLDisplay, EGLConfig[] eGLConfigArr);

    private int[] filterConfigSpec(int[] iArr) {
        if (this.this$0.mEGLContextClientVersion == 2) {
            int length = iArr.length;
            int[] iArr2 = new int[(length + 2)];
            int i = length - 1;
            System.arraycopy(iArr, 0, iArr2, 0, i);
            iArr2[i] = 12352;
            iArr2[length] = 4;
            iArr2[length + 1] = 12344;
            return iArr2;
        } else if (this.this$0.mEGLContextClientVersion != 3) {
            return iArr;
        } else {
            int length2 = iArr.length;
            int[] iArr3 = new int[(length2 + 2)];
            int i2 = length2 - 1;
            System.arraycopy(iArr, 0, iArr3, 0, i2);
            iArr3[i2] = 12352;
            iArr3[length2] = 64;
            iArr3[length2 + 1] = 12344;
            return iArr3;
        }
    }

    public GLTextureView$BaseConfigChooser(C05700Lw r2, int[] iArr) {
        this.this$0 = r2;
        this.mConfigSpec = filterConfigSpec(iArr);
    }

    public EGLConfig chooseConfig(EGL10 egl10, EGLDisplay eGLDisplay) {
        int[] iArr = new int[1];
        EGL10 egl102 = egl10;
        EGLDisplay eGLDisplay2 = eGLDisplay;
        if (egl102.eglChooseConfig(eGLDisplay2, this.mConfigSpec, (EGLConfig[]) null, 0, iArr)) {
            int i = iArr[0];
            if (i > 0) {
                EGLConfig[] eGLConfigArr = new EGLConfig[i];
                if (egl102.eglChooseConfig(eGLDisplay2, this.mConfigSpec, eGLConfigArr, i, iArr)) {
                    EGLConfig chooseConfig = chooseConfig(egl102, eGLDisplay2, eGLConfigArr);
                    if (chooseConfig != null) {
                        return chooseConfig;
                    }
                    throw new IllegalArgumentException("No config chosen");
                }
                throw new IllegalArgumentException("eglChooseConfig#2 failed");
            }
            throw new IllegalArgumentException("No configs match configSpec");
        }
        throw new IllegalArgumentException("eglChooseConfig failed");
    }
}
