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

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

Issue 2334123003: Add SkColor4f serialization (Closed)
Patch Set: Fix stack overflow in test Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkDeduper.h" 9 #include "SkDeduper.h"
10 #include "SkErrorInternals.h" 10 #include "SkErrorInternals.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 SkASSERT(fReader.available() > 0); 135 SkASSERT(fReader.available() > 0);
136 return *((uint8_t*) fReader.peek()); 136 return *((uint8_t*) fReader.peek());
137 } 137 }
138 138
139 void SkReadBuffer::readString(SkString* string) { 139 void SkReadBuffer::readString(SkString* string) {
140 size_t len; 140 size_t len;
141 const char* strContents = fReader.readString(&len); 141 const char* strContents = fReader.readString(&len);
142 string->set(strContents, len); 142 string->set(strContents, len);
143 } 143 }
144 144
145 static_assert(SK_SCALAR_IS_FLOAT, "Color4f serialization needs updating");
146 void SkReadBuffer::readColor4f(SkColor4f* color) {
reed1 2016/09/13 23:17:03 Is this any simpler/more-efficient? memcpy(color,
147 color->fR = fReader.readScalar();
148 color->fG = fReader.readScalar();
149 color->fB = fReader.readScalar();
150 color->fA = fReader.readScalar();
151 }
152
145 void SkReadBuffer::readPoint(SkPoint* point) { 153 void SkReadBuffer::readPoint(SkPoint* point) {
146 point->fX = fReader.readScalar(); 154 point->fX = fReader.readScalar();
147 point->fY = fReader.readScalar(); 155 point->fY = fReader.readScalar();
148 } 156 }
149 157
150 void SkReadBuffer::readMatrix(SkMatrix* matrix) { 158 void SkReadBuffer::readMatrix(SkMatrix* matrix) {
151 fReader.readMatrix(matrix); 159 fReader.readMatrix(matrix);
152 } 160 }
153 161
154 void SkReadBuffer::readIRect(SkIRect* rect) { 162 void SkReadBuffer::readIRect(SkIRect* rect) {
(...skipping 30 matching lines...) Expand all
185 } 193 }
186 194
187 bool SkReadBuffer::readByteArray(void* value, size_t size) { 195 bool SkReadBuffer::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 SkReadBuffer::readColorArray(SkColor* colors, size_t size) { 199 bool SkReadBuffer::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 SkReadBuffer::readColor4fArray(SkColor4f* colors, size_t size) {
204 return readArray(colors, size, sizeof(SkColor4f));
205 }
206
195 bool SkReadBuffer::readIntArray(int32_t* values, size_t size) { 207 bool SkReadBuffer::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 SkReadBuffer::readPointArray(SkPoint* points, size_t size) { 211 bool SkReadBuffer::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 SkReadBuffer::readScalarArray(SkScalar* values, size_t size) { 215 bool SkReadBuffer::readScalarArray(SkScalar* values, size_t size) {
204 return readArray(values, size, sizeof(SkScalar)); 216 return readArray(values, size, sizeof(SkScalar));
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (sizeRecorded != sizeRead) { 394 if (sizeRecorded != sizeRead) {
383 this->validate(false); 395 this->validate(false);
384 return nullptr; 396 return nullptr;
385 } 397 }
386 } else { 398 } else {
387 // we must skip the remaining data 399 // we must skip the remaining data
388 fReader.skip(sizeRecorded); 400 fReader.skip(sizeRecorded);
389 } 401 }
390 return obj.release(); 402 return obj.release();
391 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698