Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 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 #ifndef SkReader32_DEFINED | 10 #ifndef SkReader32_DEFINED |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 memcpy(dst, fCurr, size); | 99 memcpy(dst, fCurr, size); |
| 100 fCurr += SkAlign4(size); | 100 fCurr += SkAlign4(size); |
| 101 SkASSERT(fCurr <= fStop); | 101 SkASSERT(fCurr <= fStop); |
| 102 } | 102 } |
| 103 | 103 |
| 104 uint8_t readU8() { return (uint8_t)this->readInt(); } | 104 uint8_t readU8() { return (uint8_t)this->readInt(); } |
| 105 uint16_t readU16() { return (uint16_t)this->readInt(); } | 105 uint16_t readU16() { return (uint16_t)this->readInt(); } |
| 106 int32_t readS32() { return this->readInt(); } | 106 int32_t readS32() { return this->readInt(); } |
| 107 uint32_t readU32() { return this->readInt(); } | 107 uint32_t readU32() { return this->readInt(); } |
| 108 | 108 |
| 109 void readPath(SkPath* path) { | 109 bool readPath(SkPath* path) { |
|
sugoi1
2013/10/30 18:07:03
These 4 functions had essentially the same code, s
| |
| 110 size_t size = path->readFromMemory(this->peek()); | 110 return readObjectFromMemory(path); |
| 111 SkASSERT(SkAlign4(size) == size); | |
| 112 (void)this->skip(size); | |
| 113 } | 111 } |
| 114 | 112 |
| 115 void readMatrix(SkMatrix* matrix) { | 113 bool readMatrix(SkMatrix* matrix) { |
| 116 size_t size = matrix->readFromMemory(this->peek()); | 114 return readObjectFromMemory(matrix); |
| 117 SkASSERT(SkAlign4(size) == size); | |
| 118 (void)this->skip(size); | |
| 119 } | 115 } |
| 120 | 116 |
| 121 SkRRect* readRRect(SkRRect* rrect) { | 117 bool readRRect(SkRRect* rrect) { |
| 122 rrect->readFromMemory(this->skip(SkRRect::kSizeInMemory)); | 118 return readObjectFromMemory(rrect); |
| 123 return rrect; | |
| 124 } | 119 } |
| 125 | 120 |
| 126 void readRegion(SkRegion* rgn) { | 121 bool readRegion(SkRegion* rgn) { |
| 127 size_t size = rgn->readFromMemory(this->peek()); | 122 return readObjectFromMemory(rgn); |
| 128 SkASSERT(SkAlign4(size) == size); | |
| 129 (void)this->skip(size); | |
| 130 } | 123 } |
| 131 | 124 |
| 132 /** | 125 /** |
| 133 * Read the length of a string (written by SkWriter32::writeString) into | 126 * Read the length of a string (written by SkWriter32::writeString) into |
| 134 * len (if len is not NULL) and return the null-ternimated address of the | 127 * len (if len is not NULL) and return the null-ternimated address of the |
| 135 * string within the reader's buffer. | 128 * string within the reader's buffer. |
| 136 */ | 129 */ |
| 137 const char* readString(size_t* len = NULL); | 130 const char* readString(size_t* len = NULL); |
| 138 | 131 |
| 139 /** | 132 /** |
| 140 * Read the string (written by SkWriter32::writeString) and return it in | 133 * Read the string (written by SkWriter32::writeString) and return it in |
| 141 * copy (if copy is not null). Return the length of the string. | 134 * copy (if copy is not null). Return the length of the string. |
| 142 */ | 135 */ |
| 143 size_t readIntoString(SkString* copy); | 136 size_t readIntoString(SkString* copy); |
| 144 | 137 |
| 145 private: | 138 private: |
| 139 template <typename T> bool readObjectFromMemory(T* obj) { | |
| 140 size_t size = obj->readFromMemory(this->peek(), this->available()); | |
| 141 // If readFromMemory() fails (which means that available() was too small ), it returns 0 | |
| 142 bool success = size > 0; | |
| 143 SkASSERT(SkAlign4(size) == size && success); | |
|
reed1
2013/10/30 18:10:21
not sure we can keep the assert, if the call now r
sugoi1
2013/10/30 18:26:55
Done.
| |
| 144 // In case of failure, we want to skip to the end | |
| 145 (void)this->skip(success ? size : this->available()); | |
|
reed1
2013/10/30 18:10:21
does skip() return something that might also indic
sugoi1
2013/10/30 18:26:55
Hmmm... skip() returns the address of the pointer
| |
| 146 return success; | |
| 147 } | |
| 148 | |
| 146 // these are always 4-byte aligned | 149 // these are always 4-byte aligned |
| 147 const char* fCurr; // current position within buffer | 150 const char* fCurr; // current position within buffer |
| 148 const char* fStop; // end of buffer | 151 const char* fStop; // end of buffer |
| 149 const char* fBase; // beginning of buffer | 152 const char* fBase; // beginning of buffer |
| 150 | 153 |
| 151 #ifdef SK_DEBUG | 154 #ifdef SK_DEBUG |
| 152 static bool ptr_align_4(const void* ptr) { | 155 static bool ptr_align_4(const void* ptr) { |
| 153 return (((const char*)ptr - (const char*)NULL) & 3) == 0; | 156 return (((const char*)ptr - (const char*)NULL) & 3) == 0; |
| 154 } | 157 } |
| 155 #endif | 158 #endif |
| 156 }; | 159 }; |
| 157 | 160 |
| 158 #endif | 161 #endif |
| OLD | NEW |