package com.kwad.sdk.glide.webp.decoder; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemClock; import com.kwad.sdk.glide.d.j; import com.kwad.sdk.glide.f; import com.kwad.sdk.glide.g; import com.kwad.sdk.glide.load.e; import com.kwad.sdk.glide.load.engine.h; import com.kwad.sdk.glide.load.i; import com.kwad.sdk.utils.an; import java.nio.ByteBuffer; import java.security.MessageDigest; import java.util.ArrayList; import java.util.List; public final class o { public static final e<WebpFrameCacheStrategy> btd = e.b("com.kwad.sdk.glide.webp.decoder.WebpFrameLoader.CacheStrategy", WebpFrameCacheStrategy.bsY); public static final e<p> bte = e.b("com.kwad.sdk.glide.webp.decoder.WebpFrameLoader.WebpFrameSampleSize", p.btm); private final com.kwad.sdk.glide.load.engine.bitmap_recycle.e bhB; final g bij; private i<Bitmap> bmv; private final List<b> bqo; private boolean bqp; private boolean bqq; private f<Bitmap> bqr; private boolean bqt; private Bitmap bqv; private final i btf; private a btg; private a bth; private a bti; private int btj; private final Handler handler; private int height; private boolean isRunning; private int width; /* access modifiers changed from: package-private */ public static class a extends com.kwad.sdk.glide.request.kwai.c<Bitmap> { private final long bqx; private Bitmap bqy; private final Handler handler; final int index; a(Handler handler2, int i, long j) { this.handler = handler2; this.index = i; this.bqx = j; } private void a(Bitmap bitmap) { this.bqy = bitmap; Message obtainMessage = this.handler.obtainMessage(1, this); this.handler.removeMessages(1); this.handler.sendMessageAtTime(obtainMessage, this.bqx); } /* access modifiers changed from: package-private */ public final Bitmap TI() { return this.bqy; } @Override // com.kwad.sdk.glide.request.kwai.j public final void onLoadCleared(Drawable drawable) { this.bqy = null; } @Override // com.kwad.sdk.glide.request.kwai.j public final /* synthetic */ void onResourceReady(Object obj, com.kwad.sdk.glide.request.a.b bVar) { a((Bitmap) obj); } } public interface b { void TB(); } class c implements Handler.Callback { c() { } public final boolean handleMessage(Message message) { if (message.what == 1) { o.this.a((a) message.obj); return true; } else if (message.what != 2) { return false; } else { o.this.bij.c((a) message.obj); return false; } } } /* access modifiers changed from: package-private */ public static class d implements com.kwad.sdk.glide.load.c { private final com.kwad.sdk.glide.load.c bku; private final int btl; d(com.kwad.sdk.glide.load.c cVar, int i) { this.bku = cVar; this.btl = i; } @Override // com.kwad.sdk.glide.load.c public final boolean equals(Object obj) { if (obj instanceof d) { d dVar = (d) obj; return this.bku.equals(dVar.bku) && this.btl == dVar.btl; } } @Override // com.kwad.sdk.glide.load.c public final int hashCode() { return (this.bku.hashCode() * 31) + this.btl; } @Override // com.kwad.sdk.glide.load.c public final void updateDiskCacheKey(MessageDigest messageDigest) { messageDigest.update(ByteBuffer.allocate(12).putInt(this.btl).array()); this.bku.updateDiskCacheKey(messageDigest); } } public o(com.kwad.sdk.glide.c cVar, i iVar, int i, int i2, i<Bitmap> iVar2, Bitmap bitmap) { this(cVar.Qv(), com.kwad.sdk.glide.c.bS(cVar.getContext()), iVar, null, a(com.kwad.sdk.glide.c.bS(cVar.getContext()), i, i2), iVar2, bitmap); } private o(com.kwad.sdk.glide.load.engine.bitmap_recycle.e eVar, g gVar, i iVar, Handler handler2, f<Bitmap> fVar, i<Bitmap> iVar2, Bitmap bitmap) { this.bqo = new ArrayList(); this.isRunning = false; this.bqp = false; this.bqq = false; this.bij = gVar; Handler handler3 = new Handler(Looper.getMainLooper(), new c()); this.bhB = eVar; this.handler = handler3; this.bqr = fVar; this.btf = iVar; a(iVar2, bitmap); } private void TF() { if (this.isRunning && !this.bqp) { if (this.bqq) { an.checkArgument(this.bti == null, "Pending target must be null when starting from the first frame"); this.btf.QU(); this.bqq = false; } a aVar = this.bti; if (aVar != null) { this.bti = null; a(aVar); return; } this.bqp = true; int QS = this.btf.QS(); this.btf.advance(); int QT = this.btf.QT(); this.bth = new a(this.handler, QT, SystemClock.uptimeMillis() + ((long) QS)); this.bqr.b((com.kwad.sdk.glide.request.i) com.kwad.sdk.glide.request.i.j(dq(QT)).bZ(this.btf.Vi().noCache())).n(this.btf).b(this.bth); } } private void TG() { Bitmap bitmap = this.bqv; if (bitmap != null) { this.bhB.e(bitmap); this.bqv = null; } } private static f<Bitmap> a(g gVar, int i, int i2) { return gVar.QM().b(((com.kwad.sdk.glide.request.i) ((com.kwad.sdk.glide.request.i) com.kwad.sdk.glide.request.i.b(h.blu).bY(true)).bZ(true)).I(i, i2)); } private com.kwad.sdk.glide.load.c dq(int i) { return new d(new com.kwad.sdk.glide.c.b(this.btf), i); } private void start() { if (!this.isRunning) { this.isRunning = true; this.bqt = false; TF(); } } private void stop() { this.isRunning = false; } /* access modifiers changed from: package-private */ public final Bitmap TE() { a aVar = this.btg; return aVar != null ? aVar.TI() : this.bqv; } /* access modifiers changed from: package-private */ public final Bitmap Tu() { return this.bqv; } /* access modifiers changed from: package-private */ public final void a(i<Bitmap> iVar, Bitmap bitmap) { this.bmv = (i) an.checkNotNull(iVar); this.bqv = (Bitmap) an.checkNotNull(bitmap); this.bqr = this.bqr.b(new com.kwad.sdk.glide.request.i().a(iVar)); this.btj = j.m(bitmap); this.width = bitmap.getWidth(); this.height = bitmap.getHeight(); } /* access modifiers changed from: package-private */ public final void a(a aVar) { System.currentTimeMillis(); this.bqp = false; if (!this.bqt) { if (this.isRunning) { if (aVar.TI() != null) { TG(); a aVar2 = this.btg; this.btg = aVar; for (int size = this.bqo.size() - 1; size >= 0; size--) { this.bqo.get(size).TB(); } if (aVar2 != null) { this.handler.obtainMessage(2, aVar2).sendToTarget(); } } TF(); return; } else if (!this.bqq) { this.bti = aVar; return; } } this.handler.obtainMessage(2, aVar).sendToTarget(); } /* access modifiers changed from: package-private */ public final void a(b bVar) { if (this.bqt) { throw new IllegalStateException("Cannot subscribe to a cleared frame loader"); } else if (!this.bqo.contains(bVar)) { boolean isEmpty = this.bqo.isEmpty(); this.bqo.add(bVar); if (isEmpty) { start(); } } else { throw new IllegalStateException("Cannot subscribe twice in a row"); } } /* access modifiers changed from: package-private */ public final void b(b bVar) { this.bqo.remove(bVar); if (this.bqo.isEmpty()) { stop(); } } /* access modifiers changed from: package-private */ public final void clear() { this.bqo.clear(); TG(); stop(); a aVar = this.btg; if (aVar != null) { this.bij.c(aVar); this.btg = null; } a aVar2 = this.bth; if (aVar2 != null) { this.bij.c(aVar2); this.bth = null; } a aVar3 = this.bti; if (aVar3 != null) { this.bij.c(aVar3); this.bti = null; } this.btf.clear(); this.bqt = true; } /* access modifiers changed from: package-private */ public final ByteBuffer getBuffer() { return this.btf.getData().asReadOnlyBuffer(); } /* access modifiers changed from: package-private */ public final int getCurrentIndex() { a aVar = this.btg; if (aVar != null) { return aVar.index; } return -1; } /* access modifiers changed from: package-private */ public final int getFrameCount() { return this.btf.getFrameCount(); } /* access modifiers changed from: package-private */ public final int getHeight() { return this.height; } /* access modifiers changed from: package-private */ public final int getSize() { return this.btf.getByteSize() + this.btj; } /* access modifiers changed from: package-private */ public final int getWidth() { return this.width; } }