276 lines
11 KiB
Java
276 lines
11 KiB
Java
package com.bumptech.glide.load.engine;
|
|
|
|
import android.util.Log;
|
|
import androidx.core.util.Pools$Pool;
|
|
import com.bumptech.glide.GlideContext;
|
|
import com.bumptech.glide.Priority;
|
|
import com.bumptech.glide.load.DataSource;
|
|
import com.bumptech.glide.load.Key;
|
|
import com.bumptech.glide.load.Options;
|
|
import com.bumptech.glide.load.Transformation;
|
|
import com.bumptech.glide.load.engine.DecodeJob;
|
|
import com.bumptech.glide.load.engine.EngineResource;
|
|
import com.bumptech.glide.load.engine.cache.DiskCache;
|
|
import com.bumptech.glide.load.engine.cache.DiskCacheAdapter;
|
|
import com.bumptech.glide.load.engine.cache.MemoryCache;
|
|
import com.bumptech.glide.load.engine.executor.GlideExecutor;
|
|
import com.bumptech.glide.request.ResourceCallback;
|
|
import com.bumptech.glide.util.LogTime;
|
|
import com.bumptech.glide.util.Preconditions;
|
|
import com.bumptech.glide.util.Util;
|
|
import com.bumptech.glide.util.pool.FactoryPools;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class Engine implements EngineJobListener, MemoryCache.ResourceRemovedListener, EngineResource.ResourceListener {
|
|
private static final boolean i = Log.isLoggable("Engine", 2);
|
|
private final Jobs a;
|
|
private final EngineKeyFactory b;
|
|
private final MemoryCache c;
|
|
private final EngineJobFactory d;
|
|
private final ResourceRecycler e;
|
|
private final LazyDiskCacheProvider f;
|
|
private final DecodeJobFactory g;
|
|
private final ActiveResources h;
|
|
|
|
static class DecodeJobFactory {
|
|
final DecodeJob.DiskCacheProvider a;
|
|
final Pools$Pool<DecodeJob<?>> b = FactoryPools.a(150, new FactoryPools.Factory<DecodeJob<?>>() { // from class: com.bumptech.glide.load.engine.Engine.DecodeJobFactory.1
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // com.bumptech.glide.util.pool.FactoryPools.Factory
|
|
public DecodeJob<?> a() {
|
|
DecodeJobFactory decodeJobFactory = DecodeJobFactory.this;
|
|
return new DecodeJob<>(decodeJobFactory.a, decodeJobFactory.b);
|
|
}
|
|
});
|
|
private int c;
|
|
|
|
DecodeJobFactory(DecodeJob.DiskCacheProvider diskCacheProvider) {
|
|
this.a = diskCacheProvider;
|
|
}
|
|
|
|
<R> DecodeJob<R> a(GlideContext glideContext, Object obj, EngineKey engineKey, Key key, int i, int i2, Class<?> cls, Class<R> cls2, Priority priority, DiskCacheStrategy diskCacheStrategy, Map<Class<?>, Transformation<?>> map, boolean z, boolean z2, boolean z3, Options options, DecodeJob.Callback<R> callback) {
|
|
DecodeJob a = this.b.a();
|
|
Preconditions.a(a);
|
|
DecodeJob decodeJob = a;
|
|
int i3 = this.c;
|
|
this.c = i3 + 1;
|
|
decodeJob.a(glideContext, obj, engineKey, key, i, i2, cls, cls2, priority, diskCacheStrategy, map, z, z2, z3, options, callback, i3);
|
|
return decodeJob;
|
|
}
|
|
}
|
|
|
|
static class EngineJobFactory {
|
|
final GlideExecutor a;
|
|
final GlideExecutor b;
|
|
final GlideExecutor c;
|
|
final GlideExecutor d;
|
|
final EngineJobListener e;
|
|
final Pools$Pool<EngineJob<?>> f = FactoryPools.a(150, new FactoryPools.Factory<EngineJob<?>>() { // from class: com.bumptech.glide.load.engine.Engine.EngineJobFactory.1
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // com.bumptech.glide.util.pool.FactoryPools.Factory
|
|
public EngineJob<?> a() {
|
|
EngineJobFactory engineJobFactory = EngineJobFactory.this;
|
|
return new EngineJob<>(engineJobFactory.a, engineJobFactory.b, engineJobFactory.c, engineJobFactory.d, engineJobFactory.e, engineJobFactory.f);
|
|
}
|
|
});
|
|
|
|
EngineJobFactory(GlideExecutor glideExecutor, GlideExecutor glideExecutor2, GlideExecutor glideExecutor3, GlideExecutor glideExecutor4, EngineJobListener engineJobListener) {
|
|
this.a = glideExecutor;
|
|
this.b = glideExecutor2;
|
|
this.c = glideExecutor3;
|
|
this.d = glideExecutor4;
|
|
this.e = engineJobListener;
|
|
}
|
|
|
|
<R> EngineJob<R> a(Key key, boolean z, boolean z2, boolean z3, boolean z4) {
|
|
EngineJob a = this.f.a();
|
|
Preconditions.a(a);
|
|
EngineJob engineJob = a;
|
|
engineJob.a(key, z, z2, z3, z4);
|
|
return engineJob;
|
|
}
|
|
}
|
|
|
|
private static class LazyDiskCacheProvider implements DecodeJob.DiskCacheProvider {
|
|
private final DiskCache.Factory a;
|
|
private volatile DiskCache b;
|
|
|
|
LazyDiskCacheProvider(DiskCache.Factory factory) {
|
|
this.a = factory;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.engine.DecodeJob.DiskCacheProvider
|
|
public DiskCache a() {
|
|
if (this.b == null) {
|
|
synchronized (this) {
|
|
if (this.b == null) {
|
|
this.b = this.a.build();
|
|
}
|
|
if (this.b == null) {
|
|
this.b = new DiskCacheAdapter();
|
|
}
|
|
}
|
|
}
|
|
return this.b;
|
|
}
|
|
}
|
|
|
|
public static class LoadStatus {
|
|
private final EngineJob<?> a;
|
|
private final ResourceCallback b;
|
|
|
|
LoadStatus(ResourceCallback resourceCallback, EngineJob<?> engineJob) {
|
|
this.b = resourceCallback;
|
|
this.a = engineJob;
|
|
}
|
|
|
|
public void a() {
|
|
this.a.b(this.b);
|
|
}
|
|
}
|
|
|
|
public Engine(MemoryCache memoryCache, DiskCache.Factory factory, GlideExecutor glideExecutor, GlideExecutor glideExecutor2, GlideExecutor glideExecutor3, GlideExecutor glideExecutor4, boolean z) {
|
|
this(memoryCache, factory, glideExecutor, glideExecutor2, glideExecutor3, glideExecutor4, null, null, null, null, null, null, z);
|
|
}
|
|
|
|
private EngineResource<?> b(Key key, boolean z) {
|
|
if (!z) {
|
|
return null;
|
|
}
|
|
EngineResource<?> a = a(key);
|
|
if (a != null) {
|
|
a.c();
|
|
this.h.a(key, a);
|
|
}
|
|
return a;
|
|
}
|
|
|
|
public <R> LoadStatus a(GlideContext glideContext, Object obj, Key key, int i2, int i3, Class<?> cls, Class<R> cls2, Priority priority, DiskCacheStrategy diskCacheStrategy, Map<Class<?>, Transformation<?>> map, boolean z, boolean z2, Options options, boolean z3, boolean z4, boolean z5, boolean z6, ResourceCallback resourceCallback) {
|
|
Util.b();
|
|
long a = i ? LogTime.a() : 0L;
|
|
EngineKey a2 = this.b.a(obj, key, i2, i3, map, cls, cls2, options);
|
|
EngineResource<?> a3 = a(a2, z3);
|
|
if (a3 != null) {
|
|
resourceCallback.a(a3, DataSource.MEMORY_CACHE);
|
|
if (i) {
|
|
a("Loaded resource from active resources", a, a2);
|
|
}
|
|
return null;
|
|
}
|
|
EngineResource<?> b = b(a2, z3);
|
|
if (b != null) {
|
|
resourceCallback.a(b, DataSource.MEMORY_CACHE);
|
|
if (i) {
|
|
a("Loaded resource from cache", a, a2);
|
|
}
|
|
return null;
|
|
}
|
|
EngineJob<?> a4 = this.a.a(a2, z6);
|
|
if (a4 != null) {
|
|
a4.a(resourceCallback);
|
|
if (i) {
|
|
a("Added to existing load", a, a2);
|
|
}
|
|
return new LoadStatus(resourceCallback, a4);
|
|
}
|
|
EngineJob<R> a5 = this.d.a(a2, z3, z4, z5, z6);
|
|
DecodeJob<R> a6 = this.g.a(glideContext, obj, a2, key, i2, i3, cls, cls2, priority, diskCacheStrategy, map, z, z2, z6, options, a5);
|
|
this.a.a((Key) a2, (EngineJob<?>) a5);
|
|
a5.a(resourceCallback);
|
|
a5.b(a6);
|
|
if (i) {
|
|
a("Started new load", a, a2);
|
|
}
|
|
return new LoadStatus(resourceCallback, a5);
|
|
}
|
|
|
|
Engine(MemoryCache memoryCache, DiskCache.Factory factory, GlideExecutor glideExecutor, GlideExecutor glideExecutor2, GlideExecutor glideExecutor3, GlideExecutor glideExecutor4, Jobs jobs, EngineKeyFactory engineKeyFactory, ActiveResources activeResources, EngineJobFactory engineJobFactory, DecodeJobFactory decodeJobFactory, ResourceRecycler resourceRecycler, boolean z) {
|
|
this.c = memoryCache;
|
|
this.f = new LazyDiskCacheProvider(factory);
|
|
ActiveResources activeResources2 = activeResources == null ? new ActiveResources(z) : activeResources;
|
|
this.h = activeResources2;
|
|
activeResources2.a(this);
|
|
this.b = engineKeyFactory == null ? new EngineKeyFactory() : engineKeyFactory;
|
|
this.a = jobs == null ? new Jobs() : jobs;
|
|
this.d = engineJobFactory == null ? new EngineJobFactory(glideExecutor, glideExecutor2, glideExecutor3, glideExecutor4, this) : engineJobFactory;
|
|
this.g = decodeJobFactory == null ? new DecodeJobFactory(this.f) : decodeJobFactory;
|
|
this.e = resourceRecycler == null ? new ResourceRecycler() : resourceRecycler;
|
|
memoryCache.a(this);
|
|
}
|
|
|
|
public void b(Resource<?> resource) {
|
|
Util.b();
|
|
if (resource instanceof EngineResource) {
|
|
((EngineResource) resource).f();
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Cannot release anything but an EngineResource");
|
|
}
|
|
|
|
private static void a(String str, long j, Key key) {
|
|
Log.v("Engine", str + " in " + LogTime.a(j) + "ms, key: " + key);
|
|
}
|
|
|
|
private EngineResource<?> a(Key key, boolean z) {
|
|
if (!z) {
|
|
return null;
|
|
}
|
|
EngineResource<?> b = this.h.b(key);
|
|
if (b != null) {
|
|
b.c();
|
|
}
|
|
return b;
|
|
}
|
|
|
|
private EngineResource<?> a(Key key) {
|
|
Resource<?> a = this.c.a(key);
|
|
if (a == null) {
|
|
return null;
|
|
}
|
|
if (a instanceof EngineResource) {
|
|
return (EngineResource) a;
|
|
}
|
|
return new EngineResource<>(a, true, true);
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.engine.EngineJobListener
|
|
public void a(EngineJob<?> engineJob, Key key, EngineResource<?> engineResource) {
|
|
Util.b();
|
|
if (engineResource != null) {
|
|
engineResource.a(key, this);
|
|
if (engineResource.e()) {
|
|
this.h.a(key, engineResource);
|
|
}
|
|
}
|
|
this.a.b(key, engineJob);
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.engine.EngineJobListener
|
|
public void a(EngineJob<?> engineJob, Key key) {
|
|
Util.b();
|
|
this.a.b(key, engineJob);
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.engine.cache.MemoryCache.ResourceRemovedListener
|
|
public void a(Resource<?> resource) {
|
|
Util.b();
|
|
this.e.a(resource);
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.engine.EngineResource.ResourceListener
|
|
public void a(Key key, EngineResource<?> engineResource) {
|
|
Util.b();
|
|
this.h.a(key);
|
|
if (engineResource.e()) {
|
|
this.c.a(key, engineResource);
|
|
} else {
|
|
this.e.a(engineResource);
|
|
}
|
|
}
|
|
|
|
public void a() {
|
|
this.f.a().clear();
|
|
}
|
|
}
|