package F;

import android.os.Trace;
import android.view.Choreographer;
import android.view.Display;
import android.view.View;
import java.util.PriorityQueue;
import java.util.concurrent.TimeUnit;

/* JADX INFO: renamed from: F.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class ViewOnAttachStateChangeListenerC0147a implements k0, View.OnAttachStateChangeListener, Runnable, Choreographer.FrameCallback {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static long f1239k;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final View f1240a;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f1242c;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f1245f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public long f1246j;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final PriorityQueue f1241b = new PriorityQueue(11, new C1.c(1));

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Choreographer f1243d = Choreographer.getInstance();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final E3.p f1244e = new E3.p(1);

    /* JADX WARN: Removed duplicated region for block: B:10:0x0041  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public ViewOnAttachStateChangeListenerC0147a(View view) {
        float refreshRate;
        this.f1240a = view;
        if (f1239k == 0) {
            Display display = view.getDisplay();
            if (view.isInEditMode() || display == null) {
                refreshRate = 60.0f;
                f1239k = (long) (1000000000 / refreshRate);
            } else {
                refreshRate = display.getRefreshRate();
                if (refreshRate < 30.0f) {
                }
                f1239k = (long) (1000000000 / refreshRate);
            }
        }
        view.addOnAttachStateChangeListener(this);
        if (view.isAttachedToWindow()) {
            this.f1245f = true;
        }
    }

    @Override // F.k0
    public void a(j0 j0Var) {
        this.f1241b.add(new n0(1, j0Var));
        if (this.f1242c) {
            return;
        }
        this.f1242c = true;
        this.f1240a.post(this);
    }

    public final boolean b() {
        E3.p pVar = this.f1244e;
        long jA = pVar.a();
        W.a.B0("compose:lazy:prefetch:available_time_nanos", jA);
        boolean z6 = true;
        if (jA > 0) {
            PriorityQueue priorityQueue = this.f1241b;
            Object objPeek = priorityQueue.peek();
            kotlin.jvm.internal.o.e(objPeek);
            if (!((n0) objPeek).f1326b.c(pVar)) {
                priorityQueue.poll();
                z6 = false;
            }
            pVar.f1167b = false;
        }
        return z6;
    }

    @Override // android.view.Choreographer.FrameCallback
    public final void doFrame(long j4) {
        if (this.f1245f) {
            this.f1246j = j4;
            this.f1240a.post(this);
        }
    }

    @Override // android.view.View.OnAttachStateChangeListener
    public final void onViewAttachedToWindow(View view) {
        this.f1245f = true;
    }

    @Override // android.view.View.OnAttachStateChangeListener
    public final void onViewDetachedFromWindow(View view) {
        this.f1245f = false;
        this.f1240a.removeCallbacks(this);
        this.f1243d.removeFrameCallback(this);
    }

    @Override // java.lang.Runnable
    public final void run() {
        PriorityQueue priorityQueue = this.f1241b;
        if (!priorityQueue.isEmpty() && this.f1242c && this.f1245f) {
            View view = this.f1240a;
            if (view.getWindowVisibility() == 0) {
                long nanos = TimeUnit.MILLISECONDS.toNanos(view.getDrawingTime());
                boolean z6 = System.nanoTime() > (((long) 2) * f1239k) + nanos;
                E3.p pVar = this.f1244e;
                pVar.f1167b = z6;
                pVar.f1168c = Math.max(this.f1246j, nanos) + f1239k;
                boolean zB = false;
                while (!priorityQueue.isEmpty() && !zB) {
                    if (pVar.f1167b) {
                        Trace.beginSection("compose:lazy:prefetch:idle_frame");
                        try {
                            zB = b();
                        } finally {
                            Trace.endSection();
                        }
                    } else {
                        zB = b();
                    }
                }
                if (zB) {
                    this.f1243d.postFrameCallback(this);
                } else {
                    this.f1242c = false;
                }
                W.a.B0("compose:lazy:prefetch:available_time_nanos", 0L);
                return;
            }
        }
        this.f1242c = false;
    }
}
