Bug 1330480 - Move toWr* functions into WebRenderTypes.h r=gfx?
authorRyan Hunt <rhunt@eqrion.net>
Wed, 11 Jan 2017 19:53:28 -0600
changeset 459994 d9361bf7a173d95afd1f399ca5ab78ecec0f56fd
parent 459993 9f959dc40125c196d38e2356495d30a08267210b
child 459995 af051c2e5189e0af440bd03ac8d68cdf7e8e39ab
push id41343
push userkgupta@mozilla.com
push dateThu, 12 Jan 2017 20:13:44 +0000
reviewersgfx
bugs1330480
milestone53.0a1
Bug 1330480 - Move toWr* functions into WebRenderTypes.h r=gfx?
gfx/layers/wr/WebRenderBorderLayer.cpp
gfx/layers/wr/WebRenderCanvasLayer.cpp
gfx/layers/wr/WebRenderColorLayer.cpp
gfx/layers/wr/WebRenderContainerLayer.cpp
gfx/layers/wr/WebRenderImageLayer.cpp
gfx/layers/wr/WebRenderLayerManager.cpp
gfx/layers/wr/WebRenderLayerManager.h
gfx/layers/wr/WebRenderPaintedLayer.cpp
gfx/layers/wr/WebRenderTextLayer.cpp
gfx/layers/wr/WebRenderTypes.h
--- a/gfx/layers/wr/WebRenderBorderLayer.cpp
+++ b/gfx/layers/wr/WebRenderBorderLayer.cpp
@@ -29,27 +29,27 @@ WebRenderBorderLayer::RenderLayer()
   }
 
   if (gfxPrefs::LayersDump()) printf_stderr("BorderLayer %p using rect:%s clip:%s\n", this, Stringify(rect).c_str(), Stringify(clip).c_str());
 
   Rect relBounds = TransformedVisibleBoundsRelativeToParent();
   Rect overflow(0, 0, relBounds.width, relBounds.height);
   Matrix4x4 transform;// = GetTransform();
   WRBridge()->AddWebRenderCommand(
-      OpDPPushStackingContext(toWrRect(relBounds), toWrRect(overflow), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
+      OpDPPushStackingContext(ToWRRect(relBounds), ToWRRect(overflow), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
 
   WRBridge()->AddWebRenderCommand(
-    OpDPPushBorder(toWrRect(rect), toWrRect(clip),
-                   toWrBorderSide(mWidths[0], mColors[0]),
-                   toWrBorderSide(mWidths[1], mColors[1]),
-                   toWrBorderSide(mWidths[2], mColors[2]),
-                   toWrBorderSide(mWidths[3], mColors[3]),
-                   toWrLayoutSize(mCorners[0]),
-                   toWrLayoutSize(mCorners[1]),
-                   toWrLayoutSize(mCorners[3]),
-                   toWrLayoutSize(mCorners[2])));
+    OpDPPushBorder(ToWRRect(rect), ToWRRect(clip),
+                   ToWRBorderSide(mWidths[0], mColors[0]),
+                   ToWRBorderSide(mWidths[1], mColors[1]),
+                   ToWRBorderSide(mWidths[2], mColors[2]),
+                   ToWRBorderSide(mWidths[3], mColors[3]),
+                   ToWRLayoutSize(mCorners[0]),
+                   ToWRLayoutSize(mCorners[1]),
+                   ToWRLayoutSize(mCorners[3]),
+                   ToWRLayoutSize(mCorners[2])));
   if (gfxPrefs::LayersDump()) printf_stderr("BorderLayer %p using %s as bounds/overflow, %s for transform\n", this, Stringify(relBounds).c_str(), Stringify(transform).c_str());
 
   WRBridge()->AddWebRenderCommand(OpDPPopStackingContext());
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderCanvasLayer.cpp
+++ b/gfx/layers/wr/WebRenderCanvasLayer.cpp
@@ -68,18 +68,18 @@ WebRenderCanvasLayer::RenderLayer()
       clip = RelativeToTransformedVisible(IntRectToRect(GetClipRect().ref().ToUnknownRect()));
   } else {
       clip = rect;
   }
   if (gfxPrefs::LayersDump()) printf_stderr("CanvasLayer %p using rect:%s clip:%s\n", this, Stringify(rect).c_str(), Stringify(clip).c_str());
   gfx::Rect relBounds = TransformedVisibleBoundsRelativeToParent();
   gfx::Rect overflow(0, 0, relBounds.width, relBounds.height);
   WRBridge()->AddWebRenderCommand(
-      OpDPPushStackingContext(toWrRect(relBounds), toWrRect(overflow), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
-  WRBridge()->AddWebRenderCommand(OpDPPushExternalImageId(toWrRect(rect), toWrRect(clip), Nothing(), mExternalImageId));
+      OpDPPushStackingContext(ToWRRect(relBounds), ToWRRect(overflow), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
+  WRBridge()->AddWebRenderCommand(OpDPPushExternalImageId(ToWRRect(rect), ToWRRect(clip), Nothing(), mExternalImageId));
 
   if (gfxPrefs::LayersDump()) printf_stderr("CanvasLayer %p using %s as bounds/overflow, %s for transform\n", this, Stringify(relBounds).c_str(), Stringify(transform).c_str());
   WRBridge()->AddWebRenderCommand(OpDPPopStackingContext());
 }
 
 void
 WebRenderCanvasLayer::AttachCompositable()
 {
--- a/gfx/layers/wr/WebRenderColorLayer.cpp
+++ b/gfx/layers/wr/WebRenderColorLayer.cpp
@@ -21,13 +21,13 @@ WebRenderColorLayer::RenderLayer()
   gfx::Rect clip;
   if (GetClipRect().isSome()) {
       clip = RelativeToParent(IntRectToRect(GetClipRect().ref().ToUnknownRect()));
   } else {
       clip = rect;
   }
   if (gfxPrefs::LayersDump()) printf_stderr("ColorLayer %p using rect:%s clip:%s\n", this, Stringify(rect).c_str(), Stringify(clip).c_str());
   WRBridge()->AddWebRenderCommand(
-    OpDPPushRect(toWrRect(rect), toWrRect(clip), mColor.r, mColor.g, mColor.b, mColor.a));
+    OpDPPushRect(ToWRRect(rect), ToWRRect(clip), mColor.r, mColor.g, mColor.b, mColor.a));
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderContainerLayer.cpp
+++ b/gfx/layers/wr/WebRenderContainerLayer.cpp
@@ -19,29 +19,29 @@ WebRenderContainerLayer::RenderLayer()
 
   nsTArray<LayerPolygon> children = SortChildrenBy3DZOrder(SortMode::WITHOUT_GEOMETRY);
 
   gfx::Rect relBounds = TransformedVisibleBoundsRelativeToParent();
   gfx::Matrix4x4 transform;// = GetTransform();
   if (gfxPrefs::LayersDump()) printf_stderr("ContainerLayer %p using %s as bounds/overflow, %s as transform\n", this, Stringify(relBounds).c_str(), Stringify(transform).c_str());
 
   WRBridge()->AddWebRenderCommand(
-    OpDPPushStackingContext(toWrRect(relBounds), toWrRect(relBounds), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
+    OpDPPushStackingContext(ToWRRect(relBounds), ToWRRect(relBounds), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
   for (LayerPolygon& child : children) {
     ToWebRenderLayer(child.layer)->RenderLayer();
   }
   WRBridge()->AddWebRenderCommand(
     OpDPPopStackingContext());
 }
 
 void
 WebRenderRefLayer::RenderLayer()
 {
   WRScrollFrameStackingContextGenerator scrollFrames(this);
 
   gfx::Rect relBounds = TransformedVisibleBoundsRelativeToParent();
   gfx::Matrix4x4 transform;// = GetTransform();
   if (gfxPrefs::LayersDump()) printf_stderr("RefLayer %p (%" PRIu64 ") using %s as bounds/overflow, %s as transform\n", this, mId, Stringify(relBounds).c_str(), Stringify(transform).c_str());
-  WRBridge()->AddWebRenderCommand(OpDPPushIframe(toWrRect(relBounds), toWrRect(relBounds), mId));
+  WRBridge()->AddWebRenderCommand(OpDPPushIframe(ToWRRect(relBounds), ToWRRect(relBounds), mId));
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderImageLayer.cpp
+++ b/gfx/layers/wr/WebRenderImageLayer.cpp
@@ -138,19 +138,19 @@ WebRenderImageLayer::RenderLayer()
   } else {
       clip = rect;
   }
   if (gfxPrefs::LayersDump()) printf_stderr("ImageLayer %p using rect:%s clip:%s\n", this, Stringify(rect).c_str(), Stringify(clip).c_str());
   Rect relBounds = TransformedVisibleBoundsRelativeToParent();
   Rect overflow(0, 0, relBounds.width, relBounds.height);
   Matrix4x4 transform;// = GetTransform();
   WRBridge()->AddWebRenderCommand(
-    OpDPPushStackingContext(toWrRect(relBounds), toWrRect(overflow), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
+    OpDPPushStackingContext(ToWRRect(relBounds), ToWRRect(overflow), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
 
-  WRBridge()->AddWebRenderCommand(OpDPPushExternalImageId(toWrRect(rect), toWrRect(clip), Nothing(), mExternalImageId));
+  WRBridge()->AddWebRenderCommand(OpDPPushExternalImageId(ToWRRect(rect), ToWRRect(clip), Nothing(), mExternalImageId));
 
 
   if (gfxPrefs::LayersDump()) printf_stderr("ImageLayer %p using %s as bounds/overflow, %s for transform\n", this, Stringify(relBounds).c_str(), Stringify(transform).c_str());
   WRBridge()->AddWebRenderCommand(OpDPPopStackingContext());
 
   //mContainer->SetImageFactory(originalIF);
 }
 
--- a/gfx/layers/wr/WebRenderLayerManager.cpp
+++ b/gfx/layers/wr/WebRenderLayerManager.cpp
@@ -115,17 +115,17 @@ WRScrollFrameStackingContextGenerator::W
     // on the scroll offset, we'd fail those checks.
     overflow.MoveBy(bounds.x - scrollPos.x, bounds.y - scrollPos.y);
     if (gfxPrefs::LayersDump()) {
       printf_stderr("Pushing stacking context id %" PRIu64 " with bounds=%s overflow=%s\n",
         fm.GetScrollId(), Stringify(bounds).c_str(), Stringify(overflow).c_str());
     }
 
     mLayer->WRBridge()->AddWebRenderCommand(
-      OpDPPushStackingContext(toWrRect(bounds), toWrRect(overflow), Nothing(), identity, fm.GetScrollId()));
+      OpDPPushStackingContext(ToWRRect(bounds), ToWRRect(overflow), Nothing(), identity, fm.GetScrollId()));
   }
 }
 
 WRScrollFrameStackingContextGenerator::~WRScrollFrameStackingContextGenerator()
 {
   Layer* layer = mLayer->GetLayer();
   for (size_t i = 0; i < layer->GetScrollMetadataCount(); i++) {
     const FrameMetrics& fm = layer->GetFrameMetrics(i);
@@ -146,17 +146,17 @@ WebRenderLayerManager::WebRenderLayerMan
   MOZ_COUNT_CTOR(WebRenderLayerManager);
 }
 
 KnowsCompositor*
 WebRenderLayerManager::AsKnowsCompositor()
 {
   return mWRChild;
 }
-  
+
 void
 WebRenderLayerManager::Initialize(PCompositorBridgeChild* aCBChild,
                                   uint64_t aLayersId,
                                   TextureFactoryIdentifier* aTextureFactoryIdentifier)
 {
   MOZ_ASSERT(mWRChild == nullptr);
   MOZ_ASSERT(aTextureFactoryIdentifier);
 
--- a/gfx/layers/wr/WebRenderLayerManager.h
+++ b/gfx/layers/wr/WebRenderLayerManager.h
@@ -15,62 +15,16 @@ class nsIWidget;
 
 namespace mozilla {
 namespace layers {
 
 class CompositorBridgeChild;
 class KnowsCompositor;
 class PCompositorBridgeChild;
 class WebRenderBridgeChild;
-
-static inline WRColor toWrColor(const gfx::Color& color)
-{
-  WRColor c;
-  c.r = color.r;
-  c.g = color.g;
-  c.b = color.b;
-  c.a = color.a;
-  return c;
-}
-
-static inline WRBorderSide toWrBorderSide(const LayerCoord width, const gfx::Color& color)
-{
-  WRBorderSide bs;
-  bs.width = width;
-  bs.color = toWrColor(color);
-  bs.style = WRBorderStyle::Solid;
-  return bs;
-}
-
-static inline WRLayoutSize toWrLayoutSize(const LayerSize size)
-{
-  WRLayoutSize ls;
-  ls.width = size.width;
-  ls.height = size.height;
-  return ls;
-}
-
-template<class T>
-static inline WRRect toWrRect(const gfx::RectTyped<T>& rect)
-{
-  WRRect r;
-  r.x = rect.x;
-  r.y = rect.y;
-  r.width = rect.width;
-  r.height = rect.height;
-  return r;
-}
-
-template<class T>
-static inline WRRect toWrRect(const gfx::IntRectTyped<T>& rect)
-{
-  return toWrRect(IntRectToRect(rect));
-}
-
-
 class WebRenderLayerManager;
 class APZCTreeManager;
 
 class WebRenderLayer
 {
 public:
   virtual Layer* GetLayer() = 0;
   virtual void RenderLayer() = 0;
--- a/gfx/layers/wr/WebRenderPaintedLayer.cpp
+++ b/gfx/layers/wr/WebRenderPaintedLayer.cpp
@@ -68,18 +68,18 @@ WebRenderPaintedLayer::RenderLayer()
   }
   if (gfxPrefs::LayersDump()) printf_stderr("PaintedLayer %p using rect:%s clip:%s\n", this, Stringify(rect).c_str(), Stringify(clip).c_str());
 
   Rect relBounds = TransformedVisibleBoundsRelativeToParent();
   Rect overflow(0, 0, relBounds.width, relBounds.height);
   Matrix4x4 transform;// = GetTransform();
 
   WRBridge()->AddWebRenderCommand(
-      OpDPPushStackingContext(toWrRect(relBounds), toWrRect(overflow), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
-  WRBridge()->AddWebRenderCommand(OpDPPushImage(toWrRect(rect), toWrRect(clip), Nothing(), key));
+      OpDPPushStackingContext(ToWRRect(relBounds), ToWRRect(overflow), Nothing(), transform, FrameMetrics::NULL_SCROLL_ID));
+  WRBridge()->AddWebRenderCommand(OpDPPushImage(ToWRRect(rect), ToWRRect(clip), Nothing(), key));
   Manager()->AddImageKeyForDiscard(key);
 
   if (gfxPrefs::LayersDump()) printf_stderr("PaintedLayer %p using %s as bounds/overflow, %s for transform\n", this, Stringify(relBounds).c_str(), Stringify(transform).c_str());
   WRBridge()->AddWebRenderCommand(OpDPPopStackingContext());
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderTextLayer.cpp
+++ b/gfx/layers/wr/WebRenderTextLayer.cpp
@@ -53,28 +53,28 @@ WebRenderTextLayer::RenderLayer()
     wr_glyphs.SetLength(mGlyphs.Length());
 
     for (size_t i = 0; i < mGlyphs.Length(); i++) {
         GlyphArray glyph_array = mGlyphs[i];
         nsTArray<Glyph>& glyphs = glyph_array.glyphs();
 
         nsTArray<WRGlyphInstance>& wr_glyph_instances = wr_glyphs[i].glyphs;
         wr_glyph_instances.SetLength(glyphs.Length());
-        wr_glyphs[i].color = toWrColor(glyph_array.color().value());
+        wr_glyphs[i].color = ToWRColor(glyph_array.color().value());
 
         for (size_t j = 0; j < glyphs.Length(); j++) {
             wr_glyph_instances[j].index = glyphs[j].mIndex;
             wr_glyph_instances[j].x = glyphs[j].mPosition.x;
             wr_glyph_instances[j].y = glyphs[j].mPosition.y;
         }
     }
 
     WRBridge()->AddWebRenderCommand(OpDPPushText(
-        toWrRect(rect),
-        toWrRect(clip),
+        ToWRRect(rect),
+        ToWRRect(clip),
         wr_glyphs,
         mIndex,
         mGlyphSize,
         fontBuffer,
         mFontDataLength
     ));
 }
 
--- a/gfx/layers/wr/WebRenderTypes.h
+++ b/gfx/layers/wr/WebRenderTypes.h
@@ -7,16 +7,66 @@
 #define GFX_WEBRENDERTYPES_H
 
 #include "mozilla/gfx/webrender.h"
 #include "mozilla/Maybe.h"
 
 typedef mozilla::Maybe<WRImageMask> MaybeImageMask;
 
 namespace mozilla {
+namespace layers {
+
+static inline WRColor ToWRColor(const gfx::Color& color)
+{
+  WRColor c;
+  c.r = color.r;
+  c.g = color.g;
+  c.b = color.b;
+  c.a = color.a;
+  return c;
+}
+
+static inline WRBorderSide ToWRBorderSide(const LayerCoord width, const gfx::Color& color)
+{
+  WRBorderSide bs;
+  bs.width = width;
+  bs.color = ToWRColor(color);
+  bs.style = WRBorderStyle::Solid;
+  return bs;
+}
+
+static inline WRLayoutSize ToWRLayoutSize(const LayerSize size)
+{
+  WRLayoutSize ls;
+  ls.width = size.width;
+  ls.height = size.height;
+  return ls;
+}
+
+template<class T>
+static inline WRRect ToWRRect(const gfx::RectTyped<T>& rect)
+{
+  WRRect r;
+  r.x = rect.x;
+  r.y = rect.y;
+  r.width = rect.width;
+  r.height = rect.height;
+  return r;
+}
+
+template<class T>
+static inline WRRect ToWRRect(const gfx::IntRectTyped<T>& rect)
+{
+  return ToWRRect(IntRectToRect(rect));
+}
+
+} // namespace layers
+} // namespace mozilla
+
+namespace mozilla {
 namespace gfx {
 
 struct ByteBuffer
 {
   ByteBuffer(size_t aLength, uint8_t* aData)
     : mLength(aLength)
     , mData(aData)
     , mOwned(false)