Bug 1588019 - Add option of enabling highlighting redraw regions of DCompositionVisual r=nical
authorsotaro <sotaro.ikeda.g@gmail.com>
Mon, 14 Oct 2019 12:55:01 +0000
changeset 497428 ffd3e39768a37271b681b813183f60f7fdaf6e01
parent 497427 a934af8c3acfce302024a6e86dc6f0293476fe89
child 497429 707a1884e5c5f617706f08ccf8347478191c6dce
push id36689
push userncsoregi@mozilla.com
push dateMon, 14 Oct 2019 21:30:51 +0000
treeherdermozilla-central@a212b426f665 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1588019
milestone71.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 1588019 - Add option of enabling highlighting redraw regions of DCompositionVisual r=nical Differential Revision: https://phabricator.services.mozilla.com/D48937
gfx/webrender_bindings/DCLayerTree.cpp
gfx/webrender_bindings/DCLayerTree.h
gfx/webrender_bindings/RenderCompositorANGLE.cpp
modules/libpref/init/StaticPrefList.yaml
--- a/gfx/webrender_bindings/DCLayerTree.cpp
+++ b/gfx/webrender_bindings/DCLayerTree.cpp
@@ -37,17 +37,19 @@ UniquePtr<DCLayerTree> DCLayerTree::Crea
   if (!layerTree->Initialize(aHwnd)) {
     return nullptr;
   }
 
   return layerTree;
 }
 
 DCLayerTree::DCLayerTree(IDCompositionDevice2* aCompositionDevice)
-    : mCompositionDevice(aCompositionDevice) {}
+    : mCompositionDevice(aCompositionDevice),
+      mDebugCounter(false),
+      mDebugVisualRedrawRegions(false) {}
 
 DCLayerTree::~DCLayerTree() {}
 
 bool DCLayerTree::Initialize(HWND aHwnd) {
   HRESULT hr;
 
   RefPtr<IDCompositionDesktopDevice> desktopDevice;
   hr = mCompositionDevice->QueryInterface(
@@ -73,28 +75,16 @@ bool DCLayerTree::Initialize(HWND aHwnd)
 
   hr =
       mCompositionDevice->CreateVisual(getter_AddRefs(mDefaultSwapChainVisual));
   if (FAILED(hr)) {
     gfxCriticalNote << "Failed to create DCompositionVisual: " << gfx::hexa(hr);
     return false;
   }
 
-  if (StaticPrefs::gfx_webrender_dcomp_win_debug_counter_enabled_AtStartup()) {
-    RefPtr<IDCompositionDeviceDebug> debugDevice;
-    hr = mCompositionDevice->QueryInterface(
-        (IDCompositionDeviceDebug**)getter_AddRefs(debugDevice));
-    if (SUCCEEDED(hr)) {
-      debugDevice->EnableDebugCounters();
-    } else {
-      gfxCriticalNote << "Failed to get IDCompositionDesktopDevice: "
-                      << gfx::hexa(hr);
-    }
-  }
-
   mCompositionTarget->SetRoot(mRootVisual);
   // Set interporation mode to Linear.
   // By default, a visual inherits the interpolation mode of the parent visual.
   // If no visuals set the interpolation mode, the default for the entire visual
   // tree is nearest neighbor interpolation.
   mRootVisual->SetBitmapInterpolationMode(
       DCOMPOSITION_BITMAP_INTERPOLATION_MODE_LINEAR);
   return true;
@@ -104,11 +94,67 @@ void DCLayerTree::SetDefaultSwapChain(ID
   mRootVisual->AddVisual(mDefaultSwapChainVisual, TRUE, nullptr);
   mDefaultSwapChainVisual->SetContent(aSwapChain);
   // Default SwapChain's visual does not need linear interporation.
   mDefaultSwapChainVisual->SetBitmapInterpolationMode(
       DCOMPOSITION_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR);
   mCompositionDevice->Commit();
 }
 
+void DCLayerTree::MaybeUpdateDebug() {
+  bool updated = false;
+  updated |= MaybeUpdateDebugCounter();
+  updated |= MaybeUpdateDebugVisualRedrawRegions();
+  if (updated) {
+    mCompositionDevice->Commit();
+  }
+}
+
+bool DCLayerTree::MaybeUpdateDebugCounter() {
+  bool debugCounter = StaticPrefs::gfx_webrender_debug_dcomp_counter();
+  if (mDebugCounter == debugCounter) {
+    return false;
+  }
+
+  RefPtr<IDCompositionDeviceDebug> debugDevice;
+  HRESULT hr = mCompositionDevice->QueryInterface(
+      (IDCompositionDeviceDebug**)getter_AddRefs(debugDevice));
+  if (FAILED(hr)) {
+    return false;
+  }
+
+  if (debugCounter) {
+    debugDevice->EnableDebugCounters();
+  } else {
+    debugDevice->DisableDebugCounters();
+  }
+
+  mDebugCounter = debugCounter;
+  return true;
+}
+
+bool DCLayerTree::MaybeUpdateDebugVisualRedrawRegions() {
+  bool debugVisualRedrawRegions =
+      StaticPrefs::gfx_webrender_debug_dcomp_redraw_regions();
+  if (mDebugVisualRedrawRegions == debugVisualRedrawRegions) {
+    return false;
+  }
+
+  RefPtr<IDCompositionVisualDebug> visualDebug;
+  HRESULT hr = mRootVisual->QueryInterface(
+      (IDCompositionVisualDebug**)getter_AddRefs(visualDebug));
+  if (FAILED(hr)) {
+    return false;
+  }
+
+  if (debugVisualRedrawRegions) {
+    visualDebug->EnableRedrawRegions();
+  } else {
+    visualDebug->DisableRedrawRegions();
+  }
+
+  mDebugVisualRedrawRegions = debugVisualRedrawRegions;
+  return true;
+}
+
 #endif
 }  // namespace wr
 }  // namespace mozilla
