Bug 867656 - Part 2. Implement Dump for CompositableHost classes. r=mattwoodrow
authorNicolas Silva <nical.bugzilla@gmail.com>
Sun, 26 May 2013 04:44:24 +0200
changeset 144601 e6826a5768ef370c56d51eb40b247ab91f8061f3
parent 144600 3ded05a81797e93e0373b75ada927dbdd6f99d45
child 144602 1b16d33aaebd3b3e182a47a69b66db72e4052d73
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs867656
milestone24.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 867656 - Part 2. Implement Dump for CompositableHost classes. r=mattwoodrow
gfx/layers/Layers.cpp
gfx/layers/TiledLayerBuffer.h
gfx/layers/composite/CompositableHost.cpp
gfx/layers/composite/CompositableHost.h
gfx/layers/composite/ContentHost.cpp
gfx/layers/composite/ContentHost.h
gfx/layers/composite/ImageHost.cpp
gfx/layers/composite/ImageHost.h
gfx/layers/composite/TiledContentHost.cpp
gfx/layers/composite/TiledContentHost.h
gfx/thebes/gfxASurface.cpp
gfx/thebes/gfxASurface.h
--- a/gfx/layers/Layers.cpp
+++ b/gfx/layers/Layers.cpp
@@ -5,16 +5,17 @@
  * 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 "mozilla/DebugOnly.h"
 
 #include "mozilla/layers/PLayerTransaction.h"
 #include "mozilla/layers/LayerManagerComposite.h"
 #include "mozilla/Telemetry.h"
+#include "CompositableHost.h"
 
 #include "ImageLayers.h"
 #include "ImageContainer.h"
 #include "Layers.h"
 #include "gfxPlatform.h"
 #include "ReadbackLayer.h"
 #include "gfxUtils.h"
 #include "nsPrintfCString.h"
@@ -976,16 +977,19 @@ LayerManager::BeginTabSwitch()
 #ifdef MOZ_LAYERS_HAVE_LOG
 
 static nsACString& PrintInfo(nsACString& aTo, LayerComposite* aLayerComposite);
 
 #ifdef MOZ_DUMP_PAINTING
 template <typename T>
 void WriteSnapshotLinkToDumpFile(T* aObj, FILE* aFile)
 {
+  if (!aObj) {
+    return;
+  }
   nsCString string(aObj->Name());
   string.Append("-");
   string.AppendInt((uint64_t)aObj);
   fprintf(aFile, "href=\"javascript:ViewImage('%s')\"", string.BeginReading());
 }
 
 template <typename T>
 void WriteSnapshotToDumpFile_internal(T* aObj, gfxASurface* aSurf)
@@ -1024,33 +1028,36 @@ Layer::Dump(FILE* aFile, const char* aPr
 #ifdef MOZ_DUMP_PAINTING
     if (GetType() == TYPE_CONTAINER || GetType() == TYPE_THEBES) {
       WriteSnapshotLinkToDumpFile(this, aFile);
     }
 #endif
     fprintf(aFile, ">");
   }
   DumpSelf(aFile, aPrefix);
+  if (AsLayerComposite() && AsLayerComposite()->GetCompositableHost()) {
+    AsLayerComposite()->GetCompositableHost()->Dump(aFile, aPrefix, aDumpHtml);
+  }
   if (aDumpHtml) {
     fprintf(aFile, "</a>");
   }
 
   if (Layer* mask = GetMaskLayer()) {
     nsAutoCString pfx(aPrefix);
     pfx += "  Mask layer: ";
-    mask->Dump(aFile, pfx.get());
+    mask->Dump(aFile, pfx.get(), aDumpHtml);
   }
 
   if (Layer* kid = GetFirstChild()) {
     nsAutoCString pfx(aPrefix);
     pfx += "  ";
     if (aDumpHtml) {
       fprintf(aFile, "<ul>");
     }
-    kid->Dump(aFile, pfx.get());
+    kid->Dump(aFile, pfx.get(), aDumpHtml);
     if (aDumpHtml) {
       fprintf(aFile, "</ul>");
     }
   }
 
   if (aDumpHtml) {
     fprintf(aFile, "</li>");
   }
