Bug 770988 - Seperate DumpAsDataURL into MOZ_DUMP_IMAGES. r=ajuma
authorBenoit Girard <b56girard@gmail.com>
Thu, 05 Jul 2012 14:07:37 -0400
changeset 98428 5e9b5536926763291ad70cdf7c71a2c587ec0a97
parent 98427 66f1b29d806b7fa9a4f4bdbeda004ed82d2af2d5
child 98429 c820391d9a2ef0e53498b4e301502fbad30867e5
push id23056
push userryanvm@gmail.com
push dateFri, 06 Jul 2012 00:15:11 +0000
treeherdermozilla-central@41cbcc06d6b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersajuma
bugs770988
milestone16.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
Bug 770988 - Seperate DumpAsDataURL into MOZ_DUMP_IMAGES. r=ajuma
gfx/thebes/gfxASurface.cpp
gfx/thebes/gfxASurface.h
--- a/gfx/thebes/gfxASurface.cpp
+++ b/gfx/thebes/gfxASurface.cpp
@@ -637,45 +637,45 @@ void
 gfxASurface::RecordMemoryFreed()
 {
     if (mBytesRecorded) {
         RecordMemoryUsedForSurfaceType(GetType(), -mBytesRecorded);
         mBytesRecorded = 0;
     }
 }
 
-#ifdef MOZ_DUMP_PAINTING
+#ifdef MOZ_DUMP_IMAGES
 void
 gfxASurface::WriteAsPNG(const char* aFile)
 {
     FILE *file = fopen(aFile, "wb");
     if (file) {
       WriteAsPNG_internal(file, true);
       fclose(file);
     } else {
       NS_WARNING("Failed to create file!\n");
     }
 }
-    
-void 
-gfxASurface::DumpAsDataURL(FILE* aOutput) 
-{ 
+
+void
+gfxASurface::DumpAsDataURL(FILE* aOutput)
+{
   WriteAsPNG_internal(aOutput, false);
 }
 
 void
 gfxASurface::PrintAsDataURL()
 {
   WriteAsPNG_internal(stdout, false);
   fprintf(stdout, "\n");
 }
 
-void 
-gfxASurface::CopyAsDataURL() 
-{ 
+void
+gfxASurface::CopyAsDataURL()
+{
   WriteAsPNG_internal(nsnull, false);
 }
 
 /**
  * Write to a PNG file. If aBinary is true, then it is written
  * as binary, otherwise as a data URL. If no file is specified then
  * data is copied to the clipboard (must not be binary!).
  */
@@ -687,17 +687,17 @@ gfxASurface::WriteAsPNG_internal(FILE* a
 
   if (!imgsurf) {
     size = GetSize();
     if (size.width == -1 && size.height == -1) {
       printf("Could not determine surface size\n");
       return;
     }
 
-    imgsurf = 
+    imgsurf =
       new gfxImageSurface(gfxIntSize(size.width, size.height),
                           gfxASurface::ImageFormatARGB32);
 
     if (!imgsurf || imgsurf->CairoStatus()) {
       printf("Could not allocate image surface\n");
       return;
     }
 
@@ -723,19 +723,19 @@ gfxASurface::WriteAsPNG_internal(FILE* a
       for (PRInt32 x = 0; x < w; ++x) {
         printf("%x ", reinterpret_cast<PRUint32*>(imgsurf->Data())[y*imgsurf->Stride()+ x]);
       }
     }
     return;
   }
 
   nsresult rv = encoder->InitFromData(imgsurf->Data(),
-                                      size.width * size.height * 4, 
-                                      size.width, 
-                                      size.height, 
+                                      size.width * size.height * 4,
+                                      size.width,
+                                      size.height,
                                       imgsurf->Stride(),
                                       imgIEncoder::INPUT_FORMAT_HOSTARGB,
                                       NS_LITERAL_STRING(""));
   if (NS_FAILED(rv))
     return;
 
   nsCOMPtr<nsIInputStream> imgStream;
   CallQueryInterface(encoder.get(), getter_AddRefs(imgStream));
@@ -750,52 +750,66 @@ gfxASurface::WriteAsPNG_internal(FILE* a
   // ...leave a little extra room so we can call read again and make sure we
   // got everything. 16 bytes for better padding (maybe)
   bufSize += 16;
   PRUint32 imgSize = 0;
   char* imgData = (char*)PR_Malloc(bufSize);
   if (!imgData)
     return;
   PRUint32 numReadThisTime = 0;
-  while ((rv = imgStream->Read(&imgData[imgSize], 
+  while ((rv = imgStream->Read(&imgData[imgSize],
                                bufSize - imgSize,
-                               &numReadThisTime)) == NS_OK && numReadThisTime > 0) 
+                               &numReadThisTime)) == NS_OK && numReadThisTime > 0)
   {
     imgSize += numReadThisTime;
     if (imgSize == bufSize) {
       // need a bigger buffer, just double
       bufSize *= 2;
       char* newImgData = (char*)PR_Realloc(imgData, bufSize);
       if (!newImgData) {
         PR_Free(imgData);
         return;
       }
       imgData = newImgData;
     }
   }
 
   if (aBinary) {
     if (aFile) {
-      fwrite(imgData, 1, imgSize, aFile); 
+      fwrite(imgData, 1, imgSize, aFile);
     } else {
       NS_WARNING("Can't write binary image data without a file!");
     }
     return;
   }
-  
+
   // base 64, result will be NULL terminated
   char* encodedImg = PL_Base64Encode(imgData, imgSize, nsnull);
   PR_Free(imgData);
   if (!encodedImg) // not sure why this would fail
     return;
 
   nsCString string("data:image/png;base64,");
   string.Append(encodedImg);
 
   if (aFile) {
+#ifdef ANDROID
+     if (aFile == stdout || aFile == stderr) {
+       // ADB logcat cuts off long strings so we will break it down
+       const char* cStr = string.BeginReading();
+       size_t len = strlen(cStr);
+       while (true) {
+         printf_stderr("IMG: %.140s\n", cStr);
+         if (len <= 140)
+           break;
+         len -= 140;
+         cStr += 140;
+       }
+     }
+#endif
     fprintf(aFile, "%s", string.BeginReading());
   } else {
     nsCOMPtr<nsIClipboardHelper> clipboard(do_GetService("@mozilla.org/widget/clipboardhelper;1", &rv));
     if (clipboard) {
       clipboard->CopyString(NS_ConvertASCIItoUTF16(string), nsnull);
     }
   }
 
--- a/gfx/thebes/gfxASurface.h
+++ b/gfx/thebes/gfxASurface.h
@@ -1,16 +1,20 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_ASURFACE_H
 #define GFX_ASURFACE_H
 
+#ifdef MOZ_DUMP_PAINTING
+ #define MOZ_DUMP_IMAGES
+#endif
+
 #include "gfxTypes.h"
 #include "gfxRect.h"
 #include "nsAutoPtr.h"
 #include "nsAutoRef.h"
 #include "nsThreadUtils.h"
 
 typedef struct _cairo_surface cairo_surface_t;
 typedef struct _cairo_user_data_key cairo_user_data_key_t;
@@ -208,17 +212,17 @@ public:
      * process's heap.
      */
     virtual MemoryLocation GetMemoryLocation() const;
 
     static PRInt32 BytePerPixelFromFormat(gfxImageFormat format);
 
     virtual const gfxIntSize GetSize() const { return gfxIntSize(-1, -1); }
 
-#ifdef MOZ_DUMP_PAINTING
+#ifdef MOZ_DUMP_IMAGES
     /**
      * Debug functions to encode the current image as a PNG and export it.
      */
 
     /**
      * Writes a binary PNG file.
      */
     void WriteAsPNG(const char* aFile);