Introduce NativeLineBreaker.Builder and ParagraphConstraint

To make NativeLineBreaker public API, introduce
NativeLineBreaker.Builder and ParagraphConstraint.

Here is a performance differences:

android.text.StaticLayoutPerfTest:
    PrecomputedText Balanced Hyphenation  :    635 ->    684: ( +49, +7.7%)
    PrecomputedText Balanced NoHyphenation:    477 ->    523: ( +46, +9.6%)
    PrecomputedText Greedy Hyphenation    :    413 ->    463: ( +50, +12.1%)
    PrecomputedText Greedy NoHyphenation  :    413 ->    463: ( +50, +12.1%)
    RandomText Balanced Hyphenation       : 18,030 -> 18,157: (+127, +0.7%)
    RandomText Balanced NoHyphenation     :  7,390 ->  7,388: (  -2, -0.0%)
    RandomText Greedy Hyphenation         :  7,319 ->  7,331: ( +12, +0.2%)
    RandomText Greedy NoHyphenation       :  7,316 ->  7,375: ( +59, +0.8%)
  draw
    PrecomputedText NoStyle               :    631 ->    627: (  -4, -0.6%)
    PrecomputedText Style                 :    842 ->    847: (  +5, +0.6%)
    RandomText NoStyle                    :    531 ->    547: ( +16, +3.0%)
    RandomText Style                      :    754 ->    758: (  +4, +0.5%)

Bug: 112327179
Test: atest CtsWidgetTestCases:EditTextTest
    CtsWidgetTestCases:TextViewFadingEdgeTest
    FrameworksCoreTests:TextViewFallbackLineSpacingTest
    FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest
    CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest
    CtsTextTestCases FrameworksCoreTests:android.text
    CtsWidgetTestCases:TextViewPrecomputedTextTest
    CtsGraphicsTestCases:android.graphics.fonts

Change-Id: I5b817bbc9f00e5806efa98f239ee20ff3d688c50
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index dc01178..128f860 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -626,11 +626,16 @@
             indents = null;
         }
 
-        final NativeLineBreaker lineBreaker = new NativeLineBreaker(
-                b.mBreakStrategy, b.mHyphenationFrequency,
+        final NativeLineBreaker lineBreaker = new NativeLineBreaker.Builder()
+                .setBreakStrategy(b.mBreakStrategy)
+                .setHyphenationFrequency(b.mHyphenationFrequency)
                 // TODO: Support more justification mode, e.g. letter spacing, stretching.
-                b.mJustificationMode != Layout.JUSTIFICATION_MODE_NONE,
-                indents);
+                .setJustified(b.mJustificationMode)
+                .setIndents(indents)
+                .build();
+
+        NativeLineBreaker.ParagraphConstraints constraints =
+                new NativeLineBreaker.ParagraphConstraints();
 
         PrecomputedText.ParagraphInfo[] paragraphInfo = null;
         final Spanned spanned = (source instanceof Spanned) ? (Spanned) source : null;
@@ -721,18 +726,14 @@
             final char[] chs = measuredPara.getChars();
             final int[] spanEndCache = measuredPara.getSpanEndCache().getRawArray();
             final int[] fmCache = measuredPara.getFontMetrics().getRawArray();
-            int breakCount = lineBreaker.computeLineBreaks(
-                    measuredPara.getChars(),
-                    measuredPara.getNativeMeasuredParagraph(),
-                    paraEnd - paraStart,
-                    firstWidth,
-                    firstWidthLineCount,
-                    restWidth,
-                    variableTabStops,
-                    TAB_INCREMENT,
-                    mLineCount,
-                    lineBreaks);
 
+            constraints.setWidth(restWidth);
+            constraints.setIndent(firstWidth, firstWidthLineCount);
+            constraints.setTabStops(variableTabStops, TAB_INCREMENT);
+
+            lineBreaker.computeLineBreaks(measuredPara.getNativeMeasuredParagraph(),
+                    constraints, mLineCount, lineBreaks);
+            int breakCount = lineBreaks.breakCount;
             final int[] breaks = lineBreaks.breaks;
             final float[] lineWidths = lineBreaks.widths;
             final float[] ascents = lineBreaks.ascents;