Chromium Code Reviews| Index: src/core/SkBitmap.cpp |
| diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp |
| index 2464d5d5967409f77d87ce7cbf26cc5e4b82ab4d..6c52c56a9f92c007a131ae1760c49868d9d8f822 100644 |
| --- a/src/core/SkBitmap.cpp |
| +++ b/src/core/SkBitmap.cpp |
| @@ -488,13 +488,60 @@ void SkBitmap::setPixels(void* p, SkColorTable* ctable) { |
| bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { |
| HeapAllocator stdalloc; |
| - |
| + |
| if (NULL == allocator) { |
| allocator = &stdalloc; |
| } |
| return allocator->allocPixelRef(this, ctable); |
| } |
| +/////////////////////////////////////////////////////////////////////////////// |
| + |
| +static bool reset_return_false(SkBitmap* bm) { |
| + bm->reset(); |
| + return false; |
| +} |
| + |
| +bool SkBitmap::allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, |
| + SkColorTable* ctable) { |
| + if (kIndex_8_SkColorType == info.fColorType && NULL == ctable) { |
| + return reset_return_false(this); |
| + } |
| + if (!this->setConfig(info)) { |
| + return reset_return_false(this); |
| + } |
| + |
| + SkMallocPixelRef::PRFactory defaultFactory; |
| + if (NULL == factory) { |
| + factory = &defaultFactory; |
| + } |
| + |
| + SkPixelRef* pr = factory->create(info, ctable); |
| + if (NULL == pr) { |
| + return reset_return_false(this); |
| + } |
| + return this->setPixelRef(pr); |
|
scroggo
2014/01/24 16:18:59
pr needs to be unref'ed.
hal.canary
2014/01/24 16:46:50
Use a SkAutoTUnref<SkPixelRef>!
|
| +} |
| + |
| +bool SkBitmap::installPixels(const SkImageInfo& info, void* pixels, size_t rb, |
| + void (*releaseProc)(void* addr, void* context), |
| + void* context) { |
| + if (!this->setConfig(info)) { |
| + this->reset(); |
| + return false; |
| + } |
| + |
| + SkPixelRef* pr = SkMallocPixelRef::NewWithProc(info, rb, NULL, pixels, |
| + releaseProc, context); |
| + if (!pr) { |
| + this->reset(); |
| + return false; |
| + } |
| + |
| + this->setPixelRef(pr)->unref(); |
| + return true; |
| +} |
| + |
| void SkBitmap::freePixels() { |
| // if we're gonna free the pixels, we certainly need to free the mipmap |
| this->freeMipMap(); |