Add helper functions for dumping MLGTextures as files. (bug 1381666 part 2, r=mattwoodrow)

This commit is contained in:
David Anderson 2017-07-31 12:28:41 -07:00
parent b05dbf58c2
commit 4d45c02ee0
2 changed files with 43 additions and 0 deletions

View File

@ -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<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

View File

@ -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<MLGTexture> CopyAndCreateReadbackTexture(MLGTexture* aTexture);
protected:
virtual ~MLGDevice();