package ඓ.ῲ.K.ᕣ.ᨨ;

import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.CallbackException;
import com.bumptech.glide.load.engine.DecodeJob;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.SingleRequest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import ඓ.ῲ.K.ᓣ.C0825;
import ඓ.ῲ.K.ᓣ.ᕣ.AbstractC0836;
import ඓ.ῲ.K.ᓣ.ᕣ.C0830;
import ඓ.ῲ.K.ᕣ.AbstractC1029;
import ඓ.ῲ.K.ᕣ.ᨨ.C1005;
import ඓ.ῲ.K.ᕣ.ᨨ.㮔.ExecutorServiceC1008;
import ඓ.ῲ.K.㗗.AbstractC1199;
import ῲ.ᨨ.㳳.C1841;
import ῲ.ᨨ.㿎.AbstractC1871;

/* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ᕣ  reason: contains not printable characters */
/* compiled from: EngineJob */
public class C0945<R> implements DecodeJob.AbstractC0334<R>, C0830.AbstractC0835 {

    /* renamed from: ゎ  reason: contains not printable characters */
    public static final C0946 f4266 = new C0946();

    /* renamed from: ʬ  reason: contains not printable characters */
    public final AbstractC0836 f4267 = new AbstractC0836.C0837();

    /* renamed from: Ԕ  reason: contains not printable characters */
    public boolean f4268;

    /* renamed from: Ԛ  reason: contains not printable characters */
    public GlideException f4269;

    /* renamed from: ؿ  reason: contains not printable characters */
    public boolean f4270;

    /* renamed from: ݜ  reason: contains not printable characters */
    public DataSource f4271;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final AbstractC1871<C0945<?>> f4272;

    /* renamed from: ᑓ  reason: contains not printable characters */
    public volatile boolean f4273;

    /* renamed from: ᓆ  reason: contains not printable characters */
    public C1005<?> f4274;

    /* renamed from: ᓣ  reason: contains not printable characters */
    public boolean f4275;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public final ExecutorServiceC1008 f4276;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final ExecutorServiceC1008 f4277;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final C0947 f4278 = new C0947(new ArrayList(2));

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final AbstractC1004 f4279;

    /* renamed from: 㑃  reason: contains not printable characters */
    public final AtomicInteger f4280 = new AtomicInteger();

    /* renamed from: 㗗  reason: contains not printable characters */
    public boolean f4281;

    /* renamed from: 㗽  reason: contains not printable characters */
    public AbstractC1027<?> f4282;

    /* renamed from: 㳳  reason: contains not printable characters */
    public final ExecutorServiceC1008 f4283;

    /* renamed from: 㴪  reason: contains not printable characters */
    public DecodeJob<R> f4284;

    /* renamed from: 㴹  reason: contains not printable characters */
    public final C0946 f4285;

    /* renamed from: 㶋  reason: contains not printable characters */
    public boolean f4286;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final C1005.AbstractC1006 f4287;

    /* renamed from: 㿎  reason: contains not printable characters */
    public final ExecutorServiceC1008 f4288;

    /* renamed from: 䀟  reason: contains not printable characters */
    public boolean f4289;

    /* renamed from: 䁗  reason: contains not printable characters */
    public AbstractC1029 f4290;

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ᕣ$ʬ  reason: contains not printable characters */
    /* compiled from: EngineJob */
    public static class C0946 {
        /* renamed from: K  reason: contains not printable characters */
        public <R> C1005<R> m2688(AbstractC1027<R> r8, boolean z, AbstractC1029 r10, C1005.AbstractC1006 k) {
            return new C1005<>(r8, z, true, r10, k);
        }
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ᕣ$ඓ  reason: contains not printable characters */
    /* compiled from: EngineJob */
    public static final class C0947 implements Iterable<C0950> {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final List<C0950> f4291;

        public C0947(List<C0950> list) {
            this.f4291 = list;
        }

        /* renamed from: ῲ  reason: contains not printable characters */
        public static C0950 m2689(AbstractC1199 r2) {
            return new C0950(r2, C0825.f4049);
        }

        public boolean isEmpty() {
            return this.f4291.isEmpty();
        }

        @Override // java.lang.Iterable
        public Iterator<C0950> iterator() {
            return this.f4291.iterator();
        }

        /* renamed from: K  reason: contains not printable characters */
        public boolean m2691(AbstractC1199 r2) {
            return this.f4291.contains(m2689(r2));
        }

        /* renamed from: K  reason: contains not printable characters */
        public C0947 m2690() {
            return new C0947(new ArrayList(this.f4291));
        }
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ᕣ$ῲ  reason: contains not printable characters */
    /* compiled from: EngineJob */
    public class RunnableC0948 implements Runnable {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final AbstractC1199 f4293;

        public RunnableC0948(AbstractC1199 r2) {
            this.f4293 = r2;
        }