--- a/gfx/layers/TiledLayerBuffer.h
+++ b/gfx/layers/TiledLayerBuffer.h
@@ -140,16 +140,20 @@ public:
       return;
     }
 
     Update(nsIntRegion(), nsIntRegion());
     mResolution = aResolution;
   }
   bool IsLowPrecision() const { return mResolution < 1; }
 
+  typedef Tile* Iterator;
+  Iterator TilesBegin() { return mRetainedTiles.Elements(); }
+  Iterator TilesEnd() { return mRetainedTiles.Elements() + mRetainedTiles.Length(); }
+
 protected:
   // The implementor should call Update() to change
   // the new valid region. This implementation will call
   // validateTile on each tile that is dirty, which is left
   // to the implementor.
   void Update(const nsIntRegion& aNewValidRegion, const nsIntRegion& aPaintRegion);
 
   nsIntRegion     mValidRegion;
--- a/gfx/layers/composite/CompositableHost.cpp
+++ b/gfx/layers/composite/CompositableHost.cpp
@@ -73,16 +73,29 @@ CompositableHost::Create(const TextureIn
     return result;
   default:
     MOZ_NOT_REACHED("Unknown CompositableType");
     return nullptr;
   }
 }
 
 void
+CompositableHost::DumpTextureHost(FILE* aFile, TextureHost* aTexture)
+{
+  if (!aTexture) {
+    return;
+  }
+  nsRefPtr<gfxImageSurface> surf = aTexture->GetAsSurface();
+  if (!surf) {
+    return;
+  }
+  surf->DumpAsDataURL(aFile ? aFile : stderr);
+}
+
+void
 CompositableParent::ActorDestroy(ActorDestroyReason why)
 {
   if (mHost) {
     mHost->Detach();
   }
 }
 
 CompositableParent::CompositableParent(CompositableParentManager* aMgr,
--- a/gfx/layers/composite/CompositableHost.h
+++ b/gfx/layers/composite/CompositableHost.h
@@ -189,16 +189,21 @@ public:
     SetCompositor(aCompositor);
     SetLayer(aLayer);
   }
   void Detach() {
     SetLayer(nullptr);
     SetCompositor(nullptr);
   }
 
+  virtual void Dump(FILE* aFile=NULL,
+                    const char* aPrefix="",
+                    bool aDumpHtml=false) { }
+  static void DumpTextureHost(FILE* aFile, TextureHost* aTexture);
+
 #ifdef MOZ_DUMP_PAINTING
   virtual already_AddRefed<gfxImageSurface> GetAsSurface() { return nullptr; }
 #endif
 
 #ifdef MOZ_LAYERS_HAVE_LOG
   virtual void PrintInfo(nsACString& aTo, const char* aPrefix) { }
 #endif
 
--- a/gfx/layers/composite/ContentHost.cpp
+++ b/gfx/layers/composite/ContentHost.cpp
@@ -202,16 +202,45 @@ ContentHostBase::SetCompositor(Composito
   if (mTextureHost) {
     mTextureHost->SetCompositor(aCompositor);
   }
   if (mTextureHostOnWhite) {
     mTextureHostOnWhite->SetCompositor(aCompositor);
   }
 }
 
