zlib/pdf: remove HaveFlate(), depend on preprocessor defines
Review URL: https://codereview.chromium.org/933523007
This commit is contained in:
parent
82079fb7aa
commit
91d1d621de
@ -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();
|
||||
|
||||
|
@ -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': [
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()) {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
SkMemoryStream memStream;
|
||||
TestFlate(reporter, &memStream, 512);
|
||||
TestFlate(reporter, &memStream, 10240);
|
||||
|
||||
SkZeroSizeMemStream fileStream;
|
||||
TestFlate(reporter, &fileStream, 512);
|
||||
TestFlate(reporter, &fileStream, 10240);
|
||||
}
|
||||
SkZeroSizeMemStream fileStream;
|
||||
TestFlate(reporter, &fileStream, 512);
|
||||
TestFlate(reporter, &fileStream, 10240);
|
||||
}
|
||||
#endif // SK_NO_FLATE
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user