Bug 970327 - Add PNG dump utils for SourceSurface. r=nical
authorAli Akhtarzada <ali@comoyo.com>
Tue, 11 Feb 2014 13:41:09 -0500
changeset 168452 47167978bd6320b6113b24db8d228906ee9548c7
parent 168451 72910da4cb7787799b3b5340991e05ad62e23f26
child 168453 0489e6fcf52ec68a8a52d2a3b61d5ba0d30b59f1
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersnical
bugs970327
milestone30.0a1
Bug 970327 - Add PNG dump utils for SourceSurface. r=nical
gfx/thebes/gfxUtils.cpp
gfx/thebes/gfxUtils.h
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -880,13 +880,53 @@ gfxUtils::CopyAsDataURL(DrawTarget* aDT)
   nsRefPtr<gfxASurface> surf = gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(aDT);
   if (surf) {
     surf->CopyAsDataURL();
   } else {
     NS_WARNING("Failed to get Thebes surface!");
   }
 }
 
+/* static */ void
+gfxUtils::WriteAsPNG(RefPtr<gfx::SourceSurface> aSourceSurface, const char* aFile)
+{
+  RefPtr<gfx::DataSourceSurface> dataSurface = aSourceSurface->GetDataSurface();
+  RefPtr<gfx::DrawTarget> dt
+            = gfxPlatform::GetPlatform()
+                ->CreateDrawTargetForData(dataSurface->GetData(),
+                                          dataSurface->GetSize(),
+                                          dataSurface->Stride(),
+                                          aSourceSurface->GetFormat());
+  gfxUtils::WriteAsPNG(dt.get(), aFile);
+}
+
+/* static */ void
+gfxUtils::DumpAsDataURL(RefPtr<gfx::SourceSurface> aSourceSurface)
+{
+  RefPtr<gfx::DataSourceSurface> dataSurface = aSourceSurface->GetDataSurface();
+  RefPtr<gfx::DrawTarget> dt
+            = gfxPlatform::GetPlatform()
+                ->CreateDrawTargetForData(dataSurface->GetData(),
+                                          dataSurface->GetSize(),
+                                          dataSurface->Stride(),
+                                          aSourceSurface->GetFormat());
+  gfxUtils::DumpAsDataURL(dt.get());
+}
+
+/* static */ void
+gfxUtils::CopyAsDataURL(RefPtr<gfx::SourceSurface> aSourceSurface)
+{
+  RefPtr<gfx::DataSourceSurface> dataSurface = aSourceSurface->GetDataSurface();
+  RefPtr<gfx::DrawTarget> 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;
 FILE *gfxUtils::sDumpPaintFile = nullptr;
 #endif
--- a/gfx/thebes/gfxUtils.h
+++ b/gfx/thebes/gfxUtils.h
@@ -172,16 +172,34 @@ public:
      * Copy a PNG encoded Data URL to the clipboard.
      */
     static void CopyAsDataURL(mozilla::gfx::DrawTarget* aDT);
 
     static bool sDumpPaintList;
     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<mozilla::gfx::SourceSurface> 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<mozilla::gfx::SourceSurface> 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<mozilla::gfx::SourceSurface> aSourceSurface);
 #endif
 };
 
 namespace mozilla {
 namespace gfx {
 
 
 /* These techniques are suggested by "Bit Twiddling Hacks"