package lh;

import android.util.Log;
import fi.a;
import java.util.Map;
import java.util.concurrent.Executor;
import lh.h;
import lh.p;
import nh.a;
import nh.h;

/* loaded from: classes4.dex */
public class k implements m, h.a, p.a {

    /* renamed from: i, reason: collision with root package name */
    private static final boolean f28173i = Log.isLoggable("Engine", 2);

    /* renamed from: a, reason: collision with root package name */
    private final s f28174a;

    /* renamed from: b, reason: collision with root package name */
    private final o f28175b;

    /* renamed from: c, reason: collision with root package name */
    private final nh.h f28176c;

    /* renamed from: d, reason: collision with root package name */
    private final b f28177d;

    /* renamed from: e, reason: collision with root package name */
    private final y f28178e;

    /* renamed from: f, reason: collision with root package name */
    private final c f28179f;

    /* renamed from: g, reason: collision with root package name */
    private final a f28180g;

    /* renamed from: h, reason: collision with root package name */
    private final lh.a f28181h;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static class a {

        /* renamed from: a, reason: collision with root package name */
        final h.e f28182a;

        /* renamed from: b, reason: collision with root package name */
        final s3.f f28183b = fi.a.d(150, new C0631a());

        /* renamed from: c, reason: collision with root package name */
        private int f28184c;

        /* renamed from: lh.k$a$a, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        class C0631a implements a.d {
            C0631a() {
            }

            @Override // fi.a.d
            /* renamed from: b, reason: merged with bridge method [inline-methods] */
            public h a() {
                a aVar = a.this;
                return new h(aVar.f28182a, aVar.f28183b);
            }
        }

        a(h.e eVar) {
            this.f28182a = eVar;
        }

