OLD | NEW |
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" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 | 131 |
132 void SkOrderedReadBuffer::readRegion(SkRegion* region) { | 132 void SkOrderedReadBuffer::readRegion(SkRegion* region) { |
133 fReader.readRegion(region); | 133 fReader.readRegion(region); |
134 } | 134 } |
135 | 135 |
136 void SkOrderedReadBuffer::readPath(SkPath* path) { | 136 void SkOrderedReadBuffer::readPath(SkPath* path) { |
137 fReader.readPath(path); | 137 fReader.readPath(path); |
138 } | 138 } |
139 | 139 |
140 uint32_t SkOrderedReadBuffer::readByteArray(void* value) { | 140 bool SkOrderedReadBuffer::readByteArray(void* value, size_t size) { |
141 const uint32_t length = fReader.readU32(); | 141 const size_t length = this->getArrayCount(); |
142 memcpy(value, fReader.skip(SkAlign4(length)), length); | 142 if (length == size) { |
143 return length; | 143 (void)fReader.skip(sizeof(uint32_t)); // Skip array count |
| 144 memcpy(value, fReader.skip(SkAlign4(length)), length); |
| 145 return true; |
| 146 } |
| 147 SkASSERT(false); |
| 148 return false; |
144 } | 149 } |
145 | 150 |
146 uint32_t SkOrderedReadBuffer::readColorArray(SkColor* colors) { | 151 bool SkOrderedReadBuffer::readColorArray(SkColor* colors, size_t size) { |
147 const uint32_t count = fReader.readU32(); | 152 const uint32_t count = this->getArrayCount(); |
148 const uint32_t byteLength = count * sizeof(SkColor); | 153 const size_t byteLength = count * sizeof(SkColor); |
149 memcpy(colors, fReader.skip(SkAlign4(byteLength)), byteLength); | 154 if (byteLength == size) { |
150 return count; | 155 (void)fReader.skip(sizeof(uint32_t)); // Skip array count |
| 156 memcpy(colors, fReader.skip(SkAlign4(byteLength)), byteLength); |
| 157 return true; |
| 158 } |
| 159 SkASSERT(false); |
| 160 return false; |
151 } | 161 } |
152 | 162 |
153 uint32_t SkOrderedReadBuffer::readIntArray(int32_t* values) { | 163 bool SkOrderedReadBuffer::readIntArray(int32_t* values, size_t size) { |
154 const uint32_t count = fReader.readU32(); | 164 const uint32_t count = this->getArrayCount(); |
155 const uint32_t byteLength = count * sizeof(int32_t); | 165 const size_t byteLength = count * sizeof(int32_t); |
156 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); | 166 if (byteLength == size) { |
157 return count; | 167 (void)fReader.skip(sizeof(uint32_t)); // Skip array count |
| 168 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); |
| 169 return true; |
| 170 } |
| 171 SkASSERT(false); |
| 172 return false; |
158 } | 173 } |
159 | 174 |
160 uint32_t SkOrderedReadBuffer::readPointArray(SkPoint* points) { | 175 bool SkOrderedReadBuffer::readPointArray(SkPoint* points, size_t size) { |
161 const uint32_t count = fReader.readU32(); | 176 const uint32_t count = this->getArrayCount(); |
162 const uint32_t byteLength = count * sizeof(SkPoint); | 177 const size_t byteLength = count * sizeof(SkPoint); |
163 memcpy(points, fReader.skip(SkAlign4(byteLength)), byteLength); | 178 if (byteLength == size) { |
164 return count; | 179 (void)fReader.skip(sizeof(uint32_t)); // Skip array count |
| 180 memcpy(points, fReader.skip(SkAlign4(byteLength)), byteLength); |
| 181 return true; |
| 182 } |
| 183 SkASSERT(false); |
| 184 return false; |
165 } | 185 } |
166 | 186 |
167 uint32_t SkOrderedReadBuffer::readScalarArray(SkScalar* values) { | 187 bool SkOrderedReadBuffer::readScalarArray(SkScalar* values, size_t size) { |
168 const uint32_t count = fReader.readU32(); | 188 const uint32_t count = this->getArrayCount(); |
169 const uint32_t byteLength = count * sizeof(SkScalar); | 189 const size_t byteLength = count * sizeof(SkScalar); |
170 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); | 190 if (byteLength == size) { |
171 return count; | 191 (void)fReader.skip(sizeof(uint32_t)); // Skip array count |
| 192 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); |
| 193 return true; |
| 194 } |
| 195 SkASSERT(false); |
| 196 return false; |
172 } | 197 } |
173 | 198 |
174 uint32_t SkOrderedReadBuffer::getArrayCount() { | 199 uint32_t SkOrderedReadBuffer::getArrayCount() { |
175 return *(uint32_t*)fReader.peek(); | 200 return *(uint32_t*)fReader.peek(); |
176 } | 201 } |
177 | 202 |
178 void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) { | 203 void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) { |
179 const int width = this->readInt(); | 204 const int width = this->readInt(); |
180 const int height = this->readInt(); | 205 const int height = this->readInt(); |
181 // The writer stored a boolean value to determine whether an SkBitmapHeap wa
s used during | 206 // The writer stored a boolean value to determine whether an SkBitmapHeap wa
s used during |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 if (sizeRecorded != sizeRead) { | 334 if (sizeRecorded != sizeRead) { |
310 // we could try to fix up the offset... | 335 // we could try to fix up the offset... |
311 sk_throw(); | 336 sk_throw(); |
312 } | 337 } |
313 } else { | 338 } else { |
314 // we must skip the remaining data | 339 // we must skip the remaining data |
315 fReader.skip(sizeRecorded); | 340 fReader.skip(sizeRecorded); |
316 } | 341 } |
317 return obj; | 342 return obj; |
318 } | 343 } |
OLD | NEW |