aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-02-17 14:43:06 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-17 14:43:06 -0800
commit91d1d621de03faa41528ba2581d172f3a41104ff (patch)
treeba66b74a2625ff3765e747dfaf9e7cb59b519434
parent82079fb7aaf000591300e0662301594901d56d06 (diff)
zlib/pdf: remove HaveFlate(), depend on preprocessor defines
-rw-r--r--experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp6
-rw-r--r--gyp/skflate.gyp2
-rw-r--r--src/core/SkFlate.cpp16
-rw-r--r--src/core/SkFlate.h9
-rw-r--r--src/pdf/SkPDFImage.cpp11
-rw-r--r--src/pdf/SkPDFStream.cpp17
-rw-r--r--tests/FlateTest.cpp22
-rw-r--r--tests/PDFPrimitivesTest.cpp9
8 files changed, 45 insertions, 47 deletions
diff --git a/experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp b/experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp
index d9b3c01201..3f12267cc5 100644
--- a/experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp
+++ b/experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp
@@ -22,12 +22,6 @@
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();
diff --git a/gyp/skflate.gyp b/gyp/skflate.gyp
index 9e11cd9cc0..4f3b1763eb 100644
--- a/gyp/skflate.gyp
+++ b/gyp/skflate.gyp
@@ -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': [
diff --git a/src/core/SkFlate.cpp b/src/core/SkFlate.cpp
index ff11a11ca8..888af6b77c 100644
--- a/src/core/SkFlate.cpp
+++ b/src/core/SkFlate.cpp
@@ -11,18 +11,7 @@
#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
+
diff --git a/src/core/SkFlate.h b/src/core/SkFlate.h
index e4c1417d91..69dac018de 100644
--- a/src/core/SkFlate.h
+++ b/src/core/SkFlate.h
@@ -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
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index 3c0d850fda..0b6c81f77a 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -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()) {
diff --git a/src/pdf/SkPDFStream.cpp b/src/pdf/SkPDFStream.cpp
index 5eaa6c28b6..150338b6ca 100644
--- a/src/pdf/SkPDFStream.cpp
+++ b/src/pdf/SkPDFStream.cpp
@@ -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
}
diff --git a/tests/FlateTest.cpp b/tests/FlateTest.cpp
index 8ad4d50376..17e8b2de2a 100644
--- a/tests/FlateTest.cpp
+++ b/tests/FlateTest.cpp
@@ -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
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index 7cc010f7c1..8dbde65b3c 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -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) {