Bug 1236750 - Add some specialized typedefs of Matrix4x4 to represent layer transform matrices. r=kats draft
authorBotond Ballo <botond@mozilla.com>
Wed, 06 Jan 2016 18:56:25 -0500
changeset 319429 3cfbdf6de595324bcbafa58dcbc35ea080b96f89
parent 319428 ae2a5cab2c78523a236e93abcce2871b4aa39f96
child 319430 a8b991a115b6374c7df774ae4bcbeca2cd4a645a
push id9040
push userbballo@mozilla.com
push dateWed, 06 Jan 2016 23:57:33 +0000
reviewerskats
bugs1236750
milestone45.0a1
Bug 1236750 - Add some specialized typedefs of Matrix4x4 to represent layer transform matrices. r=kats Also add a related PixelCastJustification and a utility function.
gfx/layers/LayersTypes.h
gfx/layers/apz/src/APZUtils.h
layout/base/UnitTransforms.h
--- a/gfx/layers/LayersTypes.h
+++ b/gfx/layers/LayersTypes.h
@@ -10,16 +10,17 @@
 
 #ifdef MOZ_WIDGET_GONK
 #include <utils/RefBase.h>
 #if ANDROID_VERSION >= 21
 #include <utils/NativeHandle.h>
 #endif
 #endif
 
+#include "Units.h"
 #include "mozilla/gfx/Point.h"          // for IntPoint
 #include "mozilla/TypedEnumBits.h"
 #include "nsRegion.h"
 
 #include <stdio.h>            // FILE
 #include "mozilla/Logging.h"            // for PR_LOG
 
 #ifndef MOZ_LAYERS_HAVE_LOG
@@ -280,12 +281,28 @@ operator|=(EventRegionsOverride& a, Even
 }
 
 // Flags used as an argument to functions that dump textures.
 enum TextureDumpMode {
   Compress,      // dump texture with LZ4 compression
   DoNotCompress  // dump texture uncompressed
 };
 
+// Some specialized typedefs of Matrix4x4Typed.
+typedef gfx::Matrix4x4Typed<LayerPixel, CSSTransformedLayerPixel> CSSTransformMatrix;
+// Several different async transforms can contribute to a layer's transform
+// (specifically, an async animation can contribute a transform, and each APZC
+// that scrolls a layer can contribute async scroll/zoom and overscroll
+// transforms).
+// To try to model this with typed units, we represent individual async
+// transforms as ParentLayer -> ParentLayer transforms (aliased as
+// AsyncTransformComponentMatrix), and we represent the product of all of them
+// as a CSSTransformLayer -> ParentLayer transform (aliased as
+// AsyncTransformMatrix). To create an AsyncTransformMatrix from component
+// matrices, a ViewAs operation is needed. A MultipleAsyncTransforms
+// PixelCastJustification is provided for this purpose.
+typedef gfx::Matrix4x4Typed<ParentLayerPixel, ParentLayerPixel> AsyncTransformComponentMatrix;
+typedef gfx::Matrix4x4Typed<CSSTransformedLayerPixel, ParentLayerPixel> AsyncTransformMatrix;
+
 } // namespace layers
 } // namespace mozilla
 
 #endif /* GFX_LAYERSTYPES_H */
--- a/gfx/layers/apz/src/APZUtils.h
+++ b/gfx/layers/apz/src/APZUtils.h
@@ -3,16 +3,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_layers_APZUtils_h
 #define mozilla_layers_APZUtils_h
 
 #include <stdint.h>                     // for uint32_t
+#include "LayersTypes.h"
+#include "UnitTransforms.h"
 #include "mozilla/gfx/Point.h"
 #include "mozilla/FloatingPoint.h"
 
 namespace mozilla {
 namespace layers {
 
 enum HitTestResult {
   HitNothing,
@@ -56,12 +58,22 @@ const float COORDINATE_EPSILON = 0.01f;
 
 template <typename Units>
 static bool IsZero(const gfx::PointTyped<Units>& aPoint)
 {
   return FuzzyEqualsAdditive(aPoint.x, 0.0f, COORDINATE_EPSILON)
       && FuzzyEqualsAdditive(aPoint.y, 0.0f, COORDINATE_EPSILON);
 }
 
+// Deem an AsyncTransformComponentMatrix (obtained by multiplying together
+// one or more AsyncTarnsformComponentMatrix objects) as constituting a
+// complete async transform.
+inline AsyncTransformMatrix
+CompleteAsyncTransform(const AsyncTransformComponentMatrix& aMatrix)
+{
+  return ViewAs<AsyncTransformMatrix>(aMatrix,
+      PixelCastJustification::MultipleAsyncTransforms);
+}
+
 } // namespace layers
 } // namespace mozilla
 
 #endif // mozilla_layers_APZUtils_h
--- a/layout/base/UnitTransforms.h
+++ b/layout/base/UnitTransforms.h
@@ -42,17 +42,21 @@ enum class PixelCastJustification : uint
   // reference point as a screen point. The reverse is useful when synthetically
   // created WidgetEvents need to be converted back to InputData.
   LayoutDeviceIsScreenForUntransformedEvent,
   // Similar to LayoutDeviceIsScreenForUntransformedEvent, PBrowser handles
   // some widget/tab dimension information as the OS does -- in screen units.
   LayoutDeviceIsScreenForTabDims,
   // A combination of LayoutDeviceIsScreenForBounds and
   // ScreenIsParentLayerForRoot, which is how we're using it.
-  LayoutDeviceIsParentLayerForRCDRSF
+  LayoutDeviceIsParentLayerForRCDRSF,
+  // Used to treat the product of AsyncTransformComponentMatrix objects
+  // as an AsyncTransformMatrix. See the definitions of these matrices in
+  // LayersTypes.h for details.
+  MultipleAsyncTransforms
 };
 
 template <class TargetUnits, class SourceUnits>
 gfx::SizeTyped<TargetUnits> ViewAs(const gfx::SizeTyped<SourceUnits>& aSize, PixelCastJustification) {
   return gfx::SizeTyped<TargetUnits>(aSize.width, aSize.height);
 }
 template <class TargetUnits, class SourceUnits>
 gfx::IntSizeTyped<TargetUnits> ViewAs(const gfx::IntSizeTyped<SourceUnits>& aSize, PixelCastJustification) {