        public void run() {
            SingleRequest singleRequest = (SingleRequest) this.f4293;
            singleRequest.f2270.m2431();
            synchronized (singleRequest.f2259) {
                synchronized (C0945.this) {
                    if (C0945.this.f4278.m2691(this.f4293)) {
                        C0945.this.f4274.m2812();
                        C0945.this.m2676(this.f4293);
                        C0945.this.m2672(this.f4293);
                    }
                    C0945.this.m2679();
                }
            }
        }
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ᕣ$K  reason: contains not printable characters */
    /* compiled from: EngineJob */
    public class RunnableC0949 implements Runnable {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final AbstractC1199 f4295;

        public RunnableC0949(AbstractC1199 r2) {
            this.f4295 = r2;
        }

        public void run() {
            SingleRequest singleRequest = (SingleRequest) this.f4295;
            singleRequest.f2270.m2431();
            synchronized (singleRequest.f2259) {
                synchronized (C0945.this) {
                    if (C0945.this.f4278.m2691(this.f4295)) {
                        C0945.this.m2684(this.f4295);
                    }
                    C0945.this.m2679();
                }
            }
        }
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ᕣ$㸾  reason: contains not printable characters */
    /* compiled from: EngineJob */
    public static final class C0950 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final Executor f4296;

        /* renamed from: K  reason: contains not printable characters */
        public final AbstractC1199 f4297;

        public C0950(AbstractC1199 r1, Executor executor) {
            this.f4297 = r1;
            this.f4296 = executor;
        }

        public boolean equals(Object obj) {
            if (obj instanceof C0950) {
                return this.f4297.equals(((C0950) obj).f4297);
            }
            return false;
        }

        public int hashCode() {
            return this.f4297.hashCode();
        }
    }

