DO NOT MERGE Disable filtering for BufferLayers which are not scaled

Previously, linear filtering was applied based on the window scaling
mode only. If the buffer size matches the layer size (after applying
any transforms), point filtering can/should be used instead.

This affects cases where overlays are composited with GL, because it
relied on sampling the exact center of texels, to not get any
contribution of neighboring texels in the filter result. This is not
guaranteed, due to numerical imprecision in texture coordinate
interpolation, perspective correction, sub-texel accuracy, and/or
other precision losses which GL implementations may incur.

BufferStateLayers already had the logic for checking whether the buffer
is actually scaled, to fix a similar case. This change moves it to the
BufferLayer base class, with a shortcut for the
NATIVE_WINDOW_SCALING_MODE_FREEZE case.

Bug: b/182584062
Test: android.uirendering.cts.testclasses.SurfaceViewTests#testMovingWhiteSurfaceView
Change-Id: I3e765b8aef23dce6346cf2c64a8e36a28baebd9f
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index f64e0d2..5a24d51 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -848,7 +848,33 @@
 }
 
 bool BufferLayer::bufferNeedsFiltering() const {
-    return isFixedSize();
+    // Layers that don't resize along with their buffer, don't need filtering.
+    if (!isFixedSize()) {
+        return false;
+    }
+
+    if (!mBufferInfo.mBuffer) {
+        return false;
+    }
+
+    uint32_t bufferWidth = mBufferInfo.mBuffer->width;
+    uint32_t bufferHeight = mBufferInfo.mBuffer->height;
+
+    // Undo any transformations on the buffer and return the result.
+    const State& s(getDrawingState());
+    if (s.transform & ui::Transform::ROT_90) {
+        std::swap(bufferWidth, bufferHeight);
+    }
+
+    if (s.transformToDisplayInverse) {
+        uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags();
+        if (invTransform & ui::Transform::ROT_90) {
+            std::swap(bufferWidth, bufferHeight);
+        }
+    }
+
+    const Rect layerSize{getBounds()};
+    return layerSize.width() != bufferWidth || layerSize.height() != bufferHeight;
 }
 
 } // namespace android
diff --git a/services/surfaceflinger/BufferLayer.h b/services/surfaceflinger/BufferLayer.h
index a3d8b68..c7e8ad7 100644
--- a/services/surfaceflinger/BufferLayer.h
+++ b/services/surfaceflinger/BufferLayer.h
@@ -120,7 +120,7 @@
 
     // Returns true if the transformed buffer size does not match the layer size and we need
     // to apply filtering.
-    virtual bool bufferNeedsFiltering() const;
+    bool bufferNeedsFiltering() const;
 
     // -----------------------------------------------------------------------
     // Functions that must be implemented by derived classes
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index ad2620c..41dd7bf 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -761,30 +761,6 @@
                               radius);
 }
 
-bool BufferStateLayer::bufferNeedsFiltering() const {
-    const State& s(getDrawingState());
-    if (!s.buffer) {
-        return false;
-    }
-
-    uint32_t bufferWidth = s.buffer->width;
-    uint32_t bufferHeight = s.buffer->height;
-
-    // Undo any transformations on the buffer and return the result.
-    if (s.transform & ui::Transform::ROT_90) {
-        std::swap(bufferWidth, bufferHeight);
-    }
-
-    if (s.transformToDisplayInverse) {
-        uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags();
-        if (invTransform & ui::Transform::ROT_90) {
-            std::swap(bufferWidth, bufferHeight);
-        }
-    }
-
-    const Rect layerSize{getBounds()};
-    return layerSize.width() != bufferWidth || layerSize.height() != bufferHeight;
-}
 } // namespace android
 
 // TODO(b/129481165): remove the #pragma below and fix conversion issues
diff --git a/services/surfaceflinger/BufferStateLayer.h b/services/surfaceflinger/BufferStateLayer.h
index b408113..00fa7f7 100644
--- a/services/surfaceflinger/BufferStateLayer.h
+++ b/services/surfaceflinger/BufferStateLayer.h
@@ -145,8 +145,6 @@
     friend class SlotGenerationTest;
     bool willPresentCurrentTransaction() const;
 
-    bool bufferNeedsFiltering() const override;
-
     static const std::array<float, 16> IDENTITY_MATRIX;
 
     std::unique_ptr<renderengine::Image> mTextureImage;