zlib/pdf: remove HaveFlate(), depend on preprocessor defines
authorhalcanary <halcanary@google.com>
Tue, 17 Feb 2015 22:43:06 +0000 (14:43 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 17 Feb 2015 22:43:06 +0000 (14:43 -0800)
Review URL: https://codereview.chromium.org/933523007

experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp
gyp/skflate.gyp
src/core/SkFlate.cpp
src/core/SkFlate.h
src/pdf/SkPDFImage.cpp
src/pdf/SkPDFStream.cpp
tests/FlateTest.cpp
tests/PDFPrimitivesTest.cpp

index d9b3c01201e314efe6a64b0981df11d2a5e6a2a7..3f12267cc5992ce2a83f77f326ffe8bd68bc037f 100644 (file)
 SkPdfNativeObject SkPdfNativeObject::kNull = SkPdfNativeObject::makeNull();
 
 bool SkPdfNativeObject::applyFlateDecodeFilter() {
-    if (!SkFlate::HaveFlate()) {
-        SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kNoFlateLibrary_SkPdfIssue,
-                    "forgot to link with flate library?", NULL, NULL);
-        return false;
-    }
-
     const unsigned char* old = fStr.fBuffer;
     bool deleteOld = isStreamOwned();
 
index 9e11cd9cc02ff2e602e1b25adb253620ee6bad51..4f3b1763eb4fca5de9d9f13bea4aecfdd64cf2c0 100644 (file)
@@ -9,7 +9,7 @@
       ],
       'conditions': [
         # When zlib is not availible on a system,
-        # SkFlate::HaveFlate will just return false.
+        # SK_NO_FLATE will be defined.
         [ 'skia_os != "win"',
           {
             'dependencies': [
index ff11a11ca89eecdb01ab90aa1f178c5aae49bef0..888af6b77c60972d9d385eaaca9bc4afd9f4dacf 100644 (file)
 #include "SkFlate.h"
 #include "SkStream.h"
 
-#ifdef SK_NO_FLATE
-bool SkFlate::HaveFlate() { return false; }
-bool SkFlate::Deflate(SkStream*, SkWStream*) { return false; }
-bool SkFlate::Deflate(const void*, size_t, SkWStream*) { return false; }
-bool SkFlate::Deflate(const SkData*, SkWStream*) { return false; }
-bool SkFlate::Inflate(SkStream*, SkWStream*) { return false; }
-#else
-
-// static
-bool SkFlate::HaveFlate() {
-    return true;
-}
+#ifndef SK_NO_FLATE
 
 namespace {
 
@@ -133,4 +122,5 @@ bool SkFlate::Inflate(SkStream* src, SkWStream* dst) {
     return doFlate(false, src, dst);
 }
 
-#endif
+#endif  // SK_NO_FLATE
+
index e4c1417d910d4d8c75f7a7f7aa42dc1fd8fc41e8..69dac018de6e93733a980cfc098b77a7ca5e1c2d 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "SkTypes.h"
 
+#ifndef Sk_NO_FLATE
+
 class SkData;
 class SkWStream;
 class SkStream;
@@ -21,10 +23,6 @@ class SkStream;
 */
 class SkFlate {
 public:
-    /** Indicates if the flate algorithm is available.
-     */
-    static bool HaveFlate();
-
     /**
      *  Use the flate compression algorithm to compress the data in src,
      *  putting the result into dst.  Returns false if an error occurs.
@@ -49,4 +47,5 @@ public:
     static bool Inflate(SkStream* src, SkWStream* dst);
 };
 
-#endif
+#endif  // SK_NO_FLATE
+#endif  // SkFlate_DEFINED
index 3c0d850fda9d1d0273e280d13452c3a239aa521a..0b6c81f77a382a6cded9bdc61db3b27f8f623e76 100644 (file)
@@ -630,9 +630,14 @@ bool SkPDFImage::populate(SkPDFCatalog* catalog) {
             fStreamValid = true;
         }
         return INHERITED::populate(catalog);
-    } else if (getState() == kNoCompression_State &&
-            !skip_compression(catalog) &&
-            (SkFlate::HaveFlate() || fEncoder)) {
+    }
+#ifndef SK_NO_FLATE
+    else if (getState() == kNoCompression_State && !skip_compression(catalog)) {
+#else  // SK_NO_FLATE
+    else if (getState() == kNoCompression_State &&
+             !skip_compression(catalog) &&
+             fEncoder) {
+#endif  // SK_NO_FLATE
         // Compression has not been requested when the stream was first created,
         // but the new catalog wants it compressed.
         if (!getSubstitute()) {
index 5eaa6c28b69b3968247b0f72cc11f0dff2d3d0a5..150338b6ca0ec937759b6ef7650f080387f5d65e 100644 (file)
@@ -83,8 +83,18 @@ size_t SkPDFStream::dataSize() const {
 }
 
 bool SkPDFStream::populate(SkPDFCatalog* catalog) {
+#ifdef SK_NO_FLATE
     if (fState == kUnused_State) {
-        if (!skip_compression(catalog) && SkFlate::HaveFlate()) {
+        fState = kNoCompression_State;
+        insertInt("Length", this->dataSize());
+    }
+    return true;
+
+#else  // !SK_NO_FLATE
+
+    if (fState == kUnused_State) {
+        fState = kNoCompression_State;
+        if (!skip_compression(catalog)) {
             SkDynamicMemoryWStream compressedData;
 
             SkAssertResult(
@@ -101,8 +111,8 @@ bool SkPDFStream::populate(SkPDFCatalog* catalog) {
             fState = kNoCompression_State;
         }
         insertInt("Length", this->dataSize());
-    } else if (fState == kNoCompression_State && !skip_compression(catalog) &&
-               SkFlate::HaveFlate()) {
+    }
+    else if (fState == kNoCompression_State && !skip_compression(catalog)) {
         if (!fSubstitute.get()) {
             fSubstitute.reset(new SkPDFStream(*this));
             catalog->setSubstitute(this, fSubstitute.get());
@@ -110,4 +120,5 @@ bool SkPDFStream::populate(SkPDFCatalog* catalog) {
         return false;
     }
     return true;
+#endif  // SK_NO_FLATE
 }
index 8ad4d50376e86ca9d6a8e72f00288e04fb84ae61..17e8b2de2ab65589ea10ddefba435bd2f6ce921d 100644 (file)
@@ -10,6 +10,8 @@
 #include "SkStream.h"
 #include "Test.h"
 
+#ifndef SK_NO_FLATE
+
 // A memory stream that reports zero size with the standard call, like
 // an unseekable file stream would.
 class SkZeroSizeMemStream : public SkMemoryStream {
@@ -104,16 +106,12 @@ static void TestFlate(skiatest::Reporter* reporter, SkMemoryStream* testStream,
 }
 
 DEF_TEST(Flate, reporter) {
-#ifndef SK_NO_FLATE
-    REPORTER_ASSERT(reporter, SkFlate::HaveFlate());
-#endif
-    if (SkFlate::HaveFlate()) {
-        SkMemoryStream memStream;
-        TestFlate(reporter, &memStream, 512);
-        TestFlate(reporter, &memStream, 10240);
-
-        SkZeroSizeMemStream fileStream;
-        TestFlate(reporter, &fileStream, 512);
-        TestFlate(reporter, &fileStream, 10240);
-    }
+    SkMemoryStream memStream;
+    TestFlate(reporter, &memStream, 512);
+    TestFlate(reporter, &memStream, 10240);
+
+    SkZeroSizeMemStream fileStream;
+    TestFlate(reporter, &fileStream, 512);
+    TestFlate(reporter, &fileStream, 10240);
 }
+#endif  // SK_NO_FLATE
index 7cc010f7c1532e2d386892a4f57407ec52cd5652..8dbde65b3cc801d69123003b34d7a21cbcf2a05b 100644 (file)
@@ -153,7 +153,8 @@ static void TestPDFStream(skiatest::Reporter* reporter) {
                             "<</Length 12\n/Attribute 42\n>> stream\n"
                                 "Test\nFoo\tBar\nendstream");
 
-    if (SkFlate::HaveFlate()) {
+#ifndef SK_NO_FLATE
+    {
         char streamBytes2[] = "This is a longer string, so that compression "
                               "can do something with it. With shorter strings, "
                               "the short circuit logic cuts in and we end up "
@@ -187,6 +188,7 @@ static void TestPDFStream(skiatest::Reporter* reporter) {
                           (const char*) expectedResultData2->data(),
                           expectedResultData2->size(), true, true);
     }
+#endif  // SK_NO_FLATE
 }
 
 static void TestCatalog(skiatest::Reporter* reporter) {
@@ -283,9 +285,7 @@ static void TestUncompressed(skiatest::Reporter* reporter) {
 }
 
 static void TestFlateDecode(skiatest::Reporter* reporter) {
-    if (!SkFlate::HaveFlate()) {
-        return;
-    }
+#ifndef SK_NO_FLATE
     SkBitmap bitmap;
     setup_bitmap(&bitmap, 10, 10);
     TestImage(reporter, bitmap,
@@ -298,6 +298,7 @@ static void TestFlateDecode(skiatest::Reporter* reporter) {
               "/Length 13\n"
               ">> stream",
               false);
+#endif  // SK_NO_FLATE
 }
 
 static void TestDCTDecode(skiatest::Reporter* reporter) {