Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
SkDeflateWStream Class Referencefinal

#include <SkDeflate.h>

Inheritance diagram for SkDeflateWStream:
SkWStream

Classes

struct  Impl
 

Public Member Functions

 SkDeflateWStream (SkWStream *, int compressionLevel, bool gzip=false)
 
 ~SkDeflateWStream () override
 
void finalize ()
 
bool write (const void *, size_t) override
 
size_t bytesWritten () const override
 
- Public Member Functions inherited from SkWStream
virtual ~SkWStream ()
 
 SkWStream ()
 
virtual bool write (const void *buffer, size_t size)=0
 
virtual void flush ()
 
virtual size_t bytesWritten () const =0
 
bool write8 (U8CPU value)
 
bool write16 (U16CPU value)
 
bool write32 (uint32_t v)
 
bool writeText (const char text[])
 
bool newline ()
 
bool writeDecAsText (int32_t)
 
bool writeBigDecAsText (int64_t, int minDigits=0)
 
bool writeHexAsText (uint32_t, int minDigits=0)
 
bool writeScalarAsText (SkScalar)
 
bool writeBool (bool v)
 
bool writeScalar (SkScalar)
 
bool writePackedUInt (size_t)
 
bool writeStream (SkStream *input, size_t length)
 

Additional Inherited Members

- Static Public Member Functions inherited from SkWStream
static int SizeOfPackedUInt (size_t value)
 

Detailed Description

Wrap a stream in this class to compress the information written to this stream using the Deflate algorithm.

See http://en.wikipedia.org/wiki/DEFLATE

Definition at line 23 of file SkDeflate.h.

Constructor & Destructor Documentation

◆ SkDeflateWStream()

SkDeflateWStream::SkDeflateWStream ( SkWStream out,
int  compressionLevel,
bool  gzip = false 
)

Does not take ownership of the stream.

Parameters
compressionLevel1 is best speed; 9 is best compression. The default, -1, is to use zlib's Z_DEFAULT_COMPRESSION level. 0 would be no compression, but due to broken zlibs, users should handle that themselves.
gzipiff true, output a gzip file. "The gzip format is a wrapper, documented in RFC 1952, around a deflate stream." gzip adds a header with a magic number to the beginning of the stream, allowing a client to identify a gzip file.

Definition at line 70 of file SkDeflate.cpp.

73 : fImpl(std::make_unique<SkDeflateWStream::Impl>()) {
74
75 // There has existed at some point at least one zlib implementation which thought it was being
76 // clever by randomizing the compression level. This is actually not entirely incorrect, except
77 // for the no-compression level which should always be deterministically pass-through.
78 // Users should instead consider the zero compression level broken and handle it themselves.
79 SkASSERT(compressionLevel != 0);
80
81 fImpl->fOut = out;
82 fImpl->fInBufferIndex = 0;
83 if (!fImpl->fOut) {
84 return;
85 }
86 fImpl->fZStream.next_in = nullptr;
87 fImpl->fZStream.zalloc = &skia_alloc_func;
88 fImpl->fZStream.zfree = &skia_free_func;
89 fImpl->fZStream.opaque = nullptr;
90 SkASSERT(compressionLevel <= 9 && compressionLevel >= -1);
91 SkDEBUGCODE(int r =) deflateInit2(&fImpl->fZStream, compressionLevel,
92 Z_DEFLATED, gzip ? 0x1F : 0x0F,
93 8, Z_DEFAULT_STRATEGY);
94 SkASSERT(Z_OK == r);
95}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()

◆ ~SkDeflateWStream()

SkDeflateWStream::~SkDeflateWStream ( )
override

The destructor calls finalize().

Definition at line 97 of file SkDeflate.cpp.

97{ this->finalize(); }

Member Function Documentation

◆ bytesWritten()

size_t SkDeflateWStream::bytesWritten ( ) const
overridevirtual

Implements SkWStream.

Definition at line 135 of file SkDeflate.cpp.

135 {
136 return fImpl->fZStream.total_in + fImpl->fInBufferIndex;
137}

◆ finalize()

void SkDeflateWStream::finalize ( )

Write the end of the compressed stream. All subsequent calls to write() will fail. Subsequent calls to finalize() do nothing.

Definition at line 99 of file SkDeflate.cpp.

99 {
100 TRACE_EVENT0("skia", TRACE_FUNC);
101 if (!fImpl->fOut) {
102 return;
103 }
104 do_deflate(Z_FINISH, &fImpl->fZStream, fImpl->fOut, fImpl->fInBuffer,
105 fImpl->fInBufferIndex);
106 (void)deflateEnd(&fImpl->fZStream);
107 fImpl->fOut = nullptr;
108}
static void do_deflate(int flush, z_stream *zStream, SkWStream *out, unsigned char *inBuffer, size_t inBufferSize)
Definition: SkDeflate.cpp:40
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ write()

bool SkDeflateWStream::write ( const void *  buffer,
size_t  size 
)
overridevirtual

Called to write bytes to a SkWStream. Returns true on success

Parameters
bufferthe address of at least size bytes to be written to the stream
sizeThe number of bytes in buffer to write to the stream
Returns
true on success

Implements SkWStream.

Definition at line 110 of file SkDeflate.cpp.

110 {
111 TRACE_EVENT0("skia", TRACE_FUNC);
112 if (!fImpl->fOut) {
113 return false;
114 }
115 const char* buffer = (const char*)void_buffer;
116 while (len > 0) {
117 size_t tocopy =
118 std::min(len, sizeof(fImpl->fInBuffer) - fImpl->fInBufferIndex);
119 memcpy(fImpl->fInBuffer + fImpl->fInBufferIndex, buffer, tocopy);
120 len -= tocopy;
121 buffer += tocopy;
122 fImpl->fInBufferIndex += tocopy;
123 SkASSERT(fImpl->fInBufferIndex <= sizeof(fImpl->fInBuffer));
124
125 // if the buffer isn't filled, don't call into zlib yet.
126 if (sizeof(fImpl->fInBuffer) == fImpl->fInBufferIndex) {
127 do_deflate(Z_NO_FLUSH, &fImpl->fZStream, fImpl->fOut,
128 fImpl->fInBuffer, fImpl->fInBufferIndex);
129 fImpl->fInBufferIndex = 0;
130 }
131 }
132 return true;
133}
static float min(float r, float g, float b)
Definition: hsl.cpp:48
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

The documentation for this class was generated from the following files: