Bug 735178 - Add debug coloring of sorted 3d layers to help identification. r=roc
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 27 Apr 2012 12:24:53 +1200
changeset 92558 7a077df0c773fc9044cfa33ec58a64ff919f5de4
parent 92557 2841b49cfb165b575697ed509ad8ef21a2101823
child 92559 302c5a56596573df8124f30823a2e798e2b17a4f
push id8753
push usermwoodrow@mozilla.com
push dateFri, 27 Apr 2012 00:25:03 +0000
treeherdermozilla-inbound@e8bf76219f36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs735178
milestone15.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 735178 - Add debug coloring of sorted 3d layers to help identification. r=roc
gfx/layers/LayerSorter.cpp
gfx/layers/Layers.h
gfx/layers/basic/BasicLayers.cpp
--- a/gfx/layers/LayerSorter.cpp
+++ b/gfx/layers/LayerSorter.cpp
@@ -161,49 +161,115 @@ static LayerSortOrder CompareDepth(Layer
   } else {
     return BBeforeA;
   }
 }
 
 #ifdef DEBUG
 static bool gDumpLayerSortList = getenv("MOZ_DUMP_LAYER_SORT_LIST") != 0;
 
+#define BLACK       0
+#define RED         1
+#define GREEN       2
+#define YELLOW      3
+#define BLUE        4
+#define MAGENTA     5
+#define CYAN        6
+#define WHITE       7
+
+//#define USE_XTERM_COLORING
+#ifdef USE_XTERM_COLORING
+
+#define RESET       0
+#define BRIGHT      1
+#define DIM         2
+#define UNDERLINE   3
+#define BLINK       4
+#define REVERSE     7
+#define HIDDEN      8
+
+static void SetTextColor(PRUint32 aColor)
+{
+  char command[13];
+
+  /* Command is the control command to the terminal */
+  sprintf(command, "%c[%d;%d;%dm", 0x1B, RESET, aColor + 30, BLACK + 40);
+  printf("%s", command);
+}
+
+static void print_layer_internal(FILE* aFile, Layer* aLayer, PRUint32 aColor)
+{
+  SetTextColor(aColor);
+  fprintf(aFile, "%p", aLayer);
+  SetTextColor(GREEN);
+}
+#else
+
+const char *colors[] = { "Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White" };
+
+static void print_layer_internal(FILE* aFile, Layer* aLayer, PRUint32 aColor)
+{
+  fprintf(aFile, "%p(%s)", aLayer, colors[aColor]);
+}
+#endif
+
+static void print_layer(FILE* aFile, Layer* aLayer)
+{
+  print_layer_internal(aFile, aLayer, aLayer->GetDebugColorIndex());
+}
+
 static void DumpLayerList(nsTArray<Layer*>& aLayers)
 {
   for (PRUint32 i = 0; i < aLayers.Length(); i++) {
-    fprintf(stderr, "%p, ", aLayers.ElementAt(i));
+    print_layer(stderr, aLayers.ElementAt(i));
+    fprintf(stderr, " ");
   }
   fprintf(stderr, "\n");
 }
 
 static void DumpEdgeList(DirectedGraph<Layer*>& aGraph)
 {
   nsTArray<DirectedGraph<Layer*>::Edge> edges = aGraph.GetEdgeList();
   
   for (PRUint32 i = 0; i < edges.Length(); i++) {
-    fprintf(stderr, "From: %p, To: %p\n", edges.ElementAt(i).mFrom, edges.ElementAt(i).mTo);
+    fprintf(stderr, "From: ");
+    print_layer(stderr, edges.ElementAt(i).mFrom);
+    fprintf(stderr, ", To: ");
+    print_layer(stderr, edges.ElementAt(i).mTo);
+    fprintf(stderr, "\n");
   }
 }
 #endif
 
 // The maximum number of layers that we will attempt to sort. Anything
 // greater than this will be left unsorted. We should consider enabling
 // depth buffering for the scene in this case.
 #define MAX_SORTABLE_LAYERS 100
 
