Initial commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
interface ArrayAdapterInterface<T> {
|
||||
int a(T t);
|
||||
|
||||
String a();
|
||||
|
||||
int b();
|
||||
|
||||
T newArray(int i);
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface ArrayPool {
|
||||
<T> T a(int i, Class<T> cls);
|
||||
|
||||
void a();
|
||||
|
||||
void a(int i);
|
||||
|
||||
<T> T b(int i, Class<T> cls);
|
||||
|
||||
<T> void put(T t);
|
||||
}
|
@@ -0,0 +1,113 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import com.bumptech.glide.util.Util;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class AttributeStrategy implements LruPoolStrategy {
|
||||
private final KeyPool a = new KeyPool();
|
||||
private final GroupedLinkedMap<Key, Bitmap> b = new GroupedLinkedMap<>();
|
||||
|
||||
static class KeyPool extends BaseKeyPool<Key> {
|
||||
KeyPool() {
|
||||
}
|
||||
|
||||
Key a(int i, int i2, Bitmap.Config config) {
|
||||
Key b = b();
|
||||
b.a(i, i2, config);
|
||||
return b;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: protected */
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BaseKeyPool
|
||||
public Key a() {
|
||||
return new Key(this);
|
||||
}
|
||||
}
|
||||
|
||||
AttributeStrategy() {
|
||||
}
|
||||
|
||||
private static String d(Bitmap bitmap) {
|
||||
return c(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public void a(Bitmap bitmap) {
|
||||
this.b.a(this.a.a(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()), bitmap);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public String b(int i, int i2, Bitmap.Config config) {
|
||||
return c(i, i2, config);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public String c(Bitmap bitmap) {
|
||||
return d(bitmap);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public Bitmap removeLast() {
|
||||
return this.b.a();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AttributeStrategy:\n " + this.b;
|
||||
}
|
||||
|
||||
static String c(int i, int i2, Bitmap.Config config) {
|
||||
return "[" + i + "x" + i2 + "], " + config;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public int b(Bitmap bitmap) {
|
||||
return Util.a(bitmap);
|
||||
}
|
||||
|
||||
static class Key implements Poolable {
|
||||
private final KeyPool a;
|
||||
private int b;
|
||||
private int c;
|
||||
private Bitmap.Config d;
|
||||
|
||||
public Key(KeyPool keyPool) {
|
||||
this.a = keyPool;
|
||||
}
|
||||
|
||||
public void a(int i, int i2, Bitmap.Config config) {
|
||||
this.b = i;
|
||||
this.c = i2;
|
||||
this.d = config;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Key)) {
|
||||
return false;
|
||||
}
|
||||
Key key = (Key) obj;
|
||||
return this.b == key.b && this.c == key.c && this.d == key.d;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int i = ((this.b * 31) + this.c) * 31;
|
||||
Bitmap.Config config = this.d;
|
||||
return i + (config != null ? config.hashCode() : 0);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return AttributeStrategy.c(this.b, this.c, this.d);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.Poolable
|
||||
public void a() {
|
||||
this.a.a(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public Bitmap a(int i, int i2, Bitmap.Config config) {
|
||||
return this.b.a((GroupedLinkedMap<Key, Bitmap>) this.a.a(i, i2, config));
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.Poolable;
|
||||
import com.bumptech.glide.util.Util;
|
||||
import java.util.Queue;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
abstract class BaseKeyPool<T extends Poolable> {
|
||||
private final Queue<T> a = Util.a(20);
|
||||
|
||||
BaseKeyPool() {
|
||||
}
|
||||
|
||||
abstract T a();
|
||||
|
||||
public void a(T t) {
|
||||
if (this.a.size() < 20) {
|
||||
this.a.offer(t);
|
||||
}
|
||||
}
|
||||
|
||||
T b() {
|
||||
T poll = this.a.poll();
|
||||
return poll == null ? a() : poll;
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface BitmapPool {
|
||||
Bitmap a(int i, int i2, Bitmap.Config config);
|
||||
|
||||
void a();
|
||||
|
||||
void a(int i);
|
||||
|
||||
void a(Bitmap bitmap);
|
||||
|
||||
Bitmap b(int i, int i2, Bitmap.Config config);
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BitmapPoolAdapter implements BitmapPool {
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
public void a() {
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
public void a(int i) {
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
public void a(Bitmap bitmap) {
|
||||
bitmap.recycle();
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
public Bitmap b(int i, int i2, Bitmap.Config config) {
|
||||
return a(i, i2, config);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
public Bitmap a(int i, int i2, Bitmap.Config config) {
|
||||
return Bitmap.createBitmap(i, i2, config);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class ByteArrayAdapter implements ArrayAdapterInterface<byte[]> {
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayAdapterInterface
|
||||
public String a() {
|
||||
return "ByteArrayPool";
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayAdapterInterface
|
||||
public int b() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayAdapterInterface
|
||||
public int a(byte[] bArr) {
|
||||
return bArr.length;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayAdapterInterface
|
||||
public byte[] newArray(int i) {
|
||||
return new byte[i];
|
||||
}
|
||||
}
|
@@ -0,0 +1,138 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.Poolable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class GroupedLinkedMap<K extends Poolable, V> {
|
||||
private final LinkedEntry<K, V> a = new LinkedEntry<>();
|
||||
private final Map<K, LinkedEntry<K, V>> b = new HashMap();
|
||||
|
||||
private static class LinkedEntry<K, V> {
|
||||
final K a;
|
||||
private List<V> b;
|
||||
LinkedEntry<K, V> c;
|
||||
LinkedEntry<K, V> d;
|
||||
|
||||
LinkedEntry() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public V a() {
|
||||
int b = b();
|
||||
if (b > 0) {
|
||||
return this.b.remove(b - 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
List<V> list = this.b;
|
||||
if (list != null) {
|
||||
return list.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LinkedEntry(K k) {
|
||||
this.d = this;
|
||||
this.c = this;
|
||||
this.a = k;
|
||||
}
|
||||
|
||||
public void a(V v) {
|
||||
if (this.b == null) {
|
||||
this.b = new ArrayList();
|
||||
}
|
||||
this.b.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
GroupedLinkedMap() {
|
||||
}
|
||||
|
||||
private void b(LinkedEntry<K, V> linkedEntry) {
|
||||
c(linkedEntry);
|
||||
LinkedEntry<K, V> linkedEntry2 = this.a;
|
||||
linkedEntry.d = linkedEntry2.d;
|
||||
linkedEntry.c = linkedEntry2;
|
||||
d(linkedEntry);
|
||||
}
|
||||
|
||||
private static <K, V> void c(LinkedEntry<K, V> linkedEntry) {
|
||||
LinkedEntry<K, V> linkedEntry2 = linkedEntry.d;
|
||||
linkedEntry2.c = linkedEntry.c;
|
||||
linkedEntry.c.d = linkedEntry2;
|
||||
}
|
||||
|
||||
private static <K, V> void d(LinkedEntry<K, V> linkedEntry) {
|
||||
linkedEntry.c.d = linkedEntry;
|
||||
linkedEntry.d.c = linkedEntry;
|
||||
}
|
||||
|
||||
public void a(K k, V v) {
|
||||
LinkedEntry<K, V> linkedEntry = this.b.get(k);
|
||||
if (linkedEntry == null) {
|
||||
linkedEntry = new LinkedEntry<>(k);
|
||||
b(linkedEntry);
|
||||
this.b.put(k, linkedEntry);
|
||||
} else {
|
||||
k.a();
|
||||
}
|
||||
linkedEntry.a(v);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("GroupedLinkedMap( ");
|
||||
boolean z = false;
|
||||
for (LinkedEntry linkedEntry = this.a.c; !linkedEntry.equals(this.a); linkedEntry = linkedEntry.c) {
|
||||
z = true;
|
||||
sb.append('{');
|
||||
sb.append(linkedEntry.a);
|
||||
sb.append(':');
|
||||
sb.append(linkedEntry.b());
|
||||
sb.append("}, ");
|
||||
}
|
||||
if (z) {
|
||||
sb.delete(sb.length() - 2, sb.length());
|
||||
}
|
||||
sb.append(" )");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public V a(K k) {
|
||||
LinkedEntry<K, V> linkedEntry = this.b.get(k);
|
||||
if (linkedEntry == null) {
|
||||
linkedEntry = new LinkedEntry<>(k);
|
||||
this.b.put(k, linkedEntry);
|
||||
} else {
|
||||
k.a();
|
||||
}
|
||||
a(linkedEntry);
|
||||
return linkedEntry.a();
|
||||
}
|
||||
|
||||
public V a() {
|
||||
for (LinkedEntry linkedEntry = this.a.d; !linkedEntry.equals(this.a); linkedEntry = linkedEntry.d) {
|
||||
V v = (V) linkedEntry.a();
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
c(linkedEntry);
|
||||
this.b.remove(linkedEntry.a);
|
||||
((Poolable) linkedEntry.a).a();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void a(LinkedEntry<K, V> linkedEntry) {
|
||||
c(linkedEntry);
|
||||
LinkedEntry<K, V> linkedEntry2 = this.a;
|
||||
linkedEntry.d = linkedEntry2;
|
||||
linkedEntry.c = linkedEntry2.c;
|
||||
d(linkedEntry);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class IntegerArrayAdapter implements ArrayAdapterInterface<int[]> {
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayAdapterInterface
|
||||
public String a() {
|
||||
return "IntegerArrayPool";
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayAdapterInterface
|
||||
public int b() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayAdapterInterface
|
||||
public int a(int[] iArr) {
|
||||
return iArr.length;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayAdapterInterface
|
||||
public int[] newArray(int i) {
|
||||
return new int[i];
|
||||
}
|
||||
}
|
@@ -0,0 +1,224 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
import android.util.Log;
|
||||
import com.bumptech.glide.util.Preconditions;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class LruArrayPool implements ArrayPool {
|
||||
private final GroupedLinkedMap<Key, Object> a = new GroupedLinkedMap<>();
|
||||
private final KeyPool b = new KeyPool();
|
||||
private final Map<Class<?>, NavigableMap<Integer, Integer>> c = new HashMap();
|
||||
private final Map<Class<?>, ArrayAdapterInterface<?>> d = new HashMap();
|
||||
private final int e;
|
||||
private int f;
|
||||
|
||||
private static final class KeyPool extends BaseKeyPool<Key> {
|
||||
KeyPool() {
|
||||
}
|
||||
|
||||
Key a(int i, Class<?> cls) {
|
||||
Key b = b();
|
||||
b.a(i, cls);
|
||||
return b;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: protected */
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BaseKeyPool
|
||||
public Key a() {
|
||||
return new Key(this);
|
||||
}
|
||||
}
|
||||
|
||||
public LruArrayPool(int i) {
|
||||
this.e = i;
|
||||
}
|
||||
|
||||
private boolean c(int i) {
|
||||
return i <= this.e / 2;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool
|
||||
public synchronized <T> T a(int i, Class<T> cls) {
|
||||
return (T) a(this.b.a(i, cls), cls);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool
|
||||
public synchronized <T> T b(int i, Class<T> cls) {
|
||||
Integer ceilingKey;
|
||||
ceilingKey = b((Class<?>) cls).ceilingKey(Integer.valueOf(i));
|
||||
return (T) a(a(i, ceilingKey) ? this.b.a(ceilingKey.intValue(), cls) : this.b.a(i, cls), cls);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool
|
||||
public synchronized <T> void put(T t) {
|
||||
Class<?> cls = t.getClass();
|
||||
ArrayAdapterInterface<T> a = a((Class) cls);
|
||||
int a2 = a.a(t);
|
||||
int b = a.b() * a2;
|
||||
if (c(b)) {
|
||||
Key a3 = this.b.a(a2, cls);
|
||||
this.a.a(a3, t);
|
||||
NavigableMap<Integer, Integer> b2 = b(cls);
|
||||
Integer num = (Integer) b2.get(Integer.valueOf(a3.b));
|
||||
Integer valueOf = Integer.valueOf(a3.b);
|
||||
int i = 1;
|
||||
if (num != null) {
|
||||
i = 1 + num.intValue();
|
||||
}
|
||||
b2.put(valueOf, Integer.valueOf(i));
|
||||
this.f += b;
|
||||
b();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Key implements Poolable {
|
||||
private final KeyPool a;
|
||||
int b;
|
||||
private Class<?> c;
|
||||
|
||||
Key(KeyPool keyPool) {
|
||||
this.a = keyPool;
|
||||
}
|
||||
|
||||
void a(int i, Class<?> cls) {
|
||||
this.b = i;
|
||||
this.c = cls;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Key)) {
|
||||
return false;
|
||||
}
|
||||
Key key = (Key) obj;
|
||||
return this.b == key.b && this.c == key.c;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int i = this.b * 31;
|
||||
Class<?> cls = this.c;
|
||||
return i + (cls != null ? cls.hashCode() : 0);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Key{size=" + this.b + "array=" + this.c + '}';
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.Poolable
|
||||
public void a() {
|
||||
this.a.a(this);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean c() {
|
||||
int i = this.f;
|
||||
return i == 0 || this.e / i >= 2;
|
||||
}
|
||||
|
||||
private <T> T a(Key key, Class<T> cls) {
|
||||
ArrayAdapterInterface<T> a = a((Class) cls);
|
||||
T t = (T) a(key);
|
||||
if (t != null) {
|
||||
this.f -= a.a(t) * a.b();
|
||||
c(a.a(t), cls);
|
||||
}
|
||||
if (t != null) {
|
||||
return t;
|
||||
}
|
||||
if (Log.isLoggable(a.a(), 2)) {
|
||||
Log.v(a.a(), "Allocated " + key.b + " bytes");
|
||||
}
|
||||
return a.newArray(key.b);
|
||||
}
|
||||
|
||||
private void c(int i, Class<?> cls) {
|
||||
NavigableMap<Integer, Integer> b = b(cls);
|
||||
Integer num = (Integer) b.get(Integer.valueOf(i));
|
||||
if (num != null) {
|
||||
if (num.intValue() == 1) {
|
||||
b.remove(Integer.valueOf(i));
|
||||
return;
|
||||
} else {
|
||||
b.put(Integer.valueOf(i), Integer.valueOf(num.intValue() - 1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new NullPointerException("Tried to decrement empty size, size: " + i + ", this: " + this);
|
||||
}
|
||||
|
||||
private void b() {
|
||||
b(this.e);
|
||||
}
|
||||
|
||||
private void b(int i) {
|
||||
while (this.f > i) {
|
||||
Object a = this.a.a();
|
||||
Preconditions.a(a);
|
||||
ArrayAdapterInterface a2 = a((LruArrayPool) a);
|
||||
this.f -= a2.a(a) * a2.b();
|
||||
c(a2.a(a), a.getClass());
|
||||
if (Log.isLoggable(a2.a(), 2)) {
|
||||
Log.v(a2.a(), "evicted: " + a2.a(a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T a(Key key) {
|
||||
return (T) this.a.a((GroupedLinkedMap<Key, Object>) key);
|
||||
}
|
||||
|
||||
private boolean a(int i, Integer num) {
|
||||
return num != null && (c() || num.intValue() <= i * 8);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool
|
||||
public synchronized void a() {
|
||||
b(0);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool
|
||||
public synchronized void a(int i) {
|
||||
try {
|
||||
if (i >= 40) {
|
||||
a();
|
||||
} else if (i >= 20 || i == 15) {
|
||||
b(this.e / 2);
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
|
||||
private NavigableMap<Integer, Integer> b(Class<?> cls) {
|
||||
NavigableMap<Integer, Integer> navigableMap = this.c.get(cls);
|
||||
if (navigableMap != null) {
|
||||
return navigableMap;
|
||||
}
|
||||
TreeMap treeMap = new TreeMap();
|
||||
this.c.put(cls, treeMap);
|
||||
return treeMap;
|
||||
}
|
||||
|
||||
private <T> ArrayAdapterInterface<T> a(T t) {
|
||||
return a((Class) t.getClass());
|
||||
}
|
||||
|
||||
private <T> ArrayAdapterInterface<T> a(Class<T> cls) {
|
||||
ArrayAdapterInterface<T> arrayAdapterInterface = (ArrayAdapterInterface) this.d.get(cls);
|
||||
if (arrayAdapterInterface == null) {
|
||||
if (cls.equals(int[].class)) {
|
||||
arrayAdapterInterface = new IntegerArrayAdapter();
|
||||
} else if (cls.equals(byte[].class)) {
|
||||
arrayAdapterInterface = new ByteArrayAdapter();
|
||||
} else {
|
||||
throw new IllegalArgumentException("No array pool found for: " + cls.getSimpleName());
|
||||
}
|
||||
this.d.put(cls, arrayAdapterInterface);
|
||||
}
|
||||
return arrayAdapterInterface;
|
||||
}
|
||||
}
|
@@ -0,0 +1,227 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
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 LruBitmapPool implements BitmapPool {
|
||||
private static final Bitmap.Config j = Bitmap.Config.ARGB_8888;
|
||||
private final LruPoolStrategy a;
|
||||
private final Set<Bitmap.Config> b;
|
||||
private final BitmapTracker c;
|
||||
private long d;
|
||||
private long e;
|
||||
private int f;
|
||||
private int g;
|
||||
private int h;
|
||||
private int i;
|
||||
|
||||
private interface BitmapTracker {
|
||||
void a(Bitmap bitmap);
|
||||
|
||||
void b(Bitmap bitmap);
|
||||
}
|
||||
|
||||
private static final class NullBitmapTracker implements BitmapTracker {
|
||||
NullBitmapTracker() {
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.BitmapTracker
|
||||
public void a(Bitmap bitmap) {
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.BitmapTracker
|
||||
public void b(Bitmap bitmap) {
|
||||
}
|
||||
}
|
||||
|
||||
LruBitmapPool(long j2, LruPoolStrategy lruPoolStrategy, Set<Bitmap.Config> set) {
|
||||
this.d = j2;
|
||||
this.a = lruPoolStrategy;
|
||||
this.b = set;
|
||||
this.c = new NullBitmapTracker();
|
||||
}
|
||||
|
||||
private static Bitmap c(int i, int i2, Bitmap.Config config) {
|
||||
if (config == null) {
|
||||
config = j;
|
||||
}
|
||||
return Bitmap.createBitmap(i, i2, config);
|
||||
}
|
||||
|
||||
private synchronized Bitmap d(int i, int i2, Bitmap.Config config) {
|
||||
Bitmap a;
|
||||
a(config);
|
||||
a = this.a.a(i, i2, config != null ? config : j);
|
||||
if (a == null) {
|
||||
if (Log.isLoggable("LruBitmapPool", 3)) {
|
||||
Log.d("LruBitmapPool", "Missing bitmap=" + this.a.b(i, i2, config));
|
||||
}
|
||||
this.g++;
|
||||
} else {
|
||||
this.f++;
|
||||
this.e -= this.a.b(a);
|
||||
this.c.a(a);
|
||||
c(a);
|
||||
}
|
||||
if (Log.isLoggable("LruBitmapPool", 2)) {
|
||||
Log.v("LruBitmapPool", "Get bitmap=" + this.a.b(i, i2, config));
|
||||
}
|
||||
c();
|
||||
return a;
|
||||
}
|
||||
|
||||
private void e() {
|
||||
a(this.d);
|
||||
}
|
||||
|
||||
@TargetApi(26)
|
||||
private static Set<Bitmap.Config> f() {
|
||||
HashSet hashSet = new HashSet(Arrays.asList(Bitmap.Config.values()));
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
hashSet.add(null);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
hashSet.remove(Bitmap.Config.HARDWARE);
|
||||
}
|
||||
return Collections.unmodifiableSet(hashSet);
|
||||
}
|
||||
|
||||
private static LruPoolStrategy g() {
|
||||
return Build.VERSION.SDK_INT >= 19 ? new SizeConfigStrategy() : new AttributeStrategy();
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
public synchronized void a(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.a.b(bitmap) <= this.d && this.b.contains(bitmap.getConfig())) {
|
||||
int b = this.a.b(bitmap);
|
||||
this.a.a(bitmap);
|
||||
this.c.b(bitmap);
|
||||
this.h++;
|
||||
this.e += b;
|
||||
if (Log.isLoggable("LruBitmapPool", 2)) {
|
||||
Log.v("LruBitmapPool", "Put bitmap in pool=" + this.a.c(bitmap));
|
||||
}
|
||||
c();
|
||||
e();
|
||||
return;
|
||||
}
|
||||
if (Log.isLoggable("LruBitmapPool", 2)) {
|
||||
Log.v("LruBitmapPool", "Reject bitmap from pool, bitmap: " + this.a.c(bitmap) + ", is mutable: " + bitmap.isMutable() + ", is allowed config: " + this.b.contains(bitmap.getConfig()));
|
||||
}
|
||||
bitmap.recycle();
|
||||
} catch (Throwable th) {
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
|
||||
public long b() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
private static void c(Bitmap bitmap) {
|
||||
bitmap.setHasAlpha(true);
|
||||
b(bitmap);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
public Bitmap b(int i, int i2, Bitmap.Config config) {
|
||||
Bitmap d = d(i, i2, config);
|
||||
return d == null ? c(i, i2, config) : d;
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
private static void b(Bitmap bitmap) {
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
bitmap.setPremultiplied(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void c() {
|
||||
if (Log.isLoggable("LruBitmapPool", 2)) {
|
||||
d();
|
||||
}
|
||||
}
|
||||
|
||||
public LruBitmapPool(long j2) {
|
||||
this(j2, g(), f());
|
||||
}
|
||||
|
||||
private void d() {
|
||||
Log.v("LruBitmapPool", "Hits=" + this.f + ", misses=" + this.g + ", puts=" + this.h + ", evictions=" + this.i + ", currentSize=" + this.e + ", maxSize=" + this.d + "\nStrategy=" + this.a);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
public Bitmap a(int i, int i2, Bitmap.Config config) {
|
||||
Bitmap d = d(i, i2, config);
|
||||
if (d != null) {
|
||||
d.eraseColor(0);
|
||||
return d;
|
||||
}
|
||||
return c(i, i2, config);
|
||||
}
|
||||
|
||||
@TargetApi(26)
|
||||
private static void a(Bitmap.Config config) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
public void a() {
|
||||
if (Log.isLoggable("LruBitmapPool", 3)) {
|
||||
Log.d("LruBitmapPool", "clearMemory");
|
||||
}
|
||||
a(0L);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
@SuppressLint({"InlinedApi"})
|
||||
public void a(int i) {
|
||||
if (Log.isLoggable("LruBitmapPool", 3)) {
|
||||
Log.d("LruBitmapPool", "trimMemory, level=" + i);
|
||||
}
|
||||
if (i >= 40) {
|
||||
a();
|
||||
} else if (i >= 20 || i == 15) {
|
||||
a(b() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void a(long j2) {
|
||||
while (this.e > j2) {
|
||||
Bitmap removeLast = this.a.removeLast();
|
||||
if (removeLast == null) {
|
||||
if (Log.isLoggable("LruBitmapPool", 5)) {
|
||||
Log.w("LruBitmapPool", "Size mismatch, resetting");
|
||||
d();
|
||||
}
|
||||
this.e = 0L;
|
||||
return;
|
||||
}
|
||||
this.c.a(removeLast);
|
||||
this.e -= this.a.b(removeLast);
|
||||
this.i++;
|
||||
if (Log.isLoggable("LruBitmapPool", 3)) {
|
||||
Log.d("LruBitmapPool", "Evicting bitmap=" + this.a.c(removeLast));
|
||||
}
|
||||
c();
|
||||
removeLast.recycle();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
interface LruPoolStrategy {
|
||||
Bitmap a(int i, int i2, Bitmap.Config config);
|
||||
|
||||
void a(Bitmap bitmap);
|
||||
|
||||
int b(Bitmap bitmap);
|
||||
|
||||
String b(int i, int i2, Bitmap.Config config);
|
||||
|
||||
String c(Bitmap bitmap);
|
||||
|
||||
Bitmap removeLast();
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
interface Poolable {
|
||||
void a();
|
||||
}
|
@@ -0,0 +1,243 @@
|
||||
package com.bumptech.glide.load.engine.bitmap_recycle;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import com.bumptech.glide.util.Util;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class SizeConfigStrategy implements LruPoolStrategy {
|
||||
private static final Bitmap.Config[] d;
|
||||
private static final Bitmap.Config[] e;
|
||||
private static final Bitmap.Config[] f;
|
||||
private static final Bitmap.Config[] g;
|
||||
private static final Bitmap.Config[] h;
|
||||
private final KeyPool a = new KeyPool();
|
||||
private final GroupedLinkedMap<Key, Bitmap> b = new GroupedLinkedMap<>();
|
||||
private final Map<Bitmap.Config, NavigableMap<Integer, Integer>> c = new HashMap();
|
||||
|
||||
/* renamed from: com.bumptech.glide.load.engine.bitmap_recycle.SizeConfigStrategy$1, reason: invalid class name */
|
||||
static /* synthetic */ class AnonymousClass1 {
|
||||
static final /* synthetic */ int[] a = new int[Bitmap.Config.values().length];
|
||||
|
||||
static {
|
||||
try {
|
||||
a[Bitmap.Config.ARGB_8888.ordinal()] = 1;
|
||||
} catch (NoSuchFieldError unused) {
|
||||
}
|
||||
try {
|
||||
a[Bitmap.Config.RGB_565.ordinal()] = 2;
|
||||
} catch (NoSuchFieldError unused2) {
|
||||
}
|
||||
try {
|
||||
a[Bitmap.Config.ARGB_4444.ordinal()] = 3;
|
||||
} catch (NoSuchFieldError unused3) {
|
||||
}
|
||||
try {
|
||||
a[Bitmap.Config.ALPHA_8.ordinal()] = 4;
|
||||
} catch (NoSuchFieldError unused4) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class KeyPool extends BaseKeyPool<Key> {
|
||||
KeyPool() {
|
||||
}
|
||||
|
||||
public Key a(int i, Bitmap.Config config) {
|
||||
Key b = b();
|
||||
b.a(i, config);
|
||||
return b;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: protected */
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BaseKeyPool
|
||||
public Key a() {
|
||||
return new Key(this);
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
Bitmap.Config[] configArr = {Bitmap.Config.ARGB_8888, null};
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
configArr = (Bitmap.Config[]) Arrays.copyOf(configArr, configArr.length + 1);
|
||||
configArr[configArr.length - 1] = Bitmap.Config.RGBA_F16;
|
||||
}
|
||||
d = configArr;
|
||||
e = d;
|
||||
f = new Bitmap.Config[]{Bitmap.Config.RGB_565};
|
||||
g = new Bitmap.Config[]{Bitmap.Config.ARGB_4444};
|
||||
h = new Bitmap.Config[]{Bitmap.Config.ALPHA_8};
|
||||
}
|
||||
|
||||
private NavigableMap<Integer, Integer> b(Bitmap.Config config) {
|
||||
NavigableMap<Integer, Integer> navigableMap = this.c.get(config);
|
||||
if (navigableMap != null) {
|
||||
return navigableMap;
|
||||
}
|
||||
TreeMap treeMap = new TreeMap();
|
||||
this.c.put(config, treeMap);
|
||||
return treeMap;
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public void a(Bitmap bitmap) {
|
||||
Key a = this.a.a(Util.a(bitmap), bitmap.getConfig());
|
||||
this.b.a(a, bitmap);
|
||||
NavigableMap<Integer, Integer> b = b(bitmap.getConfig());
|
||||
Integer num = (Integer) b.get(Integer.valueOf(a.b));
|
||||
b.put(Integer.valueOf(a.b), Integer.valueOf(num != null ? 1 + num.intValue() : 1));
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public String c(Bitmap bitmap) {
|
||||
return b(Util.a(bitmap), bitmap.getConfig());
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public Bitmap removeLast() {
|
||||
Bitmap a = this.b.a();
|
||||
if (a != null) {
|
||||
a(Integer.valueOf(Util.a(a)), a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SizeConfigStrategy{groupedMap=");
|
||||
sb.append(this.b);
|
||||
sb.append(", sortedSizes=(");
|
||||
for (Map.Entry<Bitmap.Config, NavigableMap<Integer, Integer>> entry : this.c.entrySet()) {
|
||||
sb.append(entry.getKey());
|
||||
sb.append('[');
|
||||
sb.append(entry.getValue());
|
||||
sb.append("], ");
|
||||
}
|
||||
if (!this.c.isEmpty()) {
|
||||
sb.replace(sb.length() - 2, sb.length(), "");
|
||||
}
|
||||
sb.append(")}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static final class Key implements Poolable {
|
||||
private final KeyPool a;
|
||||
int b;
|
||||
private Bitmap.Config c;
|
||||
|
||||
public Key(KeyPool keyPool) {
|
||||
this.a = keyPool;
|
||||
}
|
||||
|
||||
public void a(int i, Bitmap.Config config) {
|
||||
this.b = i;
|
||||
this.c = config;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Key)) {
|
||||
return false;
|
||||
}
|
||||
Key key = (Key) obj;
|
||||
return this.b == key.b && Util.b(this.c, key.c);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int i = this.b * 31;
|
||||
Bitmap.Config config = this.c;
|
||||
return i + (config != null ? config.hashCode() : 0);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return SizeConfigStrategy.b(this.b, this.c);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.Poolable
|
||||
public void a() {
|
||||
this.a.a(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public String b(int i, int i2, Bitmap.Config config) {
|
||||
return b(Util.a(i, i2, config), config);
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public int b(Bitmap bitmap) {
|
||||
return Util.a(bitmap);
|
||||
}
|
||||
|
||||
static String b(int i, Bitmap.Config config) {
|
||||
return "[" + i + "](" + config + ")";
|
||||
}
|
||||
|
||||
@Override // com.bumptech.glide.load.engine.bitmap_recycle.LruPoolStrategy
|
||||
public Bitmap a(int i, int i2, Bitmap.Config config) {
|
||||
Key a = a(Util.a(i, i2, config), config);
|
||||
Bitmap a2 = this.b.a((GroupedLinkedMap<Key, Bitmap>) a);
|
||||
if (a2 != null) {
|
||||
a(Integer.valueOf(a.b), a2);
|
||||
a2.reconfigure(i, i2, a2.getConfig() != null ? a2.getConfig() : Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
return a2;
|
||||
}
|
||||
|
||||
private Key a(int i, Bitmap.Config config) {
|
||||
Key a = this.a.a(i, config);
|
||||
for (Bitmap.Config config2 : a(config)) {
|
||||
Integer ceilingKey = b(config2).ceilingKey(Integer.valueOf(i));
|
||||
if (ceilingKey != null && ceilingKey.intValue() <= i * 8) {
|
||||
if (ceilingKey.intValue() == i) {
|
||||
if (config2 == null) {
|
||||
if (config == null) {
|
||||
return a;
|
||||
}
|
||||
} else if (config2.equals(config)) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
this.a.a(a);
|
||||
return this.a.a(ceilingKey.intValue(), config2);
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private void a(Integer num, Bitmap bitmap) {
|
||||
NavigableMap<Integer, Integer> b = b(bitmap.getConfig());
|
||||
Integer num2 = (Integer) b.get(num);
|
||||
if (num2 != null) {
|
||||
if (num2.intValue() == 1) {
|
||||
b.remove(num);
|
||||
return;
|
||||
} else {
|
||||
b.put(num, Integer.valueOf(num2.intValue() - 1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new NullPointerException("Tried to decrement empty size, size: " + num + ", removed: " + c(bitmap) + ", this: " + this);
|
||||
}
|
||||
|
||||
private static Bitmap.Config[] a(Bitmap.Config config) {
|
||||
if (Build.VERSION.SDK_INT >= 26 && Bitmap.Config.RGBA_F16.equals(config)) {
|
||||
return e;
|
||||
}
|
||||
int i = AnonymousClass1.a[config.ordinal()];
|
||||
if (i == 1) {
|
||||
return d;
|
||||
}
|
||||
if (i == 2) {
|
||||
return f;
|
||||
}
|
||||
if (i != 3) {
|
||||
return i != 4 ? new Bitmap.Config[]{config} : h;
|
||||
}
|
||||
return g;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user