6976076: sun/java2d/pipe/MutableColorTest/MutableColorTest.java failed
authorbae
Tue, 05 Oct 2010 10:23:14 +0400
changeset 6811 a0fd2f4b2197
parent 6632 96bd7ecf0e1b
child 6812 83cac1fcd3ed
6976076: sun/java2d/pipe/MutableColorTest/MutableColorTest.java failed Reviewed-by: igor, prr
jdk/test/sun/java2d/pipe/MutableColorTest/MutableColorTest.java
--- a/jdk/test/sun/java2d/pipe/MutableColorTest/MutableColorTest.java	Sat Oct 02 12:41:20 2010 +0400
+++ b/jdk/test/sun/java2d/pipe/MutableColorTest/MutableColorTest.java	Tue Oct 05 10:23:14 2010 +0400
@@ -105,7 +105,7 @@
         for (int y = 0; y < snapshot.getHeight(); y++) {
             for (int x = 0; x < snapshot.getWidth(); x++) {
                 int snapRGB = snapshot.getRGB(x, y);
-                if (snapRGB != evilColor) {
+                if (!isSameColor(snapRGB, evilColor)) {
                     System.err.printf("Wrong RGB for %s at (%d,%d): 0x%x " +
                         "instead of 0x%x\n", desc, x, y, snapRGB, evilColor);
                     String fileName = "MutableColorTest_"+desc+".png";
@@ -166,4 +166,24 @@
 
         System.err.println("Test passed.");
     }
+
+    /*
+     * We assume that colors with slightly different components
+     * are the same. This is done just in order to workaround
+     * peculiarities of OGL rendering pipeline on some platforms.
+     * See CR 6989217 for more details.
+     */
+     private static boolean isSameColor(int color1, int color2) {
+        final int tolerance = 2;
+
+        for (int i = 0; i < 32; i += 8) {
+            int c1 = 0xff & (color1 >> i);
+            int c2 = 0xff & (color2 >> i);
+
+            if (Math.abs(c1 - c2) > tolerance) {
+                return false;
+            }
+        }
+        return true;
+    }
 }