Title: [116332] trunk/Source
Revision
116332
Author
shawnsi...@chromium.org
Date
2012-05-07 11:48:06 -0700 (Mon, 07 May 2012)

Log Message

[chromium] CCMathUtil projectPoint needs to avoid divide-by-zero
https://bugs.webkit.org/show_bug.cgi?id=85560

Reviewed by Adrienne Walker.

Source/WebCore:

Unit test added: CCMathUtilTest.cpp - verifyProjectionOfPerpendicularPlane
Unit test updated/renamed: CCLayerTreeHostCommonTest.cpp - verifyVisibleRectFor3dPerspectiveWhenClippedByW

The divide-by-zero occurs in an innocuous case where the layers
are probably invisible anyway. However, producing Infs and NaNs
could cause values to be used when un-intended, so its appropriate
to handle the divide-by-zero correctly.

* platform/graphics/chromium/cc/CCMathUtil.cpp:
(WebCore::projectPoint):

Source/WebKit/chromium:

* tests/CCLayerTreeHostCommonTest.cpp:
(WebKitTests::TEST):
* tests/CCMathUtilTest.cpp:
(WebCore::TEST):
(WebCore):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (116331 => 116332)


--- trunk/Source/WebCore/ChangeLog	2012-05-07 18:41:08 UTC (rev 116331)
+++ trunk/Source/WebCore/ChangeLog	2012-05-07 18:48:06 UTC (rev 116332)
@@ -1,3 +1,21 @@
+2012-05-07  Shawn Singh  <shawnsi...@chromium.org>
+
+        [chromium] CCMathUtil projectPoint needs to avoid divide-by-zero
+        https://bugs.webkit.org/show_bug.cgi?id=85560
+
+        Reviewed by Adrienne Walker.
+
+        Unit test added: CCMathUtilTest.cpp - verifyProjectionOfPerpendicularPlane
+        Unit test updated/renamed: CCLayerTreeHostCommonTest.cpp - verifyVisibleRectFor3dPerspectiveWhenClippedByW
+
+        The divide-by-zero occurs in an innocuous case where the layers
+        are probably invisible anyway. However, producing Infs and NaNs
+        could cause values to be used when un-intended, so its appropriate
+        to handle the divide-by-zero correctly.
+
+        * platform/graphics/chromium/cc/CCMathUtil.cpp:
+        (WebCore::projectPoint):
+
 2012-05-07  Pravin D  <pravind....@gmail.com>
 
         Wrong positioning due to wrong width calculation wrt width:0

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCMathUtil.cpp (116331 => 116332)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCMathUtil.cpp	2012-05-07 18:41:08 UTC (rev 116331)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCMathUtil.cpp	2012-05-07 18:48:06 UTC (rev 116332)
@@ -66,6 +66,13 @@
 
 static HomogeneousCoordinate projectPoint(const TransformationMatrix& transform, const FloatPoint& p)
 {
+    // In this case, the layer we are trying to project onto is perpendicular to ray
+    // (point p and z-axis direction) that we are trying to project. This happens when the
+    // layer is rotated so that it is infinitesimally thin, or when it is co-planar with
+    // the camera origin -- i.e. when the layer is invisible anyway.
+    if (!transform.m33())
+        return HomogeneousCoordinate(0, 0, 0, 1);
+
     double x = p.x();
     double y = p.y();
     double z = -(transform.m13() * x + transform.m23() * y + transform.m43()) / transform.m33();

Modified: trunk/Source/WebKit/chromium/ChangeLog (116331 => 116332)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-05-07 18:41:08 UTC (rev 116331)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-05-07 18:48:06 UTC (rev 116332)
@@ -1,3 +1,16 @@
+2012-05-07  Shawn Singh  <shawnsi...@chromium.org>
+
+        [chromium] CCMathUtil projectPoint needs to avoid divide-by-zero
+        https://bugs.webkit.org/show_bug.cgi?id=85560
+
+        Reviewed by Adrienne Walker.
+
+        * tests/CCLayerTreeHostCommonTest.cpp:
+        (WebKitTests::TEST):
+        * tests/CCMathUtilTest.cpp:
+        (WebCore::TEST):
+        (WebCore):
+
 2012-05-07  Nat Duca  <nd...@chromium.org>
 
         Unreviewed, rolling out r115525.

Modified: trunk/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp (116331 => 116332)


--- trunk/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp	2012-05-07 18:41:08 UTC (rev 116331)
+++ trunk/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp	2012-05-07 18:48:06 UTC (rev 116332)
@@ -1172,7 +1172,7 @@
     EXPECT_INT_RECT_EQ(expected, actual);
 }
 
-TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveIsClipped)
+TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW)
 {
     // Test the calculateVisibleRect() function works correctly when projecting a surface
     // onto a layer, but the layer is partially behind the camera (not just behind the
@@ -1190,7 +1190,7 @@
     // center of the layer.
     layerToSurfaceTransform.makeIdentity();
     layerToSurfaceTransform.applyPerspective(1);
-    layerToSurfaceTransform.translate3d(0, 0, 1);
+    layerToSurfaceTransform.translate3d(-1, 0, 1);
     layerToSurfaceTransform.rotate3d(0, 45, 0);
 
     // Sanity check that this transform does indeed cause w < 0 when applying the
@@ -1199,7 +1199,7 @@
     CCMathUtil::mapQuad(layerToSurfaceTransform, FloatQuad(FloatRect(layerContentRect)), clipped);
     ASSERT_TRUE(clipped);
 
-    int expectedXPosition = -10;
+    int expectedXPosition = 0;
     int expectedWidth = 10;
     IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
     EXPECT_EQ(expectedXPosition, actual.x());

Modified: trunk/Source/WebKit/chromium/tests/CCMathUtilTest.cpp (116331 => 116332)


--- trunk/Source/WebKit/chromium/tests/CCMathUtilTest.cpp	2012-05-07 18:41:08 UTC (rev 116331)
+++ trunk/Source/WebKit/chromium/tests/CCMathUtilTest.cpp	2012-05-07 18:48:06 UTC (rev 116332)
@@ -99,4 +99,21 @@
     EXPECT_TRUE(layerSpaceToProjectionPlane.isBackFaceVisible());
 }
 
+TEST(CCMathUtilTest, verifyProjectionOfPerpendicularPlane)
+{
+    // In this case, the m33() element of the transform becomes zero, which could cause a
+    // divide-by-zero when projecting points/quads.
+
+    TransformationMatrix transform;
+    transform.makeIdentity();
+    transform.setM33(0);
+
+    FloatRect rect = FloatRect(0, 0, 1, 1);
+    FloatRect projectedRect = CCMathUtil::projectClippedRect(transform, rect);
+
+    EXPECT_EQ(0, projectedRect.x());
+    EXPECT_EQ(0, projectedRect.y());
+    EXPECT_TRUE(projectedRect.isEmpty());
+}
+
 } // namespace
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to