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::readArray(void* value, size_t size, size_t elementSize ) { |
141 const uint32_t length = fReader.readU32(); | 141 const size_t count = this->getArrayCount(); |
142 memcpy(value, fReader.skip(SkAlign4(length)), length); | 142 if (count == size) { |
Stephen White
2013/10/31 15:19:28
Nit: prefer the early-out to be the error case rat
| |
143 return length; | 143 (void)fReader.skip(sizeof(uint32_t)); // Skip array count |
144 const size_t byteLength = count * elementSize; | |
Stephen White
2013/10/31 15:19:28
Should we be checking for overflow here? At worst,
| |
145 memcpy(value, fReader.skip(SkAlign4(byteLength)), byteLength); | |
146 return true; | |
147 } | |
148 SkASSERT(false); | |
149 fReader.skip(fReader.available()); | |
150 return false; | |
144 } | 151 } |
145 | 152 |
146 uint32_t SkOrderedReadBuffer::readColorArray(SkColor* colors) { | 153 bool SkOrderedReadBuffer::readByteArray(void* value, size_t size) { |
147 const uint32_t count = fReader.readU32(); | 154 return readArray(static_cast<unsigned char*>(value), size, sizeof(unsigned c har)); |
148 const uint32_t byteLength = count * sizeof(SkColor); | |
149 memcpy(colors, fReader.skip(SkAlign4(byteLength)), byteLength); | |
150 return count; | |
151 } | 155 } |
152 | 156 |
153 uint32_t SkOrderedReadBuffer::readIntArray(int32_t* values) { | 157 bool SkOrderedReadBuffer::readColorArray(SkColor* colors, size_t size) { |
154 const uint32_t count = fReader.readU32(); | 158 return readArray(colors, size, sizeof(SkColor)); |
155 const uint32_t byteLength = count * sizeof(int32_t); | |
156 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); | |
157 return count; | |
158 } | 159 } |
159 | 160 |
160 uint32_t SkOrderedReadBuffer::readPointArray(SkPoint* points) { | 161 bool SkOrderedReadBuffer::readIntArray(int32_t* values, size_t size) { |
161 const uint32_t count = fReader.readU32(); | 162 return readArray(values, size, sizeof(int32_t)); |
162 const uint32_t byteLength = count * sizeof(SkPoint); | |
163 memcpy(points, fReader.skip(SkAlign4(byteLength)), byteLength); | |
164 return count; | |
165 } | 163 } |
166 | 164 |
167 uint32_t SkOrderedReadBuffer::readScalarArray(SkScalar* values) { | 165 bool SkOrderedReadBuffer::readPointArray(SkPoint* points, size_t size) { |
168 const uint32_t count = fReader.readU32(); | 166 return readArray(points, size, sizeof(SkPoint)); |
169 const uint32_t byteLength = count * sizeof(SkScalar); | 167 } |
170 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); | 168 |
171 return count; | 169 bool SkOrderedReadBuffer::readScalarArray(SkScalar* values, size_t size) { |
170 return readArray(values, size, sizeof(SkScalar)); | |
172 } | 171 } |
173 | 172 |
174 uint32_t SkOrderedReadBuffer::getArrayCount() { | 173 uint32_t SkOrderedReadBuffer::getArrayCount() { |
175 return *(uint32_t*)fReader.peek(); | 174 return *(uint32_t*)fReader.peek(); |
176 } | 175 } |
177 | 176 |
178 void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) { | 177 void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) { |
179 const int width = this->readInt(); | 178 const int width = this->readInt(); |
180 const int height = this->readInt(); | 179 const int height = this->readInt(); |
181 // The writer stored a boolean value to determine whether an SkBitmapHeap wa s used during | 180 // 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) { | 308 if (sizeRecorded != sizeRead) { |
310 // we could try to fix up the offset... | 309 // we could try to fix up the offset... |
311 sk_throw(); | 310 sk_throw(); |
312 } | 311 } |
313 } else { | 312 } else { |
314 // we must skip the remaining data | 313 // we must skip the remaining data |
315 fReader.skip(sizeRecorded); | 314 fReader.skip(sizeRecorded); |
316 } | 315 } |
317 return obj; | 316 return obj; |
318 } | 317 } |
OLD | NEW |