package androidx.compose.ui.platform;

import android.graphics.Canvas;
import android.os.Build;
import androidx.compose.ui.graphics.a;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import s1.b1;

/* loaded from: classes.dex */
public final class m1 implements j2.i1 {
    private int C;
    private s1.b1 E;
    private s1.f1 F;
    private s1.d1 G;
    private boolean H;

    /* renamed from: p, reason: collision with root package name */
    private v1.c f2527p;

    /* renamed from: q, reason: collision with root package name */
    private final s1.s0 f2528q;

    /* renamed from: r, reason: collision with root package name */
    private final r f2529r;

    /* renamed from: s, reason: collision with root package name */
    private dn.p f2530s;

    /* renamed from: t, reason: collision with root package name */
    private dn.a f2531t;

    /* renamed from: v, reason: collision with root package name */
    private boolean f2533v;

    /* renamed from: x, reason: collision with root package name */
    private float[] f2535x;

    /* renamed from: y, reason: collision with root package name */
    private boolean f2536y;

    /* renamed from: u, reason: collision with root package name */
    private long f2532u = c3.s.a(Api.BaseClientBuilder.API_PRIORITY_OTHER, Api.BaseClientBuilder.API_PRIORITY_OTHER);

    /* renamed from: w, reason: collision with root package name */
    private final float[] f2534w = s1.z0.c(null, 1, null);

    /* renamed from: z, reason: collision with root package name */
    private c3.d f2537z = c3.f.b(1.0f, BitmapDescriptorFactory.HUE_RED, 2, null);
    private c3.t A = c3.t.Ltr;
    private final u1.a B = new u1.a();
    private long D = androidx.compose.ui.graphics.f.f2249b.a();
    private final dn.l I = new a();

    /* loaded from: classes.dex */
    static final class a extends kotlin.jvm.internal.v implements dn.l {
        a() {
            super(1);
        }

        public final void a(u1.f fVar) {
            m1 m1Var = m1.this;
            s1.a0 i10 = fVar.Q0().i();
            dn.p pVar = m1Var.f2530s;
            if (pVar != null) {
                pVar.invoke(i10, fVar.Q0().h());
            }
        }

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

    public m1(v1.c cVar, s1.s0 s0Var, r rVar, dn.p pVar, dn.a aVar) {
        this.f2527p = cVar;
        this.f2528q = s0Var;
        this.f2529r = rVar;
        this.f2530s = pVar;
        this.f2531t = aVar;
    }

    private final void n(s1.a0 a0Var) {
        if (this.f2527p.k()) {
            s1.b1 n10 = this.f2527p.n();
            if (n10 instanceof b1.b) {
                s1.a0.m(a0Var, ((b1.b) n10).b(), 0, 2, null);
                return;
            }
            if (!(n10 instanceof b1.c)) {
                if (n10 instanceof b1.a) {
                    s1.a0.w(a0Var, ((b1.a) n10).b(), 0, 2, null);
                    return;
                }
                return;
            }
            s1.f1 f1Var = this.F;
            if (f1Var == null) {
                f1Var = s1.p.a();
                this.F = f1Var;
            }
            f1Var.reset();
            s1.f1.g(f1Var, ((b1.c) n10).b(), null, 2, null);
            s1.a0.w(a0Var, f1Var, 0, 2, null);
        }
    }

    private final float[] o() {
        float[] p10 = p();
        float[] fArr = this.f2535x;
        if (fArr == null) {
            fArr = s1.z0.c(null, 1, null);
            this.f2535x = fArr;
        }
        if (v1.a(p10, fArr)) {
            return fArr;
        }
        return null;
    }

    private final float[] p() {
        s();
        return this.f2534w;
    }

    private final void q(boolean z10) {
        if (z10 != this.f2536y) {
            this.f2536y = z10;
            this.f2529r.y0(this, z10);
        }
    }

    private final void r() {
        o3.f2607a.a(this.f2529r);
    }

    private final void s() {
        v1.c cVar = this.f2527p;
        long b10 = r1.h.d(cVar.o()) ? r1.n.b(c3.s.d(this.f2532u)) : cVar.o();
        s1.z0.h(this.f2534w);
        float[] fArr = this.f2534w;
        float[] c10 = s1.z0.c(null, 1, null);
        s1.z0.q(c10, -r1.g.m(b10), -r1.g.n(b10), BitmapDescriptorFactory.HUE_RED, 4, null);
        s1.z0.n(fArr, c10);
        float[] fArr2 = this.f2534w;
        float[] c11 = s1.z0.c(null, 1, null);
        s1.z0.q(c11, cVar.x(), cVar.y(), BitmapDescriptorFactory.HUE_RED, 4, null);
        s1.z0.i(c11, cVar.p());
        s1.z0.j(c11, cVar.q());
        s1.z0.k(c11, cVar.r());
        s1.z0.m(c11, cVar.s(), cVar.t(), BitmapDescriptorFactory.HUE_RED, 4, null);
        s1.z0.n(fArr2, c11);
        float[] fArr3 = this.f2534w;
        float[] c12 = s1.z0.c(null, 1, null);
        s1.z0.q(c12, r1.g.m(b10), r1.g.n(b10), BitmapDescriptorFactory.HUE_RED, 4, null);
        s1.z0.n(fArr3, c12);
    }

