Add helper functions for dumping MLGTextures as files. (bug 1381666 part 2, r=mattwoodrow)
authorDavid Anderson <danderson@mozilla.com>
Mon, 31 Jul 2017 12:28:41 -0700
changeset 420848 368331e8a462cd0fe6e6ea81afb5f4a817e2e5e3
parent 420847 bb46fd08bcff60198e2468064e1ce96f2d385c7f
child 420849 2736371868ec427366574b77098440ed41cc0e39
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1381666
milestone56.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
Add helper functions for dumping MLGTextures as files. (bug 1381666 part 2, r=mattwoodrow)
gfx/layers/mlgpu/MLGDevice.cpp
gfx/layers/mlgpu/MLGDevice.h
--- a/gfx/layers/mlgpu/MLGDevice.cpp
+++ b/gfx/layers/mlgpu/MLGDevice.cpp
@@ -349,10 +349,47 @@ MLGDevice::DrawClearRegion(const ClearRe
   // Otherwise, if we have a normal rect list, we wanted to use the faster
   // ClearView.
   if (!aHelper.mRects.IsEmpty()) {
     Color color(0.0, 0.0, 0.0, 0.0);
     ClearView(mCurrentRT, color, aHelper.mRects.Elements(), aHelper.mRects.Length());
   }
 }
 
+void
+MLGDevice::WriteAsPNG(MLGTexture* aTexture, const char* aPath)
+{
+  MLGMappedResource map;
+  if (!Map(aTexture, MLGMapType::READ, &map)) {
+    return;
+  }
+
+  RefPtr<DataSourceSurface> surface = Factory::CreateWrappingDataSourceSurface(
+    map.mData,
+    map.mStride,
+    aTexture->GetSize(),
+    SurfaceFormat::B8G8R8A8);
+  gfxUtils::WriteAsPNG(surface, aPath);
+
+  Unmap(aTexture);
+}
+
+RefPtr<MLGTexture>
+MLGDevice::CopyAndCreateReadbackTexture(MLGTexture* aTexture)
+{
+  RefPtr<MLGTexture> copy = CreateTexture(
+    aTexture->GetSize(),
+    SurfaceFormat::B8G8R8A8,
+    MLGUsage::Staging,
+    MLGTextureFlags::None);
+  if (!copy) {
+    return nullptr;
+  }
+  CopyTexture(
+    copy,
+    IntPoint(0, 0),
+    aTexture,
+    IntRect(IntPoint(0, 0), aTexture->GetSize()));
+  return copy;
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/mlgpu/MLGDevice.h
+++ b/gfx/layers/mlgpu/MLGDevice.h
@@ -425,16 +425,22 @@ public:
   }
 
   // Helper function for unbinding textures since SetPSTexture is overloaded.
   void UnsetPSTexture(uint32_t aSlot) {
     TextureSource* nullTexture = nullptr;
     SetPSTexture(aSlot, nullTexture);
   }
 
+  // Debugging helper function for dumping an MLGTexture to a file.
+  void WriteAsPNG(MLGTexture* aTexture, const char* aPath);
+
+  // Debugging helper function for copying a texture for later dumping to a file.
+  RefPtr<MLGTexture> CopyAndCreateReadbackTexture(MLGTexture* aTexture);
+
 protected:
   virtual ~MLGDevice();
 
   virtual void SetPrimitiveTopology(MLGPrimitiveTopology aTopology) = 0;
 
   // Optionally run a runtime test to determine if constant buffer offset
   // binding works.
   virtual bool VerifyConstantBufferOffsetting() {