package p138.p176.p177.p190.p236.p237;

import android.content.Context;
import android.graphics.PointF;
import android.graphics.SurfaceTexture;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.os.Handler;
import android.os.Looper;
import android.view.Surface;
import android.view.WindowManager;
import java.nio.Buffer;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p190.C3446;
import p138.p176.p177.p190.C3454;
import p138.p176.p177.p190.InterfaceC3442;
import p138.p176.p177.p190.InterfaceC3450;
import p138.p176.p177.p190.p236.p237.C4076;
import p138.p176.p177.p190.p236.p237.C4078;
import p138.p176.p177.p190.p236.p237.ViewOnTouchListenerC4084;
import p138.p176.p177.p190.p239.C4150;
import p138.p176.p177.p190.p240.p241.C4180;
import p138.p176.p177.p190.p240.p241.C4181;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ྉ.ޒ.ޅ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C4082 extends GLSurfaceView {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final SensorManager f13025;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final Sensor f13026;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final C4076 f13027;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final Handler f13028;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final ViewOnTouchListenerC4084 f13029;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final C4080 f13030;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public SurfaceTexture f13031;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public Surface f13032;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public InterfaceC3442.InterfaceC3445 f13033;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public boolean f13034;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public boolean f13035;

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public boolean f13036;

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ྉ.ޒ.ޅ$֏, reason: contains not printable characters */
    public class C4083 implements GLSurfaceView.Renderer, ViewOnTouchListenerC4084.InterfaceC4085, C4076.InterfaceC4077 {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final C4080 f13037;

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public final float[] f13040;

        /* JADX INFO: renamed from: މ, reason: contains not printable characters */
        public float f13043;

        /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
        public float f13044;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public final float[] f13038 = new float[16];

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public final float[] f13039 = new float[16];

        /* JADX INFO: renamed from: އ, reason: contains not printable characters */
        public final float[] f13041 = new float[16];

        /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
        public final float[] f13042 = new float[16];

        /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
        public final float[] f13045 = new float[16];

        /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
        public final float[] f13046 = new float[16];

        public C4083(C4080 c4080) {
            float[] fArr = new float[16];
            this.f13040 = fArr;
            this.f13037 = c4080;
            Matrix.setIdentityM(fArr, 0);
            Matrix.setIdentityM(this.f13041, 0);
            Matrix.setIdentityM(this.f13042, 0);
            this.f13044 = 3.1415927f;
        }

        @Override // android.opengl.GLSurfaceView.Renderer
        public void onDrawFrame(GL10 gl10) {
            float[] fArr;
            synchronized (this) {
                Matrix.multiplyMM(this.f13046, 0, this.f13040, 0, this.f13042, 0);
                Matrix.multiplyMM(this.f13045, 0, this.f13041, 0, this.f13046, 0);
            }
            Matrix.multiplyMM(this.f13039, 0, this.f13038, 0, this.f13045, 0);
            C4080 c4080 = this.f13037;
            float[] fArr2 = this.f13039;
            if (c4080 == null) {
                throw null;
            }
            GLES20.glClear(16384);
            C0567.m1873();
            if (c4080.f13012.compareAndSet(true, false)) {
                SurfaceTexture surfaceTexture = c4080.f13021;
                C0567.m1856(surfaceTexture);
                surfaceTexture.updateTexImage();
                C0567.m1873();
                if (c4080.f13013.compareAndSet(true, false)) {
                    Matrix.setIdentityM(c4080.f13018, 0);
                }
                long timestamp = c4080.f13021.getTimestamp();
                Long lM6729 = c4080.f13016.m6729(timestamp);
                if (lM6729 != null) {
                    C4180 c4180 = c4080.f13015;
                    float[] fArr3 = c4080.f13018;
                    float[] fArrM6733 = c4180.f13363.m6733(lM6729.longValue());
                    if (fArrM6733 != null) {
                        float[] fArr4 = c4180.f13362;
                        float f = fArrM6733[0];
                        float f2 = -fArrM6733[1];
                        float f3 = -fArrM6733[2];
                        float length = Matrix.length(f, f2, f3);
                        if (length != 0.0f) {
                            fArr = fArr3;
                            Matrix.setRotateM(fArr4, 0, (float) Math.toDegrees(length), f / length, f2 / length, f3 / length);
                        } else {
                            fArr = fArr3;
                            Matrix.setIdentityM(fArr4, 0);
                        }
                        if (!c4180.f13364) {
                            C4180.m6831(c4180.f13361, c4180.f13362);
                            c4180.f13364 = true;
                        }
                        Matrix.multiplyMM(fArr, 0, c4180.f13361, 0, c4180.f13362, 0);
                    }
                }
                C4181 c4181M6733 = c4080.f13017.m6733(timestamp);
                if (c4181M6733 != null) {
                    C4078 c4078 = c4080.f13014;
                    if (c4078 == null) {
                        throw null;
                    }
                    if (C4078.m6564(c4181M6733)) {
                        c4078.f12999 = c4181M6733.f13367;
                        C4078.C4079 c4079 = new C4078.C4079(c4181M6733.f13365.f13369[0]);
                        c4078.f13000 = c4079;
                        if (!c4181M6733.f13368) {
                            c4079 = new C4078.C4079(c4181M6733.f13366.f13369[0]);
                        }
                        c4078.f13001 = c4079;
                    }
                }
            }
            Matrix.multiplyMM(c4080.f13019, 0, fArr2, 0, c4080.f13018, 0);
            C4078 c40782 = c4080.f13014;
            int i = c4080.f13020;
            float[] fArr5 = c4080.f13019;
            C4078.C4079 c40792 = c40782.f13000;
            if (c40792 == null) {
                return;
            }
            GLES20.glUseProgram(c40782.f13002);
            C0567.m1873();
            GLES20.glEnableVertexAttribArray(c40782.f13005);
            GLES20.glEnableVertexAttribArray(c40782.f13006);
            C0567.m1873();
            int i2 = c40782.f12999;
            GLES20.glUniformMatrix3fv(c40782.f13004, 1, false, i2 == 1 ? C4078.f12995 : i2 == 2 ? C4078.f12997 : C4078.f12994, 0);
            GLES20.glUniformMatrix4fv(c40782.f13003, 1, false, fArr5, 0);
            GLES20.glActiveTexture(33984);
            GLES20.glBindTexture(36197, i);
            GLES20.glUniform1i(c40782.f13007, 0);
            C0567.m1873();
            GLES20.glVertexAttribPointer(c40782.f13005, 3, 5126, false, 12, (Buffer) c40792.f13009);
            C0567.m1873();
            GLES20.glVertexAttribPointer(c40782.f13006, 2, 5126, false, 8, (Buffer) c40792.f13010);
            C0567.m1873();
            GLES20.glDrawArrays(c40792.f13011, 0, c40792.f13008);
            C0567.m1873();
            GLES20.glDisableVertexAttribArray(c40782.f13005);
            GLES20.glDisableVertexAttribArray(c40782.f13006);
        }

        @Override // android.opengl.GLSurfaceView.Renderer
        public void onSurfaceChanged(GL10 gl10, int i, int i2) {
            GLES20.glViewport(0, 0, i, i2);
            float f = i / i2;
            Matrix.perspectiveM(this.f13038, 0, f > 1.0f ? (float) (Math.toDegrees(Math.atan(Math.tan(Math.toRadians(45.0d)) / ((double) f))) * 2.0d) : 90.0f, f, 0.1f, 100.0f);
        }

        @Override // android.opengl.GLSurfaceView.Renderer
        public synchronized void onSurfaceCreated(GL10 gl10, EGLConfig eGLConfig) {
            final C4082 c4082 = C4082.this;
            final SurfaceTexture surfaceTextureM6569 = this.f13037.m6569();
            c4082.f13028.post(new Runnable() { // from class: ދ.ހ.֏.ؠ.ྉ.ޒ.ؠ
                @Override // java.lang.Runnable
                public final void run() {
                    c4082.m6571(surfaceTextureM6569);
                }
            });
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void m6573() {
            Matrix.setRotateM(this.f13041, 0, -this.f13043, (float) Math.cos(this.f13044), (float) Math.sin(this.f13044), 0.0f);
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public synchronized void m6574(PointF pointF) {
            this.f13043 = pointF.y;
            m6573();
            Matrix.setRotateM(this.f13042, 0, -pointF.x, 0.0f, 1.0f, 0.0f);
        }

        @Override // p138.p176.p177.p190.p236.p237.C4076.InterfaceC4077
        /* JADX INFO: renamed from: ֏ */
        public synchronized void mo6563(float[] fArr, float f) {
            System.arraycopy(fArr, 0, this.f13040, 0, this.f13040.length);
            this.f13044 = -f;
            m6573();
        }
    }

    public C4082(Context context) {
        super(context, null);
        this.f13028 = new Handler(Looper.getMainLooper());
        Object systemService = context.getSystemService("sensor");
        C0567.m1856(systemService);
        SensorManager sensorManager = (SensorManager) systemService;
        this.f13025 = sensorManager;
        Sensor defaultSensor = C4150.f13259 >= 18 ? sensorManager.getDefaultSensor(15) : null;
        this.f13026 = defaultSensor == null ? this.f13025.getDefaultSensor(11) : defaultSensor;
        C4080 c4080 = new C4080();
        this.f13030 = c4080;
        C4083 c4083 = new C4083(c4080);
        this.f13029 = new ViewOnTouchListenerC4084(context, c4083, 25.0f);
        WindowManager windowManager = (WindowManager) context.getSystemService("window");
        C0567.m1856(windowManager);
        this.f13027 = new C4076(windowManager.getDefaultDisplay(), this.f13029, c4083);
        this.f13034 = true;
        setEGLContextClientVersion(2);
        setRenderer(c4083);
        setOnTouchListener(this.f13029);
    }

    @Override // android.opengl.GLSurfaceView, android.view.SurfaceView, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.f13028.post(new Runnable() { // from class: ދ.ހ.֏.ؠ.ྉ.ޒ.ހ
            @Override // java.lang.Runnable
            public final void run() {
                this.f12984.m6570();
            }
        });
    }

    @Override // android.opengl.GLSurfaceView
    public void onPause() {
        this.f13035 = false;
        m6572();
        super.onPause();
    }

    @Override // android.opengl.GLSurfaceView
    public void onResume() {
        super.onResume();
        this.f13035 = true;
        m6572();
    }

    public void setDefaultStereoMode(int i) {
        this.f13030.f13022 = i;
    }

    public void setSingleTapListener(InterfaceC4081 interfaceC4081) {
        this.f13029.f13054 = interfaceC4081;
    }

    public void setUseSensorRotation(boolean z) {
        this.f13034 = z;
        m6572();
    }

    public void setVideoComponent(InterfaceC3442.InterfaceC3445 interfaceC3445) {
        InterfaceC3442.InterfaceC3445 interfaceC34452 = this.f13033;
        if (interfaceC3445 == interfaceC34452) {
            return;
        }
        if (interfaceC34452 != null) {
            Surface surface = this.f13032;
            if (surface != null) {
                ((C3454) interfaceC34452).m5653(surface);
            }
            InterfaceC3442.InterfaceC3445 interfaceC34453 = this.f13033;
            C4080 c4080 = this.f13030;
            C3454 c3454 = (C3454) interfaceC34453;
            c3454.m5662();
            if (c3454.f10216 == c4080) {
                for (InterfaceC3450 interfaceC3450 : c3454.f10185) {
                    if (interfaceC3450.mo5455() == 2) {
                        C3446 c3446M5479 = c3454.f10186.m5479(interfaceC3450);
                        c3446M5479.m5643(6);
                        c3446M5479.m5644((Object) null);
                        c3446M5479.m5648();
                    }
                }
            }
            InterfaceC3442.InterfaceC3445 interfaceC34454 = this.f13033;
            C4080 c40802 = this.f13030;
            C3454 c34542 = (C3454) interfaceC34454;
            c34542.m5662();
            if (c34542.f10217 == c40802) {
                for (InterfaceC3450 interfaceC34502 : c34542.f10185) {
                    if (interfaceC34502.mo5455() == 5) {
                        C3446 c3446M54792 = c34542.f10186.m5479(interfaceC34502);
                        c3446M54792.m5643(7);
                        c3446M54792.m5644((Object) null);
                        c3446M54792.m5648();
                    }
                }
            }
        }
        this.f13033 = interfaceC3445;
        if (interfaceC3445 != null) {
            C4080 c40803 = this.f13030;
            C3454 c34543 = (C3454) interfaceC3445;
            c34543.m5662();
            c34543.f10216 = c40803;
            for (InterfaceC3450 interfaceC34503 : c34543.f10185) {
                if (interfaceC34503.mo5455() == 2) {
                    C3446 c3446M54793 = c34543.f10186.m5479(interfaceC34503);
                    c3446M54793.m5643(6);
                    C0567.m1932(!c3446M54793.f10176);
                    c3446M54793.f10171 = c40803;
                    c3446M54793.m5648();
                }
            }
            InterfaceC3442.InterfaceC3445 interfaceC34455 = this.f13033;
            C4080 c40804 = this.f13030;
            C3454 c34544 = (C3454) interfaceC34455;
            c34544.m5662();
            c34544.f10217 = c40804;
            for (InterfaceC3450 interfaceC34504 : c34544.f10185) {
                if (interfaceC34504.mo5455() == 5) {
                    C3446 c3446M54794 = c34544.f10186.m5479(interfaceC34504);
                    c3446M54794.m5643(7);
                    C0567.m1932(!c3446M54794.f10176);
                    c3446M54794.f10171 = c40804;
                    c3446M54794.m5648();
                }
            }
            ((C3454) this.f13033).m5660(this.f13032);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public /* synthetic */ void m6570() {
        Surface surface = this.f13032;
        if (surface != null) {
            InterfaceC3442.InterfaceC3445 interfaceC3445 = this.f13033;
            if (interfaceC3445 != null) {
                ((C3454) interfaceC3445).m5653(surface);
            }
            SurfaceTexture surfaceTexture = this.f13031;
            Surface surface2 = this.f13032;
            if (surfaceTexture != null) {
                surfaceTexture.release();
            }
            if (surface2 != null) {
                surface2.release();
            }
            this.f13031 = null;
            this.f13032 = null;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public /* synthetic */ void m6571(SurfaceTexture surfaceTexture) {
        SurfaceTexture surfaceTexture2 = this.f13031;
        Surface surface = this.f13032;
        this.f13031 = surfaceTexture;
        Surface surface2 = new Surface(surfaceTexture);
        this.f13032 = surface2;
        InterfaceC3442.InterfaceC3445 interfaceC3445 = this.f13033;
        if (interfaceC3445 != null) {
            ((C3454) interfaceC3445).m5660(surface2);
        }
        if (surfaceTexture2 != null) {
            surfaceTexture2.release();
        }
        if (surface != null) {
            surface.release();
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m6572() {
        boolean z = this.f13034 && this.f13035;
        Sensor sensor = this.f13026;
        if (sensor == null || z == this.f13036) {
            return;
        }
        if (z) {
            this.f13025.registerListener(this.f13027, sensor, 0);
        } else {
            this.f13025.unregisterListener(this.f13027);
        }
        this.f13036 = z;
    }
}