    private final void t() {
        dn.a aVar;
        s1.b1 b1Var = this.E;
        if (b1Var == null) {
            return;
        }
        v1.e.b(this.f2527p, b1Var);
        if (!(b1Var instanceof b1.a) || Build.VERSION.SDK_INT >= 33 || (aVar = this.f2531t) == null) {
            return;
        }
        aVar.invoke();
    }

    @Override // j2.i1
    public void b(float[] fArr) {
        s1.z0.n(fArr, p());
    }

    @Override // j2.i1
    public void c(s1.a0 a0Var, v1.c cVar) {
        Canvas d10 = s1.c.d(a0Var);
        if (d10.isHardwareAccelerated()) {
            m();
            this.H = this.f2527p.u() > BitmapDescriptorFactory.HUE_RED;
            u1.d Q0 = this.B.Q0();
            Q0.d(a0Var);
            Q0.e(cVar);
            v1.e.a(this.B, this.f2527p);
            return;
        }
        float h10 = c3.n.h(this.f2527p.w());
        float i10 = c3.n.i(this.f2527p.w());
        float g10 = h10 + c3.r.g(this.f2532u);
        float f10 = i10 + c3.r.f(this.f2532u);
        if (this.f2527p.i() < 1.0f) {
            s1.d1 d1Var = this.G;
            if (d1Var == null) {
                d1Var = s1.l.a();
                this.G = d1Var;
            }
            d1Var.a(this.f2527p.i());
            d10.saveLayer(h10, i10, g10, f10, d1Var.v());
        } else {
            a0Var.n();
        }
        a0Var.d(h10, i10);
        a0Var.q(p());
        if (this.f2527p.k()) {
            n(a0Var);
        }
        dn.p pVar = this.f2530s;
        if (pVar != null) {
            pVar.invoke(a0Var, null);
        }
        a0Var.x();
    }

    @Override // j2.i1
    public void d() {
        this.f2530s = null;
        this.f2531t = null;
        this.f2533v = true;
        q(false);
        s1.s0 s0Var = this.f2528q;
        if (s0Var != null) {
            s0Var.b(this.f2527p);
            this.f2529r.H0(this);
        }
    }

    @Override // j2.i1
    public boolean e(long j10) {
        float m10 = r1.g.m(j10);
        float n10 = r1.g.n(j10);
        if (this.f2527p.k()) {
            return o2.c(this.f2527p.n(), m10, n10, null, null, 24, null);
        }
        return true;
    }

    @Override // j2.i1
    public void f(dn.p pVar, dn.a aVar) {
        s1.s0 s0Var = this.f2528q;
        if (s0Var == null) {
            throw new IllegalArgumentException("currently reuse is only supported when we manage the layer lifecycle".toString());
        }
        if (!this.f2527p.z()) {
            throw new IllegalArgumentException("layer should have been released before reuse".toString());
        }
        this.f2527p = s0Var.a();
        this.f2533v = false;
        this.f2530s = pVar;
        this.f2531t = aVar;
        this.D = androidx.compose.ui.graphics.f.f2249b.a();
        this.H = false;
        this.f2532u = c3.s.a(Api.BaseClientBuilder.API_PRIORITY_OTHER, Api.BaseClientBuilder.API_PRIORITY_OTHER);
        this.E = null;
        this.C = 0;
    }

