package s6; 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 b7.k; import e6.n; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; /* loaded from: classes2.dex */ class g { /* renamed from: a, reason: collision with root package name */ private final d6.a f14032a; /* renamed from: b, reason: collision with root package name */ private final Handler f14033b; /* renamed from: c, reason: collision with root package name */ private final List f14034c; /* renamed from: d, reason: collision with root package name */ final b6.j f14035d; /* renamed from: e, reason: collision with root package name */ private final i6.b f14036e; /* renamed from: f, reason: collision with root package name */ private boolean f14037f; /* renamed from: g, reason: collision with root package name */ private boolean f14038g; /* renamed from: h, reason: collision with root package name */ private boolean f14039h; /* renamed from: i, reason: collision with root package name */ private b6.i f14040i; /* renamed from: j, reason: collision with root package name */ private b f14041j; /* renamed from: k, reason: collision with root package name */ private boolean f14042k; /* renamed from: l, reason: collision with root package name */ private b f14043l; /* renamed from: m, reason: collision with root package name */ private Bitmap f14044m; /* renamed from: n, reason: collision with root package name */ private n f14045n; /* renamed from: o, reason: collision with root package name */ private b f14046o; /* renamed from: p, reason: collision with root package name */ private int f14047p; /* renamed from: q, reason: collision with root package name */ private int f14048q; /* renamed from: r, reason: collision with root package name */ private int f14049r; public interface a { void a(); } static class b extends y6.c { /* renamed from: d, reason: collision with root package name */ private final Handler f14050d; /* renamed from: e, reason: collision with root package name */ final int f14051e; /* renamed from: f, reason: collision with root package name */ private final long f14052f; /* renamed from: g, reason: collision with root package name */ private Bitmap f14053g; b(Handler handler, int i10, long j10) { this.f14050d = handler; this.f14051e = i10; this.f14052f = j10; } @Override // y6.h public void d(Drawable drawable) { this.f14053g = null; } Bitmap g() { return this.f14053g; } @Override // y6.h /* renamed from: i, reason: merged with bridge method [inline-methods] */ public void h(Bitmap bitmap, z6.d dVar) { this.f14053g = bitmap; this.f14050d.sendMessageAtTime(this.f14050d.obtainMessage(1, this), this.f14052f); } } private class c implements Handler.Callback { c() { } @Override // android.os.Handler.Callback public boolean handleMessage(Message message) { int i10 = message.what; if (i10 == 1) { g.this.e((b) message.obj); return true; } if (i10 != 2) { return false; } g.this.f14035d.s((b) message.obj); return false; } } g(b6.e eVar, d6.a aVar, int i10, int i11, n nVar, Bitmap bitmap) { this(eVar.o(), b6.e.t(eVar.p()), aVar, null, a(b6.e.t(eVar.p()), i10, i11), nVar, bitmap); } private static b6.i a(b6.j jVar, int i10, int i11) { return jVar.o().i(((x6.f) ((x6.f) x6.f.n0(h6.c.f10338b).l0(true)).j0(true)).d0(i10, i11)); } private static e6.h l() { return new a7.d(Double.valueOf(Math.random())); } private void p() { if (!this.f14037f || this.f14038g) { return; } if (this.f14039h) { b7.j.a(this.f14046o == null, "Pending target must be null when starting from the first frame"); this.f14032a.f(); this.f14039h = false; } b bVar = this.f14046o; if (bVar != null) { this.f14046o = null; e(bVar); return; } this.f14038g = true; long uptimeMillis = SystemClock.uptimeMillis() + this.f14032a.d(); this.f14032a.b(); this.f14043l = new b(this.f14033b, this.f14032a.g(), uptimeMillis); this.f14040i.i(x6.f.o0(l())).D0(this.f14032a).z0(this.f14043l); } private void q() { Bitmap bitmap = this.f14044m; if (bitmap != null) { this.f14036e.c(bitmap); this.f14044m = null; } } private void r() { if (this.f14037f) { return; } this.f14037f = true; this.f14042k = false; p(); } private void s() { this.f14037f = false; } void b() { this.f14034c.clear(); q(); s(); b bVar = this.f14041j; if (bVar != null) { this.f14035d.s(bVar); this.f14041j = null; } b bVar2 = this.f14043l; if (bVar2 != null) { this.f14035d.s(bVar2); this.f14043l = null; } b bVar3 = this.f14046o; if (bVar3 != null) { this.f14035d.s(bVar3); this.f14046o = null; } this.f14032a.clear(); this.f14042k = true; } void c(n nVar, Bitmap bitmap) { this.f14045n = (n) b7.j.d(nVar); this.f14044m = (Bitmap) b7.j.d(bitmap); this.f14040i = this.f14040i.i(new x6.f().k0(nVar)); this.f14047p = k.j(bitmap); this.f14048q = bitmap.getWidth(); this.f14049r = bitmap.getHeight(); } void d(a aVar) { if (this.f14042k) { throw new IllegalStateException("Cannot subscribe to a cleared frame loader"); } if (this.f14034c.contains(aVar)) { throw new IllegalStateException("Cannot subscribe twice in a row"); } boolean isEmpty = this.f14034c.isEmpty(); this.f14034c.add(aVar); if (isEmpty) { r(); } } void e(b bVar) { this.f14038g = false; if (this.f14042k) { this.f14033b.obtainMessage(2, bVar).sendToTarget(); return; } if (!this.f14037f) { if (this.f14039h) { this.f14033b.obtainMessage(2, bVar).sendToTarget(); return; } else { this.f14046o = bVar; return; } } if (bVar.g() != null) { q(); b bVar2 = this.f14041j; this.f14041j = bVar; for (int size = this.f14034c.size() - 1; size >= 0; size--) { ((a) this.f14034c.get(size)).a(); } if (bVar2 != null) { this.f14033b.obtainMessage(2, bVar2).sendToTarget(); } } p(); } ByteBuffer f() { return this.f14032a.getData().asReadOnlyBuffer(); } void g(a aVar) { this.f14034c.remove(aVar); if (this.f14034c.isEmpty()) { s(); } } Bitmap h() { b bVar = this.f14041j; return bVar != null ? bVar.g() : this.f14044m; } int i() { b bVar = this.f14041j; if (bVar != null) { return bVar.f14051e; } return -1; } Bitmap j() { return this.f14044m; } int k() { return this.f14032a.c(); } int m() { return this.f14049r; } int n() { return this.f14032a.h() + this.f14047p; } int o() { return this.f14048q; } g(i6.b bVar, b6.j jVar, d6.a aVar, Handler handler, b6.i iVar, n nVar, Bitmap bitmap) { this.f14034c = new ArrayList(); this.f14035d = jVar; handler = handler == null ? new Handler(Looper.getMainLooper(), new c()) : handler; this.f14036e = bVar; this.f14033b = handler; this.f14040i = iVar; this.f14032a = aVar; c(nVar, bitmap); } }