OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
10 #include "SkValidatingReadBuffer.h" | 10 #include "SkValidatingReadBuffer.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 const size_t alignedSize = SkAlign4(len + 1); | 103 const size_t alignedSize = SkAlign4(len + 1); |
104 this->skip(alignedSize); | 104 this->skip(alignedSize); |
105 if (!fError) { | 105 if (!fError) { |
106 this->validate(cptr[len] == '\0'); | 106 this->validate(cptr[len] == '\0'); |
107 } | 107 } |
108 if (!fError) { | 108 if (!fError) { |
109 string->set(cptr, len); | 109 string->set(cptr, len); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
| 113 static_assert(SK_SCALAR_IS_FLOAT, "Color4f serialization needs updating"); |
| 114 void SkValidatingReadBuffer::readColor4f(SkColor4f* color) { |
| 115 color->fR = this->readScalar(); |
| 116 color->fG = this->readScalar(); |
| 117 color->fB = this->readScalar(); |
| 118 color->fA = this->readScalar(); |
| 119 } |
| 120 |
113 void SkValidatingReadBuffer::readPoint(SkPoint* point) { | 121 void SkValidatingReadBuffer::readPoint(SkPoint* point) { |
114 point->fX = this->readScalar(); | 122 point->fX = this->readScalar(); |
115 point->fY = this->readScalar(); | 123 point->fY = this->readScalar(); |
116 } | 124 } |
117 | 125 |
118 void SkValidatingReadBuffer::readMatrix(SkMatrix* matrix) { | 126 void SkValidatingReadBuffer::readMatrix(SkMatrix* matrix) { |
119 size_t size = 0; | 127 size_t size = 0; |
120 if (!fError) { | 128 if (!fError) { |
121 size = matrix->readFromMemory(fReader.peek(), fReader.available()); | 129 size = matrix->readFromMemory(fReader.peek(), fReader.available()); |
122 this->validate((SkAlign4(size) == size) && (0 != size)); | 130 this->validate((SkAlign4(size) == size) && (0 != size)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 193 } |
186 | 194 |
187 bool SkValidatingReadBuffer::readByteArray(void* value, size_t size) { | 195 bool SkValidatingReadBuffer::readByteArray(void* value, size_t size) { |
188 return readArray(static_cast<unsigned char*>(value), size, sizeof(unsigned c
har)); | 196 return readArray(static_cast<unsigned char*>(value), size, sizeof(unsigned c
har)); |
189 } | 197 } |
190 | 198 |
191 bool SkValidatingReadBuffer::readColorArray(SkColor* colors, size_t size) { | 199 bool SkValidatingReadBuffer::readColorArray(SkColor* colors, size_t size) { |
192 return readArray(colors, size, sizeof(SkColor)); | 200 return readArray(colors, size, sizeof(SkColor)); |
193 } | 201 } |
194 | 202 |
| 203 bool SkValidatingReadBuffer::readColor4fArray(SkColor4f* colors, size_t size) { |
| 204 return readArray(colors, size, sizeof(SkColor4f)); |
| 205 } |
| 206 |
195 bool SkValidatingReadBuffer::readIntArray(int32_t* values, size_t size) { | 207 bool SkValidatingReadBuffer::readIntArray(int32_t* values, size_t size) { |
196 return readArray(values, size, sizeof(int32_t)); | 208 return readArray(values, size, sizeof(int32_t)); |
197 } | 209 } |
198 | 210 |
199 bool SkValidatingReadBuffer::readPointArray(SkPoint* points, size_t size) { | 211 bool SkValidatingReadBuffer::readPointArray(SkPoint* points, size_t size) { |
200 return readArray(points, size, sizeof(SkPoint)); | 212 return readArray(points, size, sizeof(SkPoint)); |
201 } | 213 } |
202 | 214 |
203 bool SkValidatingReadBuffer::readScalarArray(SkScalar* values, size_t size) { | 215 bool SkValidatingReadBuffer::readScalarArray(SkScalar* values, size_t size) { |
204 return readArray(values, size, sizeof(SkScalar)); | 216 return readArray(values, size, sizeof(SkScalar)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 size_t offset = fReader.offset(); | 282 size_t offset = fReader.offset(); |
271 obj = (*factory)(*this); | 283 obj = (*factory)(*this); |
272 // check that we read the amount we expected | 284 // check that we read the amount we expected |
273 size_t sizeRead = fReader.offset() - offset; | 285 size_t sizeRead = fReader.offset() - offset; |
274 this->validate(sizeRecorded == sizeRead); | 286 this->validate(sizeRecorded == sizeRead); |
275 if (fError) { | 287 if (fError) { |
276 obj = nullptr; | 288 obj = nullptr; |
277 } | 289 } |
278 return obj.release(); | 290 return obj.release(); |
279 } | 291 } |
OLD | NEW |