+void
+ContentHostBase::Dump(FILE* aFile,
+                      const char* aPrefix,
+                      bool aDumpHtml)
+{
+  if (!aFile) {
+    aFile = stderr;
+  }
+  if (aDumpHtml) {
+    fprintf(aFile, "<ul>");
+  }
+  if (mTextureHost) {
+    fprintf(aFile, aPrefix);
+    fprintf(aFile, aDumpHtml ? "<li> <a href=" : "Front buffer: ");
+    DumpTextureHost(aFile, mTextureHost);
+    fprintf(aFile, aDumpHtml ? "> Front buffer </a></li> " : " ");
+  }
+  if (mTextureHostOnWhite) {
+    fprintf(aFile, aPrefix);
+    fprintf(aFile, aDumpHtml ? "<li> <a href=" : "TextureHost on white: ");
+    DumpTextureHost(aFile, mTextureHostOnWhite);
+    fprintf(aFile, aDumpHtml ? "> Front buffer on white </a> </li> " : " ");
+  }
+  if (aDumpHtml) {
+    fprintf(aFile, "</ul>");
+  }
+
+}
+
 ContentHostSingleBuffered::~ContentHostSingleBuffered()
 {
   DestroyTextures();
   DestroyFrontHost();
 }
 
 void
 ContentHostSingleBuffered::EnsureTextureHost(TextureIdentifier aTextureId,
@@ -689,11 +718,40 @@ ContentHostDoubleBuffered::PrintInfo(nsA
 
   if (mBackHost) {
     aTo += "\n";
     mBackHost->PrintInfo(aTo, prefix.get());
   }
 }
 #endif
 
+void
+ContentHostDoubleBuffered::Dump(FILE* aFile,
+                                const char* aPrefix,
+                                bool aDumpHtml)
+{
+  ContentHostBase::Dump(aFile, aPrefix, aDumpHtml);
+  if (!aFile) {
+    aFile = stderr;
+  }
+  if (aDumpHtml) {
+    fprintf(aFile, "<ul>");
+  }
+  if (mBackHost) {
+    fprintf(aFile, aPrefix);
+    fprintf(aFile, aDumpHtml ? "<li> <a href=" : "Back buffer: ");
+    DumpTextureHost(aFile, mBackHost);
+    fprintf(aFile, aDumpHtml ? " >Back buffer</a></li>" : " ");
+  }
+  if (mBackHostOnWhite) {
+    fprintf(aFile, aPrefix);
+    fprintf(aFile, aDumpHtml ? "<li> <a href=" : "Back buffer on white: ");
+    DumpTextureHost(aFile, mBackHostOnWhite);
+    fprintf(aFile, aDumpHtml ? " >Back buffer on white</a> </li>" : " ");
+  }
+  if (aDumpHtml) {
+    fprintf(aFile, "</ul>");
+  }
+
+}
 
 } // namespace
 } // namespace
--- a/gfx/layers/composite/ContentHost.h
+++ b/gfx/layers/composite/ContentHost.h
@@ -90,16 +90,20 @@ public:
 
 #ifdef MOZ_DUMP_PAINTING
   virtual already_AddRefed<gfxImageSurface> GetAsSurface()
   {
     return mTextureHost->GetAsSurface();
   }
 #endif
 
+  virtual void Dump(FILE* aFile=NULL,
+                    const char* aPrefix="",
+                    bool aDumpHtml=false) MOZ_OVERRIDE;
+
   virtual TextureHost* GetTextureHost() MOZ_OVERRIDE;
 
   virtual void SetPaintWillResample(bool aResample) { mPaintWillResample = aResample; }
   // The client has destroyed its texture clients and we should destroy our
   // texture hosts and SurfaceDescriptors. Note that we don't immediately
   // destroy our front buffer so that we can continue to composite.
   virtual void DestroyTextures() = 0;
 
@@ -148,16 +152,20 @@ public:
                             nsIntRegion* aUpdatedRegionBack);
 
   virtual void EnsureTextureHost(TextureIdentifier aTextureId,
                                  const SurfaceDescriptor& aSurface,
                                  ISurfaceAllocator* aAllocator,
                                  const TextureInfo& aTextureInfo) MOZ_OVERRIDE;
   virtual void DestroyTextures() MOZ_OVERRIDE;
 
