Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64bab3e8 authored by George Mount's avatar George Mount
Browse files

[VRR] Add sysprop to allow disabling View VRR frame rate check

Bug: 343518413
Fixes: 335232645

Test: ran broken performance test
Test: ran existing tests with View VRR disabled
Change-Id: I59d110ae17ffd9f72e2a45f2a1af158e58379394
parent a71e4b4a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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.
+9 −6
Original line number Diff line number Diff line
@@ -201,6 +201,7 @@ import android.os.Trace;
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;
@@ -1198,6 +1199,7 @@ public final class ViewRootImpl implements ViewParent,
            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();
@@ -12853,13 +12855,13 @@ public final class ViewRootImpl implements ViewParent,
    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) {
@@ -12894,7 +12896,7 @@ public final class ViewRootImpl implements ViewParent,
     * @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);
        }
    }
@@ -12906,7 +12908,8 @@ public final class ViewRootImpl implements ViewParent,
     */
    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);
        }
@@ -13127,7 +13130,7 @@ public final class ViewRootImpl implements ViewParent,
    private boolean shouldEnableDvrr() {
        // uncomment this when we are ready for enabling dVRR
        if (sToolkitFrameRateViewEnablingReadOnlyFlagValue) {
        if (sEnableVrr && sToolkitFrameRateViewEnablingReadOnlyFlagValue) {
            return sToolkitSetFrameRateReadOnlyFlagValue && isFrameRatePowerSavingsBalanced();
        }
        return false;
+7 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
# 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 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.platform.test.annotations.LargeTest;
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;
@@ -101,6 +102,9 @@ public class ViewFrameRateTest {
    @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);
@@ -127,6 +131,9 @@ public class ViewFrameRateTest {
    @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(
@@ -155,6 +162,9 @@ public class ViewFrameRateTest {
            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;
@@ -175,6 +185,9 @@ public class ViewFrameRateTest {
            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(
@@ -201,6 +214,9 @@ public class ViewFrameRateTest {
            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;
@@ -222,6 +238,9 @@ public class ViewFrameRateTest {
    @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();
@@ -259,6 +278,9 @@ public class ViewFrameRateTest {
    @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();
@@ -295,6 +317,9 @@ public class ViewFrameRateTest {
    @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();
@@ -331,6 +356,9 @@ public class ViewFrameRateTest {
    @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();
@@ -367,6 +395,9 @@ public class ViewFrameRateTest {
    @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();
@@ -403,6 +434,9 @@ public class ViewFrameRateTest {
    @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();
@@ -427,6 +461,9 @@ public class ViewFrameRateTest {
            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(() -> {
@@ -447,6 +484,9 @@ public class ViewFrameRateTest {
            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);
@@ -480,6 +520,9 @@ public class ViewFrameRateTest {
    @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);
@@ -529,6 +572,9 @@ public class ViewFrameRateTest {
            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();

@@ -552,6 +598,9 @@ public class ViewFrameRateTest {
            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));
@@ -573,6 +622,9 @@ public class ViewFrameRateTest {
            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);
@@ -593,6 +645,9 @@ public class ViewFrameRateTest {
            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();
@@ -633,6 +688,9 @@ public class ViewFrameRateTest {
            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);
@@ -657,6 +715,9 @@ public class ViewFrameRateTest {
            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(() -> {
@@ -714,6 +775,9 @@ public class ViewFrameRateTest {
            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();

@@ -751,6 +815,9 @@ public class ViewFrameRateTest {
            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();

Loading