package androidx.compose.ui.platform;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.view.ViewOutlineProvider;
import androidx.compose.ui.graphics.a;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/* loaded from: classes.dex */
public final class z2 extends View implements j2.i1 {
    public static final c E = new c(null);
    public static final int F = 8;
    private static final dn.p G = b.f2806p;
    private static final ViewOutlineProvider H = new a();
    private static Method I;
    private static Field J;
    private static boolean K;
    private static boolean L;
    private long A;
    private boolean B;
    private final long C;
    private int D;

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

    /* renamed from: q, reason: collision with root package name */
    private final j1 f2796q;

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

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

    /* renamed from: t, reason: collision with root package name */
    private final c2 f2799t;

    /* renamed from: u, reason: collision with root package name */
    private boolean f2800u;

    /* renamed from: v, reason: collision with root package name */
    private Rect f2801v;

    /* renamed from: w, reason: collision with root package name */
    private boolean f2802w;

    /* renamed from: x, reason: collision with root package name */
    private boolean f2803x;

    /* renamed from: y, reason: collision with root package name */
    private final s1.b0 f2804y;

    /* renamed from: z, reason: collision with root package name */
    private final x1 f2805z;

    /* loaded from: classes.dex */
    public static final class a extends ViewOutlineProvider {
        a() {
        }

        @Override // android.view.ViewOutlineProvider
        public void getOutline(View view, Outline outline) {
            kotlin.jvm.internal.t.e(view, "null cannot be cast to non-null type androidx.compose.ui.platform.ViewLayer");
            Outline b10 = ((z2) view).f2799t.b();
            kotlin.jvm.internal.t.d(b10);
            outline.set(b10);
        }
    }

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

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

        b() {
            super(2);
        }

        public final void a(View view, Matrix matrix) {
            matrix.set(view.getMatrix());
        }

