Bug 982275 - Part 2: Add a pref for drawing layer-info inside layers. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Wed, 12 Mar 2014 03:27:33 +0100
changeset 173105 244a1a183d2a83ba2103b885e56c0c762a521a4f
parent 173104 df75bcbc6eeb79363b379bb436e8f3eb77f812d5
child 173106 e358272c309364ea14f2afe9743adc6310948af3
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjrmuizel
bugs982275
milestone30.0a1
Bug 982275 - Part 2: Add a pref for drawing layer-info inside layers. r=jrmuizel
gfx/layers/Layers.h
gfx/layers/composite/ContainerLayerComposite.cpp
gfx/layers/composite/LayerManagerComposite.cpp
gfx/thebes/gfxPrefs.h
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -1303,16 +1303,23 @@ public:
    */
   void Log(const char* aPrefix="");
   /**
    * Log information about just this layer manager itself to the NSPR
    * log (if enabled for "Layers").
    */
   void LogSelf(const char* aPrefix="");
 
+  // Print interesting information about this into aTo.  Internally
+  // used to implement Dump*() and Log*().  If subclasses have
+  // additional interesting properties, they should override this with
+  // an implementation that first calls the base implementation then
+  // appends additional info to aTo.
+  virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
+
   static bool IsLogEnabled() { return LayerManager::IsLogEnabled(); }
 
   /**
    * Returns the current area of the layer (in layer-space coordinates)
    * marked as needed to be recomposited.
    */
   const nsIntRegion& GetInvalidRegion() { return mInvalidRegion; }
   const void SetInvalidRegion(const nsIntRegion& aRect) { mInvalidRegion = aRect; }
@@ -1346,23 +1353,16 @@ public:
   void Mutated()
   {
     mManager->Mutated(this);
   }
 
 protected:
   Layer(LayerManager* aManager, void* aImplData);
 
