Class LayoutCache

java.lang.Object
icyllis.modernui.graphics.text.LayoutCache

@ThreadSafe public final class LayoutCache extends Object
Globally shared layout cache. Useful when recycling layouts, or raw data source and layout information are separated. Max memory usage: 7~10 MB.
Since:
2.6
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Also computes per-cluster advances.
    static final int
    Also computes total pixel bounds of all glyph images.
    static final int
    The internal policy on the maximum length of a text run, shared globally.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Clear the cache.
    static int
    This only returns measurable memory usage, in other words, at least
    getOrCreate(char[] buf, int contextStart, int contextLimit, int start, int limit, boolean isRtl, FontPaint paint, int computeFlags)
    Get or create the layout piece from the global cache with given requirements.
    static int
    Returns the approximate number of entries in this cache.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • LayoutCache

      public LayoutCache()
  • Method Details

    • getOrCreate

      @NonNull public static LayoutPiece getOrCreate(@NonNull char[] buf, int contextStart, int contextLimit, int start, int limit, boolean isRtl, @NonNull FontPaint paint, int computeFlags)
      Get or create the layout piece from the global cache with given requirements.

      In particular, the given range cannot exceed MAX_PIECE_LENGTH to increase the reuse rate of pieced text. The given text must be in the same paragraph and should not break the grapheme cluster.

      Use computeFlags to compute optional info lazily.

      Parameters:
      buf - text buffer, cannot be null or empty, only referred in stack
      start - start char offset
      limit - end char index
      isRtl - whether to layout in right-to-left
      paint - the font paint affecting measurement
      computeFlags - additional desired info to compute, or 0
      Returns:
      the layout piece
    • getSize

      public static int getSize()
      Returns the approximate number of entries in this cache.
    • getMemoryUsage

      public static int getMemoryUsage()
      This only returns measurable memory usage, in other words, at least
      Returns:
      memory usage in bytes
    • clear

      public static void clear()
      Clear the cache.