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
diff --git a/libs/hwui/NinePatchUtils.h b/libs/hwui/NinePatchUtils.h
index 8f866f5..db9509f 100644
--- a/libs/hwui/NinePatchUtils.h
+++ b/libs/hwui/NinePatchUtils.h
@@ -53,10 +53,13 @@
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 @@
if (needPadRow) {
// Skip flags for the degenerate first row of rects.
flags += lattice->fXCount + 1;
+ colors += lattice->fXCount + 1;
yCount--;
}
@@ -75,20 +79,28 @@
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;
}
}