Rabbit-R1/android (non root)/java/sources/androidx/compose/ui/platform/AndroidUiFrameClock.java
2024-05-21 17:08:36 -04:00

136 lines
8.1 KiB
Java

package androidx.compose.ui.platform;
import android.view.Choreographer;
import androidx.compose.runtime.MonotonicFrameClock;
import kotlin.Metadata;
import kotlin.Result;
import kotlin.ResultKt;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.ContinuationInterceptor;
import kotlin.coroutines.CoroutineContext;
import kotlin.coroutines.intrinsics.IntrinsicsKt;
import kotlin.coroutines.jvm.internal.DebugProbesKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.Intrinsics;
import kotlinx.coroutines.CancellableContinuationImpl;
/* compiled from: AndroidUiFrameClock.android.kt */
@Metadata(d1 = {"\u0000&\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\u0010\t\n\u0002\b\u0002\b\u0007\u0018\u00002\u00020\u0001B\u000f\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004B\u0019\b\u0000\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006¢\u0006\u0002\u0010\u0007J+\u0010\n\u001a\u0002H\u000b\"\u0004\b\u0000\u0010\u000b2\u0012\u0010\f\u001a\u000e\u0012\u0004\u0012\u00020\u000e\u0012\u0004\u0012\u0002H\u000b0\rH\u0096@ø\u0001\u0000¢\u0006\u0002\u0010\u000fR\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\tR\u0010\u0010\u0005\u001a\u0004\u0018\u00010\u0006X\u0082\u0004¢\u0006\u0002\n\u0000\u0082\u0002\u0004\n\u0002\b\u0019¨\u0006\u0010"}, d2 = {"Landroidx/compose/ui/platform/AndroidUiFrameClock;", "Landroidx/compose/runtime/MonotonicFrameClock;", "choreographer", "Landroid/view/Choreographer;", "(Landroid/view/Choreographer;)V", "dispatcher", "Landroidx/compose/ui/platform/AndroidUiDispatcher;", "(Landroid/view/Choreographer;Landroidx/compose/ui/platform/AndroidUiDispatcher;)V", "getChoreographer", "()Landroid/view/Choreographer;", "withFrameNanos", "R", "onFrame", "Lkotlin/Function1;", "", "(Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "ui_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
/* loaded from: classes.dex */
public final class AndroidUiFrameClock implements MonotonicFrameClock {
public static final int $stable = 8;
private final Choreographer choreographer;
private final AndroidUiDispatcher dispatcher;
public final Choreographer getChoreographer() {
return this.choreographer;
}
public AndroidUiFrameClock(Choreographer choreographer, AndroidUiDispatcher androidUiDispatcher) {
Intrinsics.checkNotNullParameter(choreographer, "choreographer");
this.choreographer = choreographer;
this.dispatcher = androidUiDispatcher;
}
@Override // kotlin.coroutines.CoroutineContext.Element, kotlin.coroutines.CoroutineContext
public <R> R fold(R r, Function2<? super R, ? super CoroutineContext.Element, ? extends R> function2) {
return (R) MonotonicFrameClock.DefaultImpls.fold(this, r, function2);
}
@Override // kotlin.coroutines.CoroutineContext.Element, kotlin.coroutines.CoroutineContext
public <E extends CoroutineContext.Element> E get(CoroutineContext.Key<E> key) {
return (E) MonotonicFrameClock.DefaultImpls.get(this, key);
}
@Override // kotlin.coroutines.CoroutineContext.Element, kotlin.coroutines.CoroutineContext
public CoroutineContext minusKey(CoroutineContext.Key<?> key) {
return MonotonicFrameClock.DefaultImpls.minusKey(this, key);
}
@Override // kotlin.coroutines.CoroutineContext
public CoroutineContext plus(CoroutineContext coroutineContext) {
return MonotonicFrameClock.DefaultImpls.plus(this, coroutineContext);
}
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
public AndroidUiFrameClock(Choreographer choreographer) {
this(choreographer, null);
Intrinsics.checkNotNullParameter(choreographer, "choreographer");
}
@Override // androidx.compose.runtime.MonotonicFrameClock
public <R> Object withFrameNanos(final Function1<? super Long, ? extends R> function1, Continuation<? super R> continuation) {
final AndroidUiDispatcher androidUiDispatcher = this.dispatcher;
if (androidUiDispatcher == null) {
CoroutineContext.Element element = continuation.getContext().get(ContinuationInterceptor.INSTANCE);
androidUiDispatcher = element instanceof AndroidUiDispatcher ? (AndroidUiDispatcher) element : null;
}
CancellableContinuationImpl cancellableContinuationImpl = new CancellableContinuationImpl(IntrinsicsKt.intercepted(continuation), 1);
cancellableContinuationImpl.initCancellability();
final CancellableContinuationImpl cancellableContinuationImpl2 = cancellableContinuationImpl;
final Choreographer.FrameCallback frameCallback = new Choreographer.FrameCallback() { // from class: androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1
@Override // android.view.Choreographer.FrameCallback
public final void doFrame(long j) {
Object m5698constructorimpl;
Continuation continuation2 = cancellableContinuationImpl2;
Function1<Long, R> function12 = function1;
try {
Result.Companion companion = Result.INSTANCE;
m5698constructorimpl = Result.m5698constructorimpl(function12.invoke(Long.valueOf(j)));
} catch (Throwable th) {
Result.Companion companion2 = Result.INSTANCE;
m5698constructorimpl = Result.m5698constructorimpl(ResultKt.createFailure(th));
}
continuation2.resumeWith(m5698constructorimpl);
}
};
if (androidUiDispatcher != null && Intrinsics.areEqual(androidUiDispatcher.getChoreographer(), getChoreographer())) {
androidUiDispatcher.postFrameCallback$ui_release(frameCallback);
cancellableContinuationImpl2.invokeOnCancellation(new Function1<Throwable, Unit>() { // from class: androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$1
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
{
super(1);
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(Throwable th) {
invoke2(th);
return Unit.INSTANCE;
}
/* renamed from: invoke, reason: avoid collision after fix types in other method */
public final void invoke2(Throwable th) {
AndroidUiDispatcher.this.removeFrameCallback$ui_release(frameCallback);
}
});
} else {
getChoreographer().postFrameCallback(frameCallback);
cancellableContinuationImpl2.invokeOnCancellation(new Function1<Throwable, Unit>() { // from class: androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$2
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
{
super(1);
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(Throwable th) {
invoke2(th);
return Unit.INSTANCE;
}
/* renamed from: invoke, reason: avoid collision after fix types in other method */
public final void invoke2(Throwable th) {
AndroidUiFrameClock.this.getChoreographer().removeFrameCallback(frameCallback);
}
});
}
Object result = cancellableContinuationImpl.getResult();
if (result == IntrinsicsKt.getCOROUTINE_SUSPENDED()) {
DebugProbesKt.probeCoroutineSuspended(continuation);
}
return result;
}
}