        @Override // dn.p
        public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2) {
            a((View) obj, (Matrix) obj2);
            return rm.n0.f34904a;
        }
    }

    /* loaded from: classes.dex */
    public static final class c {
        private c() {
        }

        public /* synthetic */ c(kotlin.jvm.internal.k kVar) {
            this();
        }

        public final boolean a() {
            return z2.K;
        }

        public final boolean b() {
            return z2.L;
        }

        public final void c(boolean z10) {
            z2.L = z10;
        }

        public final void d(View view) {
            try {
                if (!a()) {
                    z2.K = true;
                    z2.I = (Method) Class.class.getDeclaredMethod("getDeclaredMethod", String.class, new Class[0].getClass()).invoke(View.class, "updateDisplayListIfDirty", new Class[0]);
                    z2.J = (Field) Class.class.getDeclaredMethod("getDeclaredField", String.class).invoke(View.class, "mRecreateDisplayList");
                    Method method = z2.I;
                    if (method != null) {
                        method.setAccessible(true);
                    }
                    Field field = z2.J;
                    if (field != null) {
                        field.setAccessible(true);
                    }
                }
                Field field2 = z2.J;
                if (field2 != null) {
                    field2.setBoolean(view, true);
                }
                Method method2 = z2.I;
                if (method2 != null) {
                    method2.invoke(view, new Object[0]);
                }
            } catch (Throwable unused) {
                c(true);
            }
        }
    }

    /* loaded from: classes.dex */
    private static final class d {

        /* renamed from: a, reason: collision with root package name */
        public static final d f2807a = new d();

        private d() {
        }

        public static final long a(View view) {
            return view.getUniqueDrawingId();
        }
    }

    public z2(r rVar, j1 j1Var, dn.p pVar, dn.a aVar) {
        super(rVar.getContext());
        this.f2795p = rVar;
        this.f2796q = j1Var;
        this.f2797r = pVar;
        this.f2798s = aVar;
        this.f2799t = new c2();
        this.f2804y = new s1.b0();
        this.f2805z = new x1(G);
        this.A = androidx.compose.ui.graphics.f.f2249b.a();
        this.B = true;
        setWillNotDraw(false);
        j1Var.addView(this);
        this.C = View.generateViewId();
    }

    private final s1.f1 getManualClipPath() {
        if (!getClipToOutline() || this.f2799t.e()) {
            return null;
        }
        return this.f2799t.d();
    }

    private final void setInvalidated(boolean z10) {
        if (z10 != this.f2802w) {
            this.f2802w = z10;
            this.f2795p.y0(this, z10);
        }
    }

    private final void w() {
        Rect rect;
        if (this.f2800u) {
            Rect rect2 = this.f2801v;
            if (rect2 == null) {
                this.f2801v = new Rect(0, 0, getWidth(), getHeight());
            } else {
                kotlin.jvm.internal.t.d(rect2);
                rect2.set(0, 0, getWidth(), getHeight());
            }
            rect = this.f2801v;
        } else {
            rect = null;
        }
        setClipBounds(rect);
    }

    private final void x() {
        setOutlineProvider(this.f2799t.b() != null ? H : null);
    }

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

    @Override // j2.i1
    public void c(s1.a0 a0Var, v1.c cVar) {
        boolean z10 = getElevation() > BitmapDescriptorFactory.HUE_RED;
        this.f2803x = z10;
        if (z10) {
            a0Var.y();
        }
        this.f2796q.a(a0Var, this, getDrawingTime());
        if (this.f2803x) {
            a0Var.o();
        }
    }

    @Override // j2.i1
    public void d() {
        setInvalidated(false);
        this.f2795p.J0();
        this.f2797r = null;
        this.f2798s = null;
        this.f2795p.H0(this);
        this.f2796q.removeViewInLayout(this);
    }

    @Override // android.view.View
    protected void dispatchDraw(Canvas canvas) {
        boolean z10;
        s1.b0 b0Var = this.f2804y;
        Canvas b10 = b0Var.a().b();
        b0Var.a().z(canvas);
        s1.b a10 = b0Var.a();
        if (getManualClipPath() == null && canvas.isHardwareAccelerated()) {
            z10 = false;
        } else {
            a10.n();
            this.f2799t.a(a10);
            z10 = true;
        }
        dn.p pVar = this.f2797r;
        if (pVar != null) {
            pVar.invoke(a10, null);
        }
        if (z10) {
            a10.x();
        }
        b0Var.a().z(b10);
        setInvalidated(false);
    }

    @Override // j2.i1
    public boolean e(long j10) {
        float m10 = r1.g.m(j10);
        float n10 = r1.g.n(j10);
        if (this.f2800u) {
            return BitmapDescriptorFactory.HUE_RED <= m10 && m10 < ((float) getWidth()) && BitmapDescriptorFactory.HUE_RED <= n10 && n10 < ((float) getHeight());
        }
        if (getClipToOutline()) {
            return this.f2799t.f(j10);
        }
        return true;
    }

    @Override // j2.i1
    public void f(dn.p pVar, dn.a aVar) {
        this.f2796q.addView(this);
        this.f2800u = false;
        this.f2803x = false;
        this.A = androidx.compose.ui.graphics.f.f2249b.a();
        this.f2797r = pVar;
        this.f2798s = aVar;
    }

    @Override // android.view.View
    public void forceLayout() {
    }

    @Override // j2.i1
    public void g(androidx.compose.ui.graphics.d dVar) {
        dn.a aVar;
        int z10 = dVar.z() | this.D;
        if ((z10 & 4096) != 0) {
            long W0 = dVar.W0();
            this.A = W0;
            setPivotX(androidx.compose.ui.graphics.f.f(W0) * getWidth());
            setPivotY(androidx.compose.ui.graphics.f.g(this.A) * getHeight());
        }
        if ((z10 & 1) != 0) {
            setScaleX(dVar.n());
        }
        if ((z10 & 2) != 0) {
            setScaleY(dVar.J());
        }
        if ((z10 & 4) != 0) {
            setAlpha(dVar.h());
        }
        if ((z10 & 8) != 0) {
            setTranslationX(dVar.E());
        }
        if ((z10 & 16) != 0) {
            setTranslationY(dVar.y());
        }
        if ((z10 & 32) != 0) {
            setElevation(dVar.I());
        }
        if ((z10 & UserMetadata.MAX_ATTRIBUTE_SIZE) != 0) {
            setRotation(dVar.v());
        }
        if ((z10 & 256) != 0) {
            setRotationX(dVar.G());
        }
        if ((z10 & 512) != 0) {
            setRotationY(dVar.u());
        }
        if ((z10 & 2048) != 0) {
            setCameraDistancePx(dVar.D());
        }
        boolean z11 = false;
        boolean z12 = getManualClipPath() != null;
        boolean z13 = dVar.q() && dVar.L() != s1.l1.a();
        if ((z10 & 24576) != 0) {
            this.f2800u = dVar.q() && dVar.L() == s1.l1.a();
            w();
            setClipToOutline(z13);
        }
        boolean h10 = this.f2799t.h(dVar.B(), dVar.h(), z13, dVar.I(), dVar.b());
        if (this.f2799t.c()) {
            x();
        }
        boolean z14 = getManualClipPath() != null;
        if (z12 != z14 || (z14 && h10)) {
            invalidate();
        }
        if (!this.f2803x && getElevation() > BitmapDescriptorFactory.HUE_RED && (aVar = this.f2798s) != null) {
            aVar.invoke();
        }
        if ((z10 & 7963) != 0) {
            this.f2805z.c();
        }
        int i10 = Build.VERSION.SDK_INT;
        if ((z10 & 64) != 0) {
            b3.f2340a.a(this, s1.i0.j(dVar.p()));
        }
        if ((z10 & 128) != 0) {
            b3.f2340a.b(this, s1.i0.j(dVar.M()));
        }
        if (i10 >= 31 && (131072 & z10) != 0) {
            d3 d3Var = d3.f2417a;
            dVar.C();
            d3Var.a(this, null);
        }
        if ((z10 & 32768) != 0) {
            int r10 = dVar.r();
            a.C0062a c0062a = androidx.compose.ui.graphics.a.f2231a;
            if (androidx.compose.ui.graphics.a.e(r10, c0062a.c())) {
                setLayerType(2, null);
            } else if (androidx.compose.ui.graphics.a.e(r10, c0062a.b())) {
                setLayerType(0, null);
                this.B = z11;
            } else {
                setLayerType(0, null);
            }
            z11 = true;
            this.B = z11;
        }
        this.D = dVar.z();
    }

    public final float getCameraDistancePx() {
        return getCameraDistance() / getResources().getDisplayMetrics().densityDpi;
    }

    public final j1 getContainer() {
        return this.f2796q;
    }

    public long getLayerId() {
        return this.C;
    }

    public final r getOwnerView() {
        return this.f2795p;
    }

    public long getOwnerViewId() {
        return d.a(this.f2795p);
    }

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

    @Override // android.view.View
    public boolean hasOverlappingRendering() {
        return this.B;
    }

    @Override // j2.i1
    public void i(long j10) {
        int g10 = c3.r.g(j10);
        int f10 = c3.r.f(j10);
        if (g10 == getWidth() && f10 == getHeight()) {
            return;
        }
        setPivotX(androidx.compose.ui.graphics.f.f(this.A) * g10);
        setPivotY(androidx.compose.ui.graphics.f.g(this.A) * f10);
        x();
        layout(getLeft(), getTop(), getLeft() + g10, getTop() + f10);
        w();
        this.f2805z.c();
    }

    @Override // android.view.View, j2.i1
    public void invalidate() {
        if (this.f2802w) {
            return;
        }
        setInvalidated(true);
        super.invalidate();
        this.f2795p.invalidate();
    }

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

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

    @Override // j2.i1
    public void l(long j10) {
        int h10 = c3.n.h(j10);
        if (h10 != getLeft()) {
            offsetLeftAndRight(h10 - getLeft());
            this.f2805z.c();
        }
        int i10 = c3.n.i(j10);
        if (i10 != getTop()) {
            offsetTopAndBottom(i10 - getTop());
            this.f2805z.c();
        }
    }

    @Override // j2.i1
    public void m() {
        if (!this.f2802w || L) {
            return;
        }
        E.d(this);
        setInvalidated(false);
    }

    @Override // android.view.View
    protected void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
    }

    public final void setCameraDistancePx(float f10) {
        setCameraDistance(f10 * getResources().getDisplayMetrics().densityDpi);
    }

    public final boolean v() {
        return this.f2802w;
    }
}
