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

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

[ADPF]: boost cpu when processing long text layout

To speed up many calculateBounds invocation happens during scrolling
list view with complicated text view layout from
   TextLine.measure
     -> minikin::Layout::measureText ..
     -> minikin::LayoutCache::getOrCreate

Flag: android.widget.flags.boost_cpu_load_for_long_text_rendering
Bug: 380088697
Test: run PTS test UiBenchLayoutCacheLowHitrateFlingMicrobenchmark
without seeing jank frame by long execution on AbsListView#obtainView

Change-Id: I32c362a50875a50be9a69a5e39151afd9ef3a5fe
parent 11fae1bc
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -128,6 +128,12 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable, ThemedSp
    /** Layout inflater used for {@link #getDropDownView(int, View, ViewGroup)}. */
    private LayoutInflater mDropDownInflater;

    private static final boolean sBoostCpuLoadFlag =
            android.widget.flags.Flags.boostCpuLoadForLongTextRendering();

    /** The threshold at which to boost cpu work load for long text rendering. */
    private static final int BOOST_CPU_TEXT_LENGTH_THRESHOLD = 500;

    /**
     * Constructor
     *
@@ -448,11 +454,24 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable, ThemedSp
        }

        final T item = getItem(position);
        int textLength;
        CharSequence textContent;
        if (item instanceof CharSequence) {
            text.setText((CharSequence) item);
            textLength = ((CharSequence) item).length();
            textContent = (CharSequence) item;
        } else {
            text.setText(item.toString());
        }
            textLength = item.toString() == null ? 0 : item.toString().length();
            textContent = item.toString();
        }
        // Send a hint to boost the renderer when processing text content rendering takes time.
        // (e.g. text rendering in minikin may take 2 ~ 4 ms when the text length > 500 during
        // calculating text bounds)
        if (sBoostCpuLoadFlag && parent.isAttachedToWindow()
                && textLength > BOOST_CPU_TEXT_LENGTH_THRESHOLD) {
            parent.getViewRootImpl().notifyRendererOfExpensiveFrame(
                    "ADPF_SendHint: Expensive text rendering");
        }
        text.setText(textContent);

        return view;
    }
+10 −0
Original line number Diff line number Diff line
@@ -17,3 +17,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "boost_cpu_load_for_long_text_rendering"
  namespace: "text"
  description: "Use ADPF APIs to boost cpu when processing long text layout"
  bug: "380088697"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}