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

Commit d47bc8b8 authored by George Mount's avatar George Mount Committed by Android (Google) Code Review
Browse files

Merge "Feature flag to change back to 7% small area." into main

parents 632bfaeb 6fe15567
Loading
Loading
Loading
Loading
+38 −27
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import static android.view.flags.Flags.enableUseMeasureCacheDuringForceLayout;
import static android.view.flags.Flags.sensitiveContentAppProtection;
import static android.view.flags.Flags.toolkitFrameRateBySizeReadOnly;
import static android.view.flags.Flags.toolkitFrameRateDefaultNormalReadOnly;
import static android.view.flags.Flags.toolkitFrameRateSmallUsesPercentReadOnly;
import static android.view.flags.Flags.toolkitMetricsForFrameRateDecision;
import static android.view.flags.Flags.toolkitSetFrameRateReadOnly;
import static android.view.flags.Flags.viewVelocityApi;
@@ -2436,6 +2437,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    private static final boolean sToolkitFrameRateBySizeReadOnlyFlagValue =
            toolkitFrameRateBySizeReadOnly();
    private static final boolean sToolkitFrameRateSmallUsesPercentReadOnlyFlagValue =
            toolkitFrameRateSmallUsesPercentReadOnly();
    // Used to set frame rate compatibility.
    @Surface.FrameRateCompatibility int mFrameRateCompatibility =
            FRAME_RATE_COMPATIBILITY_FIXED_SOURCE;
@@ -5725,6 +5729,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private static final float FRAME_RATE_NARROW_SIZE_DP = 10f;
    /**
     * A threshold value to determine the frame rate category of the View based on the size.
     */
    private static final float FRAME_RATE_SIZE_PERCENTAGE_THRESHOLD = 0.07f;
    private static final int INFREQUENT_UPDATE_INTERVAL_MILLIS = 100;
    private static final int INFREQUENT_UPDATE_COUNTS = 2;
