Chromium Code Reviews| Index: src/core/SkImageGenerator.cpp |
| diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp |
| index 6fe9f84a08821b8e78fc714e1045b7b264818baf..6fd97f9fc42a4dedc89cebbabe7cb7e3de7f847a 100644 |
| --- a/src/core/SkImageGenerator.cpp |
| +++ b/src/core/SkImageGenerator.cpp |
| @@ -128,11 +128,8 @@ bool SkImageGenerator::onGetPixels(const SkImageInfo& info, void* dst, size_t rb |
| #include "SkBitmap.h" |
| #include "SkColorTable.h" |
| -static void release_malloc_proc(void* pixels, void* ctx) { |
| - sk_free(pixels); |
| -} |
| - |
| -bool SkImageGenerator::tryGenerateBitmap(SkBitmap* bitmap, const SkImageInfo* infoPtr) { |
| +bool SkImageGenerator::tryGenerateBitmap(SkBitmap* bitmap, const SkImageInfo* infoPtr, |
| + SkBitmap::Allocator* allocator) { |
| const SkImageInfo info = infoPtr ? *infoPtr : this->getInfo(); |
| const size_t rowBytes = info.minRowBytes(); |
| const size_t pixelSize = info.getSafeSize(rowBytes); |
| @@ -140,29 +137,45 @@ bool SkImageGenerator::tryGenerateBitmap(SkBitmap* bitmap, const SkImageInfo* in |
| return false; |
| } |
| - SkAutoFree pixelStorage(sk_malloc_flags(pixelSize, 0)); |
| - void* pixels = pixelStorage.get(); |
| - if (!pixels) { |
| + if (!bitmap->setInfo(info)) { |
| return false; |
| } |
| - |
| + |
| SkPMColor ctStorage[256]; |
| + memset(ctStorage, 0xFF, sizeof(ctStorage)); // init with opaque-white for the moment |
| + SkAutoTUnref<SkColorTable> ctable(new SkColorTable(ctStorage, 256)); |
| + if (!bitmap->tryAllocPixels(allocator, ctable)) { |
| + return false; |
| + } |
| + |
| + bitmap->lockPixels(); |
| + if (!bitmap->getPixels()) { |
| + bitmap->reset(); |
| + return false; |
| + } |
| + |
| int ctCount = 0; |
| - |
| - if (!this->getPixels(info, pixels, rowBytes, ctStorage, &ctCount)) { |
| + if (!this->getPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), |
| + ctStorage, &ctCount)) { |
|
tomhudson
2015/09/17 18:58:07
Do we need to reset the bitmap here?
reed1
2015/09/17 19:57:22
Done.
|
| return false; |
| } |
| - |
| - SkAutoTUnref<SkColorTable> ctable; |
| + |
| if (ctCount > 0) { |
| - SkASSERT(kIndex_8_SkColorType == info.colorType()); |
| - ctable.reset(new SkColorTable(ctStorage, ctCount)); |
| + SkASSERT(kIndex_8_SkColorType == bitmap->colorType()); |
| + // we and bitmap should be owners |
| + SkASSERT(!ctable->unique()); |
| + |
| + // Now we need to overwrite the ctable we built earlier, with the correct colors. |
| + // This does mean that we may have made the table too big, but that cannot be avoided |
| + // until we can change SkImageGenerator's API to return us the ctable *before* we have to |
| + // allocate space for all the pixels. |
| +// ctable->dangerous_overwriteColors(ctStorage, ctCount); |
|
tomhudson
2015/09/17 18:58:07
Resolve commented-out code before landing.
reed1
2015/09/17 19:57:23
Done.
|
| } else { |
| - SkASSERT(kIndex_8_SkColorType != info.colorType()); |
| + SkASSERT(kIndex_8_SkColorType != bitmap->colorType()); |
| + // we should be the only owner |
| + SkASSERT(ctable->unique()); |
| } |
| - |
| - return bitmap->installPixels(info, pixelStorage.detach(), rowBytes, ctable, |
| - release_malloc_proc, nullptr); |
| + return true; |
| } |
| #include "SkGraphics.h" |