package com.bumptech.glide.load.engine;

import android.util.Log;
import com.bumptech.glide.Registry$MissingComponentException;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.EncodeStrategy;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Class f5745a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final m5.e f5747c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final p0.e f5748d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final String f5749e;

    public m(Class cls, Class cls2, Class cls3, List list, m5.e eVar, xyz.stream.utils.t tVar) {
        this.f5745a = cls;
        this.f5746b = list;
        this.f5747c = eVar;
        this.f5748d = tVar;
        this.f5749e = "Failed DecodePath{" + cls.getSimpleName() + "->" + cls2.getSimpleName() + "->" + cls3.getSimpleName() + "}";
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00d7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final e0 a(int i10, int i11, a5.l lVar, com.bumptech.glide.load.data.g gVar, xyz.stream.utils.e0 e0Var) {
        e0 e0VarA;
        a5.o oVar;
        EncodeStrategy encodeStrategyK;
        boolean z10;
        boolean z11;
        boolean z12;
        Object fVar;
        p0.e eVar = this.f5748d;
        List list = (List) t5.n.checkNotNull(eVar.acquire());
        try {
            e0 e0VarB = b(gVar, i10, i11, lVar, list);
            eVar.a(list);
            l lVar2 = (l) e0Var.f36129c;
            DataSource dataSource = (DataSource) e0Var.f36128b;
            lVar2.getClass();
            Class<?> cls = e0VarB.get().getClass();
            DataSource dataSource2 = DataSource.f5592d;
            i iVar = lVar2.f5724a;
            a5.n nVar = null;
            if (dataSource != dataSource2) {
                a5.o oVarE = iVar.e(cls);
                oVar = oVarE;
                e0VarA = oVarE.a(lVar2.f5738h, e0VarB, lVar2.f5743l, lVar2.f5744m);
            } else {
                e0VarA = e0VarB;
                oVar = null;
            }
            if (!e0VarB.equals(e0VarA)) {
                e0VarB.a();
            }
            if (iVar.f5696c.f5581b.f5833d.get(e0VarA.b()) != null) {
                com.bumptech.glide.p pVar = iVar.f5696c.f5581b;
                pVar.getClass();
                nVar = pVar.f5833d.get(e0VarA.b());
                if (nVar == null) {
                    final Class clsB = e0VarA.b();
                    throw new Registry$MissingComponentException(clsB) { // from class: com.bumptech.glide.Registry$NoResultEncoderAvailableException
                        {
                            super("Failed to find result encoder for resource class: " + clsB + ", you may need to consider registering a new Encoder for the requested type or DiskCacheStrategy.DATA/DiskCacheStrategy.NONE if caching your transformed resource is unnecessary.");
                        }
                    };
                }
                encodeStrategyK = nVar.k(lVar2.R);
            } else {
                encodeStrategyK = EncodeStrategy.f5601c;
            }
            a5.h hVar = lVar2.Z;
            ArrayList arrayListB = iVar.b();
            int size = arrayListB.size();
            int i12 = 0;
            while (true) {
                if (i12 >= size) {
                    z10 = false;
                    break;
                }
                if (((g5.a0) arrayListB.get(i12)).f26165a.equals(hVar)) {
                    z10 = true;
                    break;
                }
                i12++;
            }
            boolean z13 = !z10;
            int i13 = ((n) lVar2.Q).f5750f;
            DataSource dataSource3 = DataSource.f5593e;
            switch (i13) {
                case 0:
                    if (dataSource != dataSource2 && dataSource != dataSource3) {
                        if (nVar == null) {
                            final Class<?> cls2 = e0VarA.get().getClass();
                            throw new Registry$MissingComponentException(cls2) { // from class: com.bumptech.glide.Registry$NoResultEncoderAvailableException
                                {
                                    super("Failed to find result encoder for resource class: " + cls2 + ", you may need to consider registering a new Encoder for the requested type or DiskCacheStrategy.DATA/DiskCacheStrategy.NONE if caching your transformed resource is unnecessary.");
                                }
                            };
                        }
                        int iOrdinal = encodeStrategyK.ordinal();
                        if (iOrdinal == 0) {
                            z11 = true;
                            z12 = false;
                            fVar = new f(lVar2.Z, lVar2.f5740i);
                        } else {
                            if (iOrdinal != 1) {
                                throw new IllegalArgumentException("Unknown strategy: " + encodeStrategyK);
                            }
                            z11 = true;
                            fVar = new g0(iVar.f5696c.f5580a, lVar2.Z, lVar2.f5740i, lVar2.f5743l, lVar2.f5744m, oVar, cls, lVar2.R);
                            z12 = false;
                        }
                        d0 d0Var = (d0) t5.n.checkNotNull((d0) d0.f5658e.acquire());
                        d0Var.f5662d = z12;
                        d0Var.f5661c = z11;
                        d0Var.f5660b = e0VarA;
                        k kVar = lVar2.f5734f;
                        kVar.f5721a = fVar;
                        kVar.f5722b = nVar;
                        kVar.f5723c = d0Var;
                        e0VarA = d0Var;
                    }
                    return this.f5747c.transcode(e0VarA, lVar);
                case 1:
                case 2:
                    return this.f5747c.transcode(e0VarA, lVar);
                case 3:
                    if (dataSource != dataSource2 && dataSource != dataSource3) {
                    }
                    return this.f5747c.transcode(e0VarA, lVar);
                default:
                    if (((z13 && dataSource == DataSource.f5591c) || dataSource == DataSource.f5589a) && encodeStrategyK == EncodeStrategy.f5600b) {
                    }
                    return this.f5747c.transcode(e0VarA, lVar);
            }
        } catch (Throwable th) {
            eVar.a(list);
            throw th;
        }
    }

    public final e0 b(com.bumptech.glide.load.data.g gVar, int i10, int i11, a5.l lVar, List list) throws GlideException {
        List list2 = this.f5746b;
        int size = list2.size();
        e0 e0VarDecode = null;
        for (int i12 = 0; i12 < size; i12++) {
            a5.m mVar = (a5.m) list2.get(i12);
            try {
                if (mVar.a(gVar.c(), lVar)) {
                    e0VarDecode = mVar.decode(gVar.c(), i10, i11, lVar);
                }
            } catch (IOException | OutOfMemoryError | RuntimeException e10) {
                if (Log.isLoggable("DecodePath", 2)) {
                    Objects.toString(mVar);
                }
                list.add(e10);
            }
            if (e0VarDecode != null) {
                break;
            }
        }
        if (e0VarDecode != null) {
            return e0VarDecode;
        }
        throw new GlideException(this.f5749e, new ArrayList(list));
    }

    public final String toString() {
        return "DecodePath{ dataClass=" + this.f5745a + ", decoders=" + this.f5746b + ", transcoder=" + this.f5747c + '}';
    }
}
