Bug 1360246 - Clean up WebRenderTextLayer::RenderLayer. r=nical
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 03 May 2017 08:48:07 -0400
changeset 357028 ca74bdc958e1e09b3a83a6eee300adb717c7817c
parent 357027 3b25a123e53f9817050d2030014e2291ba6e8d06
child 357029 4776be9cd57ac5796548d124b46e7ad1a5a42f99
push id31780
push userkwierso@gmail.com
push dateMon, 08 May 2017 20:34:47 +0000
treeherdermozilla-central@bab7046ee2d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1360246
milestone55.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 1360246 - Clean up WebRenderTextLayer::RenderLayer. r=nical This uses the StackingContextHelper and typed helper functions in WebRenderLayer to simplify WebRenderTextLayer::RenderLayer. It also removes the implicit assumption in WebRenderTextLayer that the parent layer pushed a stacking context, which is an assumption we will probably break in the future. MozReview-Commit-ID: CARoGVQd56i
gfx/layers/wr/StackingContextHelper.cpp
gfx/layers/wr/StackingContextHelper.h
gfx/layers/wr/WebRenderBridgeChild.cpp
gfx/layers/wr/WebRenderBridgeChild.h
gfx/layers/wr/WebRenderLayer.cpp
gfx/layers/wr/WebRenderLayer.h
gfx/layers/wr/WebRenderTextLayer.cpp
layout/generic/nsBulletFrame.cpp
--- a/gfx/layers/wr/StackingContextHelper.cpp
+++ b/gfx/layers/wr/StackingContextHelper.cpp
@@ -55,10 +55,16 @@ StackingContextHelper::~StackingContextH
 }
 
 WrRect
 StackingContextHelper::ToRelativeWrRect(const LayerRect& aRect) const
 {
   return wr::ToWrRect(aRect - mOrigin);
 }
 
