package j5;

import android.content.res.Resources;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;

/* JADX INFO: loaded from: classes.dex */
public final class a implements a5.m {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f28633a = 0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f28634b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Object f28635c;

    public a(n nVar, c5.b bVar) {
        this.f28634b = nVar;
        this.f28635c = bVar;
    }

    @Override // a5.m
    public final boolean a(Object obj, a5.l lVar) {
        int i10 = this.f28633a;
        Object obj2 = this.f28634b;
        switch (i10) {
            case 0:
                return ((a5.m) obj2).a(obj, lVar);
            default:
                ((n) obj2).getClass();
                return true;
        }
    }

    @Override // a5.m
    public final com.bumptech.glide.load.engine.e0 decode(Object obj, int i10, int i11, a5.l lVar) throws IOException {
        com.bumptech.glide.load.resource.bitmap.a aVar;
        boolean z10;
        t5.f fVar;
        switch (this.f28633a) {
            case 0:
                return y.obtain((Resources) this.f28635c, ((a5.m) this.f28634b).decode(obj, i10, i11, lVar));
            default:
                InputStream inputStream = (InputStream) obj;
                if (inputStream instanceof com.bumptech.glide.load.resource.bitmap.a) {
                    aVar = (com.bumptech.glide.load.resource.bitmap.a) inputStream;
                    z10 = false;
                } else {
                    aVar = new com.bumptech.glide.load.resource.bitmap.a(inputStream, (c5.b) this.f28635c);
                    z10 = true;
                }
                ArrayDeque arrayDeque = t5.f.f32961c;
                synchronized (arrayDeque) {
                    fVar = (t5.f) arrayDeque.poll();
                    break;
                }
                if (fVar == null) {
                    fVar = new t5.f();
                }
                t5.f fVar2 = fVar;
                fVar2.f32962a = aVar;
                t5.l lVar2 = new t5.l(fVar2);
                xyz.stream.utils.e0 e0Var = new xyz.stream.utils.e0(aVar, fVar2, 8, 0);
                try {
                    n nVar = (n) this.f28634b;
                    d dVarA = nVar.a(new v(nVar.f28675d, lVar2, nVar.f28674c), i10, i11, lVar, e0Var);
                    fVar2.f32963b = null;
                    fVar2.f32962a = null;
                    synchronized (arrayDeque) {
                        arrayDeque.offer(fVar2);
                        break;
                    }
                    if (z10) {
                        aVar.g();
                    }
                    return dVarA;
                } catch (Throwable th) {
                    fVar2.f32963b = null;
                    fVar2.f32962a = null;
                    ArrayDeque arrayDeque2 = t5.f.f32961c;
                    synchronized (arrayDeque2) {
                        arrayDeque2.offer(fVar2);
                        if (z10) {
                            aVar.g();
                        }
                        throw th;
                    }
                }
        }
    }

    public a(Resources resources, a5.m mVar) {
        this.f28635c = (Resources) t5.n.checkNotNull(resources);
        this.f28634b = (a5.m) t5.n.checkNotNull(mVar);
    }
}
