aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-02-26 13:25:05 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-26 13:25:05 -0800
commite6cf9cb68511ff08156f834859db39232eb37be8 (patch)
treea709ab6369279dd3f0c343295e4ebbdf1c9251c6 /src/pdf
parent6be6f7cb66b277e7b1ce13d09b635fb8e09a2f68 (diff)
miniz support in SkFlate / PDF
- Adds miniz.c v115_r4 (latest release) to third_party. - Merges SkDeflateWStream into SkFlate so including "miniz.c" links without duplicating symbols. The only interesting code change I've made is to remove the line fImpl->fZStream.data_type = Z_BINARY; from SkDeflateWStream::SkDeflateWStream(). miniz doesn't have Z_BINARY defined, and as far as I can tell, both zlib and miniz ignore data_type. We should be able to swap skflate.gyp's dependency between zlib.gyp:zlib and zlib.gyp:miniz at will (except of course on Windows) if we're interested in zlib itself. I've left android framework on its own zlib. I think this all means we can stop defining SK_NO_FLATE on Windows. I'll leave the possible cleanup of SK_NO_FLATE itself for another time. Might be we always want to keep this dependency optional. CQ_EXTRA_TRYBOTS=client.skia:Test-Win8-ShuttleA-HD7770-x86-Debug-Trybot BUG=skia: Review URL: https://codereview.chromium.org/957323003
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/SkDeflateWStream.cpp106
-rw-r--r--src/pdf/SkDeflateWStream.h45
-rw-r--r--src/pdf/SkPDFBitmap.cpp2
3 files changed, 1 insertions, 152 deletions
diff --git a/src/pdf/SkDeflateWStream.cpp b/src/pdf/SkDeflateWStream.cpp
deleted file mode 100644
index 5122588857..0000000000
--- a/src/pdf/SkDeflateWStream.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkDeflateWStream.h"
-// https://skia.org/dev/contrib/style#no-define-before-sktypes
-
-#ifndef SK_NO_FLATE
-
-#include "zlib.h"
-
-#define SKDEFLATEWSTREAM_INPUT_BUFFER_SIZE 4096
-#define SKDEFLATEWSTREAM_OUTPUT_BUFFER_SIZE 4224 // 4096 + 128, usually big
- // enough to always do a
- // single loop.
-
-// called by both write() and finalize()
-static void do_deflate(int flush,
- z_stream* zStream,
- SkWStream* out,
- unsigned char* inBuffer,
- size_t inBufferSize) {
- zStream->next_in = inBuffer;
- zStream->avail_in = inBufferSize;
- unsigned char outBuffer[SKDEFLATEWSTREAM_OUTPUT_BUFFER_SIZE];
- SkDEBUGCODE(int returnValue;)
- do {
- zStream->next_out = outBuffer;
- zStream->avail_out = sizeof(outBuffer);
- SkDEBUGCODE(returnValue =) deflate(zStream, flush);
- SkASSERT(!zStream->msg);
-
- out->write(outBuffer, sizeof(outBuffer) - zStream->avail_out);
- } while (zStream->avail_in || !zStream->avail_out);
- SkASSERT(flush == Z_FINISH
- ? returnValue == Z_STREAM_END
- : returnValue == Z_OK);
-}
-
-// Hide all zlib impl details.
-struct SkDeflateWStream::Impl {
- SkWStream* fOut;
- unsigned char fInBuffer[SKDEFLATEWSTREAM_INPUT_BUFFER_SIZE];
- size_t fInBufferIndex;
- z_stream fZStream;
-};
-
-SkDeflateWStream::SkDeflateWStream(SkWStream* out)
- : fImpl(SkNEW(SkDeflateWStream::Impl)) {
- fImpl->fOut = out;
- fImpl->fInBufferIndex = 0;
- if (!fImpl->fOut) {
- return;
- }
- fImpl->fZStream.zalloc = Z_NULL;
- fImpl->fZStream.zfree = Z_NULL;
- fImpl->fZStream.opaque = Z_NULL;
- fImpl->fZStream.data_type = Z_BINARY;
- SkDEBUGCODE(int r =) deflateInit(&fImpl->fZStream, Z_DEFAULT_COMPRESSION);
- SkASSERT(Z_OK == r);
-}
-
-SkDeflateWStream::~SkDeflateWStream() { this->finalize(); }
-
-void SkDeflateWStream::finalize() {
- if (!fImpl->fOut) {
- return;
- }
- do_deflate(Z_FINISH, &fImpl->fZStream, fImpl->fOut, fImpl->fInBuffer,
- fImpl->fInBufferIndex);
- (void)deflateEnd(&fImpl->fZStream);
- fImpl->fOut = NULL;
-}
-
-bool SkDeflateWStream::write(const void* void_buffer, size_t len) {
- if (!fImpl->fOut) {
- return false;
- }
- const char* buffer = (const char*)void_buffer;
- while (len > 0) {
- size_t tocopy =
- SkTMin(len, sizeof(fImpl->fInBuffer) - fImpl->fInBufferIndex);
- memcpy(fImpl->fInBuffer + fImpl->fInBufferIndex, buffer, tocopy);
- len -= tocopy;
- buffer += tocopy;
- fImpl->fInBufferIndex += tocopy;
- SkASSERT(fImpl->fInBufferIndex <= sizeof(fImpl->fInBuffer));
-
- // if the buffer isn't filled, don't call into zlib yet.
- if (sizeof(fImpl->fInBuffer) == fImpl->fInBufferIndex) {
- do_deflate(Z_NO_FLUSH, &fImpl->fZStream, fImpl->fOut,
- fImpl->fInBuffer, fImpl->fInBufferIndex);
- fImpl->fInBufferIndex = 0;
- }
- }
- return true;
-}
-
-size_t SkDeflateWStream::bytesWritten() const {
- return fImpl->fZStream.total_in + fImpl->fInBufferIndex;
-}
-
-#endif // SK_NO_ZLIB
diff --git a/src/pdf/SkDeflateWStream.h b/src/pdf/SkDeflateWStream.h
deleted file mode 100644
index bccb4db220..0000000000
--- a/src/pdf/SkDeflateWStream.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkDeflateWStream_DEFINED
-#define SkDeflateWStream_DEFINED
-
-#include "SkStream.h"
-// https://skia.org/dev/contrib/style#no-define-before-sktypes
-
-#ifndef SK_NO_FLATE // Clients of this class should be guarded.
-
-/**
- * Wrap a stream in this class to compress the information written to
- * this stream using the Deflate algorithm. Uses Zlib's
- * Z_DEFAULT_COMPRESSION level.
- *
- * See http://en.wikipedia.org/wiki/DEFLATE
- */
-class SkDeflateWStream : public SkWStream {
-public:
- /** Does not take ownership of the stream. */
- SkDeflateWStream(SkWStream*);
-
- /** The destructor calls finalize(). */
- ~SkDeflateWStream();
-
- /** Write the end of the compressed stream. All subsequent calls to
- write() will fail. Subsequent calls to finalize() do nothing. */
- void finalize();
-
- // The SkWStream interface:
- bool write(const void*, size_t) SK_OVERRIDE;
- size_t bytesWritten() const SK_OVERRIDE;
-
-private:
- struct Impl;
- SkAutoTDelete<Impl> fImpl;
-};
-#endif // SK_NO_FLATE
-
-#endif // SkDeflateWStream_DEFINED
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp
index f8742a674e..03230341a4 100644
--- a/src/pdf/SkPDFBitmap.cpp
+++ b/src/pdf/SkPDFBitmap.cpp
@@ -6,7 +6,7 @@
*/
#include "SkColorPriv.h"
-#include "SkDeflateWStream.h"
+#include "SkFlate.h"
#include "SkPDFBitmap.h"
#include "SkPDFCanon.h"
#include "SkPDFCatalog.h"