diff options
| author | 2024-04-01 15:44:04 +0000 | |
|---|---|---|
| committer | 2024-04-01 15:44:04 +0000 | |
| commit | d47bc8b845c2e489fb652fb23693e8e7b6dedadc (patch) | |
| tree | a5b702b5b12b05c0b6bfc80c31c88549cf784659 | |
| parent | 632bfaebd8a70a857845578cf2ce0c86ef67052d (diff) | |
| parent | 6fe15567001773b79b073e72c95c9dfb411533b4 (diff) | |
Merge "Feature flag to change back to 7% small area." into main
| -rw-r--r-- | core/java/android/view/View.java | 65 | ||||
| -rw-r--r-- | core/java/android/view/flags/refresh_rate_flags.aconfig | 8 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/view/ViewFrameRateTest.java | 80 |
3 files changed, 111 insertions, 42 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 36d8ff0ae495..a82c9a8c9e8b 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -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) { - 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)) { + 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); + 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; @@ -32091,6 +32108,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); } diff --git a/core/java/android/view/flags/refresh_rate_flags.aconfig b/core/java/android/view/flags/refresh_rate_flags.aconfig index 1d4d18b120c9..442f1dadf651 100644 --- a/core/java/android/view/flags/refresh_rate_flags.aconfig +++ b/core/java/android/view/flags/refresh_rate_flags.aconfig @@ -81,6 +81,14 @@ flag { } 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" description: "Feature flag for suppressing boost on typing" diff --git a/core/tests/coretests/src/android/view/ViewFrameRateTest.java b/core/tests/coretests/src/android/view/ViewFrameRateTest.java index 260693d814df..3e172c1400b0 100644 --- a/core/tests/coretests/src/android/view/ViewFrameRateTest.java +++ b/core/tests/coretests/src/android/view/ViewFrameRateTest.java @@ -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(); - layoutParams.height = ((int) (40 * density)); - layoutParams.width = ((int) (40 * density)); + 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; - layoutParams.width = (int) (10 * density); + 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); - layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; + 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); - layoutParams.width = ((int) Math.ceil(40 * density)) + 1; + 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; - layoutParams.width = ((int) (40 * density)); + 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(); |