Bug 1337130. Add a WebRenderDisplayItemLayer. r=mattwoodrow
authorMason Chang <mchang@mozilla.com>
Tue, 14 Feb 2017 15:06:50 -0800
changeset 372997 669d6b1f3031116d74d1d53b8b67c802c698693d
parent 372996 052e1a7bbc5b135e81ee55157daa0f80e1a91750
child 372998 935cd55673ed501555d1f0273c3909c37fe17507
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1337130
milestone54.0a1
Bug 1337130. Add a WebRenderDisplayItemLayer. r=mattwoodrow
gfx/layers/moz.build
gfx/layers/wr/WebRenderBridgeChild.cpp
gfx/layers/wr/WebRenderBridgeChild.h
gfx/layers/wr/WebRenderDisplayItemLayer.cpp
gfx/layers/wr/WebRenderDisplayItemLayer.h
gfx/layers/wr/WebRenderLayerManager.cpp
gfx/layers/wr/WebRenderLayerManager.h
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -394,16 +394,17 @@ UNIFIED_SOURCES += [
     'wr/WebRenderBorderLayer.cpp',
     'wr/WebRenderBridgeChild.cpp',
     'wr/WebRenderBridgeParent.cpp',
     'wr/WebRenderCanvasLayer.cpp',
     'wr/WebRenderColorLayer.cpp',
     'wr/WebRenderCompositableHolder.cpp',
     'wr/WebRenderCompositorOGL.cpp',
     'wr/WebRenderContainerLayer.cpp',
+    'wr/WebRenderDisplayItemLayer.cpp',
     'wr/WebRenderImageHost.cpp',
     'wr/WebRenderImageLayer.cpp',
     'wr/WebRenderLayerManager.cpp',
     'wr/WebRenderLayersLogging.cpp',
     'wr/WebRenderPaintedLayer.cpp',
     'wr/WebRenderTextLayer.cpp',
 ]
 
