package com.bumptech.glide;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import g5.b0;
import g5.c0;
import g5.d0;
import g5.e0;
import g5.j0;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import xyz.stream.utils.a0;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final fe.h f5830a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final p5.b f5831b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final xyz.stream.utils.f f5832c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final p5.g f5833d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final com.bumptech.glide.load.data.i f5834e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final a0 f5835f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final xyz.stream.api.r f5836g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final p5.d f5837h = new p5.d();

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final p5.c f5838i = new p5.c();

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final xyz.stream.utils.t f5839j;

    public p() {
        int i10 = 21;
        xyz.stream.utils.t tVar = new xyz.stream.utils.t((Object) new p0.f(20), (Object) new com.google.android.gms.measurement.internal.a0(i10), (x6.b) new androidx.window.core.h(i10), 8);
        this.f5839j = tVar;
        this.f5830a = new fe.h(tVar);
        this.f5831b = new p5.b();
        this.f5832c = new xyz.stream.utils.f(9);
        this.f5833d = new p5.g();
        this.f5834e = new com.bumptech.glide.load.data.i();
        this.f5835f = new a0(11);
        this.f5836g = new xyz.stream.api.r(1);
        List listAsList = Arrays.asList("Animation", "Bitmap", "BitmapDrawable");
        ArrayList arrayList = new ArrayList(listAsList.size());
        arrayList.add("legacy_prepend_all");
        Iterator it = listAsList.iterator();
        while (it.hasNext()) {
            arrayList.add((String) it.next());
        }
        arrayList.add("legacy_append");
        xyz.stream.utils.f fVar = this.f5832c;
        synchronized (fVar) {
            try {
                ArrayList<String> arrayList2 = new ArrayList((List) fVar.f36132b);
                ((List) fVar.f36132b).clear();
                Iterator it2 = arrayList.iterator();
                while (it2.hasNext()) {
                    ((List) fVar.f36132b).add((String) it2.next());
                }
                for (String str : arrayList2) {
                    if (!arrayList.contains(str)) {
                        ((List) fVar.f36132b).add(str);
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void a(a5.m mVar, Class cls, Class cls2, String str) {
        xyz.stream.utils.f fVar = this.f5832c;
        synchronized (fVar) {
            fVar.s(str).add(new p5.e(cls, cls2, mVar));
        }
    }

    public final void b(Class cls, a5.a aVar) {
        p5.b bVar = this.f5831b;
        synchronized (bVar) {
            bVar.f31628a.add(new p5.a(cls, aVar));
        }
    }

    public final void c(Class cls, a5.n nVar) {
        p5.g gVar = this.f5833d;
        synchronized (gVar) {
            gVar.f31639a.add(new p5.f(cls, nVar));
        }
    }

    public final void d(Class cls, Class cls2, c0 c0Var) {
        fe.h hVar = this.f5830a;
        synchronized (hVar) {
            ((j0) hVar.f26080b).a(cls, cls2, c0Var);
            ((e0) hVar.f26081c).f26174a.clear();
        }
    }

    public final ArrayList e() {
        ArrayList arrayList;
        xyz.stream.api.r rVar = this.f5836g;
        synchronized (rVar) {
            arrayList = rVar.f35933a;
        }
        if (arrayList.isEmpty()) {
            throw new Registry$MissingComponentException() { // from class: com.bumptech.glide.Registry$NoImageHeaderParserException
            };
        }
        return arrayList;
    }

    public final List f(Object obj) {
        List<b0> listUnmodifiableList;
        fe.h hVar = this.f5830a;
        hVar.getClass();
        Class<?> cls = obj.getClass();
        synchronized (hVar) {
            listUnmodifiableList = ((e0) hVar.f26081c).get(cls);
            if (listUnmodifiableList == null) {
                listUnmodifiableList = Collections.unmodifiableList(((j0) hVar.f26080b).d(cls));
                if (((d0) ((e0) hVar.f26081c).f26174a.put(cls, new d0(listUnmodifiableList))) != null) {
                    throw new IllegalStateException("Already cached loaders for model: " + cls);
                }
            }
        }
        if (listUnmodifiableList.isEmpty()) {
            throw new Registry$NoModelLoaderAvailableException("Failed to find any ModelLoaders registered for model class: " + obj.getClass());
        }
        int size = listUnmodifiableList.size();
        List listEmptyList = Collections.emptyList();
        boolean z10 = true;
        for (int i10 = 0; i10 < size; i10++) {
            b0 b0Var = listUnmodifiableList.get(i10);
            if (b0Var.a(obj)) {
                if (z10) {
                    listEmptyList = new ArrayList(size - i10);
                    z10 = false;
                }
                listEmptyList.add(b0Var);
            }
        }
        if (!listEmptyList.isEmpty()) {
            return listEmptyList;
        }
        throw new Registry$NoModelLoaderAvailableException("Found ModelLoaders for model class: " + listUnmodifiableList + ", but none that handle this specific model instance: " + obj);
    }

    public final com.bumptech.glide.load.data.g g(Object obj) {
        com.bumptech.glide.load.data.g gVarB;
        com.bumptech.glide.load.data.i iVar = this.f5834e;
        synchronized (iVar) {
            try {
                t5.n.checkNotNull(obj);
                com.bumptech.glide.load.data.f fVar = (com.bumptech.glide.load.data.f) iVar.f5617a.get(obj.getClass());
                if (fVar == null) {
                    Iterator it = iVar.f5617a.values().iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        com.bumptech.glide.load.data.f fVar2 = (com.bumptech.glide.load.data.f) it.next();
                        if (fVar2.a().isAssignableFrom(obj.getClass())) {
                            fVar = fVar2;
                            break;
                        }
                    }
                }
                if (fVar == null) {
                    fVar = com.bumptech.glide.load.data.i.f5616b;
                }
                gVarB = fVar.b(obj);
            } catch (Throwable th) {
                throw th;
            }
        }
        return gVarB;
    }

    @Nullable
    public <Data, TResource, Transcode> com.bumptech.glide.load.engine.c0 getLoadPath(@NonNull Class<Data> cls, @NonNull Class<TResource> cls2, @NonNull Class<Transcode> cls3) {
        ArrayList arrayList;
        m5.e eVar;
        com.bumptech.glide.load.engine.c0 c0Var = this.f5838i.get(cls, cls2, cls3);
        if (this.f5838i.isEmptyLoadPath(c0Var)) {
            return null;
        }
        if (c0Var == null) {
            ArrayList arrayList2 = new ArrayList();
            for (Class<?> cls4 : this.f5832c.t(cls, cls2)) {
                for (Class cls5 : this.f5835f.w(cls4, cls3)) {
                    xyz.stream.utils.f fVar = this.f5832c;
                    synchronized (fVar) {
                        arrayList = new ArrayList();
                        Iterator it = ((List) fVar.f36132b).iterator();
                        while (it.hasNext()) {
                            List<p5.e> list = (List) ((Map) fVar.f36133c).get((String) it.next());
                            if (list != null) {
                                for (p5.e eVar2 : list) {
                                    if (eVar2.f31634a.isAssignableFrom(cls) && cls4.isAssignableFrom(eVar2.f31635b)) {
                                        arrayList.add(eVar2.f31636c);
                                    }
                                }
                            }
                        }
                    }
                    a0 a0Var = this.f5835f;
                    synchronized (a0Var) {
                        if (!cls5.isAssignableFrom(cls4)) {
                            for (m5.f fVar2 : (List) a0Var.f36098a) {
                                if (fVar2.f30386a.isAssignableFrom(cls4) && cls5.isAssignableFrom(fVar2.f30387b)) {
                                    eVar = fVar2.f30388c;
                                }
                            }
                            throw new IllegalArgumentException("No transcoder registered to transcode from " + cls4 + " to " + cls5);
                        }
                        eVar = m5.g.f30389a;
                    }
                    arrayList2.add(new com.bumptech.glide.load.engine.m(cls, cls4, cls5, arrayList, eVar, this.f5839j));
                }
            }
            c0Var = arrayList2.isEmpty() ? null : new com.bumptech.glide.load.engine.c0(cls, cls2, cls3, arrayList2, this.f5839j);
            this.f5838i.put(cls, cls2, cls3, c0Var);
        }
        return c0Var;
    }

    public final void h(com.bumptech.glide.load.data.f fVar) {
        com.bumptech.glide.load.data.i iVar = this.f5834e;
        synchronized (iVar) {
            iVar.f5617a.put(fVar.a(), fVar);
        }
    }

    public final void i(Class cls, Class cls2, m5.e eVar) {
        a0 a0Var = this.f5835f;
        synchronized (a0Var) {
            ((List) a0Var.f36098a).add(new m5.f(cls, cls2, eVar));
        }
    }

    public final void j(z4.b bVar) {
        ArrayList arrayListF;
        fe.h hVar = this.f5830a;
        synchronized (hVar) {
            try {
                j0 j0Var = (j0) hVar.f26080b;
                synchronized (j0Var) {
                    arrayListF = j0Var.f();
                    j0Var.a(g5.o.class, InputStream.class, bVar);
                }
                Iterator it = arrayListF.iterator();
                while (it.hasNext()) {
                    ((c0) it.next()).b();
                }
                ((e0) hVar.f26081c).f26174a.clear();
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