--- a/gfx/webrender_bindings/DCLayerTree.h
+++ b/gfx/webrender_bindings/DCLayerTree.h
@@ -30,29 +30,36 @@ namespace wr {
  */
 class DCLayerTree {
  public:
   static UniquePtr<DCLayerTree> Create(HWND aHwnd);
   explicit DCLayerTree(IDCompositionDevice2* aCompositionDevice);
   ~DCLayerTree();
 
   void SetDefaultSwapChain(IDXGISwapChain1* aSwapChain);
+  void MaybeUpdateDebug();
 
  protected:
   bool Initialize(HWND aHwnd);
+  bool MaybeUpdateDebugCounter();
+  bool MaybeUpdateDebugVisualRedrawRegions();
 
   RefPtr<IDCompositionDevice2> mCompositionDevice;
   RefPtr<IDCompositionTarget> mCompositionTarget;
   RefPtr<IDCompositionVisual2> mRootVisual;
   RefPtr<IDCompositionVisual2> mDefaultSwapChainVisual;
+
+  bool mDebugCounter;
+  bool mDebugVisualRedrawRegions;
 };
 #else
 class DCLayerTree {
  public:
   static UniquePtr<DCLayerTree> Create(HWND aHwnd) { return nullptr; }
   void SetDefaultSwapChain(IDXGISwapChain1* aSwapChain) {}
+  void MaybeUpdateDebug() {}
 };
 #endif
 
 }  // namespace wr
 }  // namespace mozilla
 
 #endif
--- a/gfx/webrender_bindings/RenderCompositorANGLE.cpp
+++ b/gfx/webrender_bindings/RenderCompositorANGLE.cpp
@@ -401,16 +401,20 @@ void RenderCompositorANGLE::EndFrame() {
     // window's contents to the VR window.
     FxROutputHandler* fxrHandler = mWidget->AsWindows()->GetFxrOutputHandler();
     if (fxrHandler->TryInitialize(mSwapChain, mDevice)) {
       fxrHandler->UpdateOutput(mCtx);
     }
   }
 
   mSwapChain->Present(0, 0);
+
+  if (mDCLayerTree) {
+    mDCLayerTree->MaybeUpdateDebug();
+  }
 }
 
 bool RenderCompositorANGLE::WaitForGPU() {
   // Note: this waits on the query we inserted in the previous frame,
   // not the one we just inserted now. Example:
   //   Insert query #1
   //   Present #1
   //   (first frame, no wait)
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -3547,20 +3547,25 @@
     value: false
     mirror: always
 #endif
 
 #ifdef XP_WIN
   # Enables display of performance debugging counters when DirectComposition
   # is used.
   # Performance counters are displayed on the top-right corner of the screen.
-- name: gfx.webrender.dcomp-win.debug-counter.enabled
-  type: bool
-  value: false
-  mirror: once
+-   name: gfx.webrender.debug.dcomp-counter
+    type: RelaxedAtomicBool
+    value: false
+    mirror: always
+  # Enables highlighting redraw regions of DCompositionVisual
+-   name: gfx.webrender.debug.dcomp-redraw-regions
+    type: RelaxedAtomicBool
+    value: false
+    mirror: always
 #endif
 
 # Use vsync events generated by hardware
 - name: gfx.work-around-driver-bugs
   type: bool
   value: true
   mirror: once