+  virtual void Dump(FILE* aFile=NULL,
+                    const char* aPrefix="",
+                    bool aDumpHtml=false) MOZ_OVERRIDE;
+
 #ifdef MOZ_LAYERS_HAVE_LOG
   virtual void PrintInfo(nsACString& aTo, const char* aPrefix);
 #endif
 protected:
   nsIntRegion mValidRegionForNextBackBuffer;
   // Texture host for the back buffer. We never read or write this buffer. We
   // only swap it with the front buffer (mTextureHost) when we are told by the
   // content thread.
--- a/gfx/layers/composite/ImageHost.cpp
+++ b/gfx/layers/composite/ImageHost.cpp
@@ -175,10 +175,27 @@ ImageHostBuffered::MakeTextureHost(Textu
                                    aSurface,
                                    aAllocator,
                                    aTextureInfo);
   if (mTextureHost) {
     mTextureHost->SetBuffer(new SurfaceDescriptor(null_t()), aAllocator);
   }
 }
 
+void
+ImageHostSingle::Dump(FILE* aFile,
+                      const char* aPrefix,
+                      bool aDumpHtml)
+{
+  if (!aFile) {
+    aFile = stderr;
+  }
+  if (mTextureHost) {
+    fprintf(aFile, aPrefix);
+    fprintf(aFile, aDumpHtml ? "<ul><li>TextureHost: "
+                             : "TextureHost: ");
+    DumpTextureHost(aFile, mTextureHost);
+    fprintf(aFile, aDumpHtml ? " </li></ul> " : " ");
+  }
+}
+
 }
 }
--- a/gfx/layers/composite/ImageHost.h
+++ b/gfx/layers/composite/ImageHost.h
@@ -78,16 +78,20 @@ public:
 
   virtual LayerRenderState GetRenderState() MOZ_OVERRIDE
   {
     return mTextureHost->GetRenderState();
   }
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
 
+  virtual void Dump(FILE* aFile=NULL,
+                    const char* aPrefix="",
+                    bool aDumpHtml=false) MOZ_OVERRIDE;
+
 #ifdef MOZ_LAYERS_HAVE_LOG
   virtual void PrintInfo(nsACString& aTo, const char* aPrefix);
 #endif
 
 #ifdef MOZ_DUMP_PAINTING
   virtual already_AddRefed<gfxImageSurface> GetAsSurface() MOZ_OVERRIDE
   {
     return mTextureHost->GetAsSurface();
--- a/gfx/layers/composite/TiledContentHost.cpp
+++ b/gfx/layers/composite/TiledContentHost.cpp
@@ -307,11 +307,35 @@ void
 TiledContentHost::PrintInfo(nsACString& aTo, const char* aPrefix)
 {
   aTo += aPrefix;
   aTo += nsPrintfCString("TiledContentHost (0x%p)", this);
 
 }
 #endif
 
+void
+TiledContentHost::Dump(FILE* aFile,
+                       const char* aPrefix,
+                       bool aDumpHtml)
+{
+  if (!aFile) {
+    aFile = stderr;
+  }
+
+  TiledLayerBufferComposite::Iterator it = mVideoMemoryTiledBuffer.TilesBegin();
+  TiledLayerBufferComposite::Iterator stop = mVideoMemoryTiledBuffer.TilesEnd();
+  if (aDumpHtml) {
+    fprintf(aFile, "<ul>");
+  }
+  for (;it != stop; ++it) {
+    fprintf(aFile, aPrefix);
+    fprintf(aFile, aDumpHtml ? "<li> <a href=" : "Tile ");
+    DumpTextureHost(aFile, it->mTextureHost);
+    fprintf(aFile, aDumpHtml ? " >Tile</a></li>" : " ");
+  }
+    if (aDumpHtml) {
+    fprintf(aFile, "</ul>");
+  }
+}
 
 } // namespace
 } // namespace
