Remove unused parameters to SkDocument::CreatePDF

All image compression currently uses (losseless) Deflate, not Jpeg.

All clients simply use SkDocument::CreatePDF(stream).

SampleApp and SkLua still use SkDocument::CreatePDF(path).

Review URL: https://codereview.chromium.org/935843007
diff --git a/include/core/SkDocument.h b/include/core/SkDocument.h
index 83098aa..db8113f 100644
--- a/include/core/SkDocument.h
+++ b/include/core/SkDocument.h
@@ -35,50 +35,33 @@
     SK_DECLARE_INST_COUNT(SkDocument)
 
     /**
-     *  Create a PDF-backed document, writing the results into a file.
-     *  If there is an error trying to create the doc, returns NULL.
-     *  encoder sets the DCTEncoder for images, to encode a bitmap
-     *    as JPEG (DCT).
-     *  rasterDpi - the DPI at which features without native PDF support
-     *              will be rasterized (e.g. draw image with perspective,
-     *              draw text with perspective, ...)
-     *              A larger DPI would create a PDF that reflects the original
-     *              intent with better fidelity, but it can make for larger
-     *              PDF files too, which would use more memory while rendering,
-     *              and it would be slower to be processed or sent online or
-     *              to printer.
+     *  Create a PDF-backed document, writing the results into a SkWStream.
+     *
+     *  PDF pages are sized in point units. 1 pt == 1/72 inch == 127/360 mm.
+     *
+     *  @param SkWStream* A PDF document will be written to this
+     *         stream.  The document may write to the stream at
+     *         anytime during its lifetime, until either close() is
+     *         called or the document is deleted.
+     *  @param dpi The DPI (pixels-per-inch) at which features without
+     *         native PDF support will be rasterized (e.g. draw image
+     *         with perspective, draw text with perspective, ...)  A
+     *         larger DPI would create a PDF that reflects the
+     *         original intent with better fidelity, but it can make
+     *         for larger PDF files too, which would use more memory
+     *         while rendering, and it would be slower to be processed
+     *         or sent online or to printer.
+     *  @returns NULL if there is an error, otherwise a newly created
+     *           PDF-backed SkDocument.
      */
