Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: src/core/SkFlate.cpp

Issue 964953002: Revert of Flate: fix valgrind miniz Conditional-jump-or-move-depends... error (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 The Android Open Source Project 3 * Copyright 2010 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkData.h" 10 #include "SkData.h"
11 #include "SkFlate.h" 11 #include "SkFlate.h"
12 #include "SkStream.h" 12 #include "SkStream.h"
13 13
14 #ifndef SK_NO_FLATE 14 #ifndef SK_NO_FLATE
15 15
16 namespace { 16 namespace {
17 17
18 #ifdef ZLIB_INCLUDE 18 #ifdef ZLIB_INCLUDE
19 #include ZLIB_INCLUDE 19 #include ZLIB_INCLUDE
20 #else 20 #else
21 #include "zlib.h" 21 #include "zlib.h"
22 #endif 22 #endif
23 23
24 // static 24 // static
25 const size_t kBufferSize = 1024; 25 const size_t kBufferSize = 1024;
26 26
27 static void* skia_alloc_func(void*, size_t items, size_t size) {
28 return sk_calloc_throw(items * size);
29 }
30
31 static void skia_free_func(void*, void* address) { sk_free(address); }
32
33 bool doFlate(bool compress, SkStream* src, SkWStream* dst) { 27 bool doFlate(bool compress, SkStream* src, SkWStream* dst) {
34 uint8_t inputBuffer[kBufferSize]; 28 uint8_t inputBuffer[kBufferSize];
35 uint8_t outputBuffer[kBufferSize]; 29 uint8_t outputBuffer[kBufferSize];
36 z_stream flateData; 30 z_stream flateData;
37 flateData.zalloc = &skia_alloc_func; 31 flateData.zalloc = NULL;
38 flateData.zfree = &skia_free_func; 32 flateData.zfree = NULL;
39 flateData.opaque = NULL;
40 flateData.next_in = NULL; 33 flateData.next_in = NULL;
41 flateData.avail_in = 0; 34 flateData.avail_in = 0;
42 flateData.next_out = outputBuffer; 35 flateData.next_out = outputBuffer;
43 flateData.avail_out = kBufferSize; 36 flateData.avail_out = kBufferSize;
44 int rc; 37 int rc;
45 if (compress) 38 if (compress)
46 rc = deflateInit(&flateData, Z_DEFAULT_COMPRESSION); 39 rc = deflateInit(&flateData, Z_DEFAULT_COMPRESSION);
47 else 40 else
48 rc = inflateInit(&flateData); 41 rc = inflateInit(&flateData);
49 if (rc != Z_OK) 42 if (rc != Z_OK)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 z_stream fZStream; 163 z_stream fZStream;
171 }; 164 };
172 165
173 SkDeflateWStream::SkDeflateWStream(SkWStream* out) 166 SkDeflateWStream::SkDeflateWStream(SkWStream* out)
174 : fImpl(SkNEW(SkDeflateWStream::Impl)) { 167 : fImpl(SkNEW(SkDeflateWStream::Impl)) {
175 fImpl->fOut = out; 168 fImpl->fOut = out;
176 fImpl->fInBufferIndex = 0; 169 fImpl->fInBufferIndex = 0;
177 if (!fImpl->fOut) { 170 if (!fImpl->fOut) {
178 return; 171 return;
179 } 172 }
180 fImpl->fZStream.zalloc = &skia_alloc_func; 173 fImpl->fZStream.zalloc = Z_NULL;
181 fImpl->fZStream.zfree = &skia_free_func; 174 fImpl->fZStream.zfree = Z_NULL;
182 fImpl->fZStream.opaque = NULL; 175 fImpl->fZStream.opaque = Z_NULL;
183 SkDEBUGCODE(int r =) deflateInit(&fImpl->fZStream, Z_DEFAULT_COMPRESSION); 176 SkDEBUGCODE(int r =) deflateInit(&fImpl->fZStream, Z_DEFAULT_COMPRESSION);
184 SkASSERT(Z_OK == r); 177 SkASSERT(Z_OK == r);
185 } 178 }
186 179
187 SkDeflateWStream::~SkDeflateWStream() { this->finalize(); } 180 SkDeflateWStream::~SkDeflateWStream() { this->finalize(); }
188 181
189 void SkDeflateWStream::finalize() { 182 void SkDeflateWStream::finalize() {
190 if (!fImpl->fOut) { 183 if (!fImpl->fOut) {
191 return; 184 return;
192 } 185 }
(...skipping 27 matching lines...) Expand all
220 return true; 213 return true;
221 } 214 }
222 215
223 size_t SkDeflateWStream::bytesWritten() const { 216 size_t SkDeflateWStream::bytesWritten() const {
224 return fImpl->fZStream.total_in + fImpl->fInBufferIndex; 217 return fImpl->fZStream.total_in + fImpl->fInBufferIndex;
225 } 218 }
226 219
227 220
228 #endif // SK_NO_FLATE 221 #endif // SK_NO_FLATE
229 222
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698