+WrPoint
+StackingContextHelper::ToRelativeWrPoint(const LayerPoint& aPoint) const
+{
+  return wr::ToWrPoint(aPoint - mOrigin);
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/StackingContextHelper.h
+++ b/gfx/layers/wr/StackingContextHelper.h
@@ -48,16 +48,18 @@ public:
   ~StackingContextHelper();
 
   // When this StackingContextHelper is in scope, this function can be used
   // to convert a rect from the layer system's coordinate space to a WrRect
   // that is relative to the stacking context. This is useful because most
   // things that are pushed inside the stacking context need to be relative
   // to the stacking context.
   WrRect ToRelativeWrRect(const LayerRect& aRect) const;
+  // Same but for points
+  WrPoint ToRelativeWrPoint(const LayerPoint& aPoint) const;
 
 private:
   wr::DisplayListBuilder* mBuilder;
   LayerPoint mOrigin;
 };
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderBridgeChild.cpp
+++ b/gfx/layers/wr/WebRenderBridgeChild.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/layers/WebRenderBridgeChild.h"
 
 #include "gfxPlatform.h"
 #include "mozilla/layers/CompositableClient.h"
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/ImageDataSerializer.h"
+#include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/PTextureChild.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 
 namespace mozilla {
 namespace layers {
 
 WebRenderBridgeChild::WebRenderBridgeChild(const wr::PipelineId& aPipelineId)
   : mReadLockSequenceNumber(0)
@@ -173,40 +174,40 @@ WriteFontFileData(const uint8_t* aData, 
   }
   memcpy(data->mFontBuffer.mData, aData, aLength);
 
   data->mFontIndex = aIndex;
 }
 
 void
 WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<GlyphArray>& aGlyphs,
-                                 gfx::ScaledFont* aFont, const LayerPoint& aOffset, const gfx::Rect& aBounds,
-                                 const gfx::Rect& aClip)
+                                 gfx::ScaledFont* aFont, const StackingContextHelper& aSc,
+                                 const LayerRect& aBounds, const LayerRect& aClip)
 {
   MOZ_ASSERT(aFont);
   MOZ_ASSERT(!aGlyphs.IsEmpty());
 
   WrFontKey key = GetFontKeyForScaledFont(aFont);
   MOZ_ASSERT(key.mNamespace && key.mHandle);
 
-  WrClipRegion clipRegion = aBuilder.BuildClipRegion(wr::ToWrRect(aClip));
+  WrClipRegion clipRegion = aBuilder.BuildClipRegion(aSc.ToRelativeWrRect(aClip));
 
   for (size_t i = 0; i < aGlyphs.Length(); i++) {
     GlyphArray glyph_array = aGlyphs[i];
     nsTArray<gfx::Glyph>& glyphs = glyph_array.glyphs();
 
     nsTArray<WrGlyphInstance> wr_glyph_instances;
     wr_glyph_instances.SetLength(glyphs.Length());
 
     for (size_t j = 0; j < glyphs.Length(); j++) {
       wr_glyph_instances[j].index = glyphs[j].mIndex;
-      wr_glyph_instances[j].point.x = glyphs[j].mPosition.x - aOffset.x;
-      wr_glyph_instances[j].point.y = glyphs[j].mPosition.y - aOffset.y;
+      wr_glyph_instances[j].point = aSc.ToRelativeWrPoint(
+              LayerPoint::FromUnknownPoint(glyphs[j].mPosition));
     }
-    aBuilder.PushText(wr::ToWrRect(aBounds),
+    aBuilder.PushText(aSc.ToRelativeWrRect(aBounds),
                       clipRegion,
                       glyph_array.color().value(),
                       key,
                       Range<const WrGlyphInstance>(wr_glyph_instances.Elements(), wr_glyph_instances.Length()),
                       aFont->GetSize());
 
   }
 }
--- a/gfx/layers/wr/WebRenderBridgeChild.h
+++ b/gfx/layers/wr/WebRenderBridgeChild.h
@@ -19,16 +19,17 @@ class CompositorWidget;
 namespace wr {
 class DisplayListBuilder;
 }
 
 namespace layers {
 
 class CompositableClient;
 class CompositorBridgeChild;
+class StackingContextHelper;
 class TextureForwarder;
 
 class UnscaledFontHashKey : public PLDHashEntryHdr
 {
 public:
   typedef gfx::UnscaledFont* KeyType;
   typedef const gfx::UnscaledFont* KeyTypePointer;
 
@@ -87,18 +88,18 @@ public:
   uint32_t GetNextResourceId() { return ++mResourceId; }
   uint32_t GetNamespace() { return mIdNamespace; }
   void SetNamespace(uint32_t aIdNamespace)
   {
     mIdNamespace = aIdNamespace;
   }
 
   void PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<GlyphArray>& aGlyphs,
-                  gfx::ScaledFont* aFont, const LayerPoint& aOffset, const gfx::Rect& aBounds,
-                  const gfx::Rect& aClip);
+                  gfx::ScaledFont* aFont, const StackingContextHelper& aSc,
+                  const LayerRect& aBounds, const LayerRect& aClip);
 
   wr::FontKey GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont);
 
   void RemoveExpiredFontKeys();
   void ClearReadLocks();
 
 private:
   friend class CompositorBridgeChild;
--- a/gfx/layers/wr/WebRenderLayer.cpp
+++ b/gfx/layers/wr/WebRenderLayer.cpp
@@ -59,22 +59,16 @@ WebRenderLayer::RelativeToParent(const L
 
 LayerRect
 WebRenderLayer::RelativeToParent(const LayoutDeviceRect& aRect)
 {
   return RelativeToParent(ViewAs<LayerPixel>(
       aRect, PixelCastJustification::WebRenderHasUnitResolution));
 }
 
-LayerPoint
-WebRenderLayer::GetOffsetToParent()
-{
-  return ParentBounds().TopLeft();
-}
-
 gfx::Rect
 WebRenderLayer::TransformedVisibleBoundsRelativeToParent()
 {
   IntRect bounds = GetLayer()->GetVisibleRegion().GetBounds().ToUnknownRect();
   Rect transformed = GetLayer()->GetTransform().TransformBounds(IntRectToRect(bounds));
   return transformed - ParentBounds().ToUnknownRect().TopLeft();
 }
 
--- a/gfx/layers/wr/WebRenderLayer.h
+++ b/gfx/layers/wr/WebRenderLayer.h
@@ -45,17 +45,16 @@ public:
                                      wr::ExternalImageId& aExternalImageId);
 
   WebRenderLayerManager* WrManager();
   WebRenderBridgeChild* WrBridge();
   WrImageKey GetImageKey();
 
   LayerRect RelativeToParent(const LayerRect& aRect);
   LayerRect RelativeToParent(const LayoutDeviceRect& aRect);
-  LayerPoint GetOffsetToParent();
 
   LayerRect Bounds();
   LayerRect BoundsForStackingContext();
 protected:
   BoundsTransformMatrix BoundsTransform();
   LayerRect ParentBounds();
   Maybe<LayerRect> ClipRect();
 