    @Override // j2.i1
    public void g(androidx.compose.ui.graphics.d dVar) {
        boolean z10;
        int b10;
        dn.a aVar;
        int z11 = dVar.z() | this.C;
        this.A = dVar.x();
        this.f2537z = dVar.s();
        int i10 = z11 & 4096;
        if (i10 != 0) {
            this.D = dVar.W0();
        }
        if ((z11 & 1) != 0) {
            this.f2527p.X(dVar.n());
        }
        if ((z11 & 2) != 0) {
            this.f2527p.Y(dVar.J());
        }
        if ((z11 & 4) != 0) {
            this.f2527p.J(dVar.h());
        }
        if ((z11 & 8) != 0) {
            this.f2527p.d0(dVar.E());
        }
        if ((z11 & 16) != 0) {
            this.f2527p.e0(dVar.y());
        }
        if ((z11 & 32) != 0) {
            this.f2527p.Z(dVar.I());
            if (dVar.I() > BitmapDescriptorFactory.HUE_RED && !this.H && (aVar = this.f2531t) != null) {
                aVar.invoke();
            }
        }
        if ((z11 & 64) != 0) {
            this.f2527p.K(dVar.p());
        }
        if ((z11 & 128) != 0) {
            this.f2527p.b0(dVar.M());
        }
        if ((z11 & UserMetadata.MAX_ATTRIBUTE_SIZE) != 0) {
            this.f2527p.V(dVar.v());
        }
        if ((z11 & 256) != 0) {
            this.f2527p.T(dVar.G());
        }
        if ((z11 & 512) != 0) {
            this.f2527p.U(dVar.u());
        }
        if ((z11 & 2048) != 0) {
            this.f2527p.L(dVar.D());
        }
        if (i10 != 0) {
            if (androidx.compose.ui.graphics.f.e(this.D, androidx.compose.ui.graphics.f.f2249b.a())) {
                this.f2527p.P(r1.g.f34318b.b());
            } else {
                this.f2527p.P(r1.h.a(androidx.compose.ui.graphics.f.f(this.D) * c3.r.g(this.f2532u), androidx.compose.ui.graphics.f.g(this.D) * c3.r.f(this.f2532u)));
            }
        }
        if ((z11 & 16384) != 0) {
            this.f2527p.M(dVar.q());
        }
        if ((131072 & z11) != 0) {
            v1.c cVar = this.f2527p;
            dVar.C();
            cVar.S(null);
        }
        if ((32768 & z11) != 0) {
            v1.c cVar2 = this.f2527p;
            int r10 = dVar.r();
            a.C0062a c0062a = androidx.compose.ui.graphics.a.f2231a;
            if (androidx.compose.ui.graphics.a.e(r10, c0062a.a())) {
                b10 = v1.b.f38879a.a();
            } else if (androidx.compose.ui.graphics.a.e(r10, c0062a.c())) {
                b10 = v1.b.f38879a.c();
            } else {
                if (!androidx.compose.ui.graphics.a.e(r10, c0062a.b())) {
                    throw new IllegalStateException("Not supported composition strategy");
                }
                b10 = v1.b.f38879a.b();
            }
            cVar2.N(b10);
        }
        if (kotlin.jvm.internal.t.b(this.E, dVar.B())) {
            z10 = false;
        } else {
            this.E = dVar.B();
            t();
            z10 = true;
        }
        this.C = dVar.z();
        if (z11 != 0 || z10) {
            r();
        }
    }

    @Override // j2.i1
    public long h(long j10, boolean z10) {
        if (!z10) {
            return s1.z0.f(p(), j10);
        }
        float[] o10 = o();
        return o10 != null ? s1.z0.f(o10, j10) : r1.g.f34318b.a();
    }

    @Override // j2.i1
    public void i(long j10) {
        if (c3.r.e(j10, this.f2532u)) {
            return;
        }
        this.f2532u = j10;
        invalidate();
    }

    @Override // j2.i1
    public void invalidate() {
        if (this.f2536y || this.f2533v) {
            return;
        }
        this.f2529r.invalidate();
        q(true);
    }

    @Override // j2.i1
    public void j(float[] fArr) {
        float[] o10 = o();
        if (o10 != null) {
            s1.z0.n(fArr, o10);
        }
    }

    @Override // j2.i1
    public void k(r1.e eVar, boolean z10) {
        if (!z10) {
            s1.z0.g(p(), eVar);
            return;
        }
        float[] o10 = o();
        if (o10 == null) {
            eVar.g(BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED);
        } else {
            s1.z0.g(o10, eVar);
        }
    }

    @Override // j2.i1
    public void l(long j10) {
        this.f2527p.c0(j10);
        r();
    }

    @Override // j2.i1
    public void m() {
        if (this.f2536y) {
            if (!androidx.compose.ui.graphics.f.e(this.D, androidx.compose.ui.graphics.f.f2249b.a()) && !c3.r.e(this.f2527p.v(), this.f2532u)) {
                this.f2527p.P(r1.h.a(androidx.compose.ui.graphics.f.f(this.D) * c3.r.g(this.f2532u), androidx.compose.ui.graphics.f.g(this.D) * c3.r.f(this.f2532u)));
            }
            this.f2527p.E(this.f2537z, this.A, this.f2532u, this.I);
            q(false);
        }
    }
}
