Bug 1359748 - Extract a WebRenderLayer.{h,cpp} from WebRenderLayerManager.{h,cpp}. r?jrmuizel draft
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 26 Apr 2017 06:10:36 -0400
changeset 568625 b4f0c79a07af4778be1af3750ea7ee0dd6299da3
parent 568624 1237124c6c9a9073a8c88a5d91b1dfba7b6bebba
child 625974 abcc6a24689b0c176342d55fdd0bb95dbed3155f
push id55924
push userkgupta@mozilla.com
push dateWed, 26 Apr 2017 11:09:37 +0000
reviewersjrmuizel
bugs1359748
milestone55.0a1
Bug 1359748 - Extract a WebRenderLayer.{h,cpp} from WebRenderLayerManager.{h,cpp}. r?jrmuizel Other than moving the code into new files, this just cleans up includes in the modified and dependent files. MozReview-Commit-ID: 3pamZZMEMSh
gfx/layers/moz.build
gfx/layers/wr/WebRenderCanvasLayer.h
gfx/layers/wr/WebRenderColorLayer.h
gfx/layers/wr/WebRenderContainerLayer.h
gfx/layers/wr/WebRenderDisplayItemLayer.h
gfx/layers/wr/WebRenderImageLayer.h
gfx/layers/wr/WebRenderLayer.cpp
gfx/layers/wr/WebRenderLayer.h
gfx/layers/wr/WebRenderLayerManager.cpp
gfx/layers/wr/WebRenderLayerManager.h
gfx/layers/wr/WebRenderPaintedLayer.h
gfx/layers/wr/WebRenderTextLayer.h
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -199,16 +199,17 @@ EXPORTS.mozilla.layers += [
     'TextureWrapperImage.h',
     'TransactionIdAllocator.h',
     'UpdateImageHelper.h',
     'wr/WebRenderBridgeChild.h',
     'wr/WebRenderBridgeParent.h',
     'wr/WebRenderCompositableHolder.h',
     'wr/WebRenderDisplayItemLayer.h',
     'wr/WebRenderImageHost.h',
+    'wr/WebRenderLayer.h',
     'wr/WebRenderLayerManager.h',
     'wr/WebRenderLayersLogging.h',
     'wr/WebRenderMessageUtils.h',
     'wr/WebRenderScrollData.h',
     'wr/WebRenderScrollDataWrapper.h',
     'wr/WebRenderTextureHost.h',
 ]
 
@@ -396,16 +397,17 @@ UNIFIED_SOURCES += [
     'wr/WebRenderBridgeParent.cpp',
     'wr/WebRenderCanvasLayer.cpp',
     'wr/WebRenderColorLayer.cpp',
     'wr/WebRenderCompositableHolder.cpp',
     'wr/WebRenderContainerLayer.cpp',
     'wr/WebRenderDisplayItemLayer.cpp',
     'wr/WebRenderImageHost.cpp',
     'wr/WebRenderImageLayer.cpp',
+    'wr/WebRenderLayer.cpp',
     'wr/WebRenderLayerManager.cpp',
     'wr/WebRenderLayersLogging.cpp',
     'wr/WebRenderPaintedLayer.cpp',
     'wr/WebRenderScrollData.cpp',
     'wr/WebRenderTextLayer.cpp',
     # XXX here are some unified build error.
     #'wr/WebRenderTextureHost.cpp'
 ]
--- a/gfx/layers/wr/WebRenderCanvasLayer.h
+++ b/gfx/layers/wr/WebRenderCanvasLayer.h
@@ -1,18 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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 GFX_WEBRENDERCANVASLAYER_H
 #define GFX_WEBRENDERCANVASLAYER_H
 
+#include "mozilla/layers/WebRenderLayer.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
 #include "ShareableCanvasLayer.h"
