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

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: 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
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 SkPixelRef* pr = SkBitmap::ReadRawPixels(this);
273 if (pr) {
274 bitmap->setConfig(pr->info());
275 bitmap->setPixelRef(pr, 0, 0);
276 pr->unref();
277 return true;
278 }
279 }
269 } 280 }
270 } 281 }
271 // Could not read the SkBitmap. Use a placeholder bitmap. 282 // Could not read the SkBitmap. Use a placeholder bitmap.
272 bitmap->allocPixels(SkImageInfo::MakeN32Premul(width, height)); 283 bitmap->setConfig(SkImageInfo::MakeUnknown(width, height));
273 bitmap->eraseColor(SK_ColorRED); 284 return false;
274 } 285 }
275 286
276 SkTypeface* SkReadBuffer::readTypeface() { 287 SkTypeface* SkReadBuffer::readTypeface() {
277 288
278 uint32_t index = fReader.readU32(); 289 uint32_t index = fReader.readU32();
279 if (0 == index || index > (unsigned)fTFCount) { 290 if (0 == index || index > (unsigned)fTFCount) {
280 if (index) { 291 if (index) {
281 SkDebugf("====== typeface index %d\n", index); 292 SkDebugf("====== typeface index %d\n", index);
282 } 293 }
283 return NULL; 294 return NULL;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (sizeRecorded != sizeRead) { 339 if (sizeRecorded != sizeRead) {
329 // we could try to fix up the offset... 340 // we could try to fix up the offset...
330 sk_throw(); 341 sk_throw();
331 } 342 }
332 } else { 343 } else {
333 // we must skip the remaining data 344 // we must skip the remaining data
334 fReader.skip(sizeRecorded); 345 fReader.skip(sizeRecorded);
335 } 346 }
336 return obj; 347 return obj;
337 } 348 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698