Bug 1339683 - Supporting send ImageContainer in the DisplayItemLayer. r=mchang r=nical draft
authorMorris Tseng <mtseng@mozilla.com>
Fri, 10 Feb 2017 11:04:33 -0500
changeset 485767 b15dd9820922fa9b6ca33adaa4729886e9c5b3f6
parent 485766 687b3bd601ba93cf746f2ef1cd3af2c60f7d2128
child 485768 c0ec82d8ef3e1ac825c36be8bb4927bb6be04aa8
push id45837
push userbmo:mtseng@mozilla.com
push dateFri, 17 Feb 2017 04:14:52 +0000
reviewersmchang, nical
bugs1339683
milestone54.0a1
Bug 1339683 - Supporting send ImageContainer in the DisplayItemLayer. r=mchang r=nical Allow to create an ImageClient for ImageContainer and send this ImageClient to WebRender for rendering. MozReview-Commit-ID: K14sCeAHJmD
gfx/layers/wr/WebRenderDisplayItemLayer.cpp
gfx/layers/wr/WebRenderDisplayItemLayer.h
--- a/gfx/layers/wr/WebRenderDisplayItemLayer.cpp
+++ b/gfx/layers/wr/WebRenderDisplayItemLayer.cpp
@@ -24,10 +24,45 @@ WebRenderDisplayItemLayer::RenderLayer()
     mItem->CreateWebRenderCommands(mCommands, this);
   }
   // else we have an empty transaction and just use the
   // old commands.
 
   WrBridge()->AddWebRenderCommands(mCommands);
 }
 
+uint64_t
+WebRenderDisplayItemLayer::SendImageContainer(ImageContainer* aContainer)
+{
+  if (mImageContainer != aContainer) {
+    AutoLockImage autoLock(aContainer);
+    Image* image = autoLock.GetImage();
+    if (!image) {
+      return 0;
+    }
+
+    if (!mImageClient) {
+      mImageClient = ImageClient::CreateImageClient(CompositableType::IMAGE,
+                                                    WrBridge(),
+                                                    TextureFlags::DEFAULT);
+      if (!mImageClient) {
+        return 0;
+      }
+      mImageClient->Connect();
+    }
+
+    if (!mExternalImageId) {
+      MOZ_ASSERT(mImageClient);
+      mExternalImageId = WrBridge()->AllocExternalImageIdForCompositable(mImageClient);
+    }
+    MOZ_ASSERT(mExternalImageId);
+
+    if (mImageClient && !mImageClient->UpdateImage(aContainer, /* unused */0)) {
+      return 0;
+    }
+    mImageContainer = aContainer;
+  }
+
+  return mExternalImageId;
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderDisplayItemLayer.h
+++ b/gfx/layers/wr/WebRenderDisplayItemLayer.h
@@ -3,41 +3,49 @@
  * 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/ImageClient.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))
+    , mExternalImageId(0)
   {
     MOZ_COUNT_CTOR(WebRenderDisplayItemLayer);
   }
 
+  uint64_t SendImageContainer(ImageContainer* aContainer);
+
 protected:
   virtual ~WebRenderDisplayItemLayer()
   {
     mCommands.Clear();
     MOZ_COUNT_DTOR(WebRenderDisplayItemLayer);
   }
 
 public:
   Layer* GetLayer() override { return this; }
   void RenderLayer() override;
 
 private:
   nsTArray<WebRenderCommand> mCommands;
+  RefPtr<ImageClient> mImageClient;
+  RefPtr<ImageContainer> mImageContainer;
+  uint64_t mExternalImageId;
+
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // GFX_WEBRENDERDisplayItemLayer_H
\ No newline at end of file