Commit dcd1a26c authored by Kazuhiro Inaba's avatar Kazuhiro Inaba Committed by Commit Bot

gpu: GL_NEAREST instead of GL_LINEAR for non-scaling copy.

On GPUs that only supports FP16 arithmetic, just doing
a copy between the same size of large (>1024px) rectangles
already introduces some imprecision. Using GL_NEAREST in
such a case increases the quality and produces results
closer to pixel-perfect copying.

BUG=b:141898654
TEST=android.view.cts.SurfaceViewSyncTest#testSmallRect on kukui (ChromeOS)

Change-Id: I2d58ee387122b3977e8e3f439179ce01ff5bf14d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076642Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Commit-Queue: Kazuhiro Inaba <kinaba@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745220}
parent 921851f5
......@@ -514,11 +514,20 @@ class ScalerImpl : public GLHelper::ScalerInterface {
GL_TEXTURE_2D, dest_texture_1, 0);
}
// Bind to the source texture and set the texture sampler to use bilinear
// filtering and clamp to the edge, as required by all shader programs.
// Use GL_NEAREST for copies between exactly same size of rectangles to
// reduce errors on low-precision GPUs. Use bilinear filtering otherwise.
//
// This is a workaround for Mali-G72 GPU (b/141898654) that uses lower
// precision than expected for interpolation.
GLint filter = (src_rect.IsExpressibleAsRect() &&
src_rect.size() == gfx::SizeF(result_size))
? GL_NEAREST
: GL_LINEAR;
// Bind to the source texture and set the filitering and clamp to the edge,
// as required by all shader programs.
ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, src_texture);
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment