package t1; 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; /* loaded from: classes.dex */ public class k implements d { /* renamed from: k, reason: collision with root package name */ private static final Bitmap.Config f14285k = Bitmap.Config.ARGB_8888; /* renamed from: a, reason: collision with root package name */ private final l f14286a; /* renamed from: b, reason: collision with root package name */ private final Set f14287b; /* renamed from: c, reason: collision with root package name */ private final long f14288c; /* renamed from: d, reason: collision with root package name */ private final a f14289d; /* renamed from: e, reason: collision with root package name */ private long f14290e; /* renamed from: f, reason: collision with root package name */ private long f14291f; /* renamed from: g, reason: collision with root package name */ private int f14292g; /* renamed from: h, reason: collision with root package name */ private int f14293h; /* renamed from: i, reason: collision with root package name */ private int f14294i; /* renamed from: j, reason: collision with root package name */ private int f14295j; private interface a { void a(Bitmap bitmap); void b(Bitmap bitmap); } private static final class b implements a { b() { } @Override // t1.k.a public void a(Bitmap bitmap) { } @Override // t1.k.a public void b(Bitmap bitmap) { } } k(long j10, l lVar, Set set) { this.f14288c = j10; this.f14290e = j10; this.f14286a = lVar; this.f14287b = set; this.f14289d = new b(); } private static void f(Bitmap.Config config) { Bitmap.Config config2; if (Build.VERSION.SDK_INT < 26) { return; } config2 = Bitmap.Config.HARDWARE; if (config != config2) { return; } 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"); } private static Bitmap g(int i10, int i11, Bitmap.Config config) { if (config == null) { config = f14285k; } return Bitmap.createBitmap(i10, i11, config); } private void h() { if (Log.isLoggable("LruBitmapPool", 2)) { i(); } } private void i() { Log.v("LruBitmapPool", "Hits=" + this.f14292g + ", misses=" + this.f14293h + ", puts=" + this.f14294i + ", evictions=" + this.f14295j + ", currentSize=" + this.f14291f + ", maxSize=" + this.f14290e + "\nStrategy=" + this.f14286a); } private void j() { q(this.f14290e); } private static Set k() { Bitmap.Config config; HashSet hashSet = new HashSet(Arrays.asList(Bitmap.Config.values())); int i10 = Build.VERSION.SDK_INT; hashSet.add(null); if (i10 >= 26) { config = Bitmap.Config.HARDWARE; hashSet.remove(config); } return Collections.unmodifiableSet(hashSet); } private static l l() { return new o(); } private synchronized Bitmap m(int i10, int i11, Bitmap.Config config) { Bitmap d10; f(config); d10 = this.f14286a.d(i10, i11, config != null ? config : f14285k); if (d10 == null) { if (Log.isLoggable("LruBitmapPool", 3)) { Log.d("LruBitmapPool", "Missing bitmap=" + this.f14286a.a(i10, i11, config)); } this.f14293h++; } else { this.f14292g++; this.f14291f -= this.f14286a.b(d10); this.f14289d.a(d10); p(d10); } if (Log.isLoggable("LruBitmapPool", 2)) { Log.v("LruBitmapPool", "Get bitmap=" + this.f14286a.a(i10, i11, config)); } h(); return d10; } private static void o(Bitmap bitmap) { bitmap.setPremultiplied(true); } private static void p(Bitmap bitmap) { bitmap.setHasAlpha(true); o(bitmap); } private synchronized void q(long j10) { while (this.f14291f > j10) { Bitmap removeLast = this.f14286a.removeLast(); if (removeLast == null) { if (Log.isLoggable("LruBitmapPool", 5)) { Log.w("LruBitmapPool", "Size mismatch, resetting"); i(); } this.f14291f = 0L; return; } this.f14289d.a(removeLast); this.f14291f -= this.f14286a.b(removeLast); this.f14295j++; if (Log.isLoggable("LruBitmapPool", 3)) { Log.d("LruBitmapPool", "Evicting bitmap=" + this.f14286a.e(removeLast)); } h(); removeLast.recycle(); } } @Override // t1.d public void a(int i10) { if (Log.isLoggable("LruBitmapPool", 3)) { Log.d("LruBitmapPool", "trimMemory, level=" + i10); } if (i10 >= 40 || (Build.VERSION.SDK_INT >= 23 && i10 >= 20)) { b(); } else if (i10 >= 20 || i10 == 15) { q(n() / 2); } } @Override // t1.d public void b() { if (Log.isLoggable("LruBitmapPool", 3)) { Log.d("LruBitmapPool", "clearMemory"); } q(0L); } @Override // t1.d public synchronized void c(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.f14286a.b(bitmap) <= this.f14290e && this.f14287b.contains(bitmap.getConfig())) { int b10 = this.f14286a.b(bitmap); this.f14286a.c(bitmap); this.f14289d.b(bitmap); this.f14294i++; this.f14291f += b10; if (Log.isLoggable("LruBitmapPool", 2)) { Log.v("LruBitmapPool", "Put bitmap in pool=" + this.f14286a.e(bitmap)); } h(); j(); return; } if (Log.isLoggable("LruBitmapPool", 2)) { Log.v("LruBitmapPool", "Reject bitmap from pool, bitmap: " + this.f14286a.e(bitmap) + ", is mutable: " + bitmap.isMutable() + ", is allowed config: " + this.f14287b.contains(bitmap.getConfig())); } bitmap.recycle(); } catch (Throwable th) { throw th; } } @Override // t1.d public Bitmap d(int i10, int i11, Bitmap.Config config) { Bitmap m10 = m(i10, i11, config); if (m10 == null) { return g(i10, i11, config); } m10.eraseColor(0); return m10; } @Override // t1.d public Bitmap e(int i10, int i11, Bitmap.Config config) { Bitmap m10 = m(i10, i11, config); return m10 == null ? g(i10, i11, config) : m10; } public long n() { return this.f14290e; } public k(long j10) { this(j10, l(), k()); } }