package n2;

import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.CancellationSignal;
import android.view.ScrollCaptureCallback;
import android.view.ScrollCaptureSession;
import android.view.Surface;
import c3.p;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import j2.z0;
import java.util.function.Consumer;
import kotlin.jvm.internal.v;
import rm.n0;
import rm.y;
import s1.a0;
import s1.k1;
import tp.i2;
import tp.m0;
import y0.i1;

/* loaded from: classes.dex */
public final class c implements ScrollCaptureCallback {

    /* renamed from: a, reason: collision with root package name */
    private final o2.m f29747a;

    /* renamed from: b, reason: collision with root package name */
    private final p f29748b;

    /* renamed from: c, reason: collision with root package name */
    private final a f29749c;

    /* renamed from: d, reason: collision with root package name */
    private final m0 f29750d;

    /* renamed from: e, reason: collision with root package name */
    private final g f29751e;

    /* renamed from: f, reason: collision with root package name */
    private int f29752f;

    /* loaded from: classes.dex */
    public interface a {
        void a();

        void b();
    }

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

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

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ Runnable f29755r;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(Runnable runnable, vm.d dVar) {
            super(2, dVar);
            this.f29755r = runnable;
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f29753p;
            if (i10 == 0) {
                y.b(obj);
                g gVar = c.this.f29751e;
                this.f29753p = 1;
                if (gVar.g(BitmapDescriptorFactory.HUE_RED, this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            c.this.f29749c.b();
            this.f29755r.run();
            return n0.f34904a;
        }

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

    /* renamed from: n2.c$c, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    static final class C0675c extends kotlin.coroutines.jvm.internal.l implements dn.p {

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

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ ScrollCaptureSession f29758r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ Rect f29759s;

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ Consumer f29760t;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        C0675c(ScrollCaptureSession scrollCaptureSession, Rect rect, Consumer consumer, vm.d dVar) {
            super(2, dVar);
            this.f29758r = scrollCaptureSession;
            this.f29759s = rect;
            this.f29760t = consumer;
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f29756p;
            if (i10 == 0) {
                y.b(obj);
                c cVar = c.this;
                ScrollCaptureSession scrollCaptureSession = this.f29758r;
                p d10 = k1.d(this.f29759s);
                this.f29756p = 1;
                obj = cVar.e(scrollCaptureSession, d10, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            this.f29760t.accept(k1.a((p) obj));
            return n0.f34904a;
        }

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

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class d extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f29761p;

        /* renamed from: q, reason: collision with root package name */
        Object f29762q;

        /* renamed from: r, reason: collision with root package name */
        Object f29763r;

        /* renamed from: s, reason: collision with root package name */
        int f29764s;

        /* renamed from: t, reason: collision with root package name */
        int f29765t;

        /* renamed from: u, reason: collision with root package name */
        /* synthetic */ Object f29766u;

        /* renamed from: w, reason: collision with root package name */
        int f29768w;

        d(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f29766u = obj;
            this.f29768w |= Integer.MIN_VALUE;
            return c.this.e(null, null, this);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class e extends v implements dn.l {

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

        e() {
            super(1);
        }

        public final void a(long j10) {
        }

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

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

        /* renamed from: p, reason: collision with root package name */
        boolean f29770p;

        /* renamed from: q, reason: collision with root package name */
        int f29771q;

        /* renamed from: r, reason: collision with root package name */
        /* synthetic */ float f29772r;

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

        public final Object b(float f10, vm.d dVar) {
            return ((f) create(Float.valueOf(f10), dVar)).invokeSuspend(n0.f34904a);
        }

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

        @Override // dn.p
        public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2) {
            return b(((Number) obj).floatValue(), (vm.d) obj2);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            boolean z10;
            f10 = wm.d.f();
            int i10 = this.f29771q;
            if (i10 == 0) {
                y.b(obj);
                float f11 = this.f29772r;
                dn.p c10 = m.c(c.this.f29747a);
                if (c10 == null) {
                    g2.a.c("Required value was null.");
                    throw new rm.k();
                }
                boolean b10 = ((o2.g) c.this.f29747a.w().x(o2.p.f30605a.I())).b();
                if (b10) {
                    f11 = -f11;
                }
                r1.g d10 = r1.g.d(r1.h.a(BitmapDescriptorFactory.HUE_RED, f11));
                this.f29770p = b10;
                this.f29771q = 1;
                obj = c10.invoke(d10, this);
                if (obj == f10) {
                    return f10;
                }
                z10 = b10;
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                z10 = this.f29770p;
                y.b(obj);
            }
            long v10 = ((r1.g) obj).v();
            return kotlin.coroutines.jvm.internal.b.b(z10 ? -r1.g.n(v10) : r1.g.n(v10));
        }
    }

    public c(o2.m mVar, p pVar, m0 m0Var, a aVar) {
        this.f29747a = mVar;
        this.f29748b = pVar;
        this.f29749c = aVar;
        this.f29750d = tp.n0.i(m0Var, n2.f.f29776p);
        this.f29751e = new g(pVar.f(), new f(null));
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:13:0x00b7  */
    /* JADX WARN: Removed duplicated region for block: B:16:0x00be  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x0098 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:35:0x0099  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x0064  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0024  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object e(ScrollCaptureSession scrollCaptureSession, p pVar, vm.d dVar) {
        d dVar2;
        Object f10;
        int i10;
        int i11;
        int d10;
        e eVar;
        p pVar2;
        c cVar;
        int i12;
        ScrollCaptureSession scrollCaptureSession2;
        int i13;
        int c10;
        int c11;
        Surface surface;
        Surface surface2;
        Surface surface3;
        int c12;
        if (dVar instanceof d) {
            dVar2 = (d) dVar;
            int i14 = dVar2.f29768w;
            if ((i14 & Integer.MIN_VALUE) != 0) {
                dVar2.f29768w = i14 - Integer.MIN_VALUE;
                Object obj = dVar2.f29766u;
                f10 = wm.d.f();
                i10 = dVar2.f29768w;
                if (i10 != 0) {
                    y.b(obj);
                    i11 = pVar.i();
                    d10 = pVar.d();
                    g gVar = this.f29751e;
                    dVar2.f29761p = this;
                    dVar2.f29762q = scrollCaptureSession;
                    dVar2.f29763r = pVar;
                    dVar2.f29764s = i11;
                    dVar2.f29765t = d10;
                    dVar2.f29768w = 1;
                    if (gVar.f(i11, d10, dVar2) == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        if (i10 != 2) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        i12 = dVar2.f29765t;
                        i13 = dVar2.f29764s;
                        p pVar3 = (p) dVar2.f29763r;
                        ScrollCaptureSession a10 = n2.a.a(dVar2.f29762q);
                        c cVar2 = (c) dVar2.f29761p;
                        y.b(obj);
                        scrollCaptureSession2 = a10;
                        pVar2 = pVar3;
                        cVar = cVar2;
                        c10 = cVar.f29751e.c(i13);
                        c11 = cVar.f29751e.c(i12);
                        p c13 = p.c(pVar2, 0, c10, 0, c11, 5, null);
                        if (c10 != c11) {
                            return p.f7426e.a();
                        }
                        z0 e10 = cVar.f29747a.e();
                        if (e10 == null) {
                            throw new IllegalStateException("Could not find coordinator for semantics node.".toString());
                        }
                        surface = scrollCaptureSession2.getSurface();
                        Canvas lockHardwareCanvas = surface.lockHardwareCanvas();
                        try {
                            lockHardwareCanvas.drawColor(0, BlendMode.CLEAR);
                            a0 b10 = s1.c.b(lockHardwareCanvas);
                            b10.d(-c13.g(), -c13.i());
                            e10.i2(b10, null);
                            surface3 = scrollCaptureSession2.getSurface();
                            surface3.unlockCanvasAndPost(lockHardwareCanvas);
                            c12 = fn.c.c(cVar.f29751e.b());
                            return c13.m(0, c12);
                        } catch (Throwable th2) {
                            surface2 = scrollCaptureSession2.getSurface();
                            surface2.unlockCanvasAndPost(lockHardwareCanvas);
                            throw th2;
                        }
                    }
                    int i15 = dVar2.f29765t;
                    int i16 = dVar2.f29764s;
                    pVar = (p) dVar2.f29763r;
                    ScrollCaptureSession a11 = n2.a.a(dVar2.f29762q);
                    c cVar3 = (c) dVar2.f29761p;
                    y.b(obj);
                    i11 = i16;
                    scrollCaptureSession = a11;
                    d10 = i15;
                    this = cVar3;
                }
                eVar = e.f29769p;
                dVar2.f29761p = this;
                dVar2.f29762q = scrollCaptureSession;
                dVar2.f29763r = pVar;
                dVar2.f29764s = i11;
                dVar2.f29765t = d10;
                dVar2.f29768w = 2;
                if (i1.c(eVar, dVar2) != f10) {
                    return f10;
                }
                pVar2 = pVar;
                cVar = this;
                i12 = d10;
                int i17 = i11;
                scrollCaptureSession2 = scrollCaptureSession;
                i13 = i17;
                c10 = cVar.f29751e.c(i13);
                c11 = cVar.f29751e.c(i12);
                p c132 = p.c(pVar2, 0, c10, 0, c11, 5, null);
                if (c10 != c11) {
                }
            }
        }
        dVar2 = new d(dVar);
        Object obj2 = dVar2.f29766u;
        f10 = wm.d.f();
        i10 = dVar2.f29768w;
        if (i10 != 0) {
        }
        eVar = e.f29769p;
        dVar2.f29761p = this;
        dVar2.f29762q = scrollCaptureSession;
        dVar2.f29763r = pVar;
        dVar2.f29764s = i11;
        dVar2.f29765t = d10;
        dVar2.f29768w = 2;
        if (i1.c(eVar, dVar2) != f10) {
        }
    }

    public void onScrollCaptureEnd(Runnable runnable) {
        tp.k.d(this.f29750d, i2.f36557q, null, new b(runnable, null), 2, null);
    }

    public void onScrollCaptureImageRequest(ScrollCaptureSession scrollCaptureSession, CancellationSignal cancellationSignal, Rect rect, Consumer consumer) {
        n2.e.c(this.f29750d, cancellationSignal, new C0675c(scrollCaptureSession, rect, consumer, null));
    }

    public void onScrollCaptureSearch(CancellationSignal cancellationSignal, Consumer consumer) {
        consumer.accept(k1.a(this.f29748b));
    }

    public void onScrollCaptureStart(ScrollCaptureSession scrollCaptureSession, CancellationSignal cancellationSignal, Runnable runnable) {
        this.f29751e.d();
        this.f29752f = 0;
        this.f29749c.a();
        runnable.run();
    }
}
