Bug 1467847 - avoid taking inverse in Polygon::TransformToScreenSpace when possible. r=miko
authorLee Salzman <lsalzman@mozilla.com>
Mon, 09 Jul 2018 15:52:42 -0400
changeset 425563 a28effafa2d7e12c381a465a55817102d41b3f32
parent 425562 e139fa8d93ef9a4a181e2c4fb027e62cc487726d
child 425564 5a0ddea9ad624286eb863e8419e144d5cbae4d58
push id34259
push usertoros@mozilla.com
push dateTue, 10 Jul 2018 09:45:44 +0000
treeherdermozilla-central@a675c5d7eb76 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmiko
bugs1467847
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1467847 - avoid taking inverse in Polygon::TransformToScreenSpace when possible. r=miko
gfx/2d/Polygon.h
gfx/layers/composite/ContainerLayerComposite.cpp
gfx/tests/crashtests/1467847-1.html
gfx/tests/crashtests/crashtests.list
--- a/gfx/2d/Polygon.h
+++ b/gfx/2d/Polygon.h
@@ -323,28 +323,35 @@ public:
   }
 
   void TransformToLayerSpace(const Matrix4x4Typed<Units, Units>& aTransform)
   {
     TransformPoints(aTransform, true);
     mNormal = DefaultNormal();
   }
 
-  void TransformToScreenSpace(const Matrix4x4Typed<Units, Units>& aTransform)
+  void TransformToScreenSpace(const Matrix4x4Typed<Units, Units>& aTransform,
+                              const Matrix4x4Typed<Units, Units>& aInverseTransform)
   {
-    MOZ_ASSERT(!aTransform.IsSingular());
-
     TransformPoints(aTransform, false);
 
     // Perspective projection transformation might produce points with w <= 0,
     // so we need to clip these points.
     mPoints = ClipPointsAtInfinity(mPoints);
 
     // Normal vectors should be transformed using inverse transpose.
-    mNormal = aTransform.Inverse().Transpose().TransformPoint(mNormal);
+    mNormal = aInverseTransform.TransposeTransform4D(mNormal);
+  }
+
+
+  void TransformToScreenSpace(const Matrix4x4Typed<Units, Units>& aTransform)
+  {
+    MOZ_ASSERT(!aTransform.IsSingular());
+
+    TransformToScreenSpace(aTransform, aTransform.Inverse());
   }
 
 private:
   static Point4DType DefaultNormal()
   {
     return Point4DType(0.0f, 0.0f, 1.0f, 0.0f);
   }
 
--- a/gfx/layers/composite/ContainerLayerComposite.cpp
+++ b/gfx/layers/composite/ContainerLayerComposite.cpp
@@ -143,17 +143,17 @@ TransformLayerGeometry(Layer* aLayer, Ma
     transform = transform * parent->GetLocalTransform();
     parent = parent->GetParent();
   }
 
   // Transform the geometry to the parent 3D context leaf coordinate space.
   transform = transform.ProjectTo2D();
 
   if (!transform.IsSingular()) {
-    aGeometry->TransformToScreenSpace(transform.Inverse());
+    aGeometry->TransformToScreenSpace(transform.Inverse(), transform);
   } else {
     // Discard the geometry since the result might not be correct.
     aGeometry.reset();
   }
 }
 
 
 template<class ContainerT>
new file mode 100644
--- /dev/null
+++ b/gfx/tests/crashtests/1467847-1.html
@@ -0,0 +1,15 @@
+<html>
+<style>
+:root{
+transform-style:preserve-3d;
+}
+</style>
+<script>
+addEventListener("DOMContentLoaded", () => {
+  let s = document.createElement("fieldset")
+  document.getElementsByTagName("body")[0].appendChild(s)
+  s.animate([{ "transform": "matrix3d(258,8,296,626,168,58,272,151,47,-0,90,-101,116,-119,65,182) translate3d(199ch,238in,47q)" }], 1000)
+})
+</script>
+<body></body>
+</html>
--- a/gfx/tests/crashtests/crashtests.list
+++ b/gfx/tests/crashtests/crashtests.list
@@ -159,8 +159,10 @@ load 1242822.html
 load 1248222.html
 load 1278305.html
 load 1308394.html
 load 1317403-1.html # bug 1331533
 load 1325159-1.html
 load 1331683.html
 skip-if(Android) pref(dom.disable_open_during_load,false) load 1343666.html
 load 1408078-1.html
+load 1467847-1.html
+