-#include "WebRenderLayerManager.h"
 
 namespace mozilla {
 namespace gfx {
 class SourceSurface;
 }; // namespace gfx
 
 namespace layers {
 
--- a/gfx/layers/wr/WebRenderColorLayer.h
+++ b/gfx/layers/wr/WebRenderColorLayer.h
@@ -2,17 +2,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 GFX_WEBRENDERCOLORLAYER_H
 #define GFX_WEBRENDERCOLORLAYER_H
 
 #include "Layers.h"
-#include "WebRenderLayerManager.h"
+#include "mozilla/layers/WebRenderLayer.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
 
 namespace mozilla {
 namespace layers {
 
 class WebRenderColorLayer : public WebRenderLayer,
                             public ColorLayer {
 public:
   explicit WebRenderColorLayer(WebRenderLayerManager* aLayerManager)
--- a/gfx/layers/wr/WebRenderContainerLayer.h
+++ b/gfx/layers/wr/WebRenderContainerLayer.h
@@ -3,17 +3,18 @@
  * 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 GFX_WEBRENDERCONTAINERLAYER_H
 #define GFX_WEBRENDERCONTAINERLAYER_H
 
 #include "gfxPrefs.h"
 #include "Layers.h"
-#include "WebRenderLayerManager.h"
+#include "mozilla/layers/WebRenderLayer.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
 
 namespace mozilla {
 namespace layers {
 
 class WebRenderContainerLayer : public WebRenderLayer,
                                 public ContainerLayer
 {
 public:
--- a/gfx/layers/wr/WebRenderDisplayItemLayer.h
+++ b/gfx/layers/wr/WebRenderDisplayItemLayer.h
@@ -4,19 +4,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_WEBRENDERDISPLAYITEMLAYER_H
 #define GFX_WEBRENDERDISPLAYITEMLAYER_H
 
 #include "Layers.h"
 #include "mozilla/layers/ImageClient.h"
 #include "mozilla/layers/PWebRenderBridgeChild.h"
+#include "mozilla/layers/WebRenderLayer.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/webrender/WebRenderTypes.h"
-#include "WebRenderLayerManager.h"
 
 namespace mozilla {
 namespace layers {
 
 class WebRenderDisplayItemLayer : public WebRenderLayer,
                                   public DisplayItemLayer {
 public:
   explicit WebRenderDisplayItemLayer(WebRenderLayerManager* aLayerManager)
--- a/gfx/layers/wr/WebRenderImageLayer.h
+++ b/gfx/layers/wr/WebRenderImageLayer.h
@@ -2,17 +2,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 GFX_WEBRENDERIMAGELAYER_H
 #define GFX_WEBRENDERIMAGELAYER_H
 
 #include "ImageLayers.h"
-#include "WebRenderLayerManager.h"
+#include "mozilla/layers/WebRenderLayer.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
 
 namespace mozilla {
 namespace layers {
 
 class ImageClient;
 
 class WebRenderImageLayer : public WebRenderLayer,
                             public ImageLayer {
new file mode 100644
--- /dev/null
+++ b/gfx/layers/wr/WebRenderLayer.cpp
@@ -0,0 +1,230 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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/. */
+
+#include "WebRenderLayer.h"
+
+#include "gfxPrefs.h"
+#include "LayersLogging.h"
+#include "mozilla/layers/ImageClient.h"
+#include "mozilla/layers/WebRenderBridgeChild.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
+#include "nsThreadUtils.h"
+
+namespace mozilla {
+
+using namespace gfx;
+
+namespace layers {
+
+WebRenderLayerManager*
+WebRenderLayer::WrManager()
+{
+  return static_cast<WebRenderLayerManager*>(GetLayer()->Manager());
+}
+
+WebRenderBridgeChild*
+WebRenderLayer::WrBridge()
+{
+  return WrManager()->WrBridge();
+}
+
+WrImageKey
+WebRenderLayer::GetImageKey()
+{
+  WrImageKey key;
+  key.mNamespace = WrBridge()->GetNamespace();
+  key.mHandle = WrBridge()->GetNextResourceId();
+  return key;
+}
+
+Rect
+WebRenderLayer::RelativeToVisible(Rect aRect)
+{
+  IntRect bounds = GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect();
+  aRect.MoveBy(-bounds.x, -bounds.y);
+  return aRect;
+}
+
+Rect
+WebRenderLayer::RelativeToTransformedVisible(Rect aRect)
+{
+  IntRect bounds = GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect();
+  Rect transformed = GetLayer()->GetTransform().TransformBounds(IntRectToRect(bounds));
+  aRect.MoveBy(-transformed.x, -transformed.y);
+  return aRect;
+}
+
+Rect
+WebRenderLayer::ParentStackingContextBounds()
+{
+  // Walk up to find the parent stacking context. This will be created either
+  // by the nearest scrollable metrics, or by the parent layer which must be a
+  // ContainerLayer.
+  Layer* layer = GetLayer();
+  if (layer->GetParent()) {
+    return IntRectToRect(layer->GetParent()->GetVisibleRegion().GetBounds().ToUnknownRect());
+  }
+  return Rect();
+}
+
+Rect
+WebRenderLayer::RelativeToParent(Rect aRect)
+{
+  Rect parentBounds = ParentStackingContextBounds();
+  aRect.MoveBy(-parentBounds.x, -parentBounds.y);
+  return aRect;
+}
+
+Point
+WebRenderLayer::GetOffsetToParent()
+{
+  Rect parentBounds = ParentStackingContextBounds();
+  return parentBounds.TopLeft();
+}
+
+Rect
+WebRenderLayer::VisibleBoundsRelativeToParent()
+{
+  return RelativeToParent(IntRectToRect(GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect()));
+}
+
+Rect
+WebRenderLayer::TransformedVisibleBoundsRelativeToParent()
+{
+  IntRect bounds = GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect();
+  Rect transformed = GetLayer()->GetTransform().TransformBounds(IntRectToRect(bounds));
+  return RelativeToParent(transformed);
+}
+
+Maybe<WrImageMask>
+WebRenderLayer::BuildWrMaskLayer(bool aUnapplyLayerTransform)
+{
+  if (GetLayer()->GetMaskLayer()) {
+    WebRenderLayer* maskLayer = ToWebRenderLayer(GetLayer()->GetMaskLayer());
+
+    // The size of mask layer is transformed, and we may set the layer transform
+    // to wr stacking context. So we should apply inverse transform for mask layer
+    // and reverse the offset of the stacking context.
+    gfx::Matrix4x4 transform = maskLayer->GetLayer()->GetTransform();
+    if (aUnapplyLayerTransform) {
+      gfx::Rect bounds = IntRectToRect(GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect());
+      transform = transform.PreTranslate(-bounds.x, -bounds.y, 0);
+      transform = transform * GetLayer()->GetTransform().Inverse();
+    }
+
+    return maskLayer->RenderMaskLayer(transform);
+  }
+
+  return Nothing();
+}
+
+gfx::Rect
+WebRenderLayer::GetWrBoundsRect()
+{
+  LayerIntRect bounds = GetLayer()->GetVisibleRegion().GetBounds();
+  return Rect(0, 0, bounds.width, bounds.height);
+}
+
+gfx::Rect
+WebRenderLayer::GetWrClipRect(gfx::Rect& aRect)
+{
+  gfx::Rect clip;
+  Layer* layer = GetLayer();
+  Matrix4x4 transform = layer->GetTransform();
+  if (layer->GetClipRect().isSome()) {
+    clip = RelativeToVisible(transform.Inverse().TransformBounds(
+             IntRectToRect(layer->GetClipRect().ref().ToUnknownRect()))
+           );
+  } else {
+    clip = aRect;
+  }
+
+  return clip;
+}
+
+gfx::Matrix4x4
+WebRenderLayer::GetWrBoundTransform()
+{
+  gfx::Matrix4x4 transform = GetLayer()->GetTransform();
+  transform._41 = 0.0f;
+  transform._42 = 0.0f;
+  transform._43 = 0.0f;
+  return transform;
+}
+
+gfx::Rect
+WebRenderLayer::GetWrRelBounds()
+{
+  gfx::Rect bounds = IntRectToRect(GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect());
+  gfx::Matrix4x4 transform = GetWrBoundTransform();
+  if (!transform.IsIdentity()) {
+    // WR will only apply the 'translate' of the transform, so we need to do the scale/rotation manually.
+    bounds.MoveTo(transform.TransformPoint(bounds.TopLeft()));
+  }
+
+  return RelativeToParent(bounds);
+}
+
+Maybe<wr::ImageKey>
+WebRenderLayer::UpdateImageKey(ImageClientSingle* aImageClient,
+                               ImageContainer* aContainer,
+                               Maybe<wr::ImageKey>& aOldKey,
+                               wr::ExternalImageId& aExternalImageId)
+{
+  MOZ_ASSERT(aImageClient);
+  MOZ_ASSERT(aContainer);
+
+  uint32_t oldCounter = aImageClient->GetLastUpdateGenerationCounter();
+
+  bool ret = aImageClient->UpdateImage(aContainer, /* unused */0);
+  if (!ret || aImageClient->IsEmpty()) {
+    // Delete old key
+    if (aOldKey.isSome()) {
+      WrManager()->AddImageKeyForDiscard(aOldKey.value());
+    }
+    return Nothing();
+  }
+
+  // Reuse old key if generation is not updated.
+  if (oldCounter == aImageClient->GetLastUpdateGenerationCounter() && aOldKey.isSome()) {
+    return aOldKey;
+  }
+
+  // Delete old key, we are generating a new key.
+  if (aOldKey.isSome()) {
+    WrManager()->AddImageKeyForDiscard(aOldKey.value());
+  }
+
+  WrImageKey key = GetImageKey();
+  WrBridge()->AddWebRenderParentCommand(OpAddExternalImage(aExternalImageId, key));
+  return Some(key);
+}
+
+void
+WebRenderLayer::DumpLayerInfo(const char* aLayerType, gfx::Rect& aRect)
+{
+  if (!gfxPrefs::LayersDump()) {
+    return;
+  }
+
+  Matrix4x4 transform = GetLayer()->GetTransform();
+  Rect clip = GetWrClipRect(aRect);
+  Rect relBounds = GetWrRelBounds();
+  Rect overflow(0, 0, relBounds.width, relBounds.height);
+  WrMixBlendMode mixBlendMode = wr::ToWrMixBlendMode(GetLayer()->GetMixBlendMode());
+
+  printf_stderr("%s %p using bounds=%s, overflow=%s, transform=%s, rect=%s, clip=%s, mix-blend-mode=%s\n",
+                aLayerType,
+                GetLayer(),
+                Stringify(relBounds).c_str(),
+                Stringify(overflow).c_str(),
+                Stringify(transform).c_str(),
+                Stringify(aRect).c_str(),
+                Stringify(clip).c_str(),
+                Stringify(mixBlendMode).c_str());
+}
+
+} // namespace layers
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/gfx/layers/wr/WebRenderLayer.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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 GFX_WEBRENDERLAYER_H
+#define GFX_WEBRENDERLAYER_H
+
+#include "Layers.h"
+#include "mozilla/webrender/WebRenderTypes.h"
+#include "mozilla/webrender/WebRenderAPI.h"
+
+namespace mozilla {
+namespace layers {
+
+class ImageClientSingle;
+class WebRenderBridgeChild;
+class WebRenderLayerManager;
+
+class WebRenderLayer
+{
+public:
+  virtual Layer* GetLayer() = 0;
+  virtual void RenderLayer(wr::DisplayListBuilder& aBuilder) = 0;
+  virtual Maybe<WrImageMask> RenderMaskLayer(const gfx::Matrix4x4& aTransform)
+  {
+    MOZ_ASSERT(false);
+    return Nothing();
+  }
+
+  virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() { return nullptr; }
+  static inline WebRenderLayer*
+  ToWebRenderLayer(Layer* aLayer)
+  {
+    return static_cast<WebRenderLayer*>(aLayer->ImplData());
+  }
+
+  Maybe<wr::ImageKey> UpdateImageKey(ImageClientSingle* aImageClient,
+                                     ImageContainer* aContainer,
+                                     Maybe<wr::ImageKey>& aOldKey,
+                                     wr::ExternalImageId& aExternalImageId);
+
+  WebRenderLayerManager* WrManager();
+  WebRenderBridgeChild* WrBridge();
+  WrImageKey GetImageKey();
+
+  gfx::Rect RelativeToVisible(gfx::Rect aRect);
+  gfx::Rect RelativeToTransformedVisible(gfx::Rect aRect);
+  gfx::Rect ParentStackingContextBounds();
+  gfx::Rect RelativeToParent(gfx::Rect aRect);
+  gfx::Rect VisibleBoundsRelativeToParent();
+  gfx::Point GetOffsetToParent();
+  gfx::Rect TransformedVisibleBoundsRelativeToParent();
+protected:
+  gfx::Rect GetWrBoundsRect();
+  gfx::Rect GetWrRelBounds();
+  gfx::Rect GetWrClipRect(gfx::Rect& aRect);
+  gfx::Matrix4x4 GetWrBoundTransform();
+  void DumpLayerInfo(const char* aLayerType, gfx::Rect& aRect);
+  Maybe<WrImageMask> BuildWrMaskLayer(bool aUnapplyLayerTransform);
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif /* GFX_WEBRENDERLAYER_H */
--- a/gfx/layers/wr/WebRenderLayerManager.cpp
+++ b/gfx/layers/wr/WebRenderLayerManager.cpp
@@ -1,249 +1,34 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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/. */
 
 #include "WebRenderLayerManager.h"
 
-#include "apz/src/AsyncPanZoomController.h"
 #include "gfxPrefs.h"
 #include "LayersLogging.h"
-#include "mozilla/dom/TabChild.h"
-#include "mozilla/layers/APZCTreeManager.h"
-#include "mozilla/layers/AsyncCompositionManager.h"
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/TextureClient.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
-#include "mozilla/widget/PlatformWidgetTypes.h"
-#include "nsThreadUtils.h"
-#include "TreeTraversal.h"
 #include "WebRenderCanvasLayer.h"
 #include "WebRenderColorLayer.h"
 #include "WebRenderContainerLayer.h"
 #include "WebRenderImageLayer.h"
 #include "WebRenderPaintedLayer.h"
 #include "WebRenderTextLayer.h"
 #include "WebRenderDisplayItemLayer.h"
 
 namespace mozilla {
 
 using namespace gfx;
 
 namespace layers {
 
-WebRenderLayerManager*
-WebRenderLayer::WrManager()
-{
-  return static_cast<WebRenderLayerManager*>(GetLayer()->Manager());
-}
-
-WebRenderBridgeChild*
-WebRenderLayer::WrBridge()
-{
-  return WrManager()->WrBridge();
-}
-
-WrImageKey
-WebRenderLayer::GetImageKey()
-{
-  WrImageKey key;
-  key.mNamespace = WrBridge()->GetNamespace();
-  key.mHandle = WrBridge()->GetNextResourceId();
-  return key;
-}
-
-Rect
-WebRenderLayer::RelativeToVisible(Rect aRect)
-{
-  IntRect bounds = GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect();
-  aRect.MoveBy(-bounds.x, -bounds.y);
-  return aRect;
-}
-
-Rect
-WebRenderLayer::RelativeToTransformedVisible(Rect aRect)
-{
-  IntRect bounds = GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect();
-  Rect transformed = GetLayer()->GetTransform().TransformBounds(IntRectToRect(bounds));
-  aRect.MoveBy(-transformed.x, -transformed.y);
-  return aRect;
-}
-
-Rect
-WebRenderLayer::ParentStackingContextBounds()
-{
-  // Walk up to find the parent stacking context. This will be created either
-  // by the nearest scrollable metrics, or by the parent layer which must be a
-  // ContainerLayer.
-  Layer* layer = GetLayer();
-  if (layer->GetParent()) {
-    return IntRectToRect(layer->GetParent()->GetVisibleRegion().GetBounds().ToUnknownRect());
-  }
-  return Rect();
-}
-
-Rect
-WebRenderLayer::RelativeToParent(Rect aRect)
-{
-  Rect parentBounds = ParentStackingContextBounds();
-  aRect.MoveBy(-parentBounds.x, -parentBounds.y);
-  return aRect;
-}
-
-Point
-WebRenderLayer::GetOffsetToParent()
-{
-  Rect parentBounds = ParentStackingContextBounds();
-  return parentBounds.TopLeft();
-}
-
-Rect
-WebRenderLayer::VisibleBoundsRelativeToParent()
-{
-  return RelativeToParent(IntRectToRect(GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect()));
-}
-
-Rect
-WebRenderLayer::TransformedVisibleBoundsRelativeToParent()
-{
-  IntRect bounds = GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect();
-  Rect transformed = GetLayer()->GetTransform().TransformBounds(IntRectToRect(bounds));
-  return RelativeToParent(transformed);
-}
-
-Maybe<WrImageMask>
-WebRenderLayer::BuildWrMaskLayer(bool aUnapplyLayerTransform)
-{
-  if (GetLayer()->GetMaskLayer()) {
-    WebRenderLayer* maskLayer = ToWebRenderLayer(GetLayer()->GetMaskLayer());
-
-    // The size of mask layer is transformed, and we may set the layer transform
-    // to wr stacking context. So we should apply inverse transform for mask layer
-    // and reverse the offset of the stacking context.
-    gfx::Matrix4x4 transform = maskLayer->GetLayer()->GetTransform();
-    if (aUnapplyLayerTransform) {
-      gfx::Rect bounds = IntRectToRect(GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect());
-      transform = transform.PreTranslate(-bounds.x, -bounds.y, 0);
-      transform = transform * GetLayer()->GetTransform().Inverse();
-    }
-
-    return maskLayer->RenderMaskLayer(transform);
-  }
-
-  return Nothing();
-}
-
-gfx::Rect
-WebRenderLayer::GetWrBoundsRect()
-{
-  LayerIntRect bounds = GetLayer()->GetVisibleRegion().GetBounds();
-  return Rect(0, 0, bounds.width, bounds.height);
-}
-
-gfx::Rect
-WebRenderLayer::GetWrClipRect(gfx::Rect& aRect)
-{
-  gfx::Rect clip;
-  Layer* layer = GetLayer();
-  Matrix4x4 transform = layer->GetTransform();
-  if (layer->GetClipRect().isSome()) {
-    clip = RelativeToVisible(transform.Inverse().TransformBounds(
-             IntRectToRect(layer->GetClipRect().ref().ToUnknownRect()))
-           );
-  } else {
-    clip = aRect;
-  }
-
-  return clip;
-}
-
-gfx::Matrix4x4
-WebRenderLayer::GetWrBoundTransform()
-{
-  gfx::Matrix4x4 transform = GetLayer()->GetTransform();
-  transform._41 = 0.0f;
-  transform._42 = 0.0f;
-  transform._43 = 0.0f;
-  return transform;
-}
-
-gfx::Rect
-WebRenderLayer::GetWrRelBounds()
-{
-  gfx::Rect bounds = IntRectToRect(GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect());
-  gfx::Matrix4x4 transform = GetWrBoundTransform();
-  if (!transform.IsIdentity()) {
-    // WR will only apply the 'translate' of the transform, so we need to do the scale/rotation manually.
-    bounds.MoveTo(transform.TransformPoint(bounds.TopLeft()));
-  }
-
-  return RelativeToParent(bounds);
-}
-
-Maybe<wr::ImageKey>
-WebRenderLayer::UpdateImageKey(ImageClientSingle* aImageClient,
-                               ImageContainer* aContainer,
-                               Maybe<wr::ImageKey>& aOldKey,
-                               wr::ExternalImageId& aExternalImageId)
-{
-  MOZ_ASSERT(aImageClient);
-  MOZ_ASSERT(aContainer);
-
-  uint32_t oldCounter = aImageClient->GetLastUpdateGenerationCounter();
-
-  bool ret = aImageClient->UpdateImage(aContainer, /* unused */0);
-  if (!ret || aImageClient->IsEmpty()) {
-    // Delete old key
-    if (aOldKey.isSome()) {
-      WrManager()->AddImageKeyForDiscard(aOldKey.value());
-    }
-    return Nothing();
-  }
-
-  // Reuse old key if generation is not updated.
-  if (oldCounter == aImageClient->GetLastUpdateGenerationCounter() && aOldKey.isSome()) {
-    return aOldKey;
-  }
-
-  // Delete old key, we are generating a new key.
-  if (aOldKey.isSome()) {
-    WrManager()->AddImageKeyForDiscard(aOldKey.value());
-  }
-
-  WrImageKey key = GetImageKey();
-  WrBridge()->AddWebRenderParentCommand(OpAddExternalImage(aExternalImageId, key));
-  return Some(key);
-}
-
-void
-WebRenderLayer::DumpLayerInfo(const char* aLayerType, gfx::Rect& aRect)
-{
-  if (!gfxPrefs::LayersDump()) {
-    return;
-  }
-
-  Matrix4x4 transform = GetLayer()->GetTransform();
-  Rect clip = GetWrClipRect(aRect);
-  Rect relBounds = GetWrRelBounds();
-  Rect overflow(0, 0, relBounds.width, relBounds.height);
-  WrMixBlendMode mixBlendMode = wr::ToWrMixBlendMode(GetLayer()->GetMixBlendMode());
-
-  printf_stderr("%s %p using bounds=%s, overflow=%s, transform=%s, rect=%s, clip=%s, mix-blend-mode=%s\n",
-                aLayerType,
-                GetLayer(),
-                Stringify(relBounds).c_str(),
-                Stringify(overflow).c_str(),
-                Stringify(transform).c_str(),
-                Stringify(aRect).c_str(),
-                Stringify(clip).c_str(),
-                Stringify(mixBlendMode).c_str());
-}
-
 WebRenderLayerManager::WebRenderLayerManager(nsIWidget* aWidget)
   : mWidget(aWidget)
   , mLatestTransactionId(0)
   , mNeedsComposite(false)
   , mIsFirstPaint(false)
   , mTarget(nullptr)
 {
   MOZ_COUNT_CTOR(WebRenderLayerManager);
--- a/gfx/layers/wr/WebRenderLayerManager.h
+++ b/gfx/layers/wr/WebRenderLayerManager.h
@@ -2,77 +2,28 @@
  * 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 GFX_WEBRENDERLAYERMANAGER_H
 #define GFX_WEBRENDERLAYERMANAGER_H
 
 #include "Layers.h"
-#include "mozilla/layers/CompositorController.h"
 #include "mozilla/layers/TransactionIdAllocator.h"
-#include "mozilla/webrender/webrender_ffi.h"
 #include "mozilla/webrender/WebRenderTypes.h"
-#include "mozilla/webrender/WebRenderAPI.h"
 
 class nsIWidget;
 
 namespace mozilla {
 namespace layers {
 
 class CompositorBridgeChild;
-class ImageClientSingle;
 class KnowsCompositor;
 class PCompositorBridgeChild;
 class WebRenderBridgeChild;
-class WebRenderLayerManager;
-class APZCTreeManager;
-
-class WebRenderLayer
-{
-public:
-  virtual Layer* GetLayer() = 0;
-  virtual void RenderLayer(wr::DisplayListBuilder& aBuilder) = 0;
-  virtual Maybe<WrImageMask> RenderMaskLayer(const gfx::Matrix4x4& aTransform)
-  {
-    MOZ_ASSERT(false);
-    return Nothing();
-  }
-
-  virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() { return nullptr; }
-  static inline WebRenderLayer*
-  ToWebRenderLayer(Layer* aLayer)
-  {
-    return static_cast<WebRenderLayer*>(aLayer->ImplData());
-  }
-
-  Maybe<wr::ImageKey> UpdateImageKey(ImageClientSingle* aImageClient,
-                                     ImageContainer* aContainer,
-                                     Maybe<wr::ImageKey>& aOldKey,
-                                     wr::ExternalImageId& aExternalImageId);
-
-  WebRenderLayerManager* WrManager();
-  WebRenderBridgeChild* WrBridge();
-  WrImageKey GetImageKey();
-
-  gfx::Rect RelativeToVisible(gfx::Rect aRect);
-  gfx::Rect RelativeToTransformedVisible(gfx::Rect aRect);
-  gfx::Rect ParentStackingContextBounds();
-  gfx::Rect RelativeToParent(gfx::Rect aRect);
-  gfx::Rect VisibleBoundsRelativeToParent();
-  gfx::Point GetOffsetToParent();
-  gfx::Rect TransformedVisibleBoundsRelativeToParent();
-protected:
-  gfx::Rect GetWrBoundsRect();
-  gfx::Rect GetWrRelBounds();
-  gfx::Rect GetWrClipRect(gfx::Rect& aRect);
-  gfx::Matrix4x4 GetWrBoundTransform();
-  void DumpLayerInfo(const char* aLayerType, gfx::Rect& aRect);
-  Maybe<WrImageMask> BuildWrMaskLayer(bool aUnapplyLayerTransform);
-};
 
 class WebRenderLayerManager final : public LayerManager
 {
   typedef nsTArray<RefPtr<Layer> > LayerRefArray;
 
 public:
   explicit WebRenderLayerManager(nsIWidget* aWidget);
   void Initialize(PCompositorBridgeChild* aCBChild, wr::PipelineId aLayersId, TextureFactoryIdentifier* aTextureFactoryIdentifier);
--- a/gfx/layers/wr/WebRenderPaintedLayer.h
+++ b/gfx/layers/wr/WebRenderPaintedLayer.h
@@ -4,17 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_WEBRENDERPAINTEDLAYER_H
 #define GFX_WEBRENDERPAINTEDLAYER_H
 
 #include "Layers.h"
 #include "mozilla/layers/ContentClient.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
-#include "WebRenderLayerManager.h"
+#include "mozilla/layers/WebRenderLayer.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/webrender/WebRenderTypes.h"
 
 namespace mozilla {
 namespace layers {
 
 class WebRenderPaintedLayer : public WebRenderLayer,
                               public PaintedLayer {
 public:
--- a/gfx/layers/wr/WebRenderTextLayer.h
+++ b/gfx/layers/wr/WebRenderTextLayer.h
@@ -4,17 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 #ifndef GFX_WEBRENDERTEXTLAYER_H
 #define GFX_WEBRENDERTEXTLAYER_H
 
 #include "gfxUtils.h"
 #include "Layers.h"
-#include "WebRenderLayerManager.h"
+#include "mozilla/layers/WebRenderLayer.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
 
 namespace mozilla {
 namespace layers {
 
 class WebRenderTextLayer : public WebRenderLayer,
                            public TextLayer {
 public:
     explicit WebRenderTextLayer(WebRenderLayerManager* aLayerManager)