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

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: Adapting code to sk_once changes Created 7 years, 1 month 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 | « include/effects/SkArithmeticMode.h ('k') | src/core/SkFlattenable.cpp » ('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 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 262 }
262 263
263 void SkBitmap::getBounds(SkIRect* bounds) const { 264 void SkBitmap::getBounds(SkIRect* bounds) const {
264 SkASSERT(bounds); 265 SkASSERT(bounds);
265 bounds->set(0, 0, fWidth, fHeight); 266 bounds->set(0, 0, fWidth, fHeight);
266 } 267 }
267 268
268 /////////////////////////////////////////////////////////////////////////////// 269 ///////////////////////////////////////////////////////////////////////////////
269 270
270 static bool validate_alphaType(SkBitmap::Config config, SkAlphaType alphaType, 271 static bool validate_alphaType(SkBitmap::Config config, SkAlphaType alphaType,
271 SkAlphaType* canonical) { 272 SkAlphaType* canonical = NULL) {
272 switch (config) { 273 switch (config) {
273 case SkBitmap::kNo_Config: 274 case SkBitmap::kNo_Config:
274 alphaType = kIgnore_SkAlphaType; 275 alphaType = kIgnore_SkAlphaType;
275 break; 276 break;
276 case SkBitmap::kA1_Config: 277 case SkBitmap::kA1_Config:
277 case SkBitmap::kA8_Config: 278 case SkBitmap::kA8_Config:
278 if (kUnpremul_SkAlphaType == alphaType) { 279 if (kUnpremul_SkAlphaType == alphaType) {
279 alphaType = kPremul_SkAlphaType; 280 alphaType = kPremul_SkAlphaType;
280 } 281 }
281 // fall-through 282 // fall-through
(...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE); 1598 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE);
1598 } 1599 }
1599 } 1600 }
1600 1601
1601 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) { 1602 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) {
1602 this->reset(); 1603 this->reset();
1603 1604
1604 int width = buffer.readInt(); 1605 int width = buffer.readInt();
1605 int height = buffer.readInt(); 1606 int height = buffer.readInt();
1606 int rowBytes = buffer.readInt(); 1607 int rowBytes = buffer.readInt();
1607 int config = buffer.readInt(); 1608 Config config = (Config)buffer.readInt();
1608 int alphaType = buffer.readInt(); 1609 SkAlphaType alphaType = (SkAlphaType)buffer.readInt();
1610 buffer.validate((width >= 0) && (height >= 0) && (rowBytes >= 0) &&
1611 SkIsValidConfig(config) && validate_alphaType(config, alphaT ype));
1609 1612
1610 this->setConfig((Config)config, width, height, rowBytes, (SkAlphaType)alphaT ype); 1613 this->setConfig(config, width, height, rowBytes, alphaType);
1611 1614
1612 int reftype = buffer.readInt(); 1615 int reftype = buffer.readInt();
1613 switch (reftype) { 1616 switch (reftype) {
1614 case SERIALIZE_PIXELTYPE_REF_DATA: { 1617 case SERIALIZE_PIXELTYPE_REF_DATA: {
1615 size_t offset = buffer.readUInt(); 1618 size_t offset = buffer.readUInt();
1616 SkPixelRef* pr = buffer.readPixelRef(); 1619 SkPixelRef* pr = buffer.readPixelRef();
1617 SkSafeUnref(this->setPixelRef(pr, offset)); 1620 SkSafeUnref(this->setPixelRef(pr, offset));
1618 break; 1621 break;
1619 } 1622 }
1620 case SERIALIZE_PIXELTYPE_NONE: 1623 case SERIALIZE_PIXELTYPE_NONE:
1621 break; 1624 break;
1622 default: 1625 default:
1626 buffer.validate(false);
1623 SkDEBUGFAIL("unrecognized pixeltype in serialized data"); 1627 SkDEBUGFAIL("unrecognized pixeltype in serialized data");
1624 sk_throw(); 1628 sk_throw();
1625 } 1629 }
1626 } 1630 }
1627 1631
1628 /////////////////////////////////////////////////////////////////////////////// 1632 ///////////////////////////////////////////////////////////////////////////////
1629 1633
1630 SkBitmap::RLEPixels::RLEPixels(int width, int height) { 1634 SkBitmap::RLEPixels::RLEPixels(int width, int height) {
1631 fHeight = height; 1635 fHeight = height;
1632 fYPtrs = (uint8_t**)sk_calloc_throw(height * sizeof(uint8_t*)); 1636 fYPtrs = (uint8_t**)sk_calloc_throw(height * sizeof(uint8_t*));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 if (NULL != uri) { 1700 if (NULL != uri) {
1697 str->appendf(" uri:\"%s\"", uri); 1701 str->appendf(" uri:\"%s\"", uri);
1698 } else { 1702 } else {
1699 str->appendf(" pixelref:%p", pr); 1703 str->appendf(" pixelref:%p", pr);
1700 } 1704 }
1701 } 1705 }
1702 1706
1703 str->append(")"); 1707 str->append(")");
1704 } 1708 }
1705 #endif 1709 #endif
OLDNEW
« no previous file with comments | « include/effects/SkArithmeticMode.h ('k') | src/core/SkFlattenable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698