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

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

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Serialization with strings as ID Created 7 years, 2 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 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
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 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkDither.h" 12 #include "SkDither.h"
13 #include "SkFlattenable.h" 13 #include "SkFlattenable.h"
14 #include "SkMallocPixelRef.h" 14 #include "SkMallocPixelRef.h"
15 #include "SkMask.h" 15 #include "SkMask.h"
16 #include "SkOrderedReadBuffer.h" 16 #include "SkOrderedReadBuffer.h"
17 #include "SkOrderedWriteBuffer.h" 17 #include "SkOrderedWriteBuffer.h"
18 #include "SkPixelRef.h" 18 #include "SkPixelRef.h"
19 #include "SkThread.h" 19 #include "SkThread.h"
20 #include "SkUnPreMultiply.h" 20 #include "SkUnPreMultiply.h"
21 #include "SkUtils.h" 21 #include "SkUtils.h"
22 #include "SkValidationUtils.h"
22 #include "SkPackBits.h" 23 #include "SkPackBits.h"
23 #include <new> 24 #include <new>
24 25
25 SK_DEFINE_INST_COUNT(SkBitmap::Allocator) 26 SK_DEFINE_INST_COUNT(SkBitmap::Allocator)
26 27
27 static bool isPos32Bits(const Sk64& value) { 28 static bool isPos32Bits(const Sk64& value) {
28 return !value.isNeg() && value.is32(); 29 return !value.isNeg() && value.is32();
29 } 30 }
30 31
31 struct MipLevel { 32 struct MipLevel {
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE); 1600 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE);
1600 } 1601 }
1601 } 1602 }
1602 1603
1603 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) { 1604 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) {
1604 this->reset(); 1605 this->reset();
1605 1606
1606 int width = buffer.readInt(); 1607 int width = buffer.readInt();
1607 int height = buffer.readInt(); 1608 int height = buffer.readInt();
1608 int rowBytes = buffer.readInt(); 1609 int rowBytes = buffer.readInt();
1609 int config = buffer.readInt(); 1610 Config config = (Config)buffer.readInt();
1611 buffer.validate((width >= 0) && (height >= 0) && (rowBytes >= 0) &&
1612 SkIsValidConfig(config));
1610 1613
1611 this->setConfig((Config)config, width, height, rowBytes); 1614 this->setConfig(config, width, height, rowBytes);
1612 this->setIsOpaque(buffer.readBool()); 1615 this->setIsOpaque(buffer.readBool());
1613 1616
1614 int reftype = buffer.readInt(); 1617 int reftype = buffer.readInt();
1615 switch (reftype) { 1618 switch (reftype) {
1616 case SERIALIZE_PIXELTYPE_REF_DATA: { 1619 case SERIALIZE_PIXELTYPE_REF_DATA: {
1617 size_t offset = buffer.readUInt(); 1620 size_t offset = buffer.readUInt();
1618 SkPixelRef* pr = buffer.readFlattenableT<SkPixelRef>(); 1621 SkPixelRef* pr = buffer.readFlattenableT<SkPixelRef>();
1619 SkSafeUnref(this->setPixelRef(pr, offset)); 1622 SkSafeUnref(this->setPixelRef(pr, offset));
1620 break; 1623 break;
1621 } 1624 }
1622 case SERIALIZE_PIXELTYPE_NONE: 1625 case SERIALIZE_PIXELTYPE_NONE:
1623 break; 1626 break;
1624 default: 1627 default:
1628 buffer.validate(false);
1625 SkDEBUGFAIL("unrecognized pixeltype in serialized data"); 1629 SkDEBUGFAIL("unrecognized pixeltype in serialized data");
1626 sk_throw(); 1630 sk_throw();
1627 } 1631 }
1628 } 1632 }
1629 1633
1630 /////////////////////////////////////////////////////////////////////////////// 1634 ///////////////////////////////////////////////////////////////////////////////
1631 1635
1632 SkBitmap::RLEPixels::RLEPixels(int width, int height) { 1636 SkBitmap::RLEPixels::RLEPixels(int width, int height) {
1633 fHeight = height; 1637 fHeight = height;
1634 fYPtrs = (uint8_t**)sk_malloc_throw(height * sizeof(uint8_t*)); 1638 fYPtrs = (uint8_t**)sk_malloc_throw(height * sizeof(uint8_t*));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 if (NULL != uri) { 1703 if (NULL != uri) {
1700 str->appendf(" uri:\"%s\"", uri); 1704 str->appendf(" uri:\"%s\"", uri);
1701 } else { 1705 } else {
1702 str->appendf(" pixelref:%p", pr); 1706 str->appendf(" pixelref:%p", pr);
1703 } 1707 }
1704 } 1708 }
1705 1709
1706 str->append(")"); 1710 str->append(")");
1707 } 1711 }
1708 #endif 1712 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698