package p138.p145.p146.p151.p154.p155;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.os.Build;
import android.util.Log;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import p138.p139.p143.p144.C2803;

/* JADX INFO: renamed from: ދ.ؠ.֏.ތ.ފ.ޙ.އ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C2951 implements InterfaceC2942 {

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public static final Bitmap.Config f9092 = Bitmap.Config.ARGB_8888;

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final InterfaceC2954 f9093;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final Set<Bitmap.Config> f9094;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final InterfaceC2952 f9095;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public long f9096;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public long f9097;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public int f9098;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public int f9099;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public int f9100;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public int f9101;

    /* JADX INFO: renamed from: ދ.ؠ.֏.ތ.ފ.ޙ.އ$֏, reason: contains not printable characters */
    public interface InterfaceC2952 {
    }

    /* JADX INFO: renamed from: ދ.ؠ.֏.ތ.ފ.ޙ.އ$ؠ, reason: contains not printable characters */
    public static final class C2953 implements InterfaceC2952 {
    }

    public C2951(long j) {
        C2956 c2956 = new C2956();
        HashSet hashSet = new HashSet(Arrays.asList(Bitmap.Config.values()));
        hashSet.add(null);
        if (Build.VERSION.SDK_INT >= 26) {
            hashSet.remove(Bitmap.Config.HARDWARE);
        }
        Set<Bitmap.Config> setUnmodifiableSet = Collections.unmodifiableSet(hashSet);
        this.f9096 = j;
        this.f9093 = c2956;
        this.f9094 = setUnmodifiableSet;
        this.f9095 = new C2953();
    }

    @Override // p138.p145.p146.p151.p154.p155.InterfaceC2942
    /* JADX INFO: renamed from: ֏ */
    public Bitmap mo5085(int i, int i2, Bitmap.Config config) {
        Bitmap bitmapM5103 = m5103(i, i2, config);
        if (bitmapM5103 != null) {
            bitmapM5103.eraseColor(0);
            return bitmapM5103;
        }
        if (config == null) {
            config = f9092;
        }
        return Bitmap.createBitmap(i, i2, config);
    }

    @Override // p138.p145.p146.p151.p154.p155.InterfaceC2942
    /* JADX INFO: renamed from: ֏ */
    public void mo5086() {
        if (Log.isLoggable("LruBitmapPool", 3)) {
            Log.d("LruBitmapPool", "clearMemory");
        }
        m5101(0L);
    }

    @Override // p138.p145.p146.p151.p154.p155.InterfaceC2942
    @SuppressLint({"InlinedApi"})
    /* JADX INFO: renamed from: ֏ */
    public void mo5087(int i) {
        if (Log.isLoggable("LruBitmapPool", 3)) {
            Log.d("LruBitmapPool", "trimMemory, level=" + i);
        }
        if (i >= 40 || (Build.VERSION.SDK_INT >= 23 && i >= 20)) {
            if (Log.isLoggable("LruBitmapPool", 3)) {
                Log.d("LruBitmapPool", "clearMemory");
            }
            m5101(0L);
        } else if (i >= 20 || i == 15) {
            m5101(this.f9096 / 2);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m5101(long j) {
        while (this.f9097 > j) {
            Bitmap bitmapMo5105 = this.f9093.mo5105();
            if (bitmapMo5105 == null) {
                if (Log.isLoggable("LruBitmapPool", 5)) {
                    Log.w("LruBitmapPool", "Size mismatch, resetting");
                    m5104();
                }
                this.f9097 = 0L;
                return;
            }
            if (((C2953) this.f9095) == null) {
                throw null;
            }
            this.f9097 -= (long) this.f9093.mo5108(bitmapMo5105);
            this.f9101++;
            if (Log.isLoggable("LruBitmapPool", 3)) {
                Log.d("LruBitmapPool", "Evicting bitmap=" + this.f9093.mo5110(bitmapMo5105));
            }
            m5102();
            bitmapMo5105.recycle();
        }
    }

    @Override // p138.p145.p146.p151.p154.p155.InterfaceC2942
    /* JADX INFO: renamed from: ֏ */
    public synchronized void mo5088(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.f9093.mo5108(bitmap) <= this.f9096 && this.f9094.contains(bitmap.getConfig())) {
                int iMo5108 = this.f9093.mo5108(bitmap);
                this.f9093.mo5107(bitmap);
                if (((C2953) this.f9095) == null) {
                    throw null;
                }
                this.f9100++;
                this.f9097 += (long) iMo5108;
                if (Log.isLoggable("LruBitmapPool", 2)) {
                    Log.v("LruBitmapPool", "Put bitmap in pool=" + this.f9093.mo5110(bitmap));
                }
                m5102();
                m5101(this.f9096);
                return;
            }
            if (Log.isLoggable("LruBitmapPool", 2)) {
                Log.v("LruBitmapPool", "Reject bitmap from pool, bitmap: " + this.f9093.mo5110(bitmap) + ", is mutable: " + bitmap.isMutable() + ", is allowed config: " + this.f9094.contains(bitmap.getConfig()));
            }
            bitmap.recycle();
        } catch (Throwable th) {
            throw th;
        }
    }

    @Override // p138.p145.p146.p151.p154.p155.InterfaceC2942
    /* JADX INFO: renamed from: ؠ */
    public Bitmap mo5089(int i, int i2, Bitmap.Config config) {
        Bitmap bitmapM5103 = m5103(i, i2, config);
        if (bitmapM5103 != null) {
            return bitmapM5103;
        }
        if (config == null) {
            config = f9092;
        }
        return Bitmap.createBitmap(i, i2, config);
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m5102() {
        if (Log.isLoggable("LruBitmapPool", 2)) {
            m5104();
        }
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final synchronized Bitmap m5103(int i, int i2, Bitmap.Config config) {
        Bitmap bitmapMo5106;
        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");
        }
        bitmapMo5106 = this.f9093.mo5106(i, i2, config != null ? config : f9092);
        if (bitmapMo5106 == null) {
            if (Log.isLoggable("LruBitmapPool", 3)) {
                Log.d("LruBitmapPool", "Missing bitmap=" + this.f9093.mo5109(i, i2, config));
            }
            this.f9099++;
        } else {
            this.f9098++;
            this.f9097 -= (long) this.f9093.mo5108(bitmapMo5106);
            if (((C2953) this.f9095) == null) {
                throw null;
            }
            bitmapMo5106.setHasAlpha(true);
            bitmapMo5106.setPremultiplied(true);
        }
        if (Log.isLoggable("LruBitmapPool", 2)) {
            Log.v("LruBitmapPool", "Get bitmap=" + this.f9093.mo5109(i, i2, config));
        }
        m5102();
        return bitmapMo5106;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final void m5104() {
        StringBuilder sbM4889 = C2803.m4889("Hits=");
        sbM4889.append(this.f9098);
        sbM4889.append(", misses=");
        sbM4889.append(this.f9099);
        sbM4889.append(", puts=");
        sbM4889.append(this.f9100);
        sbM4889.append(", evictions=");
        sbM4889.append(this.f9101);
        sbM4889.append(", currentSize=");
        sbM4889.append(this.f9097);
        sbM4889.append(", maxSize=");
        sbM4889.append(this.f9096);
        sbM4889.append("\nStrategy=");
        sbM4889.append(this.f9093);
        Log.v("LruBitmapPool", sbM4889.toString());
    }
}
