package defpackage;

import android.graphics.Bitmap;
import android.os.Build;
import android.util.Log;
import j$.util.DesugarCollections;
import j$.util.Objects;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/* renamed from: ᵙᵪʠⁱ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2611 implements InterfaceC2157 {

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public static final Bitmap.Config f10101 = Bitmap.Config.ARGB_8888;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final Set f10102;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public long f10103;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final C3002 f10104;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final long f10105;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final ʾᵠᵦ f10106;

    public C2611(long j) {
        C3002 c3002 = new C3002();
        HashSet hashSet = new HashSet(Arrays.asList(Bitmap.Config.values()));
        hashSet.add(null);
        if (Build.VERSION.SDK_INT >= 26) {
            hashSet.remove(Bitmap.Config.HARDWARE);
        }
        Set setUnmodifiableSet = DesugarCollections.unmodifiableSet(hashSet);
        this.f10105 = j;
        this.f10104 = c3002;
        this.f10102 = setUnmodifiableSet;
        this.f10106 = new ʾᵠᵦ();
    }

    @Override // defpackage.InterfaceC2157
    /* renamed from: ˇʼʤˎ */
    public final synchronized void mo5786(Bitmap bitmap) {
        try {
            if (bitmap == null) {
                throw new NullPointerException("Bitmap must not be null");
            }
            if (bitmap.isRecycled()) {
                throw new IllegalStateException("Cannot pool recycled bitmap");
            }
            if (bitmap.isMutable()) {
                this.f10104.getClass();
                if (ˊˉʤﹳ.ᵡʠ(bitmap) <= this.f10105 && this.f10102.contains(bitmap.getConfig())) {
                    this.f10104.getClass();
                    int i = ˊˉʤﹳ.ᵡʠ(bitmap);
                    this.f10104.m7344(bitmap);
                    this.f10106.getClass();
                    this.f10103 += i;
                    if (Log.isLoggable("LruBitmapPool", 2)) {
                        this.f10104.getClass();
                        C3002.m7343(ˊˉʤﹳ.ᵡʠ(bitmap), bitmap.getConfig());
                    }
                    if (Log.isLoggable("LruBitmapPool", 2)) {
                        Objects.toString(this.f10104);
                    }
                    m6562(this.f10105);
                    return;
                }
            }
            if (Log.isLoggable("LruBitmapPool", 2)) {
                this.f10104.getClass();
                C3002.m7343(ˊˉʤﹳ.ᵡʠ(bitmap), bitmap.getConfig());
                bitmap.isMutable();
                this.f10102.contains(bitmap.getConfig());
            }
            bitmap.recycle();
        } catch (Throwable th) {
            throw th;
        }
    }

    @Override // defpackage.InterfaceC2157
    /* renamed from: ˌʾˀ */
    public final void mo5787() {
        Log.isLoggable("LruBitmapPool", 3);
        m6562(0L);
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final synchronized void m6562(long j) {
        while (this.f10103 > j) {
            C3002 c3002 = this.f10104;
            Bitmap bitmap = (Bitmap) c3002.f11581.ˑᵥˁ();
            if (bitmap != null) {
                c3002.m7345(Integer.valueOf(ˊˉʤﹳ.ᵡʠ(bitmap)), bitmap);
            }
            if (bitmap == null) {
                if (Log.isLoggable("LruBitmapPool", 5)) {
                    Objects.toString(this.f10104);
                }
                this.f10103 = 0L;
                return;
            }
            this.f10106.getClass();
            long j2 = this.f10103;
            this.f10104.getClass();
            this.f10103 = j2 - ˊˉʤﹳ.ᵡʠ(bitmap);
            if (Log.isLoggable("LruBitmapPool", 3)) {
                this.f10104.getClass();
                C3002.m7343(ˊˉʤﹳ.ᵡʠ(bitmap), bitmap.getConfig());
            }
            if (Log.isLoggable("LruBitmapPool", 2)) {
                Objects.toString(this.f10104);
            }
            bitmap.recycle();
        }
    }

    @Override // defpackage.InterfaceC2157
    /* renamed from: ᵥᵯˎ */
    public final Bitmap mo5788(int i, int i2, Bitmap.Config config) {
        Bitmap bitmapM6563 = m6563(i, i2, config);
        if (bitmapM6563 != null) {
            return bitmapM6563;
        }
        if (config == null) {
            config = f10101;
        }
        return Bitmap.createBitmap(i, i2, config);
    }

    @Override // defpackage.InterfaceC2157
    /* renamed from: ᵪʩ */
    public final void mo5789(int i) {
        Log.isLoggable("LruBitmapPool", 3);
        if (i >= 40 || i >= 20) {
            mo5787();
        } else if (i >= 20 || i == 15) {
            m6562(this.f10105 / 2);
        }
    }

    @Override // defpackage.InterfaceC2157
    /* renamed from: ᵯٴᵦ */
    public final Bitmap mo5790(int i, int i2, Bitmap.Config config) {
        Bitmap bitmapM6563 = m6563(i, i2, config);
        if (bitmapM6563 != null) {
            bitmapM6563.eraseColor(0);
            return bitmapM6563;
        }
        if (config == null) {
            config = f10101;
        }
        return Bitmap.createBitmap(i, i2, config);
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final synchronized Bitmap m6563(int i, int i2, Bitmap.Config config) {
        Bitmap bitmapM7346;
        try {
            if (Build.VERSION.SDK_INT >= 26 && config == Bitmap.Config.HARDWARE) {
                throw new IllegalArgumentException("Cannot create a mutable Bitmap with config: " + config + ". Consider setting Downsampler#ALLOW_HARDWARE_CONFIG to false in your RequestOptions and/or in GlideBuilder.setDefaultRequestOptions");
            }
            bitmapM7346 = this.f10104.m7346(i, i2, config != null ? config : f10101);
            if (bitmapM7346 != null) {
                long j = this.f10103;
                this.f10104.getClass();
                this.f10103 = j - ˊˉʤﹳ.ᵡʠ(bitmapM7346);
                this.f10106.getClass();
                bitmapM7346.setHasAlpha(true);
                bitmapM7346.setPremultiplied(true);
            } else if (Log.isLoggable("LruBitmapPool", 3)) {
                this.f10104.getClass();
                C3002.m7343(ˊˉʤﹳ.ᵸʓᵠ(config) * i * i2, config);
            }
            if (Log.isLoggable("LruBitmapPool", 2)) {
                this.f10104.getClass();
                C3002.m7343(ˊˉʤﹳ.ᵸʓᵠ(config) * i * i2, config);
            }
            if (Log.isLoggable("LruBitmapPool", 2)) {
                Objects.toString(this.f10104);
            }
        } catch (Throwable th) {
            throw th;
        }
        return bitmapM7346;
    }
}
