mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-18 03:47:18 +01:00
233 lines
13 KiB
Java
233 lines
13 KiB
Java
package androidx.compose.ui.platform;
|
|
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.view.Choreographer;
|
|
import androidx.compose.runtime.MonotonicFrameClock;
|
|
import androidx.compose.runtime.internal.StabilityInferred;
|
|
import androidx.core.os.HandlerCompat;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import kotlin.Lazy;
|
|
import kotlin.LazyKt;
|
|
import kotlin.Metadata;
|
|
import kotlin.Unit;
|
|
import kotlin.collections.ArrayDeque;
|
|
import kotlin.coroutines.CoroutineContext;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.SourceDebugExtension;
|
|
import kotlinx.coroutines.BuildersKt;
|
|
import kotlinx.coroutines.CoroutineDispatcher;
|
|
import kotlinx.coroutines.Dispatchers;
|
|
import org.aspectj.lang.JoinPoint;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import rx.Single$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@StabilityInferred(parameters = 0)
|
|
@Metadata(d1 = {"\u0000c\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010!\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\t\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0003*\u0001\u0017\b\u0007\u0018\u0000 ,2\u00020\u0001:\u0001,B\u0019\b\u0002\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0004\b\u0006\u0010\u0007J\n\u0010\u0019\u001a\u0004\u0018\u00010\u000eH\u0002J\b\u0010\u001a\u001a\u00020\u001bH\u0002J\u0010\u0010\u001c\u001a\u00020\u001b2\u0006\u0010\u001d\u001a\u00020\u001eH\u0002J\u0015\u0010\u001f\u001a\u00020\u001b2\u0006\u0010 \u001a\u00020\u0011H\u0000¢\u0006\u0002\b!J\u0015\u0010\"\u001a\u00020\u001b2\u0006\u0010 \u001a\u00020\u0011H\u0000¢\u0006\u0002\b#J\u0018\u0010(\u001a\u00020\u001b2\u0006\u0010)\u001a\u00020*2\u0006\u0010+\u001a\u00020\u000eH\u0016R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\tR\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\u000bX\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\f\u001a\b\u0012\u0004\u0012\u00020\u000e0\rX\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u000f\u001a\b\u0012\u0004\u0012\u00020\u00110\u0010X\u0082\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\u0012\u001a\b\u0012\u0004\u0012\u00020\u00110\u0010X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0013\u001a\u00020\u0014X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0015\u001a\u00020\u0014X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0016\u001a\u00020\u0017X\u0082\u0004¢\u0006\u0004\n\u0002\u0010\u0018R\u0011\u0010$\u001a\u00020%¢\u0006\b\n\u0000\u001a\u0004\b&\u0010'¨\u0006-"}, d2 = {"Landroidx/compose/ui/platform/AndroidUiDispatcher;", "Lkotlinx/coroutines/CoroutineDispatcher;", "choreographer", "Landroid/view/Choreographer;", "handler", "Landroid/os/Handler;", "<init>", "(Landroid/view/Choreographer;Landroid/os/Handler;)V", "getChoreographer", "()Landroid/view/Choreographer;", JoinPoint.SYNCHRONIZATION_LOCK, "", "toRunTrampolined", "Lkotlin/collections/ArrayDeque;", "Ljava/lang/Runnable;", "toRunOnFrame", "", "Landroid/view/Choreographer$FrameCallback;", "spareToRunOnFrame", "scheduledTrampolineDispatch", "", "scheduledFrameDispatch", "dispatchCallback", "androidx/compose/ui/platform/AndroidUiDispatcher$dispatchCallback$1", "Landroidx/compose/ui/platform/AndroidUiDispatcher$dispatchCallback$1;", "nextTask", "performTrampolineDispatch", "", "performFrameDispatch", "frameTimeNanos", "", "postFrameCallback", "callback", "postFrameCallback$ui_release", "removeFrameCallback", "removeFrameCallback$ui_release", "frameClock", "Landroidx/compose/runtime/MonotonicFrameClock;", "getFrameClock", "()Landroidx/compose/runtime/MonotonicFrameClock;", "dispatch", "context", "Lkotlin/coroutines/CoroutineContext;", "block", "Companion", "ui_release"}, k = 1, mv = {2, 0, 0}, xi = 48)
|
|
@SourceDebugExtension({"SMAP\nAndroidUiDispatcher.android.kt\nKotlin\n*S Kotlin\n*F\n+ 1 AndroidUiDispatcher.android.kt\nandroidx/compose/ui/platform/AndroidUiDispatcher\n+ 2 Synchronization.android.kt\nandroidx/compose/ui/platform/Synchronization_androidKt\n*L\n1#1,193:1\n32#2:194\n32#2:195\n32#2:196\n32#2:197\n32#2:198\n32#2:199\n*S KotlinDebug\n*F\n+ 1 AndroidUiDispatcher.android.kt\nandroidx/compose/ui/platform/AndroidUiDispatcher\n*L\n73#1:194\n87#1:195\n98#1:196\n114#1:197\n124#1:198\n134#1:199\n*E\n"})
|
|
/* loaded from: classes13.dex */
|
|
public final class AndroidUiDispatcher extends CoroutineDispatcher {
|
|
|
|
@NotNull
|
|
private final Choreographer choreographer;
|
|
|
|
@NotNull
|
|
private final AndroidUiDispatcher$dispatchCallback$1 dispatchCallback;
|
|
|
|
@NotNull
|
|
private final MonotonicFrameClock frameClock;
|
|
|
|
@NotNull
|
|
private final Handler handler;
|
|
|
|
@NotNull
|
|
private final Object lock;
|
|
private boolean scheduledFrameDispatch;
|
|
private boolean scheduledTrampolineDispatch;
|
|
|
|
@NotNull
|
|
private List<Choreographer.FrameCallback> spareToRunOnFrame;
|
|
|
|
@NotNull
|
|
private List<Choreographer.FrameCallback> toRunOnFrame;
|
|
|
|
@NotNull
|
|
private final ArrayDeque<Runnable> toRunTrampolined;
|
|
|
|
/* renamed from: Companion, reason: from kotlin metadata */
|
|
@NotNull
|
|
public static final Companion INSTANCE = new Companion(null);
|
|
public static final int $stable = 8;
|
|
|
|
@NotNull
|
|
private static final Lazy<CoroutineContext> Main$delegate = LazyKt.lazy(new Function0<CoroutineContext>() { // from class: androidx.compose.ui.platform.AndroidUiDispatcher$Companion$Main$2
|
|
@Override // kotlin.jvm.functions.Function0
|
|
public final CoroutineContext invoke() {
|
|
boolean isMainThread;
|
|
isMainThread = AndroidUiDispatcher_androidKt.isMainThread();
|
|
AndroidUiDispatcher androidUiDispatcher = new AndroidUiDispatcher(isMainThread ? Choreographer.getInstance() : (Choreographer) BuildersKt.runBlocking(Dispatchers.getMain(), new AndroidUiDispatcher$Companion$Main$2$dispatcher$1(null)), HandlerCompat.createAsync(Looper.getMainLooper()), null);
|
|
return androidUiDispatcher.plus(androidUiDispatcher.getFrameClock());
|
|
}
|
|
});
|
|
|
|
@NotNull
|
|
private static final ThreadLocal<CoroutineContext> currentThread = new ThreadLocal<CoroutineContext>() { // from class: androidx.compose.ui.platform.AndroidUiDispatcher$Companion$currentThread$1
|
|
@Override // java.lang.ThreadLocal
|
|
public CoroutineContext initialValue() {
|
|
Choreographer choreographer = Choreographer.getInstance();
|
|
Looper myLooper = Looper.myLooper();
|
|
if (myLooper != null) {
|
|
AndroidUiDispatcher androidUiDispatcher = new AndroidUiDispatcher(choreographer, HandlerCompat.createAsync(myLooper), null);
|
|
return androidUiDispatcher.plus(androidUiDispatcher.getFrameClock());
|
|
}
|
|
Single$$ExternalSyntheticBUOutline0.m$2("no Looper on this thread");
|
|
return null;
|
|
}
|
|
};
|
|
|
|
private AndroidUiDispatcher(Choreographer choreographer, Handler handler) {
|
|
this.choreographer = choreographer;
|
|
this.handler = handler;
|
|
this.lock = new Object();
|
|
this.toRunTrampolined = new ArrayDeque<>();
|
|
this.toRunOnFrame = new ArrayList();
|
|
this.spareToRunOnFrame = new ArrayList();
|
|
this.dispatchCallback = new AndroidUiDispatcher$dispatchCallback$1(this);
|
|
this.frameClock = new AndroidUiFrameClock(choreographer, this);
|
|
}
|
|
|
|
private final Runnable nextTask() {
|
|
Runnable removeFirstOrNull;
|
|
synchronized (this.lock) {
|
|
removeFirstOrNull = this.toRunTrampolined.removeFirstOrNull();
|
|
}
|
|
return removeFirstOrNull;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final void performFrameDispatch(long frameTimeNanos) {
|
|
synchronized (this.lock) {
|
|
if (this.scheduledFrameDispatch) {
|
|
this.scheduledFrameDispatch = false;
|
|
List<Choreographer.FrameCallback> list = this.toRunOnFrame;
|
|
this.toRunOnFrame = this.spareToRunOnFrame;
|
|
this.spareToRunOnFrame = list;
|
|
int size = list.size();
|
|
for (int i = 0; i < size; i++) {
|
|
list.get(i).doFrame(frameTimeNanos);
|
|
}
|
|
list.clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final void performTrampolineDispatch() {
|
|
boolean z;
|
|
do {
|
|
Runnable nextTask = nextTask();
|
|
while (nextTask != null) {
|
|
nextTask.run();
|
|
nextTask = nextTask();
|
|
}
|
|
synchronized (this.lock) {
|
|
if (this.toRunTrampolined.isEmpty()) {
|
|
z = false;
|
|
this.scheduledTrampolineDispatch = false;
|
|
} else {
|
|
z = true;
|
|
}
|
|
}
|
|
} while (z);
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CoroutineDispatcher
|
|
/* renamed from: dispatch */
|
|
public void mo26869dispatch(@NotNull CoroutineContext context, @NotNull Runnable block) {
|
|
synchronized (this.lock) {
|
|
try {
|
|
this.toRunTrampolined.addLast(block);
|
|
if (!this.scheduledTrampolineDispatch) {
|
|
this.scheduledTrampolineDispatch = true;
|
|
this.handler.post(this.dispatchCallback);
|
|
if (!this.scheduledFrameDispatch) {
|
|
this.scheduledFrameDispatch = true;
|
|
this.choreographer.postFrameCallback(this.dispatchCallback);
|
|
}
|
|
}
|
|
Unit unit = Unit.INSTANCE;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
@NotNull
|
|
public final Choreographer getChoreographer() {
|
|
return this.choreographer;
|
|
}
|
|
|
|
@NotNull
|
|
public final MonotonicFrameClock getFrameClock() {
|
|
return this.frameClock;
|
|
}
|
|
|
|
public final void postFrameCallback$ui_release(@NotNull Choreographer.FrameCallback callback) {
|
|
synchronized (this.lock) {
|
|
try {
|
|
this.toRunOnFrame.add(callback);
|
|
if (!this.scheduledFrameDispatch) {
|
|
this.scheduledFrameDispatch = true;
|
|
this.choreographer.postFrameCallback(this.dispatchCallback);
|
|
}
|
|
Unit unit = Unit.INSTANCE;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void removeFrameCallback$ui_release(@NotNull Choreographer.FrameCallback callback) {
|
|
synchronized (this.lock) {
|
|
this.toRunOnFrame.remove(callback);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@Metadata(d1 = {"\u0000\u001c\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\u0002\u0010\u0003R\u001b\u0010\u0004\u001a\u00020\u00058FX\u0086\u0084\u0002¢\u0006\f\n\u0004\b\b\u0010\t\u001a\u0004\b\u0006\u0010\u0007R\u0014\u0010\n\u001a\b\u0012\u0004\u0012\u00020\u00050\u000bX\u0082\u0004¢\u0006\u0002\n\u0000R\u0011\u0010\f\u001a\u00020\u00058F¢\u0006\u0006\u001a\u0004\b\r\u0010\u0007¨\u0006\u000e"}, d2 = {"Landroidx/compose/ui/platform/AndroidUiDispatcher$Companion;", "", "<init>", "()V", "Main", "Lkotlin/coroutines/CoroutineContext;", "getMain", "()Lkotlin/coroutines/CoroutineContext;", "Main$delegate", "Lkotlin/Lazy;", "currentThread", "Ljava/lang/ThreadLocal;", "CurrentThread", "getCurrentThread", "ui_release"}, k = 1, mv = {2, 0, 0}, xi = 48)
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
@NotNull
|
|
public final CoroutineContext getCurrentThread() {
|
|
boolean isMainThread;
|
|
isMainThread = AndroidUiDispatcher_androidKt.isMainThread();
|
|
if (isMainThread) {
|
|
return getMain();
|
|
}
|
|
CoroutineContext coroutineContext = (CoroutineContext) AndroidUiDispatcher.currentThread.get();
|
|
if (coroutineContext != null) {
|
|
return coroutineContext;
|
|
}
|
|
Single$$ExternalSyntheticBUOutline0.m$2("no AndroidUiDispatcher for this thread");
|
|
return null;
|
|
}
|
|
|
|
@NotNull
|
|
public final CoroutineContext getMain() {
|
|
return (CoroutineContext) AndroidUiDispatcher.Main$delegate.getValue();
|
|
}
|
|
|
|
private Companion() {
|
|
}
|
|
}
|
|
|
|
public /* synthetic */ AndroidUiDispatcher(Choreographer choreographer, Handler handler, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(choreographer, handler);
|
|
}
|
|
}
|