    public C0945(ExecutorServiceC1008 k, ExecutorServiceC1008 k2, ExecutorServiceC1008 k3, ExecutorServiceC1008 k4, AbstractC1004 r9, C1005.AbstractC1006 k5, AbstractC1871<C0945<?>> r11) {
        C0946 r0 = f4266;
        this.f4288 = k;
        this.f4277 = k2;
        this.f4283 = k3;
        this.f4276 = k4;
        this.f4279 = r9;
        this.f4287 = k5;
        this.f4272 = r11;
        this.f4285 = r0;
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public synchronized void m2672(AbstractC1199 r3) {
        this.f4267.m2431();
        this.f4278.f4291.remove(C0947.m2689(r3));
        if (this.f4278.isEmpty()) {
            boolean z = true;
            if (!m2673()) {
                this.f4273 = true;
                DecodeJob<R> decodeJob = this.f4284;
                decodeJob.f2209 = true;
                AbstractC1021 r32 = decodeJob.f2205;
                if (r32 != null) {
                    r32.cancel();
                }
                ((C1013) this.f4279).m2823((C0945<?>) this, this.f4290);
            }
            if (!this.f4289) {
                if (!this.f4286) {
                    z = false;
                }
            }
            if (z && this.f4280.get() == 0) {
                m2677();
            }
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:13:0x0031, code lost:
        ((ඓ.ῲ.K.ᕣ.ᨨ.C1013) r4.f4279).m2824((ඓ.ῲ.K.ᕣ.ᨨ.C0945<?>) r4, r1, (ඓ.ῲ.K.ᕣ.ᨨ.C1005<?>) null);
        r0 = r2.iterator();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:15:0x0041, code lost:
        if (r0.hasNext() == false) goto L_0x0056;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:16:0x0043, code lost:
        r1 = r0.next();
        r1.f4296.execute(new ඓ.ῲ.K.ᕣ.ᨨ.C0945.RunnableC0949(r4, r1.f4297));
     */
    /* JADX WARNING: Code restructure failed: missing block: B:17:0x0056, code lost:
        m2679();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:18:0x0059, code lost:
        return;
     */
    /* renamed from: ඓ  reason: contains not printable characters */
    public void m2674() {
        synchronized (this) {
            this.f4267.m2431();
            if (this.f4273) {
                m2677();
            } else if (this.f4278.isEmpty()) {
                throw new IllegalStateException("Received an exception without any callbacks to notify");
            } else if (!this.f4286) {
                this.f4286 = true;
                AbstractC1029 r1 = this.f4290;
                C0947 r2 = this.f4278.m2690();
                m2680(r2.f4291.size() + 1);
            } else {
                throw new IllegalStateException("Already failed once");
            }
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m2676(AbstractC1199 r3) {
        try {
            ((SingleRequest) r3).m1346(this.f4274, this.f4271);
        } catch (Throwable th) {
            throw new CallbackException(th);
        }
    }

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final synchronized void m2677() {
        if (this.f4290 != null) {
            this.f4278.f4291.clear();
            this.f4290 = null;
            this.f4274 = null;
            this.f4282 = null;
            this.f4286 = false;
            this.f4273 = false;
            this.f4289 = false;
            DecodeJob<R> decodeJob = this.f4284;
            if (decodeJob.f2221.m1291(false)) {
                decodeJob.m1274();
            }
            this.f4284 = null;
            this.f4269 = null;
            this.f4271 = null;
            this.f4272.m4836(this);
        } else {
            throw new IllegalArgumentException();
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized C0945<R> m2678(AbstractC1029 r1, boolean z, boolean z2, boolean z3, boolean z4) {
        this.f4290 = r1;
        this.f4268 = z;
        this.f4281 = z2;
        this.f4270 = z3;
        this.f4275 = z4;
        return this;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:13:0x0048, code lost:
        ((ඓ.ῲ.K.ᕣ.ᨨ.C1013) r5.f4279).m2824((ඓ.ῲ.K.ᕣ.ᨨ.C0945<?>) r5, r0, r2);
        r0 = r1.iterator();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:15:0x0057, code lost:
        if (r0.hasNext() == false) goto L_0x006c;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:16:0x0059, code lost:
        r1 = r0.next();
        r1.f4296.execute(new ඓ.ῲ.K.ᕣ.ᨨ.C0945.RunnableC0948(r5, r1.f4297));
     */
    /* JADX WARNING: Code restructure failed: missing block: B:17:0x006c, code lost:
        m2679();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:18:0x006f, code lost:
        return;
     */
    /* renamed from: 㴹  reason: contains not printable characters */
    public void m2686() {
        synchronized (this) {
            this.f4267.m2431();
            if (this.f4273) {
                this.f4282.m2841();
                m2677();
            } else if (this.f4278.isEmpty()) {
                throw new IllegalStateException("Received a resource without any callbacks to notify");
            } else if (!this.f4289) {
                this.f4274 = this.f4285.m2688(this.f4282, this.f4268, this.f4290, this.f4287);
                this.f4289 = true;
                C0947 r1 = this.f4278.m2690();
                m2680(r1.f4291.size() + 1);
                AbstractC1029 r0 = this.f4290;
                C1005<?> r2 = this.f4274;
            } else {
                throw new IllegalStateException("Already have resource");
            }
        }
    }

    @Override // ඓ.ῲ.K.ᓣ.ᕣ.C0830.AbstractC0835
    /* renamed from: 㸾  reason: contains not printable characters */
    public AbstractC0836 m2687() {
        return this.f4267;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final ExecutorServiceC1008 m2675() {
        if (this.f4281) {
            return this.f4283;
        }
        return this.f4270 ? this.f4276 : this.f4277;
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m2681(DecodeJob<R> decodeJob) {
        ExecutorServiceC1008 k;
        this.f4284 = decodeJob;
        if (decodeJob.m1271()) {
            k = this.f4288;
        } else if (this.f4281) {
            k = this.f4283;
        } else {
            k = this.f4270 ? this.f4276 : this.f4277;
        }
        k.f4412.execute(decodeJob);
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m2685(AbstractC1199 r3, Executor executor) {
        this.f4267.m2431();
        this.f4278.f4291.add(new C0950(r3, executor));
        boolean z = true;
        if (this.f4289) {
            m2680(1);
            executor.execute(new RunnableC0948(r3));
        } else if (this.f4286) {
            m2680(1);
            executor.execute(new RunnableC0949(r3));
        } else {
            if (this.f4273) {
                z = false;
            }
            C1841.m4796(z, "Cannot add callbacks to a cancelled EngineJob");
        }
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public final boolean m2673() {
        return this.f4286 || this.f4289 || this.f4273;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2684(AbstractC1199 r3) {
        try {
            ((SingleRequest) r3).m1344(this.f4269, 5);
        } catch (Throwable th) {
            throw new CallbackException(th);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m2680(int i) {
        C1841.m4796(m2673(), "Not yet complete!");
        if (this.f4280.getAndAdd(i) == 0 && this.f4274 != null) {
            this.f4274.m2812();
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2679() {
        C1005<?> r0;
        synchronized (this) {
            this.f4267.m2431();
            C1841.m4796(m2673(), "Not yet complete!");
            int decrementAndGet = this.f4280.decrementAndGet();
            C1841.m4796(decrementAndGet >= 0, "Can't decrement below 0");
            if (decrementAndGet == 0) {
                r0 = this.f4274;
                m2677();
            } else {
                r0 = null;
            }
        }
        if (r0 != null) {
            r0.m2809();
        }
    }

    /* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: ඓ.ῲ.K.ᕣ.ᨨ.䀟<R> */
    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: K  reason: contains not printable characters */
    public void m2683(AbstractC1027<R> r1, DataSource dataSource) {
        synchronized (this) {
            this.f4282 = r1;
            this.f4271 = dataSource;
        }
        m2686();
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2682(GlideException glideException) {
        synchronized (this) {
            this.f4269 = glideException;
        }
        m2674();
    }
}
