| Index: src/core/SkBitmap.cpp
|
| diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
|
| index 2464d5d5967409f77d87ce7cbf26cc5e4b82ab4d..9227906eab643a60d51e008d0a1d631176c81419 100644
|
| --- a/src/core/SkBitmap.cpp
|
| +++ b/src/core/SkBitmap.cpp
|
| @@ -488,13 +488,67 @@ 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);
|
| + }
|
| + this->setPixelRef(pr)->unref();
|
| +
|
| + // TODO: lockPixels could/should return bool or void*/NULL
|
| + this->lockPixels();
|
| + if (NULL == this->getPixels()) {
|
| + return reset_return_false(this);
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +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();
|
|
|