Bug 907286 - Implement Frame Counter for non OMTC basic. r=jmuizel,tnikkel
authorBenoit Girard <b56girard@gmail.com>
Thu, 22 Aug 2013 12:54:05 -0400
changeset 143996 b66681223e7c47b1464b1278dcb1deb9500d9486
parent 143995 ed4429af6905a4895e0286f700c16ac365c057f8
child 143997 5355f7065af4d35b6b986638823c5e5aa1ab8589
push id32840
push userb56girard@gmail.com
push dateFri, 23 Aug 2013 03:43:20 +0000
treeherdermozilla-inbound@b66681223e7c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmuizel, tnikkel
bugs907286
milestone26.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 907286 - Implement Frame Counter for non OMTC basic. r=jmuizel,tnikkel
gfx/layers/basic/BasicLayerManager.cpp
gfx/layers/basic/BasicLayers.h
gfx/thebes/gfxPlatform.h
view/src/nsViewManager.cpp
--- a/gfx/layers/basic/BasicLayerManager.cpp
+++ b/gfx/layers/basic/BasicLayerManager.cpp
@@ -531,16 +531,45 @@ void
 BasicLayerManager::AbortTransaction()
 {
   NS_ASSERTION(InConstruction(), "Should be in construction phase");
   mPhase = PHASE_NONE;
   mUsingDefaultTarget = false;
   mInTransaction = false;
 }
 
+static uint16_t sFrameCount = 0;
+void
+BasicLayerManager::RenderDebugOverlay()
+{
+  if (!gfxPlatform::DrawFrameCounter()) {
+    return;
+  }
+
+  profiler_set_frame_number(sFrameCount);
+
+  uint16_t frameNumber = sFrameCount;
+  const uint16_t bitWidth = 3;
+  for (size_t i = 0; i < 16; i++) {
+
+    gfxRGBA bitColor;
+    if ((frameNumber >> i) & 0x1) {
+      bitColor = gfxRGBA(0, 0, 0, 1.0);
+    } else {
+      bitColor = gfxRGBA(1.0, 1.0, 1.0, 1.0);
+    }
+    mTarget->NewPath();
+    mTarget->SetColor(bitColor);
+    mTarget->Rectangle(gfxRect(bitWidth*i, 0, bitWidth, bitWidth));
+    mTarget->Fill();
+  }
+  // We intentionally overflow at 2^16.
+  sFrameCount++;
+}
+
 bool
 BasicLayerManager::EndTransactionInternal(DrawThebesLayerCallback aCallback,
                                           void* aCallbackData,
                                           EndTransactionFlags aFlags)
 {
   PROFILER_LABEL("BasicLayerManager", "EndTransactionInternal");
 #ifdef MOZ_LAYERS_HAVE_LOG
   MOZ_LAYERS_LOG(("  ----- (beginning paint)"));
@@ -608,16 +637,17 @@ BasicLayerManager::EndTransactionInterna
         PaintLayer(mTarget, mRoot, aCallback, aCallbackData, nullptr);
       }
       // If we're not retained, then don't composite means do nothing at all.
     } else {
       PaintLayer(mTarget, mRoot, aCallback, aCallbackData, nullptr);
       if (mWidget) {
         FlashWidgetUpdateArea(mTarget);
       }
+      RenderDebugOverlay();
       LayerManager::PostPresent();
     }
 
     if (!mTransactionIncomplete) {
       // Clear out target if we have a complete transaction.
       mTarget = nullptr;
     }
   }
--- a/gfx/layers/basic/BasicLayers.h
+++ b/gfx/layers/basic/BasicLayers.h
@@ -173,16 +173,18 @@ protected:
   void ClearLayer(Layer* aLayer);
 
   bool EndTransactionInternal(DrawThebesLayerCallback aCallback,
                               void* aCallbackData,
                               EndTransactionFlags aFlags = END_DEFAULT);
 
   void FlashWidgetUpdateArea(gfxContext* aContext);
 
+  void RenderDebugOverlay();
+
   // Widget whose surface should be used as the basis for ThebesLayer
   // buffers.
   nsIWidget* mWidget;
   // The default context for BeginTransaction.
   nsRefPtr<gfxContext> mDefaultTarget;
   // The context to draw into.
   nsRefPtr<gfxContext> mTarget;
   // When we're doing a transaction in order to draw to a non-default
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -580,16 +580,22 @@ public:
     uint32_t GetOrientationSyncMillis() const;
 
     /**
      * Return the layer debugging options to use browser-wide.
      */
     mozilla::layers::DiagnosticTypes GetLayerDiagnosticTypes();
 
     static bool DrawFrameCounter();
+    static nsIntRect FrameCounterBounds() {
+      int bits = 16;
+      int sizeOfBit = 3;
+      return nsIntRect(0, 0, bits * sizeOfBit, sizeOfBit);
+    }
+
     /**
      * Returns true if we should use raw memory to send data to the compositor
      * rather than using shmems.
      *
      * This method should not be called from the compositor thread.
      */
     bool PreferMemoryOverShmem() const;
     bool UseDeprecatedTextures() const { return mLayersUseDeprecated; }
--- a/view/src/nsViewManager.cpp
+++ b/view/src/nsViewManager.cpp
@@ -21,16 +21,17 @@
 #include "nsEventStateManager.h"
 #include "mozilla/StartupTimeline.h"
 #include "GeckoProfiler.h"
 #include "nsRefreshDriver.h"
 #include "mozilla/Preferences.h"
 #include "nsContentUtils.h" // for nsAutoScriptBlocker
 #include "nsLayoutUtils.h"
 #include "Layers.h"
+#include "gfxPlatform.h"
 
 /**
    XXX TODO XXX
 
    DeCOMify newly private methods
    Optimize view storage
 */
 
@@ -430,16 +431,24 @@ void nsViewManager::FlushDirtyRegionToWi
   nsRegion* dirtyRegion = aView->GetDirtyRegion();
   nsView* nearestViewWithWidget = aView;
   while (!nearestViewWithWidget->HasWidget() &&
          nearestViewWithWidget->GetParent()) {
     nearestViewWithWidget = nearestViewWithWidget->GetParent();
   }
   nsRegion r =
     ConvertRegionBetweenViews(*dirtyRegion, aView, nearestViewWithWidget);
+
+  // If we draw the frame counter we need to make sure we invalidate the area
+  // for it to make it on screen
+  if (gfxPlatform::DrawFrameCounter()) {
+    nsRect counterBounds = gfxPlatform::FrameCounterBounds().ToAppUnits(AppUnitsPerDevPixel());
+    r = r.Or(r, counterBounds);
+  }
+
   nsViewManager* widgetVM = nearestViewWithWidget->GetViewManager();
   widgetVM->InvalidateWidgetArea(nearestViewWithWidget, r);
   dirtyRegion->SetEmpty();
 }
 
 void
 nsViewManager::InvalidateView(nsView *aView)
 {