-    static SkDocument* CreatePDF(
-            const char filename[],
-            SkPicture::EncodeBitmap encoder = NULL,
-            SkScalar rasterDpi = SK_ScalarDefaultRasterDPI);
+    static SkDocument* CreatePDF(SkWStream*,
+                                 SkScalar dpi = SK_ScalarDefaultRasterDPI);
 
     /**
-     *  Create a PDF-backed document, writing the results into a stream.
-     *  If there is an error trying to create the doc, returns NULL.
-     *
-     *  The document may write to the stream at anytime during its lifetime,
-     *  until either close() is called or the document is deleted. Once close()
-     *  has been called, and all of the data has been written to the stream,
-     *  if there is a Done proc provided, it will be called with the stream.
-     *  The proc can delete the stream, or whatever it needs to do.
-     *  encoder sets the DCTEncoder for images, to encode a bitmap
-     *    as JPEG (DCT).
-     *  Done - clean up method intended to allow deletion of the stream.
-     *         Its aborted parameter is true if the cleanup is due to an abort
-     *         call. It is false otherwise.
-     *  rasterDpi - the DPI at which features without native PDF support
-     *              will be rasterized (e.g. draw image with perspective,
-     *              draw text with perspective, ...)
-     *              A larger DPI would create a PDF that reflects the original
-     *              intent with better fidelity, but it can make for larger
-     *              PDF files too, which would use more memory while rendering,
-     *              and it would be slower to be processed or sent online or
-     *              to printer.     */
-    static SkDocument* CreatePDF(
-            SkWStream*, void (*Done)(SkWStream*,bool aborted) = NULL,
-            SkPicture::EncodeBitmap encoder = NULL,
-            SkScalar rasterDpi = SK_ScalarDefaultRasterDPI);
+     *  Create a PDF-backed document, writing the results into a file.
+     */
+    static SkDocument* CreatePDF(const char outputFilePath[],
+                                 SkScalar dpi = SK_ScalarDefaultRasterDPI);
 
     /**
      *  Begin a new page for the document, returning the canvas that will draw
@@ -112,6 +95,7 @@
 
 protected:
     SkDocument(SkWStream*, void (*)(SkWStream*, bool aborted));
+
     // note: subclasses must call close() in their destructor, as the base class
     // cannot do this for them.
     virtual ~SkDocument();
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index 5b2f7a9..346d65b 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -139,20 +139,6 @@
     uint32_t uniqueID() const { return fUniqueID; }
 
     /**
-     *  Function to encode an SkBitmap to an SkData. A function with this
-     *  signature can be passed to serialize() and SkWriteBuffer.
-     *  Returning NULL will tell the SkWriteBuffer to use
-     *  SkBitmap::flatten() to store the bitmap.
-     *
-     *  @param pixelRefOffset DEPRECATED -- caller assumes it will return 0.
-     *  @return SkData If non-NULL, holds encoded data representing the passed
-     *      in bitmap. The caller is responsible for calling unref().
-     *
-     *  TODO: No longer used by SkPicture. Still used by PDF though. Move into PDF.
-     */
-    typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm);
-
-    /**
      *  Serialize to a stream. If non NULL, serializer will be used to serialize
      *  any bitmaps in the picture.
      *
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp
index de65efe..6d6bf63 100644
--- a/src/doc/SkDocument_PDF.cpp
+++ b/src/doc/SkDocument_PDF.cpp
@@ -11,16 +11,14 @@
 
 class SkDocument_PDF : public SkDocument {
 public:
-    SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*,bool),
-                   SkPicture::EncodeBitmap encoder,
+    SkDocument_PDF(SkWStream* stream,
+                   void (*doneProc)(SkWStream*,bool),
                    SkScalar rasterDpi)
-            : SkDocument(stream, doneProc)
-            , fEncoder(encoder)
-            , fRasterDpi(rasterDpi) {
-        fDoc = SkNEW(SkPDFDocument);
-        fCanvas = NULL;
-        fDevice = NULL;
-    }
+        : SkDocument(stream, doneProc)
+        , fDoc(SkNEW(SkPDFDocument))
+        , fDevice(NULL)
+        , fCanvas(NULL)
+        , fRasterDpi(rasterDpi) {}
 
     virtual ~SkDocument_PDF() {
         // subclasses must call close() in their destructors
@@ -37,9 +35,6 @@
         mediaBoxSize.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height));
 
         fDevice = SkNEW_ARGS(SkPDFDevice, (mediaBoxSize, mediaBoxSize, SkMatrix::I()));
-        if (fEncoder) {
-            fDevice->setDCTEncoder(fEncoder);
-        }
         if (fRasterDpi != 0) {
             fDevice->setRasterDpi(fRasterDpi);
         }
@@ -82,29 +77,24 @@
     SkPDFDocument*  fDoc;
     SkPDFDevice*    fDevice;
     SkCanvas*       fCanvas;
-    SkPicture::EncodeBitmap fEncoder;
     SkScalar        fRasterDpi;
 };
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*,bool),
-                                  SkPicture::EncodeBitmap enc,
-                                  SkScalar dpi) {
-    return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc, dpi)) : NULL;
+SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) {
+    return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, NULL, dpi)) : NULL;
 }
 
 static void delete_wstream(SkWStream* stream, bool aborted) {
     SkDELETE(stream);
 }
 
-SkDocument* SkDocument::CreatePDF(const char path[],
-                                  SkPicture::EncodeBitmap enc,
-                                  SkScalar dpi) {
+SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) {
     SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path));
     if (!stream->isValid()) {
         SkDELETE(stream);
         return NULL;
     }
-    return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi));
+    return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi));
 }
diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h
index af65005..de405c1 100644
--- a/src/pdf/SkPDFDevice.h
+++ b/src/pdf/SkPDFDevice.h
@@ -137,7 +137,7 @@
      *         encoding and decoding might not be worth the space savings,
      *         if any at all.
      */
