| Index: src/core/SkBitmap.cpp
|
| diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
|
| index 9d4aa87c857fa0bc62eb3bbf946b76e70940f70b..f8024e31cd5f1f524c793929b5fb7afc888c29e3 100644
|
| --- a/src/core/SkBitmap.cpp
|
| +++ b/src/core/SkBitmap.cpp
|
| @@ -363,6 +363,36 @@ void SkBitmap::updatePixelsFromRef() const {
|
| }
|
| }
|
|
|
| +bool SkBitmap::asImageInfo(SkImageInfo* info) const {
|
| + SkColorType ct;
|
| + switch (this->config()) {
|
| + case kNo_Config:
|
| + return false;
|
| + case kA8_Config:
|
| + ct = kAlpha_8_SkColorType;
|
| + break;
|
| + case kIndex8_Config:
|
| + ct = kIndex8_SkColorType;
|
| + break;
|
| + case kRGB_565_Config:
|
| + ct = kRGB_565_SkColorType;
|
| + break;
|
| + case kARGB_4444_Config:
|
| + ct = kARGB_4444_SkColorType;
|
| + break;
|
| + case kARGB_8888_Config:
|
| + ct = kPMColor_SkColorType;
|
| + break;
|
| + }
|
| + if (info) {
|
| + info->fWidth = fWidth;
|
| + info->fHeight = fHeight;
|
| + info->fAlphaType = this->alphaType();
|
| + info->fColorType = ct;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, size_t offset) {
|
| // do this first, we that we never have a non-zero offset with a null ref
|
| if (NULL == pr) {
|
| @@ -413,10 +443,20 @@ void SkBitmap::setPixels(void* p, SkColorTable* ctable) {
|
| return;
|
| }
|
|
|
| - Sk64 size = this->getSize64();
|
| - SkASSERT(!size.isNeg() && size.is32());
|
| + SkImageInfo info;
|
| + if (!this->asImageInfo(&info)) {
|
| + this->setPixelRef(NULL, 0);
|
| + return;
|
| + }
|
| +
|
| + SkPixelRef* pr = SkMallocPixelRef::NewDirect(info, p, fRowBytes, ctable);
|
| + if (NULL == pr) {
|
| + this->setPixelRef(NULL, 0);
|
| + return;
|
| + }
|
| +
|
| + this->setPixelRef(pr)->unref();
|
|
|
| - this->setPixelRef(new SkMallocPixelRef(p, size.get32(), ctable, false))->unref();
|
| // since we're already allocated, we lockPixels right away
|
| this->lockPixels();
|
| SkDEBUGCODE(this->validate();)
|
| @@ -481,17 +521,19 @@ GrTexture* SkBitmap::getTexture() const {
|
| */
|
| bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst,
|
| SkColorTable* ctable) {
|
| - Sk64 size = dst->getSize64();
|
| - if (size.isNeg() || !size.is32()) {
|
| + SkImageInfo info;
|
| + if (!dst->asImageInfo(&info)) {
|
| +// SkDebugf("unsupported config for info %d\n", dst->config());
|
| return false;
|
| }
|
| -
|
| - void* addr = sk_malloc_flags(size.get32(), 0); // returns NULL on failure
|
| - if (NULL == addr) {
|
| +
|
| + SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(),
|
| + ctable);
|
| + if (NULL == pr) {
|
| return false;
|
| }
|
|
|
| - dst->setPixelRef(new SkMallocPixelRef(addr, size.get32(), ctable))->unref();
|
| + dst->setPixelRef(pr, 0)->unref();
|
| // since we're already allocated, we lockPixels right away
|
| dst->lockPixels();
|
| return true;
|
| @@ -1593,6 +1635,28 @@ SkBitmap::RLEPixels::~RLEPixels() {
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| +void SkImageInfo::unflatten(SkFlattenableReadBuffer& buffer) {
|
| + fWidth = buffer.read32();
|
| + fHeight = buffer.read32();
|
| +
|
| + uint32_t packed = buffer.read32();
|
| + SkASSERT(0 == (packed >> 16));
|
| + fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
|
| + fColorType = (SkColorType)((packed >> 0) & 0xFF);
|
| +}
|
| +
|
| +void SkImageInfo::flatten(SkFlattenableWriteBuffer& buffer) const {
|
| + buffer.write32(fWidth);
|
| + buffer.write32(fHeight);
|
| +
|
| + SkASSERT(0 == (fAlphaType & ~0xFF));
|
| + SkASSERT(0 == (fColorType & ~0xFF));
|
| + uint32_t packed = (fAlphaType << 8) | fColorType;
|
| + buffer.write32(packed);
|
| +}
|
| +
|
| +///////////////////////////////////////////////////////////////////////////////
|
| +
|
| #ifdef SK_DEBUG
|
| void SkBitmap::validate() const {
|
| SkASSERT(fConfig < kConfigCount);
|
|
|