Merge "Use bilerp sampling when drawing TextureView with non-translate matrix" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9dff553798
@@ -100,15 +100,13 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer
|
|||||||
paint.setAlpha(layer->getAlpha());
|
paint.setAlpha(layer->getAlpha());
|
||||||
paint.setBlendMode(layer->getMode());
|
paint.setBlendMode(layer->getMode());
|
||||||
paint.setColorFilter(layer->getColorSpaceWithFilter());
|
paint.setColorFilter(layer->getColorSpaceWithFilter());
|
||||||
if (layer->getForceFilter()) {
|
|
||||||
paint.setFilterQuality(kLow_SkFilterQuality);
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool nonIdentityMatrix = !matrix.isIdentity();
|
const bool nonIdentityMatrix = !matrix.isIdentity();
|
||||||
if (nonIdentityMatrix) {
|
if (nonIdentityMatrix) {
|
||||||
canvas->save();
|
canvas->save();
|
||||||
canvas->concat(matrix);
|
canvas->concat(matrix);
|
||||||
}
|
}
|
||||||
|
const SkMatrix& totalMatrix = canvas->getTotalMatrix();
|
||||||
if (dstRect) {
|
if (dstRect) {
|
||||||
SkMatrix matrixInv;
|
SkMatrix matrixInv;
|
||||||
if (!matrix.invert(&matrixInv)) {
|
if (!matrix.invert(&matrixInv)) {
|
||||||
@@ -118,9 +116,28 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer
|
|||||||
matrixInv.mapRect(&srcRect);
|
matrixInv.mapRect(&srcRect);
|
||||||
SkRect skiaDestRect = *dstRect;
|
SkRect skiaDestRect = *dstRect;
|
||||||
matrixInv.mapRect(&skiaDestRect);
|
matrixInv.mapRect(&skiaDestRect);
|
||||||
|
// If (matrix is identity or an integer translation) and (src/dst buffers size match),
|
||||||
|
// then use nearest neighbor, otherwise use bilerp sampling.
|
||||||
|
// Integer translation is defined as when src rect and dst rect align fractionally.
|
||||||
|
// Skia TextureOp has the above logic build-in, but not NonAAFillRectOp. TextureOp works
|
||||||
|
// only for SrcOver blending and without color filter (readback uses Src blending).
|
||||||
|
bool isIntegerTranslate = totalMatrix.isTranslate()
|
||||||
|
&& SkScalarFraction(skiaDestRect.fLeft + totalMatrix[SkMatrix::kMTransX])
|
||||||
|
== SkScalarFraction(srcRect.fLeft)
|
||||||
|
&& SkScalarFraction(skiaDestRect.fTop + totalMatrix[SkMatrix::kMTransY])
|
||||||
|
== SkScalarFraction(srcRect.fTop);
|
||||||
|
if (layer->getForceFilter() || !isIntegerTranslate) {
|
||||||
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
||||||
|
}
|
||||||
canvas->drawImageRect(layerImage.get(), srcRect, skiaDestRect, &paint,
|
canvas->drawImageRect(layerImage.get(), srcRect, skiaDestRect, &paint,
|
||||||
SkCanvas::kFast_SrcRectConstraint);
|
SkCanvas::kFast_SrcRectConstraint);
|
||||||
} else {
|
} else {
|
||||||
|
bool isIntegerTranslate = totalMatrix.isTranslate()
|
||||||
|
&& SkScalarIsInt(totalMatrix[SkMatrix::kMTransX])
|
||||||
|
&& SkScalarIsInt(totalMatrix[SkMatrix::kMTransY]);
|
||||||
|
if (layer->getForceFilter() || !isIntegerTranslate) {
|
||||||
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
||||||
|
}
|
||||||
canvas->drawImage(layerImage.get(), 0, 0, &paint);
|
canvas->drawImage(layerImage.get(), 0, 0, &paint);
|
||||||
}
|
}
|
||||||
// restore the original matrix
|
// restore the original matrix
|
||||||
|
|||||||
Reference in New Issue
Block a user