+
+PRUint32 gColorIndex = 1;
+
 void SortLayersBy3DZOrder(nsTArray<Layer*>& aLayers)
 {
   PRUint32 nodeCount = aLayers.Length();
   if (nodeCount > MAX_SORTABLE_LAYERS) {
     return;
   }
   DirectedGraph<Layer*> graph;
 
 #ifdef DEBUG
   if (gDumpLayerSortList) {
+    for (PRUint32 i = 0; i < nodeCount; i++) {
+      if (aLayers.ElementAt(i)->GetDebugColorIndex() == 0) {
+        aLayers.ElementAt(i)->SetDebugColorIndex(gColorIndex++);
+        if (gColorIndex > 7) {
+          gColorIndex = 1;
+        }
+      }
+    }
     fprintf(stderr, " --- Layers before sorting: --- \n");
     DumpLayerList(aLayers);
   }
 #endif
 
   // Iterate layers and determine edges.
   for (PRUint32 i = 0; i < nodeCount; i++) {
     for (PRUint32 j = i + 1; j < nodeCount; j++) {
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -886,28 +886,34 @@ public:
   /**
    * Log information about just this layer manager itself to the NSPR
    * log (if enabled for "Layers").
    */
   void LogSelf(const char* aPrefix="");
 
   static bool IsLogEnabled() { return LayerManager::IsLogEnabled(); }
 
+#ifdef DEBUG
+  void SetDebugColorIndex(PRUint32 aIndex) { mDebugColorIndex = aIndex; }
+  PRUint32 GetDebugColorIndex() { return mDebugColorIndex; }
+#endif
+
 protected:
   Layer(LayerManager* aManager, void* aImplData) :
     mManager(aManager),
     mParent(nsnull),
     mNextSibling(nsnull),
     mPrevSibling(nsnull),
     mImplData(aImplData),
     mOpacity(1.0),
     mContentFlags(0),
     mUseClipRect(false),
     mUseTileSourceRect(false),
-    mIsFixedPosition(false)
+    mIsFixedPosition(false),
+    mDebugColorIndex(0)
     {}
 
   void Mutated() { mManager->Mutated(this); }
 
   // 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
@@ -946,16 +952,17 @@ protected:
   gfx3DMatrix mEffectiveTransform;
   float mOpacity;
   nsIntRect mClipRect;
   nsIntRect mTileSourceRect;
   PRUint32 mContentFlags;
   bool mUseClipRect;
   bool mUseTileSourceRect;
   bool mIsFixedPosition;
+  DebugOnly<PRUint32> mDebugColorIndex;
 };
 
 /**
  * A Layer which we can draw into using Thebes. It is a conceptually
  * infinite surface, but each ThebesLayer has an associated "valid region"
  * of contents that it is currently storing, which is finite. ThebesLayer
  * implementations can store content between paints.
  * 
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -1904,16 +1904,29 @@ BasicLayerManager::PaintLayer(gfxContext
       // Temporary fast fix for bug 725886
       // Revert these changes when 725886 is ready
       gfxRect clipExtents;
       clipExtents = aTarget->GetClipExtents();
       if (!clipExtents.IsEmpty()) {
         gfxPoint offset;
         bool dontBlit = needsClipToVisibleRegion || mTransactionIncomplete ||
                           aLayer->GetEffectiveOpacity() != 1.0f;
+#ifdef DEBUG
+        if (aLayer->GetDebugColorIndex() != 0) {
+          gfxRGBA  color((aLayer->GetDebugColorIndex() & 1) ? 1.0 : 0.0,
+                         (aLayer->GetDebugColorIndex() & 2) ? 1.0 : 0.0,
+                         (aLayer->GetDebugColorIndex() & 4) ? 1.0 : 0.0,
+                         1.0);
+
+          nsRefPtr<gfxContext> temp = new gfxContext(untransformedSurface);
+          temp->SetColor(color);
+          temp->Paint();
+        }
+#endif
+
         nsRefPtr<gfxASurface> result =
           Transform3D(untransformedSurface, aTarget, bounds,
                       effectiveTransform, offset, dontBlit);
 
         blitComplete = !result;
         if (result) {
           aTarget->SetSource(result, offset);
         }