Title: [123932] trunk/Source/WebCore
Revision
123932
Author
[email protected]
Date
2012-07-27 16:02:03 -0700 (Fri, 27 Jul 2012)

Log Message

[chromium] Fix color matrix filter computation so that filters that don't need clamping are correctly detected as such
https://bugs.webkit.org/show_bug.cgi?id=92452

Patch by Antoine Labour <[email protected]> on 2012-07-27
Reviewed by Stephen White.

Because of precision issues, some filters were returning true to
matrixNeedsClamping when they can return false. This fixes it.

No new tests in this CL, a follow-up change refactors the code to add
several tests.

* platform/graphics/chromium/cc/CCRenderSurfaceFilters.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (123931 => 123932)


--- trunk/Source/WebCore/ChangeLog	2012-07-27 22:59:14 UTC (rev 123931)
+++ trunk/Source/WebCore/ChangeLog	2012-07-27 23:02:03 UTC (rev 123932)
@@ -1,3 +1,18 @@
+2012-07-27  Antoine Labour  <[email protected]>
+
+        [chromium] Fix color matrix filter computation so that filters that don't need clamping are correctly detected as such
+        https://bugs.webkit.org/show_bug.cgi?id=92452
+
+        Reviewed by Stephen White.
+
+        Because of precision issues, some filters were returning true to
+        matrixNeedsClamping when they can return false. This fixes it.
+
+        No new tests in this CL, a follow-up change refactors the code to add
+        several tests.
+
+        * platform/graphics/chromium/cc/CCRenderSurfaceFilters.cpp:
+
 2012-07-27  Jer Noble  <[email protected]>
 
         Add diagnostic logging for plugins-per-page.

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.cpp (123931 => 123932)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.cpp	2012-07-27 22:59:14 UTC (rev 123931)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.cpp	2012-07-27 23:02:03 UTC (rev 123932)
@@ -67,17 +67,19 @@
 
 void getSaturateMatrix(float amount, SkScalar matrix[20])
 {
+    // Note, these values are computed to ensure matrixNeedsClamping is false
+    // for amount in [0..1]
     matrix[0] = 0.213f + 0.787f * amount;
     matrix[1] = 0.715f - 0.715f * amount;
-    matrix[2] = 0.072f - 0.072f * amount;
+    matrix[2] = 1.f - (matrix[0] + matrix[1]);
     matrix[3] = matrix[4] = 0;
     matrix[5] = 0.213f - 0.213f * amount;
     matrix[6] = 0.715f + 0.285f * amount;
-    matrix[7] = 0.072f - 0.072f * amount;
+    matrix[7] = 1.f - (matrix[5] + matrix[6]);
     matrix[8] = matrix[9] = 0;
     matrix[10] = 0.213f - 0.213f * amount;
     matrix[11] = 0.715f - 0.715f * amount;
-    matrix[12] = 0.072f + 0.928f * amount;
+    matrix[12] = 1.f - (matrix[10] + matrix[11]);
     matrix[13] = matrix[14] = 0;
     matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
     matrix[18] = 1;
@@ -121,19 +123,21 @@
 
 void getGrayscaleMatrix(float amount, SkScalar matrix[20])
 {
+    // Note, these values are computed to ensure matrixNeedsClamping is false
+    // for amount in [0..1]
     matrix[0] = 0.2126f + 0.7874f * amount;
     matrix[1] = 0.7152f - 0.7152f * amount;
-    matrix[2] = 0.0722f - 0.0722f * amount;
+    matrix[2] = 1.f - (matrix[0] + matrix[1]);
     matrix[3] = matrix[4] = 0;
 
     matrix[5] = 0.2126f - 0.2126f * amount;
     matrix[6] = 0.7152f + 0.2848f * amount;
-    matrix[7] = 0.0722f - 0.0722f * amount;
+    matrix[7] = 1.f - (matrix[5] + matrix[6]);
     matrix[8] = matrix[9] = 0;
 
     matrix[10] = 0.2126f - 0.2126f * amount;
     matrix[11] = 0.7152f - 0.7152f * amount;
-    matrix[12] = 0.0722f + 0.9278f * amount;
+    matrix[12] = 1.f - (matrix[10] + matrix[11]);
     matrix[13] = matrix[14] = 0;
 
     matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
@@ -187,15 +191,15 @@
 // Same goes for all components.
 bool componentNeedsClamping(SkScalar row[5])
 {
-    SkScalar maxValue = row[4];
-    SkScalar minValue = row[4];
+    SkScalar maxValue = row[4] / 255;
+    SkScalar minValue = row[4] / 255;
     for (int i = 0; i < 4; ++i) {
         if (row[i] > 0)
-            maxValue += row[i] * 255;
+            maxValue += row[i];
         else
-            minValue += row[i] * 255;
+            minValue += row[i];
     }
-    return (maxValue > 255) || (minValue < 0);
+    return (maxValue > 1) || (minValue < 0);
 }
 
 bool matrixNeedsClamping(SkScalar matrix[20])
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to