@@ -25500,11 +25509,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    private void sizeChange(int newWidth, int newHeight, int oldWidth, int oldHeight) {
        if (mAttachInfo != null) {
            boolean isSmall;
            if (sToolkitFrameRateSmallUsesPercentReadOnlyFlagValue) {
                int size = newWidth * newHeight;
                float percent = size / mAttachInfo.mDisplayPixelCount;
                isSmall = percent <= FRAME_RATE_SIZE_PERCENTAGE_THRESHOLD;
            } else {
                float density = mAttachInfo.mDensity;
                int narrowSize = (int) (density * FRAME_RATE_NARROW_SIZE_DP);
                int smallSize = (int) (density * FRAME_RATE_SQUARE_SMALL_SIZE_DP);
            if (newWidth <= narrowSize || newHeight <= narrowSize
                    || (newWidth <= smallSize && newHeight <= smallSize)) {
                isSmall = newWidth <= narrowSize || newHeight <= narrowSize
                        || (newWidth <= smallSize && newHeight <= smallSize);
            }
            if (isSmall) {
                int category = sToolkitFrameRateBySizeReadOnlyFlagValue
                        ? FRAME_RATE_CATEGORY_LOW : FRAME_RATE_CATEGORY_NORMAL;
                mSizeBasedFrameRateCategoryAndReason = category | FRAME_RATE_CATEGORY_REASON_SMALL;
@@ -32090,6 +32107,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         */
        final float mDensity;
        /**
         * The number of pixels in the display (width * height).
         */
        final float mDisplayPixelCount;
        /**
         * Creates a new set of attachment information with the specified
         * events handler and thread.
@@ -32107,7 +32129,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            mHandler = handler;
            mRootCallbacks = effectPlayer;
            mTreeObserver = new ViewTreeObserver(context);
            mDensity = context.getResources().getDisplayMetrics().density;
            DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
            mDensity = displayMetrics.density;
            float pixelCount = (float) displayMetrics.widthPixels * displayMetrics.heightPixels;
            mDisplayPixelCount = pixelCount == 0f ? Float.POSITIVE_INFINITY : pixelCount;
        }
        void increaseSensitiveViewsCount() {
@@ -33812,25 +33837,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return null;
    }
    private float getSizePercentage() {
        float alpha = mTransformationInfo != null ? mTransformationInfo.mAlpha : 1;
        int visibility = mViewFlags & VISIBILITY_MASK;
        if (mResources == null || alpha == 0 || visibility != VISIBLE) {
            return 0;
        }
        DisplayMetrics displayMetrics = mResources.getDisplayMetrics();
        int screenSize = displayMetrics.widthPixels
                * displayMetrics.heightPixels;
        int viewSize = getWidth() * getHeight();
        if (screenSize == 0 || viewSize == 0) {
            return 0f;
        }
        return (float) viewSize / screenSize;
    }
    /**
     * Used to calculate the frame rate category of a View.
     *
@@ -33853,7 +33859,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        ViewRootImpl viewRootImpl = getViewRootImpl();
        int width = mRight - mLeft;
        int height = mBottom - mTop;
        if (viewRootImpl != null && (width != 0 && height != 0)) {
        float alpha = mTransformationInfo != null ? mTransformationInfo.mAlpha : 1;
        int visibility = mViewFlags & VISIBILITY_MASK;
        if (viewRootImpl != null && (width != 0 && height != 0)
                && alpha != 0 && visibility == View.VISIBLE
        ) {
            if (mAttachInfo.mViewVelocityApi) {
                float velocity = mFrameContentVelocity;
                int mask = PFLAG4_HAS_MOVED | PFLAG4_HAS_DRAWN;
@@ -33870,7 +33881,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            }
            if (!willNotDraw()) {
                if (sToolkitMetricsForFrameRateDecisionFlagValue) {
                    float sizePercentage = getSizePercentage();
                    float sizePercentage = width * height / mAttachInfo.mDisplayPixelCount;
                    viewRootImpl.recordViewPercentage(sizePercentage);
                }
+8 −0
Original line number Diff line number Diff line
@@ -80,6 +80,14 @@ flag {
    is_fixed_read_only: true
}

flag {
    name: "toolkit_frame_rate_small_uses_percent_read_only"
    namespace: "toolkit"
    description: "VRR uses percent of size to consider a view to be small"
    bug: "239979904"
    is_fixed_read_only: true
}

flag {
    name: "toolkit_frame_rate_typing_read_only"
    namespace: "toolkit"
+65 −15
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY;
import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API;
import static android.view.flags.Flags.toolkitFrameRateBySizeReadOnly;
import static android.view.flags.Flags.toolkitFrameRateDefaultNormalReadOnly;
import static android.view.flags.Flags.toolkitFrameRateSmallUsesPercentReadOnly;

import static junit.framework.Assert.assertEquals;

@@ -34,6 +35,7 @@ import static org.junit.Assert.assertTrue;
import android.app.Activity;
import android.os.SystemClock;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.util.DisplayMetrics;

import androidx.test.annotation.UiThreadTest;
import androidx.test.filters.SmallTest;
@@ -174,10 +176,19 @@ public class ViewFrameRateTest {
    public void noVelocityUsesCategorySmall() throws Throwable {
        final CountDownLatch drawLatch1 = new CountDownLatch(1);
        mActivityRule.runOnUiThread(() -> {
            float density = mActivity.getResources().getDisplayMetrics().density;
            DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
            ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
            if (toolkitFrameRateSmallUsesPercentReadOnly()) {
                float pixels = displayMetrics.widthPixels * displayMetrics.heightPixels * 0.07f;
                double smallSize = Math.sqrt(pixels);
                layoutParams.width = (int) smallSize;
                layoutParams.height = (int) smallSize;
            } else {
                float density = displayMetrics.density;
                layoutParams.height = ((int) (40 * density));
                layoutParams.width = ((int) (40 * density));
            }

            mMovingView.setLayoutParams(layoutParams);
            mMovingView.getViewTreeObserver().addOnDrawListener(drawLatch1::countDown);
        });
@@ -199,10 +210,18 @@ public class ViewFrameRateTest {
    public void noVelocityUsesCategoryNarrowWidth() throws Throwable {
        final CountDownLatch drawLatch1 = new CountDownLatch(1);
        mActivityRule.runOnUiThread(() -> {
            float density = mActivity.getResources().getDisplayMetrics().density;
            DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
            ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
            layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
            if (toolkitFrameRateSmallUsesPercentReadOnly()) {
                float pixels = displayMetrics.widthPixels * displayMetrics.heightPixels * 0.07f;
                int parentWidth = ((View) mMovingView.getParent()).getWidth();
                layoutParams.width = parentWidth;
                layoutParams.height = (int) (pixels / parentWidth);
            } else {
                float density = displayMetrics.density;
                layoutParams.width = (int) (10 * density);
                layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
            }
            mMovingView.setLayoutParams(layoutParams);
            mMovingView.getViewTreeObserver().addOnDrawListener(drawLatch1::countDown);
        });
@@ -224,10 +243,18 @@ public class ViewFrameRateTest {
    public void noVelocityUsesCategoryNarrowHeight() throws Throwable {
        final CountDownLatch drawLatch1 = new CountDownLatch(1);
        mActivityRule.runOnUiThread(() -> {
            float density = mActivity.getResources().getDisplayMetrics().density;
            DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
            ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
            layoutParams.height = (int) (10 * density);
            if (toolkitFrameRateSmallUsesPercentReadOnly()) {
                float pixels = displayMetrics.widthPixels * displayMetrics.heightPixels * 0.07f;
                int parentHeight = ((View) mMovingView.getParent()).getHeight();
                layoutParams.width = (int) (pixels / parentHeight);
                layoutParams.height = parentHeight;
            } else {
                float density = displayMetrics.density;
                layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
                layoutParams.height = (int) (10 * density);
            }
            mMovingView.setLayoutParams(layoutParams);
            mMovingView.getViewTreeObserver().addOnDrawListener(drawLatch1::countDown);
        });
@@ -249,10 +276,18 @@ public class ViewFrameRateTest {
    public void noVelocityUsesCategoryLargeWidth() throws Throwable {
        final CountDownLatch drawLatch1 = new CountDownLatch(1);
        mActivityRule.runOnUiThread(() -> {
            float density = mActivity.getResources().getDisplayMetrics().density;
            DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
            ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
            layoutParams.height = (int) (40 * density);
            if (toolkitFrameRateSmallUsesPercentReadOnly()) {
                float pixels = displayMetrics.widthPixels * displayMetrics.heightPixels * 0.07f;
                double smallSize = Math.sqrt(pixels);
                layoutParams.width = 1 + (int) Math.ceil(pixels / smallSize);
                layoutParams.height = (int) smallSize;
            } else {
                float density = displayMetrics.density;
                layoutParams.width = ((int) Math.ceil(40 * density)) + 1;
                layoutParams.height = ((int) (40 * density));
            }
            mMovingView.setLayoutParams(layoutParams);
            mMovingView.getViewTreeObserver().addOnDrawListener(drawLatch1::countDown);
        });
@@ -274,10 +309,18 @@ public class ViewFrameRateTest {
    public void noVelocityUsesCategoryLargeHeight() throws Throwable {
        final CountDownLatch drawLatch1 = new CountDownLatch(1);
        mActivityRule.runOnUiThread(() -> {
            float density = mActivity.getResources().getDisplayMetrics().density;
            DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
            ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
            layoutParams.height = ((int) Math.ceil(40 * density)) + 1;
            if (toolkitFrameRateSmallUsesPercentReadOnly()) {
                float pixels = displayMetrics.widthPixels * displayMetrics.heightPixels * 0.07f;
                double smallSize = Math.sqrt(pixels);
                layoutParams.width = (int) smallSize;
                layoutParams.height = 1 + (int) Math.ceil(pixels / smallSize);
            } else {
                float density = displayMetrics.density;
                layoutParams.width = ((int) (40 * density));
                layoutParams.height = ((int) Math.ceil(40 * density)) + 1;
            }
            mMovingView.setLayoutParams(layoutParams);
            mMovingView.getViewTreeObserver().addOnDrawListener(drawLatch1::countDown);
        });
@@ -297,6 +340,13 @@ public class ViewFrameRateTest {
    @Test
    @RequiresFlagsEnabled(FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
    public void defaultNormal() throws Throwable {
        mActivityRule.runOnUiThread(() -> {
            View parent = (View) mMovingView.getParent();
            ViewGroup.LayoutParams layoutParams = mMovingView.getLayoutParams();
            layoutParams.width = parent.getWidth() / 2;
            layoutParams.height = parent.getHeight() / 2;
            mMovingView.setLayoutParams(layoutParams);
        });
        waitForFrameRateCategoryToSettle();
        mActivityRule.runOnUiThread(() -> {
            mMovingView.invalidate();