package io.flutter.plugin.platform;

import android.media.ImageReader;
import android.os.Build;
import android.os.Handler;
import android.view.Surface;
import io.flutter.view.TextureRegistry$ImageTextureEntry;

/* JADX INFO: loaded from: classes.dex */
public final class c implements l {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public TextureRegistry$ImageTextureEntry f28193a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public ImageReader f28194b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f28195c = 0;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f28196d = 0;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Handler f28197e = new Handler();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final b f28198f = new b(this);

    public c(TextureRegistry$ImageTextureEntry textureRegistry$ImageTextureEntry) {
        if (Build.VERSION.SDK_INT < 29) {
            throw new UnsupportedOperationException("ImageReaderPlatformViewRenderTarget requires API version 29+");
        }
        this.f28193a = textureRegistry$ImageTextureEntry;
    }

    @Override // io.flutter.plugin.platform.l
    public final int getHeight() {
        return this.f28196d;
    }

    @Override // io.flutter.plugin.platform.l
    public final long getId() {
        return this.f28193a.id();
    }

    @Override // io.flutter.plugin.platform.l
    public final Surface getSurface() {
        return this.f28194b.getSurface();
    }

    @Override // io.flutter.plugin.platform.l
    public final int getWidth() {
        return this.f28195c;
    }

    @Override // io.flutter.plugin.platform.l
    public final void i(int i10, int i11) {
        ImageReader imageReaderNewInstance;
        ImageReader imageReader = this.f28194b;
        if (imageReader != null && this.f28195c == i10 && this.f28196d == i11) {
            return;
        }
        if (imageReader != null) {
            this.f28193a.pushImage(null);
            this.f28194b.close();
            this.f28194b = null;
        }
        this.f28195c = i10;
        this.f28196d = i11;
        int i12 = Build.VERSION.SDK_INT;
        Handler handler = this.f28197e;
        b bVar = this.f28198f;
        if (i12 >= 33) {
            io.flutter.embedding.android.d.k();
            ImageReader.Builder builderC = io.flutter.embedding.android.d.c(this.f28195c, this.f28196d);
            builderC.setMaxImages(4);
            builderC.setImageFormat(34);
            builderC.setUsage(256L);
            imageReaderNewInstance = builderC.build();
            imageReaderNewInstance.setOnImageAvailableListener(bVar, handler);
        } else {
            if (i12 < 29) {
                throw new UnsupportedOperationException("ImageReaderPlatformViewRenderTarget requires API version 29+");
            }
            imageReaderNewInstance = ImageReader.newInstance(i10, i11, 34, 4, 256L);
            imageReaderNewInstance.setOnImageAvailableListener(bVar, handler);
        }
        this.f28194b = imageReaderNewInstance;
    }

    @Override // io.flutter.plugin.platform.l
    public final void release() {
        if (this.f28194b != null) {
            this.f28193a.pushImage(null);
            this.f28194b.close();
            this.f28194b = null;
        }
        this.f28193a = null;
    }
}
