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

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

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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 | « src/core/SkReadBuffer.h ('k') | src/core/SkReader32.h » ('j') | 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 2012 Google Inc. 3 * Copyright 2012 Google Inc.
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 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkErrorInternals.h" 10 #include "SkErrorInternals.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkStream.h" 12 #include "SkStream.h"
13 #include "SkTypeface.h" 13 #include "SkTypeface.h"
14 14
15 static uint32_t default_flags() { 15 static uint32_t default_flags() {
16 uint32_t flags = 0; 16 uint32_t flags = 0;
17 flags |= SkReadBuffer::kScalarIsFloat_Flag; 17 flags |= SkReadBuffer::kScalarIsFloat_Flag;
18 if (8 == sizeof(void*)) { 18 if (8 == sizeof(void*)) {
19 flags |= SkReadBuffer::kPtrIs64Bit_Flag; 19 flags |= SkReadBuffer::kPtrIs64Bit_Flag;
20 } 20 }
21 return flags; 21 return flags;
22 } 22 }
23 23
24 SkReadBuffer::SkReadBuffer() { 24 SkReadBuffer::SkReadBuffer() {
25 fFlags = default_flags(); 25 fFlags = default_flags();
26 fVersion = 0; 26 fVersion = 0;
27 fMemoryPtr = NULL; 27 fMemoryPtr = nullptr;
28 28
29 fBitmapStorage = NULL; 29 fBitmapStorage = nullptr;
30 fTFArray = NULL; 30 fTFArray = nullptr;
31 fTFCount = 0; 31 fTFCount = 0;
32 32
33 fFactoryTDArray = NULL; 33 fFactoryTDArray = nullptr;
34 fFactoryArray = NULL; 34 fFactoryArray = nullptr;
35 fFactoryCount = 0; 35 fFactoryCount = 0;
36 fBitmapDecoder = NULL; 36 fBitmapDecoder = nullptr;
37 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 37 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
38 fDecodedBitmapIndex = -1; 38 fDecodedBitmapIndex = -1;
39 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 39 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
40 } 40 }
41 41
42 SkReadBuffer::SkReadBuffer(const void* data, size_t size) { 42 SkReadBuffer::SkReadBuffer(const void* data, size_t size) {
43 fFlags = default_flags(); 43 fFlags = default_flags();
44 fVersion = 0; 44 fVersion = 0;
45 fReader.setMemory(data, size); 45 fReader.setMemory(data, size);
46 fMemoryPtr = NULL; 46 fMemoryPtr = nullptr;
47 47
48 fBitmapStorage = NULL; 48 fBitmapStorage = nullptr;
49 fTFArray = NULL; 49 fTFArray = nullptr;
50 fTFCount = 0; 50 fTFCount = 0;
51 51
52 fFactoryTDArray = NULL; 52 fFactoryTDArray = nullptr;
53 fFactoryArray = NULL; 53 fFactoryArray = nullptr;
54 fFactoryCount = 0; 54 fFactoryCount = 0;
55 fBitmapDecoder = NULL; 55 fBitmapDecoder = nullptr;
56 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 56 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
57 fDecodedBitmapIndex = -1; 57 fDecodedBitmapIndex = -1;
58 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 58 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
59 } 59 }
60 60
61 SkReadBuffer::SkReadBuffer(SkStream* stream) { 61 SkReadBuffer::SkReadBuffer(SkStream* stream) {
62 fFlags = default_flags(); 62 fFlags = default_flags();
63 fVersion = 0; 63 fVersion = 0;
64 const size_t length = stream->getLength(); 64 const size_t length = stream->getLength();
65 fMemoryPtr = sk_malloc_throw(length); 65 fMemoryPtr = sk_malloc_throw(length);
66 stream->read(fMemoryPtr, length); 66 stream->read(fMemoryPtr, length);
67 fReader.setMemory(fMemoryPtr, length); 67 fReader.setMemory(fMemoryPtr, length);
68 68
69 fBitmapStorage = NULL; 69 fBitmapStorage = nullptr;
70 fTFArray = NULL; 70 fTFArray = nullptr;
71 fTFCount = 0; 71 fTFCount = 0;
72 72
73 fFactoryTDArray = NULL; 73 fFactoryTDArray = nullptr;
74 fFactoryArray = NULL; 74 fFactoryArray = nullptr;
75 fFactoryCount = 0; 75 fFactoryCount = 0;
76 fBitmapDecoder = NULL; 76 fBitmapDecoder = nullptr;
77 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 77 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
78 fDecodedBitmapIndex = -1; 78 fDecodedBitmapIndex = -1;
79 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 79 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
80 } 80 }
81 81
82 SkReadBuffer::~SkReadBuffer() { 82 SkReadBuffer::~SkReadBuffer() {
83 sk_free(fMemoryPtr); 83 sk_free(fMemoryPtr);
84 SkSafeUnref(fBitmapStorage); 84 SkSafeUnref(fBitmapStorage);
85 } 85 }
86 86
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 const size_t length = this->readUInt(); 216 const size_t length = this->readUInt();
217 if (length > 0) { 217 if (length > 0) {
218 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 218 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
219 fDecodedBitmapIndex++; 219 fDecodedBitmapIndex++;
220 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 220 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
221 // A non-zero size means the SkBitmap was encoded. Read the data and pixel 221 // A non-zero size means the SkBitmap was encoded. Read the data and pixel
222 // offset. 222 // offset.
223 const void* data = this->skip(length); 223 const void* data = this->skip(length);
224 const int32_t xOffset = this->readInt(); 224 const int32_t xOffset = this->readInt();
225 const int32_t yOffset = this->readInt(); 225 const int32_t yOffset = this->readInt();
226 if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap)) { 226 if (fBitmapDecoder != nullptr && fBitmapDecoder(data, length, bitmap )) {
227 if (bitmap->width() == width && bitmap->height() == height) { 227 if (bitmap->width() == width && bitmap->height() == height) {
228 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 228 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
229 if (0 != xOffset || 0 != yOffset) { 229 if (0 != xOffset || 0 != yOffset) {
230 SkDebugf("SkReadBuffer::readBitmap: heights match," 230 SkDebugf("SkReadBuffer::readBitmap: heights match,"
231 " but offset is not zero. \nInfo about the bitm ap:" 231 " but offset is not zero. \nInfo about the bitm ap:"
232 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode d" 232 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode d"
233 " data size: %d\n\tOffset: (%d, %d)\n", 233 " data size: %d\n\tOffset: (%d, %d)\n",
234 fDecodedBitmapIndex, width, height, length, xOf fset, 234 fDecodedBitmapIndex, width, height, length, xOf fset,
235 yOffset); 235 yOffset);
236 } 236 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 return false; 274 return false;
275 } 275 }
276 276
277 SkTypeface* SkReadBuffer::readTypeface() { 277 SkTypeface* SkReadBuffer::readTypeface() {
278 278
279 uint32_t index = fReader.readU32(); 279 uint32_t index = fReader.readU32();
280 if (0 == index || index > (unsigned)fTFCount) { 280 if (0 == index || index > (unsigned)fTFCount) {
281 if (index) { 281 if (index) {
282 SkDebugf("====== typeface index %d\n", index); 282 SkDebugf("====== typeface index %d\n", index);
283 } 283 }
284 return NULL; 284 return nullptr;
285 } else { 285 } else {
286 SkASSERT(fTFArray); 286 SkASSERT(fTFArray);
287 return fTFArray[index - 1]; 287 return fTFArray[index - 1];
288 } 288 }
289 } 289 }
290 290
291 SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) { 291 SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
292 // 292 //
293 // TODO: confirm that ft matches the factory we decide to use 293 // TODO: confirm that ft matches the factory we decide to use
294 // 294 //
295 295
296 SkFlattenable::Factory factory = NULL; 296 SkFlattenable::Factory factory = nullptr;
297 297
298 if (fFactoryCount > 0) { 298 if (fFactoryCount > 0) {
299 int32_t index = fReader.readU32(); 299 int32_t index = fReader.readU32();
300 if (0 == index) { 300 if (0 == index) {
301 return NULL; // writer failed to give us the flattenable 301 return nullptr; // writer failed to give us the flattenable
302 } 302 }
303 index -= 1; // we stored the index-base-1 303 index -= 1; // we stored the index-base-1
304 SkASSERT(index < fFactoryCount); 304 SkASSERT(index < fFactoryCount);
305 factory = fFactoryArray[index]; 305 factory = fFactoryArray[index];
306 } else if (fFactoryTDArray) { 306 } else if (fFactoryTDArray) {
307 int32_t index = fReader.readU32(); 307 int32_t index = fReader.readU32();
308 if (0 == index) { 308 if (0 == index) {
309 return NULL; // writer failed to give us the flattenable 309 return nullptr; // writer failed to give us the flattenable
310 } 310 }
311 index -= 1; // we stored the index-base-1 311 index -= 1; // we stored the index-base-1
312 factory = (*fFactoryTDArray)[index]; 312 factory = (*fFactoryTDArray)[index];
313 } else { 313 } else {
314 factory = (SkFlattenable::Factory)readFunctionPtr(); 314 factory = (SkFlattenable::Factory)readFunctionPtr();
315 if (NULL == factory) { 315 if (nullptr == factory) {
316 return NULL; // writer failed to give us the flattenable 316 return nullptr; // writer failed to give us the flattenable
317 } 317 }
318 } 318 }
319 319
320 // if we get here, factory may still be null, but if that is the case, the 320 // if we get here, factory may still be null, but if that is the case, the
321 // failure was ours, not the writer. 321 // failure was ours, not the writer.
322 SkFlattenable* obj = NULL; 322 SkFlattenable* obj = nullptr;
323 uint32_t sizeRecorded = fReader.readU32(); 323 uint32_t sizeRecorded = fReader.readU32();
324 if (factory) { 324 if (factory) {
325 size_t offset = fReader.offset(); 325 size_t offset = fReader.offset();
326 obj = (*factory)(*this); 326 obj = (*factory)(*this);
327 // check that we read the amount we expected 327 // check that we read the amount we expected
328 size_t sizeRead = fReader.offset() - offset; 328 size_t sizeRead = fReader.offset() - offset;
329 if (sizeRecorded != sizeRead) { 329 if (sizeRecorded != sizeRead) {
330 // we could try to fix up the offset... 330 // we could try to fix up the offset...
331 sk_throw(); 331 sk_throw();
332 } 332 }
(...skipping 11 matching lines...) Expand all
344 void SkReadBuffer::skipFlattenable() { 344 void SkReadBuffer::skipFlattenable() {
345 if (fFactoryCount > 0) { 345 if (fFactoryCount > 0) {
346 if (0 == fReader.readU32()) { 346 if (0 == fReader.readU32()) {
347 return; 347 return;
348 } 348 }
349 } else if (fFactoryTDArray) { 349 } else if (fFactoryTDArray) {
350 if (0 == fReader.readU32()) { 350 if (0 == fReader.readU32()) {
351 return; 351 return;
352 } 352 }
353 } else { 353 } else {
354 if (NULL == this->readFunctionPtr()) { 354 if (nullptr == this->readFunctionPtr()) {
355 return; 355 return;
356 } 356 }
357 } 357 }
358 uint32_t sizeRecorded = fReader.readU32(); 358 uint32_t sizeRecorded = fReader.readU32();
359 fReader.skip(sizeRecorded); 359 fReader.skip(sizeRecorded);
360 } 360 }
OLDNEW
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | src/core/SkReader32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698