package ඓ.ῲ.K.ᕣ.ᨨ.ゎ;

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 ඓ.K.K.K.C1293;

/* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ゎ.㳳  reason: contains not printable characters */
/* compiled from: LruBitmapPool */
public class C0972 implements AbstractC0976 {

    /* renamed from: 㳳  reason: contains not printable characters */
    public static final Bitmap.Config f4345 = Bitmap.Config.ARGB_8888;

    /* renamed from: ʬ  reason: contains not printable characters */
    public final AbstractC0974 f4346;

    /* renamed from: ඓ  reason: contains not printable characters */
    public long f4347;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public int f4348;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final Set<Bitmap.Config> f4349;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public int f4350;

    /* renamed from: K  reason: contains not printable characters */
    public final AbstractC0963 f4351;

    /* renamed from: 㴹  reason: contains not printable characters */
    public int f4352;

    /* renamed from: 㸾  reason: contains not printable characters */
    public long f4353;

    /* renamed from: 㿎  reason: contains not printable characters */
    public int f4354;

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ゎ.㳳$ῲ  reason: contains not printable characters */
    /* compiled from: LruBitmapPool */
    public static final class C0973 implements AbstractC0974 {
        /* renamed from: ῲ  reason: contains not printable characters */
        public void m2764(Bitmap bitmap) {
        }

        /* renamed from: K  reason: contains not printable characters */
        public void m2765(Bitmap bitmap) {
        }
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ゎ.㳳$K  reason: contains not printable characters */
    /* compiled from: LruBitmapPool */
    public interface AbstractC0974 {
    }

    public C0972(long j) {
        int i = Build.VERSION.SDK_INT;
        C0978 r0 = new C0978();
        HashSet hashSet = new HashSet(Arrays.asList(Bitmap.Config.values()));
        int i2 = Build.VERSION.SDK_INT;
        hashSet.add(null);
        if (Build.VERSION.SDK_INT >= 26) {
            hashSet.remove(Bitmap.Config.HARDWARE);
        }
        Set<Bitmap.Config> unmodifiableSet = Collections.unmodifiableSet(hashSet);
        this.f4353 = j;
        this.f4351 = r0;
        this.f4349 = unmodifiableSet;
        this.f4346 = new C0973();
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public final synchronized Bitmap m2755(int i, int i2, Bitmap.Config config) {
        Bitmap r0;
        if (Build.VERSION.SDK_INT >= 26) {
            if (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");
            }
        }
        r0 = this.f4351.m2732(i, i2, config != null ? config : f4345);
        if (r0 == null) {
            if (Log.isLoggable("LruBitmapPool", 3)) {
                Log.d("LruBitmapPool", "Missing bitmap=" + this.f4351.m2730(i, i2, config));
            }
            this.f4350++;
        } else {
            this.f4352++;
            this.f4347 -= (long) this.f4351.m2729(r0);
            ((C0973) this.f4346).m2764(r0);
            r0.setHasAlpha(true);
            int i3 = Build.VERSION.SDK_INT;
            r0.setPremultiplied(true);
        }
        if (Log.isLoggable("LruBitmapPool", 2)) {
            Log.v("LruBitmapPool", "Get bitmap=" + this.f4351.m2730(i, i2, config));
        }
        m2758();
        return r0;
    }

    @Override // ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0976
    /* renamed from: ῲ  reason: contains not printable characters */
    public Bitmap m2757(int i, int i2, Bitmap.Config config) {
        Bitmap r0 = m2755(i, i2, config);
        if (r0 != null) {
            return r0;
        }
        if (config == null) {
            config = f4345;
        }
        return Bitmap.createBitmap(i, i2, config);
    }

    @Override // ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0976
    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m2763(Bitmap bitmap) {
        if (bitmap == null) {
            throw new NullPointerException("Bitmap must not be null");
        } else if (!bitmap.isRecycled()) {
            if (bitmap.isMutable() && ((long) this.f4351.m2729(bitmap)) <= this.f4353) {
                if (this.f4349.contains(bitmap.getConfig())) {
                    int r0 = this.f4351.m2729(bitmap);
                    this.f4351.m2733(bitmap);
                    ((C0973) this.f4346).m2765(bitmap);
                    this.f4354++;
                    this.f4347 += (long) r0;
                    if (Log.isLoggable("LruBitmapPool", 2)) {
                        Log.v("LruBitmapPool", "Put bitmap in pool=" + this.f4351.m2728(bitmap));
                    }
                    m2758();
                    m2762(this.f4353);
                    return;
                }
            }
            if (Log.isLoggable("LruBitmapPool", 2)) {
                Log.v("LruBitmapPool", "Reject bitmap from pool, bitmap: " + this.f4351.m2728(bitmap) + ", is mutable: " + bitmap.isMutable() + ", is allowed config: " + this.f4349.contains(bitmap.getConfig()));
            }
            bitmap.recycle();
        } else {
            throw new IllegalStateException("Cannot pool recycled bitmap");
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final void m2758() {
        if (Log.isLoggable("LruBitmapPool", 2)) {
            m2756();
        }
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public final void m2756() {
        StringBuilder r0 = C1293.m3416("Hits=");
        r0.append(this.f4352);
        r0.append(", misses=");
        r0.append(this.f4350);
        r0.append(", puts=");
        r0.append(this.f4354);
        r0.append(", evictions=");
        r0.append(this.f4348);
        r0.append(", currentSize=");
        r0.append(this.f4347);
        r0.append(", maxSize=");
        r0.append(this.f4353);
        r0.append("\nStrategy=");
        r0.append(this.f4351);
        Log.v("LruBitmapPool", r0.toString());
    }

    @Override // ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0976
    /* renamed from: K  reason: contains not printable characters */
    public Bitmap m2759(int i, int i2, Bitmap.Config config) {
        Bitmap r0 = m2755(i, i2, config);
        if (r0 != null) {
            r0.eraseColor(0);
            return r0;
        }
        if (config == null) {
            config = f4345;
        }
        return Bitmap.createBitmap(i, i2, config);
    }

    @Override // ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0976
    /* renamed from: K  reason: contains not printable characters */
    public void m2760() {
        if (Log.isLoggable("LruBitmapPool", 3)) {
            Log.d("LruBitmapPool", "clearMemory");
        }
        m2762(0L);
    }

    @Override // ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0976
    @SuppressLint({"InlinedApi"})
    /* renamed from: K  reason: contains not printable characters */
    public void m2761(int i) {
        if (Log.isLoggable("LruBitmapPool", 3)) {
            Log.d("LruBitmapPool", "trimMemory, level=" + i);
        }
        if (i >= 40 || (Build.VERSION.SDK_INT >= 23 && i >= 20)) {
            m2760();
        } else if (i >= 20 || i == 15) {
            m2762(this.f4353 / 2);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final synchronized void m2762(long j) {
        while (this.f4347 > j) {
            Bitmap r0 = this.f4351.m2731();
            if (r0 == null) {
                if (Log.isLoggable("LruBitmapPool", 5)) {
                    Log.w("LruBitmapPool", "Size mismatch, resetting");
                    m2756();
                }
                this.f4347 = 0;
                return;
            }
            ((C0973) this.f4346).m2764(r0);
            this.f4347 -= (long) this.f4351.m2729(r0);
            this.f4348++;
            if (Log.isLoggable("LruBitmapPool", 3)) {
                Log.d("LruBitmapPool", "Evicting bitmap=" + this.f4351.m2728(r0));
            }
            m2758();
            r0.recycle();
        }
    }
}
