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

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

Issue 295793002: stop calling SkBitmap::flatten (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | src/core/SkValidatingReadBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 184 }
185 185
186 bool SkReadBuffer::readScalarArray(SkScalar* values, size_t size) { 186 bool SkReadBuffer::readScalarArray(SkScalar* values, size_t size) {
187 return readArray(values, size, sizeof(SkScalar)); 187 return readArray(values, size, sizeof(SkScalar));
188 } 188 }
189 189
190 uint32_t SkReadBuffer::getArrayCount() { 190 uint32_t SkReadBuffer::getArrayCount() {
191 return *(uint32_t*)fReader.peek(); 191 return *(uint32_t*)fReader.peek();
192 } 192 }
193 193
194 void SkReadBuffer::readBitmap(SkBitmap* bitmap) { 194 bool SkReadBuffer::readBitmap(SkBitmap* bitmap) {
195 const int width = this->readInt(); 195 const int width = this->readInt();
196 const int height = this->readInt(); 196 const int height = this->readInt();
197 // The writer stored a boolean value to determine whether an SkBitmapHeap wa s used during 197 // The writer stored a boolean value to determine whether an SkBitmapHeap wa s used during
198 // writing. 198 // writing.
199 if (this->readBool()) { 199 if (this->readBool()) {
200 // An SkBitmapHeap was used for writing. Read the index from the stream and find the 200 // An SkBitmapHeap was used for writing. Read the index from the stream and find the
201 // corresponding SkBitmap in fBitmapStorage. 201 // corresponding SkBitmap in fBitmapStorage.
202 const uint32_t index = fReader.readU32(); 202 const uint32_t index = fReader.readU32();
203 fReader.readU32(); // bitmap generation ID (see SkWriteBuffer::writeBitm ap) 203 fReader.readU32(); // bitmap generation ID (see SkWriteBuffer::writeBitm ap)
204 if (fBitmapStorage) { 204 if (fBitmapStorage) {
205 *bitmap = *fBitmapStorage->getBitmap(index); 205 *bitmap = *fBitmapStorage->getBitmap(index);
206 fBitmapStorage->releaseRef(index); 206 fBitmapStorage->releaseRef(index);
207 return; 207 return true;
208 } else { 208 } else {
209 // The bitmap was stored in a heap, but there is no way to access it . Set an error and 209 // The bitmap was stored in a heap, but there is no way to access it . Set an error and
210 // fall through to use a place holder bitmap. 210 // fall through to use a place holder bitmap.
211 SkErrorInternals::SetError(kParseError_SkError, "SkWriteBuffer::writ eBitmap " 211 SkErrorInternals::SetError(kParseError_SkError, "SkWriteBuffer::writ eBitmap "
212 "stored the SkBitmap in an SkBitmapHeap, but " 212 "stored the SkBitmap in an SkBitmapHeap, but "
213 "SkReadBuffer has no SkBitmapHeapReader t o " 213 "SkReadBuffer has no SkBitmapHeapReader t o "
214 "retrieve the SkBitmap."); 214 "retrieve the SkBitmap.");
215 } 215 }
216 } else { 216 } else {
217 // The writer stored false, meaning the SkBitmap was not stored in an Sk BitmapHeap. 217 // The writer stored false, meaning the SkBitmap was not stored in an Sk BitmapHeap.
(...skipping 14 matching lines...) Expand all
232 SkDebugf("SkReadBuffer::readBitmap: heights match," 232 SkDebugf("SkReadBuffer::readBitmap: heights match,"
233 " but offset is not zero. \nInfo about the bitm ap:" 233 " but offset is not zero. \nInfo about the bitm ap:"
234 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode d" 234 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode d"
235 " data size: %d\n\tOffset: (%d, %d)\n", 235 " data size: %d\n\tOffset: (%d, %d)\n",
236 fDecodedBitmapIndex, width, height, length, xOf fset, 236 fDecodedBitmapIndex, width, height, length, xOf fset,
237 yOffset); 237 yOffset);
238 } 238 }
239 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 239 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
240 // If the width and height match, there should be no offset. 240 // If the width and height match, there should be no offset.
241 SkASSERT(0 == xOffset && 0 == yOffset); 241 SkASSERT(0 == xOffset && 0 == yOffset);
242 return; 242 return true;
243 } 243 }
244 244
245 // This case can only be reached if extractSubset was called, so 245 // This case can only be reached if extractSubset was called, so
246 // the recorded width and height must be smaller than or equal t o 246 // the recorded width and height must be smaller than or equal t o
247 // the encoded width and height. 247 // the encoded width and height.
248 // FIXME (scroggo): This assert assumes that our decoder and the 248 // FIXME (scroggo): This assert assumes that our decoder and the
249 // sources encoder agree on the width and height which may not 249 // sources encoder agree on the width and height which may not
250 // always be the case. Removing until it can be investigated 250 // always be the case. Removing until it can be investigated
251 // further. 251 // further.
252 //SkASSERT(width <= bitmap->width() && height <= bitmap->height( )); 252 //SkASSERT(width <= bitmap->width() && height <= bitmap->height( ));
253 253
254 SkBitmap subsetBm; 254 SkBitmap subsetBm;
255 SkIRect subset = SkIRect::MakeXYWH(xOffset, yOffset, width, heig ht); 255 SkIRect subset = SkIRect::MakeXYWH(xOffset, yOffset, width, heig ht);
256 if (bitmap->extractSubset(&subsetBm, subset)) { 256 if (bitmap->extractSubset(&subsetBm, subset)) {
257 bitmap->swap(subsetBm); 257 bitmap->swap(subsetBm);
258 return; 258 return true;
259 } 259 }
260 } 260 }
261 // This bitmap was encoded when written, but we are unable to decode , possibly due to 261 // This bitmap was encoded when written, but we are unable to decode , possibly due to
262 // not having a decoder. 262 // not having a decoder.
263 SkErrorInternals::SetError(kParseError_SkError, 263 SkErrorInternals::SetError(kParseError_SkError,
264 "Could not decode bitmap. Resulting bitma p will be red."); 264 "Could not decode bitmap. Resulting bitma p will be red.");
265 } else { 265 } else {
266 // A size of zero means the SkBitmap was simply flattened. 266 // A size of zero means the SkBitmap was simply flattened.
267 bitmap->unflatten(*this); 267 if (this->isVersionLT(kNoMoreBitmapFlatten_Version)) {
268 return; 268 SkBitmap tmp;
269 tmp.unflatten(*this);
270 // just throw this guy away
271 } else {
272 if (SkBitmap::ReadRawPixels(this, bitmap)) {
273 return true;
274 }
275 }
269 } 276 }
270 } 277 }
271 // Could not read the SkBitmap. Use a placeholder bitmap. 278 // Could not read the SkBitmap. Use a placeholder bitmap.
272 bitmap->allocPixels(SkImageInfo::MakeN32Premul(width, height)); 279 bitmap->setConfig(SkImageInfo::MakeUnknown(width, height));
273 bitmap->eraseColor(SK_ColorRED); 280 return false;
274 } 281 }
275 282
276 SkTypeface* SkReadBuffer::readTypeface() { 283 SkTypeface* SkReadBuffer::readTypeface() {
277 284
278 uint32_t index = fReader.readU32(); 285 uint32_t index = fReader.readU32();
279 if (0 == index || index > (unsigned)fTFCount) { 286 if (0 == index || index > (unsigned)fTFCount) {
280 if (index) { 287 if (index) {
281 SkDebugf("====== typeface index %d\n", index); 288 SkDebugf("====== typeface index %d\n", index);
282 } 289 }
283 return NULL; 290 return NULL;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 return; 357 return;
351 } 358 }
352 } else { 359 } else {
353 if (NULL == this->readFunctionPtr()) { 360 if (NULL == this->readFunctionPtr()) {
354 return; 361 return;
355 } 362 }
356 } 363 }
357 uint32_t sizeRecorded = fReader.readU32(); 364 uint32_t sizeRecorded = fReader.readU32();
358 fReader.skip(sizeRecorded); 365 fReader.skip(sizeRecorded);
359 } 366 }
OLDNEW
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | src/core/SkValidatingReadBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698