From ef197a24c40adc82d110afe2e2d2c24ccda9c29f Mon Sep 17 00:00:00 2001 From: Ali Akhtarzada Date: Tue, 11 Feb 2014 13:41:09 -0500 Subject: [PATCH] Bug 970327 - Add PNG dump utils for SourceSurface. r=nical --- gfx/thebes/gfxUtils.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ gfx/thebes/gfxUtils.h | 18 ++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/gfx/thebes/gfxUtils.cpp b/gfx/thebes/gfxUtils.cpp index d533d17df78..41a5b6530ee 100644 --- a/gfx/thebes/gfxUtils.cpp +++ b/gfx/thebes/gfxUtils.cpp @@ -885,6 +885,46 @@ gfxUtils::CopyAsDataURL(DrawTarget* aDT) } } +/* static */ void +gfxUtils::WriteAsPNG(RefPtr aSourceSurface, const char* aFile) +{ + RefPtr dataSurface = aSourceSurface->GetDataSurface(); + RefPtr dt + = gfxPlatform::GetPlatform() + ->CreateDrawTargetForData(dataSurface->GetData(), + dataSurface->GetSize(), + dataSurface->Stride(), + aSourceSurface->GetFormat()); + gfxUtils::WriteAsPNG(dt.get(), aFile); +} + +/* static */ void +gfxUtils::DumpAsDataURL(RefPtr aSourceSurface) +{ + RefPtr dataSurface = aSourceSurface->GetDataSurface(); + RefPtr dt + = gfxPlatform::GetPlatform() + ->CreateDrawTargetForData(dataSurface->GetData(), + dataSurface->GetSize(), + dataSurface->Stride(), + aSourceSurface->GetFormat()); + gfxUtils::DumpAsDataURL(dt.get()); +} + +/* static */ void +gfxUtils::CopyAsDataURL(RefPtr aSourceSurface) +{ + RefPtr dataSurface = aSourceSurface->GetDataSurface(); + RefPtr dt + = gfxPlatform::GetPlatform() + ->CreateDrawTargetForData(dataSurface->GetData(), + dataSurface->GetSize(), + dataSurface->Stride(), + aSourceSurface->GetFormat()); + + gfxUtils::CopyAsDataURL(dt.get()); +} + bool gfxUtils::sDumpPaintList = getenv("MOZ_DUMP_PAINT_LIST") != 0; bool gfxUtils::sDumpPainting = getenv("MOZ_DUMP_PAINT") != 0; bool gfxUtils::sDumpPaintingToFile = getenv("MOZ_DUMP_PAINT_TO_FILE") != 0; diff --git a/gfx/thebes/gfxUtils.h b/gfx/thebes/gfxUtils.h index 0bb4f8815d6..a19153e22d3 100644 --- a/gfx/thebes/gfxUtils.h +++ b/gfx/thebes/gfxUtils.h @@ -177,6 +177,24 @@ public: static bool sDumpPainting; static bool sDumpPaintingToFile; static FILE* sDumpPaintFile; + + /** + * Writes a binary PNG file. + * Expensive. Creates a DataSourceSurface, then a DrawTarget, then passes to DrawTarget overloads + */ + static void WriteAsPNG(mozilla::RefPtr aSourceSurface, const char* aFile); + + /** + * Write as a PNG encoded Data URL to stdout. + * Expensive. Creates a DataSourceSurface, then a DrawTarget, then passes to DrawTarget overloads + */ + static void DumpAsDataURL(mozilla::RefPtr aSourceSurface); + + /** + * Copy a PNG encoded Data URL to the clipboard. + * Expensive. Creates a DataSourceSurface, then a DrawTarget, then passes to DrawTarget overloads + */ + static void CopyAsDataURL(mozilla::RefPtr aSourceSurface); #endif };