-  // Print interesting information about this into aTo.  Internally
-  // used to implement Dump*() and Log*().  If subclasses have
-  // additional interesting properties, they should override this with
-  // an implementation that first calls the base implementation then
-  // appends additional info to aTo.
-  virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
-
   /**
    * We can snap layer transforms for two reasons:
    * 1) To avoid unnecessary resampling when a transform is a translation
    * by a non-integer number of pixels.
    * Snapping the translation to an integer number of pixels avoids
    * blurring the layer and can be faster to composite.
    * 2) When a layer is used to render a rectangular object, we need to
    * emulate the rendering of rectangular inactive content and snap the
--- a/gfx/layers/composite/ContainerLayerComposite.cpp
+++ b/gfx/layers/composite/ContainerLayerComposite.cpp
@@ -26,16 +26,17 @@
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsDebug.h"                    // for NS_ASSERTION
 #include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
 #include "nsISupportsUtils.h"           // for NS_ADDREF, NS_RELEASE
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsRect.h"                     // for nsIntRect
 #include "nsRegion.h"                   // for nsIntRegion
 #include "nsTArray.h"                   // for nsAutoTArray
+#include "TextRenderer.h"               // for TextRenderer
 #include <vector>
 
 namespace mozilla {
 namespace layers {
 
 // HasOpaqueAncestorLayer and ContainerRender are shared between RefLayer and ContainerLayer
 static bool
 HasOpaqueAncestorLayer(Layer* aLayer)
@@ -115,16 +116,42 @@ static gfx::Point GetScrollData(Layer* a
   if (aLayer->GetLocalTransform().Is2D(&matrix)) {
     return matrix.GetTranslation();
   }
 
   gfx::Point origin;
   return origin;
 }
 
+static void DrawLayerInfo(const nsIntRect& aClipRect,
+                          LayerManagerComposite* aManager,
+                          Layer* aLayer)
+{
+
+  if (aLayer->GetType() == Layer::LayerType::TYPE_CONTAINER) {
+    // XXX - should figure out a way to render this, but for now this
+    // is hard to do, since it will often get superimposed over the first
+    // child of the layer, which is bad.
+    return;
+  }
+
+  nsAutoCString layerInfo;
+  aLayer->PrintInfo(layerInfo, "");
+
+  nsIntRegion visibleRegion = aLayer->GetVisibleRegion();
+
+  uint32_t maxWidth = visibleRegion.GetBounds().width < 500 ? visibleRegion.GetBounds().width : 500;
+
+  nsIntPoint topLeft = visibleRegion.GetBounds().TopLeft();
+  aManager->GetTextRenderer()->RenderText(layerInfo.get(), gfx::IntPoint(topLeft.x, topLeft.y),
+                                          aLayer->GetEffectiveTransform(), 16,
+                                          maxWidth);
+
+}
+
 static LayerVelocityUserData* GetVelocityData(Layer* aLayer) {
   static char sLayerVelocityUserDataKey;
   void* key = reinterpret_cast<void*>(&sLayerVelocityUserDataKey);
   if (!aLayer->HasUserData(key)) {
     LayerVelocityUserData* newData = new LayerVelocityUserData();
     aLayer->SetUserData(key, newData);
   }
 
@@ -356,16 +383,20 @@ ContainerRender(ContainerT* aContainer,
     if (restoreVisibleRegion) {
       // Restore the region in case it's not covered by opaque content next time
       layerToRender->SetShadowVisibleRegion(savedVisibleRegion);
     }
 
     if (gfxPrefs::LayersScrollGraph()) {
       DrawVelGraph(clipRect, aManager, layerToRender->GetLayer());
     }
+
+    if (gfxPrefs::DrawLayerInfo()) {
+      DrawLayerInfo(clipRect, aManager, layerToRender->GetLayer());
+    }
     // invariant: our GL context should be current here, I don't think we can
     // assert it though
   }
 
   if (needsSurface) {
     // Unbind the current surface and rebind the previous one.
 #ifdef MOZ_DUMP_PAINTING
     if (gfxUtils::sDumpPainting) {
--- a/gfx/layers/composite/LayerManagerComposite.cpp
+++ b/gfx/layers/composite/LayerManagerComposite.cpp
@@ -46,17 +46,17 @@
 #include "nsIWidget.h"                  // for nsIWidget
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsRect.h"                     // for nsIntRect
 #include "nsRegion.h"                   // for nsIntRegion, etc
 #ifdef MOZ_WIDGET_ANDROID
 #include <android/log.h>
 #endif
 #include "GeckoProfiler.h"
-#include "TextRenderer.h"
+#include "TextRenderer.h"               // for TextRenderer
 
 class gfxASurface;
 class gfxContext;
 struct nsIntSize;
 
 
 namespace mozilla {
 namespace layers {
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -149,16 +149,17 @@ private:
 #else
   // If MOZ_GFX_OPTIMIZE_MOBILE is not defined, we actually take the
   // preference value, defaulting to true.
   DECL_GFX_PREF(Once, "layers.componentalpha.enabled",         ComponentAlphaEnabled, bool, true);
 #endif
   DECL_GFX_PREF(Live, "layers.draw-bigimage-borders",          DrawBigImageBorders, bool, false);
   DECL_GFX_PREF(Live, "layers.draw-borders",                   DrawLayerBorders, bool, false);
   DECL_GFX_PREF(Live, "layers.draw-tile-borders",              DrawTileBorders, bool, false);
+  DECL_GFX_PREF(Live, "layers.draw-layer-info",                DrawLayerInfo, bool, false);
   DECL_GFX_PREF(Once, "layers.dump",                           LayersDump, bool, false);
   DECL_GFX_PREF(Once, "layers.enable-tiles",                   LayersTilesEnabled, bool, false);
   DECL_GFX_PREF(Once, "layers.simple-tiles",                   LayersUseSimpleTiles, bool, false);
   DECL_GFX_PREF(Once, "layers.force-per-tile-drawing",         PerTileDrawing, bool, false);
   DECL_GFX_PREF(Once, "layers.overzealous-gralloc-unlocking",  OverzealousGrallocUnlocking, bool, false);
   DECL_GFX_PREF(Once, "layers.force-shmem-tiles",              ForceShmemTiles, bool, false);
   DECL_GFX_PREF(Live, "layers.frame-counter",                  DrawFrameCounter, bool, false);
   DECL_GFX_PREF(Live, "layers.low-precision-buffer",           UseLowPrecisionBuffer, bool, false);