Add tolerance to testSDRFromSurfaceViewAndTextureView cts test bitmap
comparison.
Bug: 238776037
Test: TextureViewTest
Change-Id: Ic638f154186c17797afd9e22c2d24040b4e38926
diff --git a/tests/tests/view/src/android/view/cts/TextureViewTest.java b/tests/tests/view/src/android/view/cts/TextureViewTest.java
index 804d0fa..3b2c086 100644
--- a/tests/tests/view/src/android/view/cts/TextureViewTest.java
+++ b/tests/tests/view/src/android/view/cts/TextureViewTest.java
@@ -372,7 +372,19 @@
WidgetTestUtils.runOnMainAndDrawSync(
mSDRActivityRule, textureView, () -> textureView.getBitmap(textureViewScreenshot));
- assertTrue(textureViewScreenshot.sameAs(surfaceViewScreenshot));
+ // sample 5 pixels on the edge for bitmap comparison.
+ // TextureView and SurfaceView use different shaders, so compare these two with tolerance.
+ final int threshold = 2;
+ assertTrue(pixelsAreSame(surfaceViewScreenshot.getPixel(width / 2, 0),
+ textureViewScreenshot.getPixel(width / 2, 0), threshold));
+ assertTrue(pixelsAreSame(surfaceViewScreenshot.getPixel(0, height / 2),
+ textureViewScreenshot.getPixel(0, height / 2), threshold));
+ assertTrue(pixelsAreSame(surfaceViewScreenshot.getPixel(width / 2, height / 2),
+ textureViewScreenshot.getPixel(width / 2, height / 2), threshold));
+ assertTrue(pixelsAreSame(surfaceViewScreenshot.getPixel(width / 2, height - 1),
+ textureViewScreenshot.getPixel(width / 2, height - 1), threshold));
+ assertTrue(pixelsAreSame(surfaceViewScreenshot.getPixel(width - 1, height / 2),
+ textureViewScreenshot.getPixel(width - 1, height / 2), threshold));
}
@Test