diff options
author | Stan Iliev <stani@google.com> | 2017-12-04 14:48:27 -0500 |
---|---|---|
committer | Stan Iliev <stani@google.com> | 2017-12-11 18:22:17 +0000 |
commit | e12d7315dd921301a18935d4c78119716753c30f (patch) | |
tree | b77c0cb3eb367b09aab531c2a12ee1bee8c889a9 /libs/hwui/NinePatchUtils.h | |
parent | 1f397705eb58ccb7fd341144e98400a7bb5f3432 (diff) |
Enable fast drawing for solid color nine patch rectangles
Pass a hint to Skia, about which lattice rectangles are solid
color rectangles.
Bug: 69796044
Test: Measured ninepatch performance using sample app from the bug
Change-Id: Ib07b1b64c78ab16195f9af88a989d28682084565
Diffstat (limited to 'libs/hwui/NinePatchUtils.h')
-rw-r--r-- | libs/hwui/NinePatchUtils.h | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/libs/hwui/NinePatchUtils.h b/libs/hwui/NinePatchUtils.h index 8f866f50e450..db9509fff378 100644 --- a/libs/hwui/NinePatchUtils.h +++ b/libs/hwui/NinePatchUtils.h @@ -53,10 +53,13 @@ static inline int NumDistinctRects(const SkCanvas::Lattice& lattice) { return xRects * yRects; } -static inline void SetLatticeFlags(SkCanvas::Lattice* lattice, SkCanvas::Lattice::Flags* flags, - int numFlags, const Res_png_9patch& chunk) { - lattice->fFlags = flags; - sk_bzero(flags, numFlags * sizeof(SkCanvas::Lattice::Flags)); +static inline void SetLatticeFlags(SkCanvas::Lattice* lattice, + SkCanvas::Lattice::RectType* flags, int numFlags, const Res_png_9patch& chunk, + SkColor* colors) { + lattice->fRectTypes = flags; + lattice->fColors = colors; + sk_bzero(flags, numFlags * sizeof(SkCanvas::Lattice::RectType)); + sk_bzero(colors, numFlags * sizeof(SkColor)); bool needPadRow = lattice->fYCount > 0 && 0 == lattice->fYDivs[0]; bool needPadCol = lattice->fXCount > 0 && 0 == lattice->fXDivs[0]; @@ -65,6 +68,7 @@ static inline void SetLatticeFlags(SkCanvas::Lattice* lattice, SkCanvas::Lattice if (needPadRow) { // Skip flags for the degenerate first row of rects. flags += lattice->fXCount + 1; + colors += lattice->fXCount + 1; yCount--; } @@ -75,20 +79,28 @@ static inline void SetLatticeFlags(SkCanvas::Lattice* lattice, SkCanvas::Lattice if (0 == x && needPadCol) { // First rect of each column is degenerate, skip the flag. flags++; + colors++; continue; } - if (0 == chunk.getColors()[i++]) { - *flags = SkCanvas::Lattice::kTransparent_Flags; + uint32_t currentColor = chunk.getColors()[i++]; + if (Res_png_9patch::TRANSPARENT_COLOR == currentColor) { + *flags = SkCanvas::Lattice::kTransparent; + setFlags = true; + } else if (Res_png_9patch::NO_COLOR != currentColor) { + *flags = SkCanvas::Lattice::kFixedColor; + *colors = currentColor; setFlags = true; } flags++; + colors++; } } if (!setFlags) { - lattice->fFlags = nullptr; + lattice->fRectTypes = nullptr; + lattice->fColors = nullptr; } } |