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

Commit 401c061c authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Notify renderer for CPU hint during process ViewPostImeInputStage

In case an expensive frame may take long time rendering when a
view requests layout/measure during processing the pointer
event in ViewPostImeInputStage that may cause the jank
(e.g. Deadline missing),

Add hasExpensiveMeasuresDuringInputEvent to notify renderer for
raising CPU load when the above potential cases happens.

Bug: 256549451
Test: Verify PTS CUJ test for gmail scolling:
   0) Enable android.os.Flags.adpfMeasureDuringInputEventBoost by
      device_config
   0-1) Log-in Gmail with a test account and enable Wifi.
   1) Run below test command
   pts-tradefed run commandAndExit cuj/scroll/gmail-list \
       -l VERBOSE \
       --fastboot-command-preparer:disable
   2) Check if any jank slice in trace during ViewPostImeInputStage
Change-Id: I3fc0c896926b6ff0f402a51d2c742d9cb7ed9379
parent bdf3e457
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -137,6 +137,13 @@ flag {
    bug: "277285195"
}

flag {
    name: "adpf_measure_during_input_event_boost"
    namespace: "game"
    description: "Guards use of a boost when view measures during input events"
    bug: "256549451"
}

flag {
    name: "battery_service_support_current_adb_command"
    namespace: "backstage_power"
+28 −0
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ import android.util.SparseArray;
import android.util.SparseIntArray;
import android.util.StateSet;
import android.util.SuperNotCalledException;
import android.util.TimeUtils;
import android.util.TypedValue;
import android.view.AccessibilityIterators.CharacterTextSegmentIterator;
import android.view.AccessibilityIterators.ParagraphTextSegmentIterator;
@@ -18067,6 +18068,24 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return false;
    }
    /**
     * Called by {@link #measure(int, int)} to check if the current frame presentation got
     * delayed by an expensive view mesures during the input event dispatching. (e.g. scrolling)
     */
    private boolean hasExpensiveMeasuresDuringInputEvent() {
        final AttachInfo attachInfo = mAttachInfo;
        if (attachInfo == null || attachInfo.mRootView == null) {
            return false;
        }
        if (!attachInfo.mHandlingPointerEvent) {
            return false;
        }
        final ViewFrameInfo info = attachInfo.mViewRootImpl.mViewFrameInfo;
        final long durationFromVsyncTimeMs = (System.nanoTime()
                - Choreographer.getInstance().getLastFrameTimeNanos()) / TimeUtils.NANOS_PER_MS;
        return durationFromVsyncTimeMs > 3L || info.getAndIncreaseViewMeasuredCount() > 10;
    }
    /**
     * @hide
     */
@@ -28078,6 +28097,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                if (isTraversalTracingEnabled()) {
                    Trace.beginSection(mTracingStrings.onMeasure);
                }
                if (android.os.Flags.adpfMeasureDuringInputEventBoost()) {
                    final boolean notifyRenderer = hasExpensiveMeasuresDuringInputEvent();
                    if (notifyRenderer) {
                        Trace.traceBegin(Trace.TRACE_TAG_VIEW,
                                "CPU_LOAD_UP: " + "hasExpensiveMeasuresDuringInputEvent");
                        getViewRootImpl().notifyRendererOfExpensiveFrame();
                        Trace.traceEnd(Trace.TRACE_TAG_VIEW);
                    }
                }
                // measure ourselves, this should set the measured dimension flag back
                onMeasure(widthMeasureSpec, heightMeasureSpec);
                if (isTraversalTracingEnabled()) {
+10 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ public class ViewFrameInfo {

    private int mInputEventId;

    private int mViewsMeasuredCounts;

    /**
     * Populate the missing fields using the data from ViewFrameInfo
     * @param frameInfo : the structure FrameInfo object to populate
@@ -51,6 +53,7 @@ public class ViewFrameInfo {
        drawStart = 0;
        mInputEventId = IInputConstants.INVALID_INPUT_EVENT_ID;
        flags = 0;
        mViewsMeasuredCounts = 0;
    }

    /**
@@ -60,6 +63,13 @@ public class ViewFrameInfo {
        drawStart = System.nanoTime();
    }

    /**
     * Record the number of view being measured for the current frame.
     */
    public int getAndIncreaseViewMeasuredCount() {
        return ++mViewsMeasuredCounts;
    }

    /**
     * Assign the value for input event id
     * @param eventId the id of the input event