DO NOT MERGE: Use GL_LINEAR filter when drawing scaled TextureView

Use GL_LINEAR instead of GL_NEAREST sampling, when drawing
a TextureView, which has a buffer size that does not match
layer size.
Scale SkImage to layer size with a matrix, instead of
passing wrong size to MakeFromTexture.
This CL must not be merged in master, becase this issue has
been fixed already by ag/4936023.

Bug: 114324288
Test: Passed CtsViewTestCases and CtsUiRenderingTestCases
Test: Ran apps using scaled TextureView including Instagram
Change-Id: I9ee659d08998c932d8b708a64f3c879ab696fd9e
This commit is contained in:
Stan Iliev
2018-09-10 14:48:38 -04:00
parent 9b5c03973e
commit 93ac4012f2
3 changed files with 25 additions and 4 deletions

View File

@@ -133,9 +133,10 @@ void DeferredLayerUpdater::doUpdateTexImage() {
bool forceFilter = false;
sp<GraphicBuffer> buffer = mSurfaceTexture->getCurrentBuffer();
if (buffer != nullptr) {
mLayer->setBufferSize(buffer->getWidth(), buffer->getHeight());
// force filtration if buffer size != layer size
forceFilter = mWidth != static_cast<int>(buffer->getWidth()) ||
mHeight != static_cast<int>(buffer->getHeight());
forceFilter = mWidth != static_cast<int>(mLayer->getBufferWidth()) ||
mHeight != static_cast<int>(mLayer->getBufferHeight());
}
#if DEBUG_RENDERER

View File

@@ -94,6 +94,15 @@ public:
*/
void postDecStrong();
inline void setBufferSize(uint32_t width, uint32_t height) {
mBufferWidth = width;
mBufferHeight = height;
}
inline uint32_t getBufferWidth() const { return mBufferWidth; }
inline uint32_t getBufferHeight() const { return mBufferHeight; }
protected:
Layer(RenderState& renderState, Api api, sk_sp<SkColorFilter>, int alpha,
SkBlendMode mode);
@@ -145,6 +154,9 @@ private:
*/
mat4 transform;
uint32_t mBufferWidth = 0;
uint32_t mBufferHeight = 0;
}; // struct Layer
}; // namespace uirenderer

View File

@@ -46,6 +46,11 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer
sk_sp<SkImage> layerImage;
const int layerWidth = layer->getWidth();
const int layerHeight = layer->getHeight();
const int bufferWidth = layer->getBufferWidth();
const int bufferHeight = layer->getBufferHeight();
if (bufferWidth <= 0 || bufferHeight <=0) {
return false;
}
if (layer->getApi() == Layer::Api::OpenGL) {
GlLayer* glLayer = static_cast<GlLayer*>(layer);
GrGLTextureInfo externalTexture;
@@ -57,7 +62,7 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer
// this is anticipated to have is that for some format types if we are not bound as an OES
// texture we may get invalid results for SKP capture if we read back the texture.
externalTexture.fFormat = GL_RGBA8;
GrBackendTexture backendTexture(layerWidth, layerHeight, GrMipMapped::kNo, externalTexture);
GrBackendTexture backendTexture(bufferWidth, bufferHeight, GrMipMapped::kNo, externalTexture);
layerImage = SkImage::MakeFromTexture(context, backendTexture, kTopLeft_GrSurfaceOrigin,
kPremul_SkAlphaType, nullptr);
} else {
@@ -76,7 +81,7 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer
flipV.setAll(1, 0, 0, 0, -1, 1, 0, 0, 1);
textureMatrixInv.preConcat(flipV);
textureMatrixInv.preScale(1.0f / layerWidth, 1.0f / layerHeight);
textureMatrixInv.postScale(layerWidth, layerHeight);
textureMatrixInv.postScale(bufferWidth, bufferHeight);
SkMatrix textureMatrix;
if (!textureMatrixInv.invert(&textureMatrix)) {
textureMatrix = textureMatrixInv;
@@ -95,6 +100,9 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer
paint.setAlpha(layer->getAlpha());
paint.setBlendMode(layer->getMode());
paint.setColorFilter(layer->getColorSpaceWithFilter());
if (layer->getForceFilter()) {
paint.setFilterQuality(kLow_SkFilterQuality);
}
const bool nonIdentityMatrix = !matrix.isIdentity();
if (nonIdentityMatrix) {