package com.google.android.exoplayer2.video.spherical; import android.graphics.SurfaceTexture; import android.opengl.GLES20; import android.opengl.Matrix; import com.amazonaws.handlers.HandlerChainFactory$$ExternalSyntheticThrowCCEIfNotNull0; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.TimedValueQueue; import java.util.concurrent.atomic.AtomicBoolean; /* loaded from: classes2.dex */ public final class SceneRenderer { public SurfaceTexture surfaceTexture; public int textureId; public final AtomicBoolean frameAvailable = new AtomicBoolean(); public final AtomicBoolean resetRotationAtNextFrame = new AtomicBoolean(true); public final ProjectionRenderer projectionRenderer = new ProjectionRenderer(); public final FrameRotationQueue frameRotationQueue = new FrameRotationQueue(); public final TimedValueQueue sampleTimestampQueue = new TimedValueQueue(); public final TimedValueQueue projectionQueue = new TimedValueQueue(); public final float[] rotationMatrix = new float[16]; public final float[] tempMatrix = new float[16]; public volatile int defaultStereoMode = 0; public int lastStereoMode = -1; public void setDefaultStereoMode(int i) { this.defaultStereoMode = i; } public SurfaceTexture init() { GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); GlUtil.checkGlError(); this.projectionRenderer.init(); GlUtil.checkGlError(); this.textureId = GlUtil.createExternalTexture(); SurfaceTexture surfaceTexture = new SurfaceTexture(this.textureId); this.surfaceTexture = surfaceTexture; surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() { // from class: com.google.android.exoplayer2.video.spherical.SceneRenderer$$ExternalSyntheticLambda0 @Override // android.graphics.SurfaceTexture.OnFrameAvailableListener public final void onFrameAvailable(SurfaceTexture surfaceTexture2) { SceneRenderer.this.lambda$init$0(surfaceTexture2); } }); return this.surfaceTexture; } public final /* synthetic */ void lambda$init$0(SurfaceTexture surfaceTexture) { this.frameAvailable.set(true); } public void drawFrame(float[] fArr, boolean z) { GLES20.glClear(16384); GlUtil.checkGlError(); if (this.frameAvailable.compareAndSet(true, false)) { ((SurfaceTexture) Assertions.checkNotNull(this.surfaceTexture)).updateTexImage(); GlUtil.checkGlError(); if (this.resetRotationAtNextFrame.compareAndSet(true, false)) { Matrix.setIdentityM(this.rotationMatrix, 0); } long timestamp = this.surfaceTexture.getTimestamp(); Long l = (Long) this.sampleTimestampQueue.poll(timestamp); if (l != null) { this.frameRotationQueue.pollRotationMatrix(this.rotationMatrix, l.longValue()); } HandlerChainFactory$$ExternalSyntheticThrowCCEIfNotNull0.m(this.projectionQueue.pollFloor(timestamp)); } Matrix.multiplyMM(this.tempMatrix, 0, fArr, 0, this.rotationMatrix, 0); this.projectionRenderer.draw(this.textureId, this.tempMatrix, z); } }