--- a/gfx/layers/wr/WebRenderTextLayer.cpp
+++ b/gfx/layers/wr/WebRenderTextLayer.cpp
@@ -20,30 +20,27 @@ using namespace mozilla::gfx;
 void
 WebRenderTextLayer::RenderLayer(wr::DisplayListBuilder& aBuilder,
                                 const StackingContextHelper& aSc)
 {
     if (mBounds.IsEmpty()) {
         return;
     }
 
-    gfx::Rect rect = GetTransform().TransformBounds(IntRectToRect(mBounds))
-        - ParentBounds().ToUnknownRect().TopLeft();
-    gfx::Rect clip;
-    if (GetClipRect().isSome()) {
-      clip = IntRectToRect(GetClipRect().ref().ToUnknownRect())
-          - ParentBounds().ToUnknownRect().TopLeft();
-    } else {
-      clip = rect;
-    }
+    LayerRect rect = LayerRect::FromUnknownRect(
+        // I am not 100% sure this is correct, but it probably is. Because:
+        // the bounds are in layer space, and when gecko composites layers it
+        // applies the transform to the layer before compositing. However with
+        // WebRender compositing, we don't pass the transform on this layer to
+        // WR, so WR has no way of knowing about the transformed bounds unless
+        // we apply it here. The glyphs that we push to WR should already be
+        // taking the transform into account.
+        GetTransform().TransformBounds(IntRectToRect(mBounds))
+    );
+    DumpLayerInfo("TextLayer", rect);
 
-    if (gfxPrefs::LayersDump()) {
-        printf_stderr("TextLayer %p using rect=%s, clip=%s\n",
-                      this->GetLayer(),
-                      Stringify(rect).c_str(),
-                      Stringify(clip).c_str());
-    }
+    LayerRect clipRect = ClipRect().valueOr(rect);
 
-    WrBridge()->PushGlyphs(aBuilder, mGlyphs, mFont, GetOffsetToParent(), rect, clip);
+    WrBridge()->PushGlyphs(aBuilder, mGlyphs, mFont, aSc, rect, clipRect);
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/layout/generic/nsBulletFrame.cpp
+++ b/layout/generic/nsBulletFrame.cpp
@@ -25,16 +25,17 @@
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIDocument.h"
 #include "nsRenderingContext.h"
 #include "nsDisplayList.h"
 #include "nsCounterManager.h"
 #include "nsBidiUtils.h"
 #include "CounterStyleManager.h"
+#include "UnitTransforms.h"
 
 #include "imgIContainer.h"
 #include "ImageLayers.h"
 #include "imgRequestProxy.h"
 #include "nsIURI.h"
 #include "SVGImageContext.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 
@@ -499,22 +500,22 @@ BulletRenderer::CreateWebRenderCommandsF
   MOZ_ASSERT(IsTextType());
   MOZ_ASSERT(mFont);
   MOZ_ASSERT(!mGlyphs.IsEmpty());
 
   layers::WebRenderDisplayItemLayer* layer = static_cast<layers::WebRenderDisplayItemLayer*>(aLayer);
   nsDisplayListBuilder* builder = layer->GetDisplayListBuilder();
   const int32_t appUnitsPerDevPixel = aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
   bool dummy;
-  LayoutDeviceRect destRect = LayoutDeviceRect::FromAppUnits(
-      aItem->GetBounds(builder, &dummy), appUnitsPerDevPixel);
-  gfx::Rect destRectTransformed = aLayer->RelativeToParent(destRect).ToUnknownRect();
+  LayerRect destRect = ViewAs<LayerPixel>(
+      LayoutDeviceRect::FromAppUnits(
+          aItem->GetBounds(builder, &dummy), appUnitsPerDevPixel),
+      PixelCastJustification::WebRenderHasUnitResolution);
 
-  layer->WrBridge()->PushGlyphs(aBuilder, mGlyphs, mFont, aLayer->GetOffsetToParent(),
-                                destRectTransformed, destRectTransformed);
+  layer->WrBridge()->PushGlyphs(aBuilder, mGlyphs, mFont, aSc, destRect, destRect);
 }
 
 class nsDisplayBullet final : public nsDisplayItem {
 public:
   nsDisplayBullet(nsDisplayListBuilder* aBuilder, nsBulletFrame* aFrame)
     : nsDisplayItem(aBuilder, aFrame)
     , mDisableSubpixelAA(false)
   {