From 4d45c02ee06c68f9f9f7b78d4c33cbd2ed276cda Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 31 Jul 2017 12:28:41 -0700 Subject: [PATCH] Add helper functions for dumping MLGTextures as files. (bug 1381666 part 2, r=mattwoodrow) --- gfx/layers/mlgpu/MLGDevice.cpp | 37 ++++++++++++++++++++++++++++++++++ gfx/layers/mlgpu/MLGDevice.h | 6 ++++++ 2 files changed, 43 insertions(+) diff --git a/gfx/layers/mlgpu/MLGDevice.cpp b/gfx/layers/mlgpu/MLGDevice.cpp index 869e9560644e..7ab60d9a32f8 100644 --- a/gfx/layers/mlgpu/MLGDevice.cpp +++ b/gfx/layers/mlgpu/MLGDevice.cpp @@ -354,5 +354,42 @@ MLGDevice::DrawClearRegion(const ClearRegionHelper& aHelper) } } +void +MLGDevice::WriteAsPNG(MLGTexture* aTexture, const char* aPath) +{ + MLGMappedResource map; + if (!Map(aTexture, MLGMapType::READ, &map)) { + return; + } + + RefPtr surface = Factory::CreateWrappingDataSourceSurface( + map.mData, + map.mStride, + aTexture->GetSize(), + SurfaceFormat::B8G8R8A8); + gfxUtils::WriteAsPNG(surface, aPath); + + Unmap(aTexture); +} + +RefPtr +MLGDevice::CopyAndCreateReadbackTexture(MLGTexture* aTexture) +{ + RefPtr 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 diff --git a/gfx/layers/mlgpu/MLGDevice.h b/gfx/layers/mlgpu/MLGDevice.h index c386d99c9b6e..1828989b4766 100644 --- a/gfx/layers/mlgpu/MLGDevice.h +++ b/gfx/layers/mlgpu/MLGDevice.h @@ -430,6 +430,12 @@ public: 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 CopyAndCreateReadbackTexture(MLGTexture* aTexture); + protected: virtual ~MLGDevice();