-    void setDCTEncoder(SkPicture::EncodeBitmap encoder) {
+    void setDCTEncoder(SkData* (*encoder)(size_t*, const SkBitmap&)) {
         fEncoder = encoder;
     }
 
@@ -245,7 +245,7 @@
     // Glyph ids used for each font on this device.
     SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage;
 
-    SkPicture::EncodeBitmap fEncoder;
+    SkData* (*fEncoder)(size_t*, const SkBitmap&);
     SkScalar fRasterDpi;
 
     SkBitmap fLegacyBitmap;
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index 6f743fd..c7836e5 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -458,7 +458,7 @@
 // static
 SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
                                     const SkIRect& srcRect,
-                                    SkPicture::EncodeBitmap encoder) {
+                                    SkData* (*encoder)(size_t*, const SkBitmap&)) {
     if (bitmap.colorType() == kUnknown_SkColorType) {
         return NULL;
     }
@@ -511,7 +511,7 @@
                        const SkBitmap& bitmap,
                        bool isAlpha,
                        const SkIRect& srcRect,
-                       SkPicture::EncodeBitmap encoder)
+                       SkData* (*encoder)(size_t*, const SkBitmap&))
     : fIsAlpha(isAlpha),
       fSrcRect(srcRect),
       fEncoder(encoder) {
@@ -720,7 +720,7 @@
 SkPDFObject* SkPDFCreateImageObject(
         const SkBitmap& bitmap,
         const SkIRect& subset,
-        SkPicture::EncodeBitmap encoder) {
+        SkData* (*encoder)(size_t*, const SkBitmap&)) {
     if (SkPDFObject* pdfBitmap = SkPDFBitmap::Create(bitmap, subset)) {
         return pdfBitmap;
     }
diff --git a/src/pdf/SkPDFImage.h b/src/pdf/SkPDFImage.h
index 24332cd..cfef38c 100644
--- a/src/pdf/SkPDFImage.h
+++ b/src/pdf/SkPDFImage.h
@@ -29,7 +29,7 @@
  *  back on SkPDFImage::CreateImage.
  */
 SkPDFObject* SkPDFCreateImageObject(
-        const SkBitmap&, const SkIRect& subset, SkPicture::EncodeBitmap);
+        const SkBitmap&, const SkIRect& subset, SkData* (*)(size_t*, const SkBitmap&));
 
 /** \class SkPDFImage
 
@@ -50,7 +50,7 @@
      */
     static SkPDFImage* CreateImage(const SkBitmap& bitmap,
                                    const SkIRect& srcRect,
-                                   SkPicture::EncodeBitmap encoder);
+                                   SkData* (*encoder)(size_t*, const SkBitmap&));
 
     virtual ~SkPDFImage();
 
@@ -62,7 +62,7 @@
     SkBitmap fBitmap;
     bool fIsAlpha;
     SkIRect fSrcRect;
-    SkPicture::EncodeBitmap fEncoder;
+    SkData* (*fEncoder)(size_t*, const SkBitmap&);
     bool fStreamValid;
 
     /** Create a PDF image XObject. Entries for the image properties are
@@ -81,7 +81,7 @@
      *                    May be NULL.
      */
     SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha,
-               const SkIRect& srcRect, SkPicture::EncodeBitmap encoder);
+               const SkIRect& srcRect, SkData* (*encoder)(size_t*, const SkBitmap&));
 
     /** Copy constructor, used to generate substitutes.
      *  @param image      The SkPDFImage to copy.
diff --git a/tools/render_pdfs_main.cpp b/tools/render_pdfs_main.cpp
index 6787877..4820a33 100644
--- a/tools/render_pdfs_main.cpp
+++ b/tools/render_pdfs_main.cpp
@@ -56,11 +56,6 @@
                "If a file does not match any list entry,\n"
                "it is skipped unless some list entry starts with ~");
 
-DEFINE_int32(jpegQuality, 100,
-             "Encodes images in JPEG at quality level N, which can be in "
-             "range 0-100).   N = -1 will disable JPEG compression. "
-             "Default is N = 100, maximum quality.");
-
 /** Replaces the extension of a file.
  * @param path File name whose extension will be changed.
  * @param old_extension The old extension.
@@ -83,25 +78,6 @@
     return false;
 }
 
-// the size_t* parameter is deprecated, so we ignore it
-static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) {
-    if (FLAGS_jpegQuality == -1) {
-        return NULL;
-    }
-
-    SkBitmap bm = bitmap;
-#if defined(SK_BUILD_FOR_MAC)
-    // Workaround bug #1043 where bitmaps with referenced pixels cause
-    // CGImageDestinationFinalize to crash
-    SkBitmap copy;
-    bitmap.deepCopyTo(&copy);
-    bm = copy;
-#endif
-
-    return SkImageEncoder::EncodeData(
-            bm, SkImageEncoder::kJPEG_Type, FLAGS_jpegQuality);
-}
-
 /** Builds the output filename. path = dir/name, and it replaces expected
  * .skp extension with .pdf extention.
  * @param path Output filename.
@@ -162,10 +138,9 @@
  *  output, using the provided encoder.
  */
 static bool pdf_to_stream(SkPicture* picture,
-                          SkWStream* output,
-                          SkPicture::EncodeBitmap encoder) {
+                          SkWStream* output) {
     SkAutoTUnref<SkDocument> pdfDocument(
-            SkDocument::CreatePDF(output, NULL, encoder));
+            SkDocument::CreatePDF(output));
     SkCanvas* canvas = pdfDocument->beginPage(picture->cullRect().width(), 
                                               picture->cullRect().height());
     canvas->drawPicture(picture);
@@ -264,7 +239,7 @@
             ++failures;
             continue;
         }
-        if (!pdf_to_stream(picture, stream.get(), encode_to_dct_data)) {
+        if (!pdf_to_stream(picture, stream.get())) {
             SkDebugf("Error in PDF Serialization.");
             ++failures;
         }