Chromium Code Reviews| Index: src/core/SkMallocPixelRef.cpp |
| diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp |
| index f229e9de34d0fa8dbdd29304dd0ac0f7a78e5611..ae783998a914b2e28654fc97fc0f31f67257a319 100644 |
| --- a/src/core/SkMallocPixelRef.cpp |
| +++ b/src/core/SkMallocPixelRef.cpp |
| @@ -8,6 +8,7 @@ |
| #include "SkMallocPixelRef.h" |
| #include "SkBitmap.h" |
| #include "SkFlattenableBuffers.h" |
| +#include "SkImageGenerator.h" |
| SkMallocPixelRef::SkMallocPixelRef(void* storage, size_t size, |
| SkColorTable* ctable, bool ownPixels) { |
| @@ -31,6 +32,34 @@ SkMallocPixelRef::~SkMallocPixelRef() { |
| } |
| } |
| +bool SkMallocPixelRef::Install(SkImageGenerator* generator, |
| + SkBitmap* destination) { |
| + SkASSERT(generator != NULL); |
| + SkAutoTDelete<SkImageGenerator> autodel(generator); |
| + // Always gets deleted by this function. |
| + SkImageInfo info; |
| + SkBitmap tmp; |
| + if ((NULL == generator) |
| + || (!generator->getInfo(&info)) |
| + || (!tmp.setConfig(info, 0))) { |
| + return false; |
| + } |
| + size_t rowBytes = tmp.rowBytes(); |
| + size_t size = tmp.getSize(); |
| + void* pixels = sk_malloc_throw(size); |
|
reed1
2013/11/25 18:06:56
Can we change this to sk_malloc_flags() so we can
|
| + if (!generator->getPixels(info, pixels, rowBytes)) { |
| + sk_free(pixels); |
| + return false; |
| + } |
| + SkAutoTUnref<SkMallocPixelRef> ref(SkNEW_ARGS(SkMallocPixelRef, |
| + (pixels, size, NULL, true))); |
| + *destination = tmp; // copy config, size, rowbytes. |
| + destination->setPixelRef(ref); |
| + destination->lockPixels(); // Since we're already allocated, we lock |
| + // right away, just like HeapAllocator. |
| + return true; |
| +} |
| + |
| void* SkMallocPixelRef::onLockPixels(SkColorTable** ct) { |
| *ct = fCTable; |
| return fStorage; |