package com.unity3d.player;

import android.opengl.GLSurfaceView;
import android.os.Build;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;

/* loaded from: /storage/emulated/0/Documents/jadec/sources/com.UBI.A90.WW/dex-files/2.dex */
class v {
    private static final int[] p;
    private static final int[] q;
    private static final int[][] r;
    private static /* synthetic */ boolean s;
    final GLSurfaceView.EGLConfigChooser a = new GLSurfaceView.EGLConfigChooser() { // from class: com.unity3d.player.v.1
        @Override // android.opengl.GLSurfaceView.EGLConfigChooser
        public final EGLConfig chooseConfig(EGL10 egl10, EGLDisplay eGLDisplay) {
            u a = v.this.a(egl10, eGLDisplay);
            if (!a.a(v.this.o)) {
                m.Log(5, "EGL configuration may not be compatiable with the current surface");
            }
            return a.a;
        }
    };
    private int b;
    private boolean c;
    private int d;
    private int e;
    private int f;
    private boolean g;
    private int h;
    private int i;
    private int j;
    private int k;
    private int l;
    private int m;
    private int n;
    private u o;

    static {
        s = !v.class.desiredAssertionStatus();
        p = new int[]{12324, 4, 12323, 4, 12322, 4, 12352, 4, 12339, 4, 12344};
        q = new int[]{12324, 5, 12323, 6, 12322, 5, 12352, 1, 12339, 4, 12344};
        r = new int[][]{new int[0], q, p};
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public v(boolean z, int i, int i2, int i3, int i4) {
        this.b = i4;
        a(z, i, i2, i3);
    }

    private u a(EGL10 egl10, EGLDisplay eGLDisplay, EGLConfig[] eGLConfigArr) {
        for (EGLConfig eGLConfig : eGLConfigArr) {
            if (!s && eGLConfig == null) {
                throw new AssertionError();
            }
            u uVar = new u(egl10, eGLDisplay, eGLConfig);
            int a = uVar.a(12325);
            int a2 = uVar.a(12326);
            int a3 = uVar.a(12337);
            int a4 = uVar.a(12513);
            if (a >= this.l && a2 >= this.m && (a3 >= this.n || a4 - 1 >= this.n)) {
                int a5 = uVar.a(12324);
                int a6 = uVar.a(12323);
                int a7 = uVar.a(12322);
                int a8 = uVar.a(12321);
                int a9 = uVar.a(12346);
                if (uVar.a(12345) == 0 && a9 == 0) {
                    a9 = 1;
                }
                if ((a5 != 8 || a6 != 8 || a7 != 8 || a9 != 0) && a5 == this.h && a6 == this.i && a7 == this.j && a8 == this.k) {
                    return uVar;
                }
            }
        }
        return null;
    }

    private void a(boolean z, int i, int i2, int i3) {
        int i4 = 8;
        this.c = z && b();
        this.d = i;
        this.e = i2;
        this.f = i3;
        this.g = this.c;
        this.h = this.c ? 8 : 5;
        this.i = this.c ? 8 : 6;
        this.j = this.c ? 8 : 5;
        if (!this.c || !c()) {
            i4 = 0;
        }
        this.k = i4;
        this.l = this.d;
        this.m = this.e;
        this.n = this.f;
        if (z && !b()) {
            m.Log(5, "Running on pre-Gingerbread device: DisplayBuffer doesn't support 32bits.");
        }
        if (this.c && !c()) {
            m.Log(5, "Running on pre-Honeycomb device: DisplayBuffer won't contain alpha channel.");
        }
        this.o = d();
    }

    private static boolean b() {
        return Build.VERSION.SDK_INT >= 9;
    }

    private static boolean c() {
        return Build.VERSION.SDK_INT >= 11;
    }

    private u d() {
        EGL10 egl10 = (EGL10) EGLContext.getEGL();
        EGLDisplay eglGetDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        if (eglGetDisplay == EGL10.EGL_NO_DISPLAY) {
            throw new RuntimeException("eglGetDisplay failed");
        }
        if (egl10.eglInitialize(eglGetDisplay, new int[2])) {
            return a(egl10, eglGetDisplay);
        }
        throw new RuntimeException("eglInitialize failed");
    }

    final u a(EGL10 egl10, EGLDisplay eGLDisplay) {
        int[] iArr = r[this.b];
        int[] iArr2 = new int[1];
        egl10.eglChooseConfig(eGLDisplay, iArr, null, 0, iArr2);
        int i = iArr2[0];
        if (i <= 0) {
            throw new IllegalArgumentException("No configs match configSpec");
        }
        EGLConfig[] eGLConfigArr = new EGLConfig[i];
        egl10.eglChooseConfig(eGLDisplay, iArr, eGLConfigArr, i, iArr2);
        u a = a(egl10, eGLDisplay, eGLConfigArr);
        while (a == null && this.n > 0) {
            this.n = this.n == 2 ? 0 : this.n / 2;
            a = a(egl10, eGLDisplay, eGLConfigArr);
        }
        if (a == null && this.l == 24) {
            this.l = 16;
            a = a(egl10, eGLDisplay, eGLConfigArr);
        }
        if (a == null && this.g) {
            this.g = false;
            this.h = 5;
            this.i = 6;
            this.j = 5;
            this.k = 0;
            a = a(egl10, eGLDisplay, eGLConfigArr);
        }
        return a == null ? new u(egl10, eGLDisplay, eGLConfigArr[0]) : a;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final boolean a() {
        return this.g;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final boolean a(int i) {
        if (this.f == i || this.n == i) {
            return false;
        }
        a(this.c, this.d, this.e, i);
        return true;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final boolean a(boolean z) {
        boolean z2 = z && b();
        if (this.c == z2 || this.g == z2) {
            return false;
        }
        a(z2, this.d, this.e, this.f);
        return true;
    }

    public String toString() {
        return "EGLConfigChooser\n\nRequested:\nmReqGlesVersion: " + this.b + "\nmReq32bit: " + this.c + "\nmReqDepthSize: " + this.d + "\nmReqStencilSize: " + this.e + "\nmReqAALevel: " + this.f + "\n\nActual\nm32bit: " + this.g + "\nmRedSize: " + this.h + "\nmGreenSize: " + this.i + "\nmBlueSize: " + this.j + "\nmAlphaSize: " + this.k + "\nmDepthSize: " + this.l + "\nmStencilSize: " + this.m + "\nmAALevel: " + this.n + "\n\nSelect default configuration: \n" + this.o;
    }
}
