package y0;

import android.view.Choreographer;
import rm.x;
import vm.g;
import y0.g1;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class g0 implements g1 {

    /* renamed from: p, reason: collision with root package name */
    public static final g0 f51536p = new g0();

    /* renamed from: q, reason: collision with root package name */
    private static final Choreographer f51537q = (Choreographer) tp.i.e(tp.a1.c().a0(), new a(null));

    /* loaded from: classes.dex */
    static final class a extends kotlin.coroutines.jvm.internal.l implements dn.p {

        /* renamed from: p, reason: collision with root package name */
        int f51538p;

        a(vm.d dVar) {
            super(2, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new a(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            wm.d.f();
            if (this.f51538p != 0) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            rm.y.b(obj);
            return Choreographer.getInstance();
        }

        @Override // dn.p
        public final Object invoke(tp.m0 m0Var, vm.d dVar) {
            return ((a) create(m0Var, dVar)).invokeSuspend(rm.n0.f34904a);
        }
    }

    /* loaded from: classes.dex */
    static final class b extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ Choreographer.FrameCallback f51539p;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(Choreographer.FrameCallback frameCallback) {
            super(1);
            this.f51539p = frameCallback;
        }

        public final void a(Throwable th2) {
            g0.f51537q.removeFrameCallback(this.f51539p);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((Throwable) obj);
            return rm.n0.f34904a;
        }
    }

    /* loaded from: classes.dex */
    static final class c implements Choreographer.FrameCallback {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ tp.o f51540p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ dn.l f51541q;

        c(tp.o oVar, dn.l lVar) {
            this.f51540p = oVar;
            this.f51541q = lVar;
        }

        @Override // android.view.Choreographer.FrameCallback
        public final void doFrame(long j10) {
            Object a10;
            tp.o oVar = this.f51540p;
            g0 g0Var = g0.f51536p;
            dn.l lVar = this.f51541q;
            try {
                x.a aVar = rm.x.f34910p;
                a10 = rm.x.a(lVar.invoke(Long.valueOf(j10)));
            } catch (Throwable th2) {
                x.a aVar2 = rm.x.f34910p;
                a10 = rm.x.a(rm.y.a(th2));
            }
            oVar.resumeWith(a10);
        }
    }

    private g0() {
    }

    @Override // y0.g1
    public Object J(dn.l lVar, vm.d dVar) {
        vm.d d10;
        Object f10;
        d10 = wm.c.d(dVar);
        tp.p pVar = new tp.p(d10, 1);
        pVar.u();
        c cVar = new c(pVar, lVar);
        f51537q.postFrameCallback(cVar);
        pVar.x(new b(cVar));
        Object r10 = pVar.r();
        f10 = wm.d.f();
        if (r10 == f10) {
            kotlin.coroutines.jvm.internal.h.c(dVar);
        }
        return r10;
    }

    @Override // vm.g.b, vm.g
    public g.b d(g.c cVar) {
        return g1.a.b(this, cVar);
    }

    @Override // vm.g
    public vm.g h(vm.g gVar) {
        return g1.a.d(this, gVar);
    }

    @Override // vm.g
    public vm.g r(g.c cVar) {
        return g1.a.c(this, cVar);
    }

    @Override // vm.g
    public Object y(Object obj, dn.p pVar) {
        return g1.a.a(this, obj, pVar);
    }
}
