Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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); |
| 1614 this->setIsOpaque(buffer.readBool()); | |
|
Stephen White
2013/10/21 21:22:37
Where is this bool written? I don't see it in flat
scroggo
2013/10/21 21:37:22
This line was deleted in a recent CL, and this one
sugoi1
2013/10/22 12:12:54
Good catch on the bad merge. Line deleted.
| |
| 1611 | 1615 |
| 1612 int reftype = buffer.readInt(); | 1616 int reftype = buffer.readInt(); |
| 1613 switch (reftype) { | 1617 switch (reftype) { |
| 1614 case SERIALIZE_PIXELTYPE_REF_DATA: { | 1618 case SERIALIZE_PIXELTYPE_REF_DATA: { |
| 1615 size_t offset = buffer.readUInt(); | 1619 size_t offset = buffer.readUInt(); |
| 1616 SkPixelRef* pr = buffer.readPixelRef(); | 1620 SkPixelRef* pr = buffer.readPixelRef(); |
| 1617 SkSafeUnref(this->setPixelRef(pr, offset)); | 1621 SkSafeUnref(this->setPixelRef(pr, offset)); |
| 1618 break; | 1622 break; |
| 1619 } | 1623 } |
| 1620 case SERIALIZE_PIXELTYPE_NONE: | 1624 case SERIALIZE_PIXELTYPE_NONE: |
| 1621 break; | 1625 break; |
| 1622 default: | 1626 default: |
| 1627 buffer.validate(false); | |
| 1623 SkDEBUGFAIL("unrecognized pixeltype in serialized data"); | 1628 SkDEBUGFAIL("unrecognized pixeltype in serialized data"); |
| 1624 sk_throw(); | 1629 sk_throw(); |
| 1625 } | 1630 } |
| 1626 } | 1631 } |
| 1627 | 1632 |
| 1628 /////////////////////////////////////////////////////////////////////////////// | 1633 /////////////////////////////////////////////////////////////////////////////// |
| 1629 | 1634 |
| 1630 SkBitmap::RLEPixels::RLEPixels(int width, int height) { | 1635 SkBitmap::RLEPixels::RLEPixels(int width, int height) { |
| 1631 fHeight = height; | 1636 fHeight = height; |
| 1632 fYPtrs = (uint8_t**)sk_calloc_throw(height * sizeof(uint8_t*)); | 1637 fYPtrs = (uint8_t**)sk_calloc_throw(height * sizeof(uint8_t*)); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1696 if (NULL != uri) { | 1701 if (NULL != uri) { |
| 1697 str->appendf(" uri:\"%s\"", uri); | 1702 str->appendf(" uri:\"%s\"", uri); |
| 1698 } else { | 1703 } else { |
| 1699 str->appendf(" pixelref:%p", pr); | 1704 str->appendf(" pixelref:%p", pr); |
| 1700 } | 1705 } |
| 1701 } | 1706 } |
| 1702 | 1707 |
| 1703 str->append(")"); | 1708 str->append(")"); |
| 1704 } | 1709 } |
| 1705 #endif | 1710 #endif |
| OLD | NEW |