diff options
author | Stan Iliev <stani@google.com> | 2017-12-11 13:01:58 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-11 18:26:18 +0000 |
commit | ca8c0953e8da1def5e6c12dde6d4368b4bf16077 (patch) | |
tree | c7c0dabde70dbebfedba579f6f9d803652201943 /src/core/SkDevice.cpp | |
parent | 51493ee8488e29499a1a0a678a50aeca44ebf718 (diff) |
Implement a fast path for solid color lattice rectangle
Add a flag that hints, which lattice rectangles are solid colors.
Draw solid rectangles and 1x1 rectangles with drawRect.
Test: Measured performance of a ninepatch drawn by HWUI
Bug: b/69796044
Change-Id: Ib3b00ca608da42fa9f2d2038cc126a978421ec7c
Reviewed-on: https://skia-review.googlesource.com/79821
Commit-Queue: Stan Iliev <stani@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Diffstat (limited to 'src/core/SkDevice.cpp')
-rw-r--r-- | src/core/SkDevice.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 5d5c9dae73..85136722b5 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -223,8 +223,24 @@ void SkBaseDevice::drawImageLattice(const SkImage* image, SkLatticeIter iter(lattice, dst); SkRect srcR, dstR; - while (iter.next(&srcR, &dstR)) { - this->drawImageRect(image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); + SkColor c; + bool isFixedColor = false; + const SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType); + + while (iter.next(&srcR, &dstR, &isFixedColor, &c)) { + if (isFixedColor || (srcR.width() <= 1.0f && srcR.height() <= 1.0f && + image->readPixels(info, &c, 4, srcR.fLeft, srcR.fTop))) { + // Fast draw with drawRect, if this is a patch containing a single color + // or if this is a patch containing a single pixel. + if (0 != c || !paint.isSrcOver()) { + SkPaint paintCopy(paint); + int alpha = SkAlphaMul(SkColorGetA(c), SkAlpha255To256(paint.getAlpha())); + paintCopy.setColor(SkColorSetA(c, alpha)); + this->drawRect(dstR, paintCopy); + } + } else { + this->drawImageRect(image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); + } } } |