--- a/gfx/layers/composite/TiledContentHost.h
+++ b/gfx/layers/composite/TiledContentHost.h
@@ -61,16 +61,17 @@ public:
 };
 
 class TiledLayerBufferComposite
   : public TiledLayerBuffer<TiledLayerBufferComposite, TiledTexture>
 {
   friend class TiledLayerBuffer<TiledLayerBufferComposite, TiledTexture>;
 
 public:
+  typedef TiledLayerBuffer<TiledLayerBufferComposite, TiledTexture>::Iterator Iterator;
   TiledLayerBufferComposite()
     : mCompositor(nullptr)
   {}
 
   void Upload(const BasicTiledLayerBuffer* aMainMemoryTiledBuffer,
               const nsIntRegion& aNewValidRegion,
               const nsIntRegion& aInvalidateRegion,
               const gfxSize& aResolution);
@@ -196,16 +197,20 @@ public:
   {
     CompositableHost::SetCompositor(aCompositor);
     mVideoMemoryTiledBuffer.SetCompositor(aCompositor);
     mLowPrecisionVideoMemoryTiledBuffer.SetCompositor(aCompositor);
   }
 
   virtual void Attach(Layer* aLayer, Compositor* aCompositor) MOZ_OVERRIDE;
 
+  virtual void Dump(FILE* aFile=NULL,
+                    const char* aPrefix="",
+                    bool aDumpHtml=false) MOZ_OVERRIDE;
+
 #ifdef MOZ_LAYERS_HAVE_LOG
   virtual void PrintInfo(nsACString& aTo, const char* aPrefix);
 #endif
 
 private:
   void ProcessUploadQueue(nsIntRegion* aNewValidRegion,
                           TiledLayerProperties* aLayerProperties);
   void ProcessLowPrecisionUploadQueue();
--- a/gfx/thebes/gfxASurface.cpp
+++ b/gfx/thebes/gfxASurface.cpp
@@ -699,17 +699,16 @@ gfxASurface::BytesPerPixel(gfxImageForma
       return 1; // Close enough
     case ImageFormatUnknown:
     default:
       NS_NOTREACHED("Not really sure what you want me to say here");
       return 0;
   }
 }
 
-#ifdef MOZ_DUMP_IMAGES
 void
 gfxASurface::WriteAsPNG(const char* aFile)
 {
     FILE *file = fopen(aFile, "wb");
     if (file) {
       WriteAsPNG_internal(file, true);
       fclose(file);
     } else {
@@ -879,10 +878,8 @@ gfxASurface::WriteAsPNG_internal(FILE* a
     nsCOMPtr<nsIClipboardHelper> clipboard(do_GetService("@mozilla.org/widget/clipboardhelper;1", &rv));
     if (clipboard) {
       clipboard->CopyString(NS_ConvertASCIItoUTF16(string), nullptr);
     }
   }
 
   return;
 }
-#endif
-
--- a/gfx/thebes/gfxASurface.h
+++ b/gfx/thebes/gfxASurface.h
@@ -237,17 +237,16 @@ public:
      * process's heap.
      */
     virtual MemoryLocation GetMemoryLocation() const;
 
     static int32_t BytePerPixelFromFormat(gfxImageFormat format);
 
     virtual const gfxIntSize GetSize() const { return gfxIntSize(-1, -1); }
 
-#ifdef MOZ_DUMP_IMAGES
     /**
      * Debug functions to encode the current image as a PNG and export it.
      */
 
     /**
      * Writes a binary PNG file.
      */
     void WriteAsPNG(const char* aFile);
@@ -263,17 +262,16 @@ public:
     void PrintAsDataURL();
 
     /**
      * Copy a PNG encoded Data URL to the clipboard.
      */
     void CopyAsDataURL();
     
     void WriteAsPNG_internal(FILE* aFile, bool aBinary);
-#endif
 
     void SetOpaqueRect(const gfxRect& aRect) {
         if (aRect.IsEmpty()) {
             mOpaqueRect = nullptr;
         } else if (mOpaqueRect) {
             *mOpaqueRect = aRect;
         } else {
             mOpaqueRect = new gfxRect(aRect);