package i6; 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: classes2.dex */ public class g implements i6.b { /* renamed from: k, reason: collision with root package name */ private static final Bitmap.Config f10900k = Bitmap.Config.ARGB_8888; /* renamed from: a, reason: collision with root package name */ private final l f10901a; /* renamed from: b, reason: collision with root package name */ private final Set f10902b; /* renamed from: c, reason: collision with root package name */ private final long f10903c; /* renamed from: d, reason: collision with root package name */ private final a f10904d; /* renamed from: e, reason: collision with root package name */ private long f10905e; /* renamed from: f, reason: collision with root package name */ private long f10906f; /* renamed from: g, reason: collision with root package name */ private int f10907g; /* renamed from: h, reason: collision with root package name */ private int f10908h; /* renamed from: i, reason: collision with root package name */ private int f10909i; /* renamed from: j, reason: collision with root package name */ private int f10910j; private interface a { void a(Bitmap bitmap); void b(Bitmap bitmap); } private static final class b implements a { b() { } @Override // i6.g.a public void a(Bitmap bitmap) { } @Override // i6.g.a public void b(Bitmap bitmap) { } } public g(long j10) { this(j10, p(), o()); } private static Bitmap f(int i10, int i11, Bitmap.Config config) { if (config == null) { config = f10900k; } return Bitmap.createBitmap(i10, i11, config); } private void g() { if (Log.isLoggable("LruBitmapPool", 2)) { l(); } } private synchronized void h(long j10) { while (this.f10906f > j10) { Bitmap removeLast = this.f10901a.removeLast(); if (removeLast == null) { if (Log.isLoggable("LruBitmapPool", 5)) { Log.w("LruBitmapPool", "Size mismatch, resetting"); l(); } this.f10906f = 0L; return; } this.f10904d.b(removeLast); this.f10906f -= this.f10901a.b(removeLast); this.f10910j++; if (Log.isLoggable("LruBitmapPool", 3)) { Log.d("LruBitmapPool", "Evicting bitmap=" + this.f10901a.e(removeLast)); } g(); removeLast.recycle(); } } private static void i(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 ImageBuilder.setDefaultRequestOptions"); } private static void j(Bitmap bitmap) { bitmap.setPremultiplied(true); } private synchronized Bitmap k(int i10, int i11, Bitmap.Config config) { Bitmap d10; i(config); d10 = this.f10901a.d(i10, i11, config != null ? config : f10900k); if (d10 == null) { if (Log.isLoggable("LruBitmapPool", 3)) { Log.d("LruBitmapPool", "Missing bitmap=" + this.f10901a.a(i10, i11, config)); } this.f10908h++; } else { this.f10907g++; this.f10906f -= this.f10901a.b(d10); this.f10904d.b(d10); m(d10); } if (Log.isLoggable("LruBitmapPool", 2)) { Log.v("LruBitmapPool", "Get bitmap=" + this.f10901a.a(i10, i11, config)); } g(); return d10; } private void l() { Log.v("LruBitmapPool", "Hits=" + this.f10907g + ", misses=" + this.f10908h + ", puts=" + this.f10909i + ", evictions=" + this.f10910j + ", currentSize=" + this.f10906f + ", maxSize=" + this.f10905e + "\nStrategy=" + this.f10901a); } private static void m(Bitmap bitmap) { bitmap.setHasAlpha(true); j(bitmap); } private void n() { h(this.f10905e); } private static Set o() { 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 p() { return new h(); } @Override // i6.b 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) { h(q() / 2); } } @Override // i6.b public void b() { if (Log.isLoggable("LruBitmapPool", 3)) { Log.d("LruBitmapPool", "clearMemory"); } h(0L); } @Override // i6.b public synchronized void c(Bitmap bitmap) { 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.f10901a.b(bitmap) <= this.f10905e && this.f10902b.contains(bitmap.getConfig())) { int b10 = this.f10901a.b(bitmap); this.f10901a.c(bitmap); this.f10904d.a(bitmap); this.f10909i++; this.f10906f += b10; if (Log.isLoggable("LruBitmapPool", 2)) { Log.v("LruBitmapPool", "Put bitmap in pool=" + this.f10901a.e(bitmap)); } g(); n(); return; } if (Log.isLoggable("LruBitmapPool", 2)) { Log.v("LruBitmapPool", "Reject bitmap from pool, bitmap: " + this.f10901a.e(bitmap) + ", is mutable: " + bitmap.isMutable() + ", is allowed config: " + this.f10902b.contains(bitmap.getConfig())); } bitmap.recycle(); } @Override // i6.b public Bitmap d(int i10, int i11, Bitmap.Config config) { Bitmap k10 = k(i10, i11, config); if (k10 == null) { return f(i10, i11, config); } k10.eraseColor(0); return k10; } @Override // i6.b public Bitmap e(int i10, int i11, Bitmap.Config config) { Bitmap k10 = k(i10, i11, config); return k10 == null ? f(i10, i11, config) : k10; } public long q() { return this.f10905e; } g(long j10, l lVar, Set set) { this.f10903c = j10; this.f10905e = j10; this.f10901a = lVar; this.f10902b = set; this.f10904d = new b(); } }