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

Commit 71d7ce01 authored by Shane's avatar Shane Committed by Jian-Syuan (Shane) Wong
Browse files

Add velocity APIs to View

This CL added public APIs to View and RenderNode to set and get the velocity information. The velocity information will be used for the VRR project so that we can the velocity as a signal to adjust the frame rate.

Bug: 293513816
Test: atest ViewTest

Change-Id: I45ca2257e2631bb986d231f997da78ab56c9a15e
parent b53ca9f0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -51711,6 +51711,7 @@ package android.view {
    method @Nullable public android.graphics.BlendMode getForegroundTintBlendMode();
    method @Nullable public android.content.res.ColorStateList getForegroundTintList();
    method @Nullable public android.graphics.PorterDuff.Mode getForegroundTintMode();
    method @FlaggedApi("android.view.flags.view_velocity_api") public float getFrameContentVelocity();
    method public boolean getGlobalVisibleRect(android.graphics.Rect, android.graphics.Point);
    method public final boolean getGlobalVisibleRect(android.graphics.Rect);
    method public android.os.Handler getHandler();
@@ -52088,6 +52089,7 @@ package android.view {
    method public void setForegroundTintBlendMode(@Nullable android.graphics.BlendMode);
    method public void setForegroundTintList(@Nullable android.content.res.ColorStateList);
    method public void setForegroundTintMode(@Nullable android.graphics.PorterDuff.Mode);
    method @FlaggedApi("android.view.flags.view_velocity_api") public void setFrameContentVelocity(float);
    method public void setHandwritingBoundsOffsets(float, float, float, float);
    method public void setHandwritingDelegatorCallback(@Nullable Runnable);
    method public void setHapticFeedbackEnabled(boolean);
+37 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ER
import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_UNKNOWN;
import static android.view.displayhash.DisplayHashResultCallback.EXTRA_DISPLAY_HASH;
import static android.view.displayhash.DisplayHashResultCallback.EXTRA_DISPLAY_HASH_ERROR_CODE;
import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API;
import static android.view.flags.Flags.viewVelocityApi;
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__DEEP_PRESS;
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__LONG_PRESS;
@@ -40,6 +42,7 @@ import android.annotation.AttrRes;
import android.annotation.CallSuper;
import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.FlaggedApi;
import android.annotation.FloatRange;
import android.annotation.IdRes;
import android.annotation.IntDef;
@@ -5491,6 +5494,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    @Nullable
    private ViewTranslationCallback mViewTranslationCallback;
    private float mFrameContentVelocity = 0;
    @Nullable
    private ViewTranslationResponse mViewTranslationResponse;
@@ -24082,6 +24087,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    public void draw(@NonNull Canvas canvas) {
        final int privateFlags = mPrivateFlags;
        mPrivateFlags = (privateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN;
        mFrameContentVelocity = 0;
        /*
         * Draw traversal performs several drawing steps which must be executed
@@ -32961,4 +32967,35 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
        return null;
    }
    /**
     * Set the current velocity of the View, we only track positive value.
     * We will use the velocity information to adjust the frame rate when applicable.
     * For example, we could potentially lower the frame rate when
     * the velocity of a fling gesture becomes slower.
     * Note that this is only valid till the next drawn frame.
     *
     * @param pixelsPerSecond how many pixels move per second.
     */
    @FlaggedApi(FLAG_VIEW_VELOCITY_API)
    public void setFrameContentVelocity(float pixelsPerSecond) {
        if (viewVelocityApi()) {
            mFrameContentVelocity = Math.abs(pixelsPerSecond);
        }
    }
    /**
     * Get the current velocity of the View.
     * The value should always be greater than or equal to 0.
     * Note that this is only valid till the next drawn frame.
     *
     * @return 0 by default, or value passed to {@link #setFrameContentVelocity(float)}.
     */
    @FlaggedApi(FLAG_VIEW_VELOCITY_API)
    public float getFrameContentVelocity() {
        if (viewVelocityApi()) {
            return mFrameContentVelocity;
        }
        return 0;
    }
}