Merge "Separating refresh rate tracking to a separate class" into tm-dev

This commit is contained in:
Sunny Goyal
2022-03-03 23:00:29 +00:00
committed by Android (Google) Code Review
14 changed files with 98 additions and 56 deletions
@@ -16,9 +16,9 @@
package com.android.launcher3;
import static com.android.launcher3.Utilities.postAsyncCallback;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import static com.android.systemui.shared.recents.utilities.Utilities.postAtFrontOfQueueAsynchronously;
import android.animation.Animator;
@@ -44,7 +44,7 @@ import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVIT
import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_TRANSITIONS;
import static com.android.launcher3.model.data.ItemInfo.NO_MATCHING_ID;
import static com.android.launcher3.statehandlers.DepthController.DEPTH;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import static com.android.launcher3.views.FloatingIconView.SHAPE_PROGRESS_DURATION;
import static com.android.launcher3.views.FloatingIconView.getFloatingIconView;
import static com.android.quickstep.TaskViewUtils.findTaskViewToLaunch;
@@ -40,7 +40,7 @@ import static com.android.launcher3.states.StateAnimationConfig.SKIP_OVERVIEW;
import static com.android.launcher3.states.StateAnimationConfig.SKIP_SCRIM;
import static com.android.launcher3.touch.BothAxesSwipeDetector.DIRECTION_RIGHT;
import static com.android.launcher3.touch.BothAxesSwipeDetector.DIRECTION_UP;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import static com.android.quickstep.util.VibratorWrapper.OVERVIEW_HAPTIC;
import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_HORIZONTAL_OFFSET;
import static com.android.quickstep.views.RecentsView.CONTENT_ALPHA;
@@ -32,10 +32,10 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_OVERVIEW_GESTURE;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_QUICKSWITCH_LEFT;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_QUICKSWITCH_RIGHT;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.SystemUiController.UI_STATE_FULLSCREEN_TASK;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import static com.android.quickstep.GestureState.GestureEndTarget.HOME;
import static com.android.quickstep.GestureState.GestureEndTarget.LAST_TASK;
import static com.android.quickstep.GestureState.GestureEndTarget.NEW_TASK;
@@ -16,7 +16,7 @@
package com.android.quickstep.interaction;
import static com.android.launcher3.anim.Interpolators.ACCEL;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import static com.android.launcher3.views.FloatingIconView.SHAPE_PROGRESS_DURATION;
import static com.android.quickstep.AbsSwipeUpHandler.MAX_SWIPE_DURATION;
import static com.android.quickstep.interaction.TutorialController.TutorialType.HOME_NAVIGATION_COMPLETE;
@@ -15,7 +15,7 @@
*/
package com.android.launcher3;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
@@ -19,7 +19,7 @@ import static com.android.launcher3.Utilities.boundToRange;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.anim.Interpolators.clampToProgress;
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
@@ -25,7 +25,7 @@ import android.util.FloatProperty;
import androidx.annotation.FloatRange;
import androidx.dynamicanimation.animation.SpringForce;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.window.RefreshRateTracker;
/**
* Utility class to build an object animator which follows the same path as a spring animation for
@@ -134,7 +134,7 @@ public class SpringAnimationBuilder {
}
public SpringAnimationBuilder computeParams() {
int singleFrameMs = DisplayController.getSingleFrameMs(mContext);
int singleFrameMs = RefreshRateTracker.getSingleFrameMs(mContext);
double naturalFreq = Math.sqrt(mStiffness);
double dampedFreq = naturalFreq * Math.sqrt(1 - mDampingRatio * mDampingRatio);
+1 -1
View File
@@ -24,7 +24,7 @@ import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustom
import static com.android.launcher3.config.FeatureFlags.ALWAYS_USE_HARDWARE_OPTIMIZATION_FOR_FOLDER_ANIMATIONS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_LABEL_UPDATED;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -26,7 +26,7 @@ import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME;
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_UNKNOWN_SWIPEDOWN;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_UNKNOWN_SWIPEUP;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator;
@@ -20,7 +20,6 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static com.android.launcher3.Utilities.dpiFromPx;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.WindowManagerCompat.MIN_TABLET_WIDTH;
import static java.util.Collections.emptyMap;
@@ -34,7 +33,6 @@ import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
import android.os.Build;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -44,7 +42,6 @@ import android.view.Display;
import androidx.annotation.AnyThread;
import androidx.annotation.UiThread;
import androidx.annotation.WorkerThread;
import com.android.launcher3.Utilities;
import com.android.launcher3.uioverrides.ApiWrapper;
@@ -58,7 +55,7 @@ import java.util.Set;
* Utility class to cache properties of default display to avoid a system RPC on every call.
*/
@SuppressLint("NewApi")
public class DisplayController implements DisplayListener, ComponentCallbacks, SafeCloseable {
public class DisplayController implements ComponentCallbacks, SafeCloseable {
private static final String TAG = "DisplayController";
@@ -102,7 +99,6 @@ public class DisplayController implements DisplayListener, ComponentCallbacks, S
}
mInfo = new Info(getDisplayInfoContext(display), display,
getInternalDisplays(mDM), emptyMap());
mDM.registerDisplayListener(this, UI_HELPER_EXECUTOR.getHandler());
}
private static ArrayMap<String, PortraitSize> getInternalDisplays(
@@ -128,35 +124,6 @@ public class DisplayController implements DisplayListener, ComponentCallbacks, S
} else {
// TODO: unregister broadcast receiver
}
mDM.unregisterDisplayListener(this);
}
@Override
public final void onDisplayAdded(int displayId) { }
@Override
public final void onDisplayRemoved(int displayId) { }
@WorkerThread
@Override
public final void onDisplayChanged(int displayId) {
if (displayId != DEFAULT_DISPLAY) {
return;
}
Display display = mDM.getDisplay(DEFAULT_DISPLAY);
if (display == null) {
return;
}
if (Utilities.ATLEAST_S) {
// Only update refresh rate. Everything else comes from component callbacks
mInfo.mSingleFrameMs = getSingleFrameMs(display);
return;
}
handleInfoChange(display);
}
public static int getSingleFrameMs(Context context) {
return INSTANCE.get(context).getInfo().mSingleFrameMs;
}
/**
@@ -287,8 +254,6 @@ public class DisplayController implements DisplayListener, ComponentCallbacks, S
public static class Info {
private int mSingleFrameMs;
// Configuration properties
public final int rotation;
public final float fontScale;
@@ -318,7 +283,6 @@ public class DisplayController implements DisplayListener, ComponentCallbacks, S
densityDpi = config.densityDpi;
mScreenSizeDp = new PortraitSize(config.screenHeightDp, config.screenWidthDp);
mSingleFrameMs = getSingleFrameMs(display);
currentSize = new Point();
display.getRealSize(currentSize);
@@ -400,9 +364,4 @@ public class DisplayController implements DisplayListener, ComponentCallbacks, S
return Objects.hash(width, height);
}
}
private static int getSingleFrameMs(Display display) {
float refreshRate = display.getRefreshRate();
return refreshRate > 0 ? (int) (1000 / refreshRate) : 16;
}
}
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.util.window;
import static android.view.Display.DEFAULT_DISPLAY;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
import android.view.Display;
import androidx.annotation.WorkerThread;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.SafeCloseable;
/**
* Utility class to track refresh rate of the current device
*/
public class RefreshRateTracker implements DisplayListener, SafeCloseable {
private static final MainThreadInitializedObject<RefreshRateTracker> INSTANCE =
new MainThreadInitializedObject<>(RefreshRateTracker::new);
private int mSingleFrameMs = 1;
private final DisplayManager mDM;
private RefreshRateTracker(Context context) {
mDM = context.getSystemService(DisplayManager.class);
updateSingleFrameMs();
mDM.registerDisplayListener(this, UI_HELPER_EXECUTOR.getHandler());
}
/**
* Returns the single frame time in ms
*/
public static int getSingleFrameMs(Context context) {
return INSTANCE.get(context).mSingleFrameMs;
}
@Override
public final void onDisplayAdded(int displayId) { }
@Override
public final void onDisplayRemoved(int displayId) { }
@WorkerThread
@Override
public final void onDisplayChanged(int displayId) {
if (displayId == DEFAULT_DISPLAY) {
updateSingleFrameMs();
}
}
private void updateSingleFrameMs() {
Display display = mDM.getDisplay(DEFAULT_DISPLAY);
if (display != null) {
float refreshRate = display.getRefreshRate();
mSingleFrameMs = refreshRate > 0 ? (int) (1000 / refreshRate) : 16;
}
}
@Override
public void close() {
mDM.unregisterDisplayListener(this);
}
}
@@ -20,7 +20,7 @@ import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_UP;
import static com.android.launcher3.util.DisplayController.getSingleFrameMs;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
import android.annotation.TargetApi;
import android.app.WallpaperManager;
@@ -40,8 +40,8 @@ import com.android.launcher3.GestureNavContract;
import com.android.launcher3.Insettable;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.window.RefreshRateTracker;
/**
* Similar to {@link FloatingIconView} but displays a surface with the targetIcon. It then passes
@@ -97,7 +97,7 @@ public class FloatingSurfaceView extends AbstractFloatingView implements
// Remove after some time, to avoid flickering
Executors.MAIN_EXECUTOR.getHandler().postDelayed(mRemoveViewRunnable,
DisplayController.getSingleFrameMs(mLauncher));
RefreshRateTracker.getSingleFrameMs(mLauncher));
}
private void removeViewFromParent() {