Skip to content

Commit

Permalink
[VRR] Add sysprop to allow disabling View VRR frame rate check
Browse files Browse the repository at this point in the history
Bug: 343518413
Fixes: 335232645

Test: ran broken performance test
Test: ran existing tests with View VRR disabled
Change-Id: I59d110ae17ffd9f72e2a45f2a1af158e58379394
  • Loading branch information
George Mount committed Jun 7, 2024
1 parent a71e4b4 commit 64bab3e
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 6 deletions.
1 change: 1 addition & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ java_defaults {
"android.hardware.common.fmq-V1-java",
"bouncycastle-repackaged-unbundled",
"com.android.sysprop.foldlockbehavior",
"com.android.sysprop.view",
"framework-internal-utils",
// If MimeMap ever becomes its own APEX, then this dependency would need to be removed
// in favor of an API stubs dependency in java_library "framework" below.
Expand Down
15 changes: 9 additions & 6 deletions core/java/android/view/ViewRootImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
import android.os.UserHandle;
import android.provider.Settings;
import android.sysprop.DisplayProperties;
import android.sysprop.ViewProperties;
import android.text.TextUtils;
import android.util.AndroidRuntimeException;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -1198,6 +1199,7 @@ public void onTransactionHang(String reason) {
Flags.enableInvalidateCheckThread();
private static boolean sSurfaceFlingerBugfixFlagValue =
com.android.graphics.surfaceflinger.flags.Flags.vrrBugfix24q4();
private static final boolean sEnableVrr = ViewProperties.vrr_enabled().orElse(true);

static {
sToolkitSetFrameRateReadOnlyFlagValue = toolkitSetFrameRateReadOnly();
Expand Down Expand Up @@ -12853,13 +12855,13 @@ private void setPreferredFrameRate(float preferredFrameRate) {

private boolean shouldSetFrameRateCategory() {
// use toolkitSetFrameRate flag to gate the change
return mSurface.isValid() && shouldEnableDvrr();
return shouldEnableDvrr() && mSurface.isValid() && shouldEnableDvrr();
}

private boolean shouldSetFrameRate() {
// use toolkitSetFrameRate flag to gate the change
return mSurface.isValid() && mPreferredFrameRate >= 0
&& shouldEnableDvrr() && !mIsFrameRateConflicted;
return shouldEnableDvrr() && mSurface.isValid() && mPreferredFrameRate >= 0
&& !mIsFrameRateConflicted;
}

private boolean shouldTouchBoost(int motionEventAction, int windowType) {
Expand Down Expand Up @@ -12894,7 +12896,7 @@ public void votePreferredFrameRateCategory(int frameRateCategory, int reason, Vi
* @param view The View with the ThreadedRenderer animation that started.
*/
public void addThreadedRendererView(View view) {
if (!mThreadedRendererViews.contains(view)) {
if (shouldEnableDvrr() && !mThreadedRendererViews.contains(view)) {
mThreadedRendererViews.add(view);
}
}
Expand All @@ -12906,7 +12908,8 @@ public void addThreadedRendererView(View view) {
*/
public void removeThreadedRendererView(View view) {
mThreadedRendererViews.remove(view);
if (!mInvalidationIdleMessagePosted && sSurfaceFlingerBugfixFlagValue) {
if (shouldEnableDvrr()
&& !mInvalidationIdleMessagePosted && sSurfaceFlingerBugfixFlagValue) {
mInvalidationIdleMessagePosted = true;
mHandler.sendEmptyMessageDelayed(MSG_CHECK_INVALIDATION_IDLE, IDLE_TIME_MILLIS);
}
Expand Down Expand Up @@ -13127,7 +13130,7 @@ public boolean isFrameRateConflicted() {

private boolean shouldEnableDvrr() {
// uncomment this when we are ready for enabling dVRR
if (sToolkitFrameRateViewEnablingReadOnlyFlagValue) {
if (sEnableVrr && sToolkitFrameRateViewEnablingReadOnlyFlagValue) {
return sToolkitSetFrameRateReadOnlyFlagValue && isFrameRatePowerSavingsBalanced();
}
return false;
Expand Down
7 changes: 7 additions & 0 deletions core/sysprop/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ sysprop_library {
property_owner: "Platform",
api_packages: ["android.sysprop"],
}

sysprop_library {
name: "com.android.sysprop.view",
srcs: ["ViewProperties.sysprop"],
property_owner: "Platform",
api_packages: ["android.sysprop"],
}
29 changes: 29 additions & 0 deletions core/sysprop/ViewProperties.sysprop
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (C) 2024 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.

module: "android.sysprop.ViewProperties"
owner: Platform

# On low-end devices, the cost of calculating frame rate can
# have noticeable overhead. These devices don't benefit from
# reduced frame rate as much as they benefit from reduced
# work. By setting this to false, the device won't do any
# VRR frame rate calculation for Views.
prop {
api_name: "vrr_enabled"
type: Boolean
prop_name: "ro.view.vrr.enabled"
scope: Internal
access: Readonly
}
67 changes: 67 additions & 0 deletions core/tests/coretests/src/android/view/ViewFrameRateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.sysprop.ViewProperties;
import android.util.DisplayMetrics;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
Expand Down Expand Up @@ -101,6 +102,9 @@ public void setUp() throws Throwable {
@RequiresFlagsEnabled({FLAG_VIEW_VELOCITY_API,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void frameRateChangesWhenContentMoves() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
waitForFrameRateCategoryToSettle();
mActivityRule.runOnUiThread(() -> {
mMovingView.offsetLeftAndRight(100);
Expand All @@ -127,6 +131,9 @@ public void firstFrameNoMovement() {
@Test
@RequiresFlagsEnabled(FLAG_VIEW_VELOCITY_API)
public void frameBoostDisable() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mActivityRule.runOnUiThread(() -> {
long now = SystemClock.uptimeMillis();
MotionEvent down = MotionEvent.obtain(
Expand Down Expand Up @@ -155,6 +162,9 @@ public void frameBoostDisable() throws Throwable {
FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void lowVelocity60() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mActivityRule.runOnUiThread(() -> {
ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
Expand All @@ -175,6 +185,9 @@ public void lowVelocity60() throws Throwable {
FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void velocityWithChildMovement() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
FrameLayout frameLayout = new FrameLayout(mActivity);
mActivityRule.runOnUiThread(() -> {
ViewGroup.LayoutParams fullSize = new ViewGroup.LayoutParams(
Expand All @@ -201,6 +214,9 @@ public void velocityWithChildMovement() throws Throwable {
FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void highVelocity120() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mActivityRule.runOnUiThread(() -> {
ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
Expand All @@ -222,6 +238,9 @@ public void highVelocity120() throws Throwable {
@RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void noVelocityUsesCategorySmall() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
final CountDownLatch drawLatch1 = new CountDownLatch(1);
mActivityRule.runOnUiThread(() -> {
DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
Expand Down Expand Up @@ -259,6 +278,9 @@ public void noVelocityUsesCategorySmall() throws Throwable {
@RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void noVelocityUsesCategoryNarrowWidth() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
final CountDownLatch drawLatch1 = new CountDownLatch(1);
mActivityRule.runOnUiThread(() -> {
DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
Expand Down Expand Up @@ -295,6 +317,9 @@ public void noVelocityUsesCategoryNarrowWidth() throws Throwable {
@RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void noVelocityUsesCategoryNarrowHeight() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
final CountDownLatch drawLatch1 = new CountDownLatch(1);
mActivityRule.runOnUiThread(() -> {
DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
Expand Down Expand Up @@ -331,6 +356,9 @@ public void noVelocityUsesCategoryNarrowHeight() throws Throwable {
@RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void noVelocityUsesCategoryLargeWidth() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
final CountDownLatch drawLatch1 = new CountDownLatch(1);
mActivityRule.runOnUiThread(() -> {
DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
Expand Down Expand Up @@ -367,6 +395,9 @@ public void noVelocityUsesCategoryLargeWidth() throws Throwable {
@RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void noVelocityUsesCategoryLargeHeight() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
final CountDownLatch drawLatch1 = new CountDownLatch(1);
mActivityRule.runOnUiThread(() -> {
DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
Expand Down Expand Up @@ -403,6 +434,9 @@ public void noVelocityUsesCategoryLargeHeight() throws Throwable {
@RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void defaultNormal() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mActivityRule.runOnUiThread(() -> {
View parent = (View) mMovingView.getParent();
ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
Expand All @@ -427,6 +461,9 @@ public void defaultNormal() throws Throwable {
FLAG_TOOLKIT_FRAME_RATE_VELOCITY_MAPPING_READ_ONLY
})
public void frameRateAndCategory() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mMovingView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE);
waitForFrameRateCategoryToSettle();
mActivityRule.runOnUiThread(() -> {
Expand All @@ -447,6 +484,9 @@ public void frameRateAndCategory() throws Throwable {
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY
})
public void willNotDrawUsesCategory() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mActivityRule.runOnUiThread(() -> {
mMovingView.setWillNotDraw(true);
mMovingView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_LOW);
Expand Down Expand Up @@ -480,6 +520,9 @@ public void willNotDrawUsesCategory() throws Throwable {
@RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY,
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY})
public void intermittentDoubleInvalidate() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
View parent = (View) mMovingView.getParent();
mActivityRule.runOnUiThread(() -> {
parent.setWillNotDraw(false);
Expand Down Expand Up @@ -529,6 +572,9 @@ public void intermittentDoubleInvalidate() throws Throwable {
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY
})
public void sameFrameMotion() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mMovingView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE);
waitForFrameRateCategoryToSettle();

Expand All @@ -552,6 +598,9 @@ public void sameFrameMotion() throws Throwable {
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY
})
public void frameRateReset() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mMovingView.setRequestedFrameRate(120f);
waitForFrameRateCategoryToSettle();
mActivityRule.runOnUiThread(() -> mMovingView.setVisibility(View.INVISIBLE));
Expand All @@ -573,6 +622,9 @@ public void frameRateReset() throws Throwable {
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY
})
public void frameRateResetWithInvalidations() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mMovingView.setRequestedFrameRate(120f);
waitForFrameRateCategoryToSettle();
mMovingView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_NORMAL);
Expand All @@ -593,6 +645,9 @@ public void frameRateResetWithInvalidations() throws Throwable {
FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY
})
public void testQuickTouchBoost() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mActivityRule.runOnUiThread(() -> {
mMovingView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_LOW);
ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
Expand Down Expand Up @@ -633,6 +688,9 @@ public void testQuickTouchBoost() throws Throwable {
com.android.graphics.surfaceflinger.flags.Flags.FLAG_VRR_BUGFIX_24Q4
})
public void idleDetected() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
waitForFrameRateCategoryToSettle();
mActivityRule.runOnUiThread(() -> {
mMovingView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_HIGH);
Expand All @@ -657,6 +715,9 @@ public void idleDetected() throws Throwable {
com.android.graphics.surfaceflinger.flags.Flags.FLAG_VRR_BUGFIX_24Q4
})
public void vectorDrawableFrameRate() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
final ProgressBar[] progressBars = new ProgressBar[3];
final ViewGroup[] parents = new ViewGroup[1];
mActivityRule.runOnUiThread(() -> {
Expand Down Expand Up @@ -714,6 +775,9 @@ public void vectorDrawableFrameRate() throws Throwable {
com.android.graphics.surfaceflinger.flags.Flags.FLAG_VRR_BUGFIX_24Q4
})
public void renderNodeAnimatorFrameRateCanceled() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mMovingView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE);
waitForFrameRateCategoryToSettle();

Expand Down Expand Up @@ -751,6 +815,9 @@ public void renderNodeAnimatorFrameRateCanceled() throws Throwable {
com.android.graphics.surfaceflinger.flags.Flags.FLAG_VRR_BUGFIX_24Q4
})
public void renderNodeAnimatorFrameRateRemoved() throws Throwable {
if (!ViewProperties.vrr_enabled().orElse(true)) {
return;
}
mMovingView.setRequestedFrameRate(View.REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE);
waitForFrameRateCategoryToSettle();

Expand Down
Loading

0 comments on commit 64bab3e

Please sign in to comment.