package com.google.android.gms.internal.ads; import android.graphics.SurfaceTexture; import android.opengl.EGL14; import android.opengl.EGLConfig; import android.opengl.EGLContext; import android.opengl.EGLDisplay; import android.opengl.EGLSurface; import android.opengl.GLES20; import android.opengl.GLU; import android.os.Handler; import androidx.annotation.Nullable; import java.util.Locale; /* loaded from: classes3.dex */ public final class zzdd implements SurfaceTexture.OnFrameAvailableListener, Runnable { private static final int[] zza = {12352, 4, 12324, 8, 12323, 8, 12322, 8, 12321, 8, 12325, 0, 12327, 12344, 12339, 4, 12344}; private final Handler zzb; private final int[] zzc = new int[1]; @Nullable private EGLDisplay zzd; @Nullable private EGLContext zze; @Nullable private EGLSurface zzf; @Nullable private SurfaceTexture zzg; public zzdd(Handler handler, @Nullable zzdc zzdcVar) { this.zzb = handler; } @Override // android.graphics.SurfaceTexture.OnFrameAvailableListener public final void onFrameAvailable(SurfaceTexture surfaceTexture) { this.zzb.post(this); } @Override // java.lang.Runnable public final void run() { SurfaceTexture surfaceTexture = this.zzg; if (surfaceTexture != null) { try { surfaceTexture.updateTexImage(); } catch (RuntimeException unused) { } } } public final void zzb(int i) throws zzde { EGLSurface eglCreatePbufferSurface; EGLDisplay eglGetDisplay = EGL14.eglGetDisplay(0); zzdf.zza(eglGetDisplay != null, "eglGetDisplay failed"); int[] iArr = new int[2]; zzdf.zza(EGL14.eglInitialize(eglGetDisplay, iArr, 0, iArr, 1), "eglInitialize failed"); this.zzd = eglGetDisplay; EGLConfig[] eGLConfigArr = new EGLConfig[1]; int[] iArr2 = new int[1]; boolean eglChooseConfig = EGL14.eglChooseConfig(eglGetDisplay, zza, 0, eGLConfigArr, 0, 1, iArr2, 0); zzdf.zza(eglChooseConfig && iArr2[0] > 0 && eGLConfigArr[0] != null, String.format(Locale.US, "eglChooseConfig failed: success=%b, numConfigs[0]=%d, configs[0]=%s", Boolean.valueOf(eglChooseConfig), Integer.valueOf(iArr2[0]), eGLConfigArr[0])); EGLConfig eGLConfig = eGLConfigArr[0]; EGLContext eglCreateContext = EGL14.eglCreateContext(this.zzd, eGLConfig, EGL14.EGL_NO_CONTEXT, i == 0 ? new int[]{12440, 2, 12344} : new int[]{12440, 2, 12992, 1, 12344}, 0); zzdf.zza(eglCreateContext != null, "eglCreateContext failed"); this.zze = eglCreateContext; EGLDisplay eGLDisplay = this.zzd; if (i == 1) { eglCreatePbufferSurface = EGL14.EGL_NO_SURFACE; } else { eglCreatePbufferSurface = EGL14.eglCreatePbufferSurface(eGLDisplay, eGLConfig, i == 2 ? new int[]{12375, 1, 12374, 1, 12992, 1, 12344} : new int[]{12375, 1, 12374, 1, 12344}, 0); zzdf.zza(eglCreatePbufferSurface != null, "eglCreatePbufferSurface failed"); } zzdf.zza(EGL14.eglMakeCurrent(eGLDisplay, eglCreatePbufferSurface, eglCreatePbufferSurface, eglCreateContext), "eglMakeCurrent failed"); this.zzf = eglCreatePbufferSurface; GLES20.glGenTextures(1, this.zzc, 0); StringBuilder sb = new StringBuilder(); boolean z = false; while (true) { int glGetError = GLES20.glGetError(); if (glGetError == 0) { break; } if (z) { sb.append('\n'); } String gluErrorString = GLU.gluErrorString(glGetError); if (gluErrorString == null) { gluErrorString = "error code: 0x".concat(String.valueOf(Integer.toHexString(glGetError))); } sb.append("glError: "); sb.append(gluErrorString); z = true; } if (z) { throw new zzde(sb.toString()); } SurfaceTexture surfaceTexture = new SurfaceTexture(this.zzc[0]); this.zzg = surfaceTexture; surfaceTexture.setOnFrameAvailableListener(this); } public final void zzc() { this.zzb.removeCallbacks(this); try { SurfaceTexture surfaceTexture = this.zzg; if (surfaceTexture != null) { surfaceTexture.release(); GLES20.glDeleteTextures(1, this.zzc, 0); } EGLDisplay eGLDisplay = this.zzd; if (eGLDisplay != null && !eGLDisplay.equals(EGL14.EGL_NO_DISPLAY)) { EGLDisplay eGLDisplay2 = this.zzd; EGLSurface eGLSurface = EGL14.EGL_NO_SURFACE; EGL14.eglMakeCurrent(eGLDisplay2, eGLSurface, eGLSurface, EGL14.EGL_NO_CONTEXT); } EGLSurface eGLSurface2 = this.zzf; if (eGLSurface2 != null && !eGLSurface2.equals(EGL14.EGL_NO_SURFACE)) { EGL14.eglDestroySurface(this.zzd, this.zzf); } EGLContext eGLContext = this.zze; if (eGLContext != null) { EGL14.eglDestroyContext(this.zzd, eGLContext); } EGL14.eglReleaseThread(); EGLDisplay eGLDisplay3 = this.zzd; if (eGLDisplay3 != null && !eGLDisplay3.equals(EGL14.EGL_NO_DISPLAY)) { EGL14.eglTerminate(this.zzd); } this.zzd = null; this.zze = null; this.zzf = null; this.zzg = null; } catch (Throwable th) { EGLDisplay eGLDisplay4 = this.zzd; if (eGLDisplay4 != null && !eGLDisplay4.equals(EGL14.EGL_NO_DISPLAY)) { EGLDisplay eGLDisplay5 = this.zzd; EGLSurface eGLSurface3 = EGL14.EGL_NO_SURFACE; EGL14.eglMakeCurrent(eGLDisplay5, eGLSurface3, eGLSurface3, EGL14.EGL_NO_CONTEXT); } EGLSurface eGLSurface4 = this.zzf; if (eGLSurface4 != null && !eGLSurface4.equals(EGL14.EGL_NO_SURFACE)) { EGL14.eglDestroySurface(this.zzd, this.zzf); } EGLContext eGLContext2 = this.zze; if (eGLContext2 != null) { EGL14.eglDestroyContext(this.zzd, eGLContext2); } EGL14.eglReleaseThread(); EGLDisplay eGLDisplay6 = this.zzd; if (eGLDisplay6 != null && !eGLDisplay6.equals(EGL14.EGL_NO_DISPLAY)) { EGL14.eglTerminate(this.zzd); } this.zzd = null; this.zze = null; this.zzf = null; this.zzg = null; throw th; } } public final SurfaceTexture zza() { SurfaceTexture surfaceTexture = this.zzg; surfaceTexture.getClass(); return surfaceTexture; } }