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

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: Integrating readFoo changes 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 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE); 1595 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE);
1595 } 1596 }
1596 } 1597 }
1597 1598
1598 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) { 1599 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) {
1599 this->reset(); 1600 this->reset();
1600 1601
1601 int width = buffer.readInt(); 1602 int width = buffer.readInt();
1602 int height = buffer.readInt(); 1603 int height = buffer.readInt();
1603 int rowBytes = buffer.readInt(); 1604 int rowBytes = buffer.readInt();
1604 int config = buffer.readInt(); 1605 Config config = (Config)buffer.readInt();
1606 buffer.validate((width >= 0) && (height >= 0) && (rowBytes >= 0) &&
1607 SkIsValidConfig(config));
1605 1608
1606 this->setConfig((Config)config, width, height, rowBytes); 1609 this->setConfig(config, width, height, rowBytes);
1607 this->setIsOpaque(buffer.readBool()); 1610 this->setIsOpaque(buffer.readBool());
1608 1611
1609 int reftype = buffer.readInt(); 1612 int reftype = buffer.readInt();
1610 switch (reftype) { 1613 switch (reftype) {
1611 case SERIALIZE_PIXELTYPE_REF_DATA: { 1614 case SERIALIZE_PIXELTYPE_REF_DATA: {
1612 size_t offset = buffer.readUInt(); 1615 size_t offset = buffer.readUInt();
1613 SkPixelRef* pr = buffer.readPixelRef(); 1616 SkPixelRef* pr = buffer.readPixelRef();
1614 SkSafeUnref(this->setPixelRef(pr, offset)); 1617 SkSafeUnref(this->setPixelRef(pr, offset));
1615 break; 1618 break;
1616 } 1619 }
1617 case SERIALIZE_PIXELTYPE_NONE: 1620 case SERIALIZE_PIXELTYPE_NONE:
1618 break; 1621 break;
1619 default: 1622 default:
1623 buffer.validate(false);
1620 SkDEBUGFAIL("unrecognized pixeltype in serialized data"); 1624 SkDEBUGFAIL("unrecognized pixeltype in serialized data");
1621 sk_throw(); 1625 sk_throw();
1622 } 1626 }
1623 } 1627 }
1624 1628
1625 /////////////////////////////////////////////////////////////////////////////// 1629 ///////////////////////////////////////////////////////////////////////////////
1626 1630
1627 SkBitmap::RLEPixels::RLEPixels(int width, int height) { 1631 SkBitmap::RLEPixels::RLEPixels(int width, int height) {
1628 fHeight = height; 1632 fHeight = height;
1629 fYPtrs = (uint8_t**)sk_calloc_throw(height * sizeof(uint8_t*)); 1633 fYPtrs = (uint8_t**)sk_calloc_throw(height * sizeof(uint8_t*));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 if (NULL != uri) { 1697 if (NULL != uri) {
1694 str->appendf(" uri:\"%s\"", uri); 1698 str->appendf(" uri:\"%s\"", uri);
1695 } else { 1699 } else {
1696 str->appendf(" pixelref:%p", pr); 1700 str->appendf(" pixelref:%p", pr);
1697 } 1701 }
1698 } 1702 }
1699 1703
1700 str->append(")"); 1704 str->append(")");
1701 } 1705 }
1702 #endif 1706 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698