        h a(com.bumptech.glide.d dVar, Object obj, n nVar, jh.f fVar, int i10, int i11, Class cls, Class cls2, com.bumptech.glide.g gVar, j jVar, Map map, boolean z10, boolean z11, boolean z12, jh.h hVar, h.b bVar) {
            h hVar2 = (h) ei.k.d((h) this.f28183b.b());
            int i12 = this.f28184c;
            this.f28184c = i12 + 1;
            return hVar2.A(dVar, obj, nVar, fVar, i10, i11, cls, cls2, gVar, jVar, map, z10, z11, z12, hVar, bVar, i12);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static class b {

        /* renamed from: a, reason: collision with root package name */
        final oh.a f28186a;

        /* renamed from: b, reason: collision with root package name */
        final oh.a f28187b;

        /* renamed from: c, reason: collision with root package name */
        final oh.a f28188c;

        /* renamed from: d, reason: collision with root package name */
        final oh.a f28189d;

        /* renamed from: e, reason: collision with root package name */
        final m f28190e;

        /* renamed from: f, reason: collision with root package name */
        final p.a f28191f;

        /* renamed from: g, reason: collision with root package name */
        final s3.f f28192g = fi.a.d(150, new a());

        /* loaded from: classes4.dex */
        class a implements a.d {
            a() {
            }

            @Override // fi.a.d
            /* renamed from: b, reason: merged with bridge method [inline-methods] */
            public l a() {
                b bVar = b.this;
                return new l(bVar.f28186a, bVar.f28187b, bVar.f28188c, bVar.f28189d, bVar.f28190e, bVar.f28191f, bVar.f28192g);
            }
        }

        b(oh.a aVar, oh.a aVar2, oh.a aVar3, oh.a aVar4, m mVar, p.a aVar5) {
            this.f28186a = aVar;
            this.f28187b = aVar2;
            this.f28188c = aVar3;
            this.f28189d = aVar4;
            this.f28190e = mVar;
            this.f28191f = aVar5;
        }

        l a(jh.f fVar, boolean z10, boolean z11, boolean z12, boolean z13) {
            return ((l) ei.k.d((l) this.f28192g.b())).k(fVar, z10, z11, z12, z13);
        }
    }

    /* loaded from: classes4.dex */
    private static class c implements h.e {

        /* renamed from: a, reason: collision with root package name */
        private final a.InterfaceC0688a f28194a;

        /* renamed from: b, reason: collision with root package name */
        private volatile nh.a f28195b;

        c(a.InterfaceC0688a interfaceC0688a) {
            this.f28194a = interfaceC0688a;
        }

        @Override // lh.h.e
        public nh.a a() {
            if (this.f28195b == null) {
                synchronized (this) {
                    if (this.f28195b == null) {
                        this.f28195b = this.f28194a.build();
                    }
                    if (this.f28195b == null) {
                        this.f28195b = new nh.b();
                    }
                }
            }
            return this.f28195b;
        }
    }

    /* loaded from: classes4.dex */
    public class d {

        /* renamed from: a, reason: collision with root package name */
        private final l f28196a;

        /* renamed from: b, reason: collision with root package name */
        private final com.bumptech.glide.request.g f28197b;

        d(com.bumptech.glide.request.g gVar, l lVar) {
            this.f28197b = gVar;
            this.f28196a = lVar;
        }

        public void a() {
            synchronized (k.this) {
                this.f28196a.r(this.f28197b);
            }
        }
    }

    public k(nh.h hVar, a.InterfaceC0688a interfaceC0688a, oh.a aVar, oh.a aVar2, oh.a aVar3, oh.a aVar4, boolean z10) {
        this(hVar, interfaceC0688a, aVar, aVar2, aVar3, aVar4, null, null, null, null, null, null, z10);
    }

    private p e(jh.f fVar) {
        v d10 = this.f28176c.d(fVar);
        if (d10 == null) {
            return null;
        }
        return d10 instanceof p ? (p) d10 : new p(d10, true, true, fVar, this);
    }

    private p g(jh.f fVar) {
        p e10 = this.f28181h.e(fVar);
        if (e10 != null) {
            e10.b();
        }
        return e10;
    }

    private p h(jh.f fVar) {
        p e10 = e(fVar);
        if (e10 != null) {
            e10.b();
            this.f28181h.a(fVar, e10);
        }
        return e10;
    }

    private p i(n nVar, boolean z10, long j10) {
        if (!z10) {
            return null;
        }
        p g10 = g(nVar);
        if (g10 != null) {
            if (f28173i) {
                j("Loaded resource from active resources", j10, nVar);
            }
            return g10;
        }
        p h10 = h(nVar);
        if (h10 == null) {
            return null;
        }
        if (f28173i) {
            j("Loaded resource from cache", j10, nVar);
        }
        return h10;
    }

    private static void j(String str, long j10, jh.f fVar) {
        Log.v("Engine", str + " in " + ei.g.a(j10) + "ms, key: " + fVar);
    }

    private d l(com.bumptech.glide.d dVar, Object obj, jh.f fVar, int i10, int i11, Class cls, Class cls2, com.bumptech.glide.g gVar, j jVar, Map map, boolean z10, boolean z11, jh.h hVar, boolean z12, boolean z13, boolean z14, boolean z15, com.bumptech.glide.request.g gVar2, Executor executor, n nVar, long j10) {
        l a10 = this.f28174a.a(nVar, z15);
        if (a10 != null) {
            a10.d(gVar2, executor);
            if (f28173i) {
                j("Added to existing load", j10, nVar);
            }
            return new d(gVar2, a10);
        }
        l a11 = this.f28177d.a(nVar, z12, z13, z14, z15);
        h a12 = this.f28180g.a(dVar, obj, nVar, fVar, i10, i11, cls, cls2, gVar, jVar, map, z10, z11, z15, hVar, a11);
        this.f28174a.c(nVar, a11);
        a11.d(gVar2, executor);
        a11.s(a12);
        if (f28173i) {
            j("Started new load", j10, nVar);
        }
        return new d(gVar2, a11);
    }

    @Override // nh.h.a
    public void a(v vVar) {
        this.f28178e.a(vVar, true);
    }

    @Override // lh.m
    public synchronized void b(l lVar, jh.f fVar) {
        this.f28174a.d(fVar, lVar);
    }

    @Override // lh.m
    public synchronized void c(l lVar, jh.f fVar, p pVar) {
        if (pVar != null) {
            if (pVar.f()) {
                this.f28181h.a(fVar, pVar);
            }
        }
        this.f28174a.d(fVar, lVar);
    }

    @Override // lh.p.a
    public void d(jh.f fVar, p pVar) {
        this.f28181h.d(fVar);
        if (pVar.f()) {
            this.f28176c.e(fVar, pVar);
        } else {
            this.f28178e.a(pVar, false);
        }
    }

    public d f(com.bumptech.glide.d dVar, Object obj, jh.f fVar, int i10, int i11, Class cls, Class cls2, com.bumptech.glide.g gVar, j jVar, Map map, boolean z10, boolean z11, jh.h hVar, boolean z12, boolean z13, boolean z14, boolean z15, com.bumptech.glide.request.g gVar2, Executor executor) {
        long b10 = f28173i ? ei.g.b() : 0L;
        n a10 = this.f28175b.a(obj, fVar, i10, i11, map, cls, cls2, hVar);
        synchronized (this) {
            p i12 = i(a10, z12, b10);
            if (i12 == null) {
                return l(dVar, obj, fVar, i10, i11, cls, cls2, gVar, jVar, map, z10, z11, hVar, z12, z13, z14, z15, gVar2, executor, a10, b10);
            }
            gVar2.a(i12, jh.a.MEMORY_CACHE, false);
            return null;
        }
    }

    public void k(v vVar) {
        if (!(vVar instanceof p)) {
            throw new IllegalArgumentException("Cannot release anything but an EngineResource");
        }
        ((p) vVar).g();
    }

    k(nh.h hVar, a.InterfaceC0688a interfaceC0688a, oh.a aVar, oh.a aVar2, oh.a aVar3, oh.a aVar4, s sVar, o oVar, lh.a aVar5, b bVar, a aVar6, y yVar, boolean z10) {
        this.f28176c = hVar;
        c cVar = new c(interfaceC0688a);
        this.f28179f = cVar;
        lh.a aVar7 = aVar5 == null ? new lh.a(z10) : aVar5;
        this.f28181h = aVar7;
        aVar7.f(this);
        this.f28175b = oVar == null ? new o() : oVar;
        this.f28174a = sVar == null ? new s() : sVar;
        this.f28177d = bVar == null ? new b(aVar, aVar2, aVar3, aVar4, this, this) : bVar;
        this.f28180g = aVar6 == null ? new a(cVar) : aVar6;
        this.f28178e = yVar == null ? new y() : yVar;
        hVar.c(this);
    }
}