--- a/gfx/layers/wr/WebRenderBridgeChild.cpp
+++ b/gfx/layers/wr/WebRenderBridgeChild.cpp
@@ -44,16 +44,23 @@ WebRenderBridgeChild::ActorDestroy(Actor
 
 void
 WebRenderBridgeChild::AddWebRenderCommand(const WebRenderCommand& aCmd)
 {
   MOZ_ASSERT(mIsInTransaction);
   mCommands.AppendElement(aCmd);
 }
 
+void
+WebRenderBridgeChild::AddWebRenderCommands(const nsTArray<WebRenderCommand>& aCommands)
+{
+  MOZ_ASSERT(mIsInTransaction);
+  mCommands.AppendElements(aCommands);
+}
+
 bool
 WebRenderBridgeChild::DPBegin(const gfx::IntSize& aSize)
 {
   MOZ_ASSERT(!mDestroyed);
   MOZ_ASSERT(!mIsInTransaction);
   bool success = false;
   UpdateFwdTransactionId();
   this->SendDPBegin(aSize, &success);
--- a/gfx/layers/wr/WebRenderBridgeChild.h
+++ b/gfx/layers/wr/WebRenderBridgeChild.h
@@ -26,16 +26,17 @@ class WebRenderBridgeChild final : publi
                                  , public CompositableForwarder
 {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebRenderBridgeChild, override)
 
 public:
   explicit WebRenderBridgeChild(const wr::PipelineId& aPipelineId);
 
   void AddWebRenderCommand(const WebRenderCommand& aCmd);
+  void AddWebRenderCommands(const nsTArray<WebRenderCommand>& aCommands);
 
   bool DPBegin(const  gfx::IntSize& aSize);
   void DPEnd(bool aIsSync, uint64_t aTransactionId);
 
   CompositorBridgeChild* GetCompositorBridgeChild();
 
   // KnowsCompositor
   TextureForwarder* GetTextureForwarder() override;
new file mode 100644
--- /dev/null
+++ b/gfx/layers/wr/WebRenderDisplayItemLayer.cpp
@@ -0,0 +1,33 @@
+/* -*- 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 "WebRenderDisplayItemLayer.h"
+
+#include "WebRenderLayersLogging.h"
+#include "mozilla/webrender/webrender_ffi.h"
+#include "mozilla/webrender/WebRenderTypes.h"
+#include "mozilla/layers/WebRenderBridgeChild.h"
+#include "nsDisplayList.h"
+#include "mozilla/gfx/Matrix.h"
+
+namespace mozilla {
+namespace layers {
+
+void
+WebRenderDisplayItemLayer::RenderLayer()
+{
+  if (mItem) {
+    // We might have recycled this layer. Throw away the old commands.
+    mCommands.Clear();
+    mItem->CreateWebRenderCommands(mCommands, this);
+  }
+  // else we have an empty transaction and just use the
+  // old commands.
+
+  WrBridge()->AddWebRenderCommands(mCommands);
+}
+
+} // namespace layers
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/gfx/layers/wr/WebRenderDisplayItemLayer.h
@@ -0,0 +1,43 @@
+/* -*- 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_WEBRENDERDISPLAYITEMLAYER_H
+#define GFX_WEBRENDERDISPLAYITEMLAYER_H
+
+#include "Layers.h"
+#include "WebRenderLayerManager.h"
+#include "mozilla/layers/PWebRenderBridgeChild.h"
+
+namespace mozilla {
+namespace layers {
+
+class WebRenderDisplayItemLayer : public WebRenderLayer,
+                                  public DisplayItemLayer {
+public:
+  explicit WebRenderDisplayItemLayer(WebRenderLayerManager* aLayerManager)
+    : DisplayItemLayer(aLayerManager, static_cast<WebRenderLayer*>(this))
+  {
+    MOZ_COUNT_CTOR(WebRenderDisplayItemLayer);
+  }
+
+protected:
+  virtual ~WebRenderDisplayItemLayer()
+  {
+    mCommands.Clear();
+    MOZ_COUNT_DTOR(WebRenderDisplayItemLayer);
+  }
+
+public:
+  Layer* GetLayer() override { return this; }
+  void RenderLayer() override;
+
+private:
+  nsTArray<WebRenderCommand> mCommands;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif // GFX_WEBRENDERDisplayItemLayer_H
\ No newline at end of file
--- a/gfx/layers/wr/WebRenderLayerManager.cpp
+++ b/gfx/layers/wr/WebRenderLayerManager.cpp
@@ -529,10 +529,16 @@ WebRenderLayerManager::CreateTextLayer()
 }
 
 already_AddRefed<BorderLayer>
 WebRenderLayerManager::CreateBorderLayer()
 {
   return MakeAndAddRef<WebRenderBorderLayer>(this);
 }
 
+already_AddRefed<DisplayItemLayer>
+WebRenderLayerManager::CreateDisplayItemLayer()
+{
+  return MakeAndAddRef<WebRenderDisplayItemLayer>(this);
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderLayerManager.h
+++ b/gfx/layers/wr/WebRenderLayerManager.h
@@ -96,16 +96,17 @@ public:
   virtual already_AddRefed<ContainerLayer> CreateContainerLayer() override;
   virtual already_AddRefed<ImageLayer> CreateImageLayer() override;
   virtual already_AddRefed<CanvasLayer> CreateCanvasLayer() override;
   virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer() override;
   virtual already_AddRefed<ColorLayer> CreateColorLayer() override;
   virtual already_AddRefed<RefLayer> CreateRefLayer() override;
   virtual already_AddRefed<TextLayer> CreateTextLayer() override;
   virtual already_AddRefed<BorderLayer> CreateBorderLayer() override;
+  virtual already_AddRefed<DisplayItemLayer> CreateDisplayItemLayer() override;
 
   virtual bool NeedsWidgetInvalidation() override { return true; }
 
   virtual void SetLayerObserverEpoch(uint64_t aLayerObserverEpoch) override;
 
   virtual void DidComposite(uint64_t aTransactionId,
                             const mozilla::TimeStamp& aCompositeStart,
                             const mozilla::TimeStamp& aCompositeEnd) override;