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