From 5a663768c463d70fa8ff0bc3080e178c16241a07 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Mon, 23 Apr 2018 11:15:00 -0400 Subject: [PATCH] Use filtering when drawing nine-patches Bug: 77917978 Test: Look at toggles; CtsUiRenderingTestCases Prior to this change, the toggles look pixelated due to using a "nearest" filter instead of a "bilerp". This matches the behavior of the hwui renderer. Depends on changes in Skia (Ib7d0abdd51981bddf36ec5c3fd84bb651f405f0f) to respect the filter quality when drawing to a GPU canvas and to remove the resulting "bleeding" effect from drawImageLattice. Change-Id: I59d81a17f351e18574539479a38a580a02e1619b --- libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp index 62d78e73ccc0f..f0da660f17b03 100644 --- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp +++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp @@ -219,8 +219,20 @@ void SkiaRecordingCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& ch SkPaint tmpPaint; sk_sp colorFilter; sk_sp image = bitmap.makeImage(&colorFilter); - mRecorder.drawImageLattice(image.get(), lattice, dst, - bitmapPaint(paint, &tmpPaint, colorFilter)); + const SkPaint* filteredPaint = bitmapPaint(paint, &tmpPaint, colorFilter); + // Besides kNone, the other three SkFilterQualities are treated the same. And Android's + // Java API only supports kLow and kNone anyway. + if (!filteredPaint || filteredPaint->getFilterQuality() == kNone_SkFilterQuality) { + if (filteredPaint != &tmpPaint) { + if (paint) { + tmpPaint = *paint; + } + filteredPaint = &tmpPaint; + } + tmpPaint.setFilterQuality(kLow_SkFilterQuality); + } + + mRecorder.drawImageLattice(image.get(), lattice, dst, filteredPaint); if (!bitmap.isImmutable() && image.get() && !image->unique() && !dst.isEmpty()) { mDisplayList->mMutableImages.push_back(image.get()); }