Bug 1143575. Move mLayer from ImageClientBridge up into its superclass ImageClient. r=nical draft
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 25 Mar 2015 22:02:04 +1300
changeset 275567 a4d9efef6b2937a831b83c8e937161b14b588d6e
parent 275566 6c9e81f36463d2b9b0f137fbe81cc7323d8d23c4
child 275568 df021e4d919062d889b0cc323e9824c7aa67228a
push id3189
push userrocallahan@mozilla.com
push dateFri, 03 Jul 2015 11:12:01 +0000
reviewersnical
bugs1143575
milestone42.0a1
Bug 1143575. Move mLayer from ImageClientBridge up into its superclass ImageClient. r=nical This simplifies code slightly.
gfx/layers/client/ClientImageLayer.cpp
gfx/layers/client/ImageClient.cpp
gfx/layers/client/ImageClient.h
--- a/gfx/layers/client/ClientImageLayer.cpp
+++ b/gfx/layers/client/ClientImageLayer.cpp
@@ -72,16 +72,17 @@ protected:
   {
     DestroyBackBuffer();
     ClientLayer::Disconnect();
   }
 
   void DestroyBackBuffer()
   {
     if (mImageClient) {
+      mImageClient->SetLayer(nullptr);
       mImageClient->OnDetach();
       mImageClient = nullptr;
     }
   }
 
   virtual CompositableClient* GetCompositableClient() override
   {
     return mImageClient;
@@ -140,23 +141,20 @@ ClientImageLayer::RenderLayer()
     }
     TextureFlags flags = TextureFlags::DEFAULT;
     if (mDisallowBigImage) {
       flags |= TextureFlags::DISALLOW_BIGIMAGE;
     }
     mImageClient = ImageClient::CreateImageClient(type,
                                                   ClientManager()->AsShadowForwarder(),
                                                   flags);
-    if (type == CompositableType::IMAGE_BRIDGE) {
-      static_cast<ImageClientBridge*>(mImageClient.get())->SetLayer(this);
-    }
-
     if (!mImageClient) {
       return;
     }
+    mImageClient->SetLayer(this);
     if (HasShadow() && !mContainer->IsAsync()) {
       mImageClient->Connect();
       ClientManager()->AsShadowForwarder()->Attach(mImageClient, this);
     }
     if (!mImageClient->UpdateImage(mContainer, GetContentFlags())) {
       return;
     }
   }
--- a/gfx/layers/client/ImageClient.cpp
+++ b/gfx/layers/client/ImageClient.cpp
@@ -268,16 +268,17 @@ void
 ImageClientSingle::OnDetach()
 {
   mFrontBuffer = nullptr;
 }
 
 ImageClient::ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags,
                          CompositableType aType)
 : CompositableClient(aFwd, aFlags)
+, mLayer(nullptr)
 , mType(aType)
 , mLastPaintedImageSerial(0)
 {}
 
 void
 ImageClient::UpdatePictureRect(IntRect aRect)
 {
   if (mPictureRect == aRect) {
@@ -287,17 +288,16 @@ ImageClient::UpdatePictureRect(IntRect a
   MOZ_ASSERT(mForwarder);
   GetForwarder()->UpdatePictureRect(this, aRect);
 }
 
 ImageClientBridge::ImageClientBridge(CompositableForwarder* aFwd,
                                      TextureFlags aFlags)
 : ImageClient(aFwd, aFlags, CompositableType::IMAGE_BRIDGE)
 , mAsyncContainerID(0)
-, mLayer(nullptr)
 {
 }
 
 bool
 ImageClientBridge::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags)
 {
   if (!GetForwarder() || !mLayer) {
     return false;
--- a/gfx/layers/client/ImageClient.h
+++ b/gfx/layers/client/ImageClient.h
@@ -18,16 +18,17 @@
 #include "mozilla/layers/TextureClient.h"  // for TextureClient, etc
 #include "mozilla/mozalloc.h"           // for operator delete
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsRect.h"                     // for mozilla::gfx::IntRect
 
 namespace mozilla {
 namespace layers {
 
+class ClientLayer;
 class CompositableForwarder;
 class AsyncTransactionTracker;
 class Image;
 class ImageContainer;
 class ShadowableLayer;
 
 /**
  * Image clients are used by basic image layers on the content thread, they
@@ -58,16 +59,19 @@ public:
   /**
    * The picture rect is the area of the texture which makes up the image. That
    * is, the area that should be composited. In texture space.
    */
   virtual void UpdatePictureRect(gfx::IntRect aPictureRect);
 
   virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) = 0;
 
+  void SetLayer(ClientLayer* aLayer) { mLayer = aLayer; }
+  ClientLayer* GetLayer() const { return mLayer; }
+
   /**
    * Create AsyncTransactionTracker that is used for FlushAllImagesAsync().
    */
   virtual already_AddRefed<AsyncTransactionTracker> PrepareFlushAllImages() { return nullptr; }
 
   /**
    * asynchronously remove all the textures used by the image client.
    *
@@ -79,16 +83,17 @@ public:
 
   void RemoveTextureWithTracker(TextureClient* aTexture,
                                 AsyncTransactionTracker* aAsyncTransactionTracker = nullptr);
 
 protected:
   ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags,
               CompositableType aType);
 
+  ClientLayer* mLayer;
   CompositableType mType;
   int32_t mLastPaintedImageSerial;
   gfx::IntRect mPictureRect;
 };
 
 /**
  * An image client which uses a single texture client.
  */
@@ -127,20 +132,16 @@ class ImageClientBridge : public ImageCl
 {
 public:
   ImageClientBridge(CompositableForwarder* aFwd,
                     TextureFlags aFlags);
 
   virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) override;
   virtual bool Connect() override { return false; }
   virtual void Updated() {}
-  void SetLayer(ShadowableLayer* aLayer)
-  {
-    mLayer = aLayer;
-  }
 
   virtual TextureInfo GetTextureInfo() const override
   {
     return TextureInfo(mType);
   }
 
   virtual void SetIPDLActor(CompositableChild* aChild) override
   {
@@ -150,17 +151,16 @@ public:
   virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) override
   {
     NS_WARNING("Should not create an image through an ImageClientBridge");
     return nullptr;
   }
 
 protected:
   uint64_t mAsyncContainerID;
-  ShadowableLayer* mLayer;
 };
 
 #ifdef MOZ_WIDGET_GONK
 /**
  * And ImageClient to handle opaque video stream.
  * Such video stream does not upload new Image for each frame.
  * Gecko have no way to get the buffer content from the Image, since the Image
  * does not contain the real buffer.